source: sasmodels/sasmodels/models/core_multi_shell.py @ f7930be

core_shell_microgelscostrafo411magnetic_modelrelease_v0.94release_v0.95ticket-1257-vesicle-productticket_1156ticket_1265_superballticket_822_more_unit_tests
Last change on this file since f7930be was f7930be, checked in by butler, 8 years ago

roughed in core_multi_shell framework including doc strings.

  • Property mode set to 100644
File size: 6.6 KB
Line 
1r"""
2Definition
3----------
4
5This model is a trivial extension of the CoreShell function to a larger number
6of shells. The scattering length density profile for the default sld values
7(w/ 4 shells).
8
9.. figure:: img/core_multi_shell_sld_default_profile.jpg
10
11    SLD profile of the core_multi_shell object from the center of sphere out
12    for the default SLDs.*
13
14The 2D scattering intensity is the same as *P(q)* above, regardless of the
15orientation of the *q* vector which is defined as
16
17.. math::
18
19    q = \sqrt{q_x^2 + q_y^2}
20
21.. note:: **Be careful!** The SLDs and scale can be highly correlated. Hold as
22         many of these parameters fixed as possible.
23
24.. note:: The outer most radius (= *radius* + *thickness*) is used as the
25          effective radius for *S(Q)* when *P(Q)* \* *S(Q)* is applied.
26
27For information about polarised and magnetic scattering, click here_.
28
29Our model uses the form factor calculations implemented in a c-library provided
30by the NIST Center for Neutron Research (Kline, 2006).
31
32References
33----------
34See the CoreShellModel_ documentation.
35
36L A Feigin and D I Svergun,
37*Structure Analysis by Small-Angle X-Ray and Neutron Scattering*,
38Plenum Press, New York, 1987.
39
40**Author:** NIST IGOR/DANSE **on:** pre 2010
41
42**Last Modified by:** in progress **on:** March 20, 2016
43
44**Last Reviewed by:** in progress **on:** March 20, 2016
45"""
46
47
48
49from __future__ import division
50
51import numpy as np
52from numpy import inf, nan
53from math import fabs, exp, expm1
54
55name = "core_multi_shell"
56title = "This model provides the scattering from a spherical core with 1 to 4 \
57 concentric shell structures. The SLDs of the core and each shell are \
58 individually specified."
59
60description = """\
61Form factor for a core muti-shell (up to 4) sphere normalized by the volume.
62Each shell can have a unique thickness and sld.
63
64        background:background,
65        rad_core0: radius of sphere(core)
66        thick_shell#:the thickness of the shell#
67        sld_core0: the SLD of the sphere
68        sld_solv: the SLD of the solvent
69        sld_shell: the SLD of the shell#
70        A_shell#: the coefficient in the exponential function
71       
72       
73    scale: 1.0 if data is on absolute scale
74    volfraction: volume fraction of spheres
75    radius: the radius of the core
76    sld: the SLD of the core
77    thick_shelli: the thickness of the i'th shell from the core
78    sld_shelli: the SLD of the i'th shell from the core
79    sld_solvent: the SLD of the solvent
80    background: incoherent background
81
82"""
83
84category = "shape:sphere"
85
86
87#             ["name", "units", default, [lower, upper], "type","description"],
88parameters = [["volfraction", "", 0.05, [0,1],"",
89               "volume fraction of spheres"],
90              ["sld", "1e-6/Ang^2", 1.0, [-inf, inf], "",
91               "Core scattering length density"],
92              ["radius", "Ang", 200., [0, inf], "",
93               "Radius of the core"],
94              ["sld_solvent", "1e-6/Ang^2", 6.4, [-inf, inf], "",
95               "Solvent scattering length density"],
96              ["n", "", 1, [0, 10], "volume",
97               "number of shells"],
98              ["sld_shell[n]", "1e-6/Ang^2", 1.7, [-inf, inf], "",
99               "scattering length density of shell k"],
100              ["thick_shell[n]", "Ang", 40., [0, inf], "volume",
101               "Thickness of shell k"],
102              ]
103
104#source = ["lib/sph_j1c.c", "onion.c"]
105
106def Iq(q, *args, **kw):
107    return q
108
109def Iqxy(qx, *args, **kw):
110    return qx
111
112
113def shape(core_sld, core_radius, solvent_sld, n, in_sld, out_sld, thickness, A):
114    """
115    SLD profile
116   
117    :return: (r, beta) where r is a list of radius of the transition points\
118      and beta is a list of the corresponding SLD values.
119
120    """
121#        r = []
122#        beta = []
123#        # for core at r=0
124#        r.append(0)
125#        beta.append(self.params['sld_core0'])
126#        # for core at r=rad_core
127#        r.append(self.params['rad_core0'])
128#        beta.append(self.params['sld_core0'])
129#
130#        # for shells
131#        for n in range(1, self.n_shells+1):
132#            # Left side of each shells
133#            r0 = r[len(r)-1]
134#            r.append(r0)
135#            exec "beta.append(self.params['sld_shell%s'% str(n)])"
136#
137#            # Right side of each shells
138#            exec "r0 += self.params['thick_shell%s'% str(n)]"
139#            r.append(r0)
140#            exec "beta.append(self.params['sld_shell%s'% str(n)])"
141#
142#        # for solvent
143#        r0 = r[len(r)-1]           
144#        r.append(r0)
145#        beta.append(self.params['sld_solv'])
146#        r_solv = 5*r0/4
147#        r.append(r_solv)
148#        beta.append(self.params['sld_solv'])
149#
150#        return r, beta
151# above is directly from old code -- below is alotered from Woitek's first
152# cut an the onion.  Seems like we should be consistant?
153
154    total_radius = 1.25*(sum(thickness[:n]) + core_radius + 1)
155    dr = total_radius/400  # 400 points for a smooth plot
156
157    r = []
158    beta = []
159
160    # add in the core
161    r.append(0)
162    beta.append(sld)
163    r.append(radius)
164    beta.append(sld)
165
166    # add in the shells
167    for k in range(n):
168        # Left side of each shells
169        r0 = r[-1]
170        r.append(r0)
171        beta.append(sld_shell[k])
172        r.append(r0 + thickness[k])
173        beta.append(sld_shell[k])
174   # add in the solvent
175    r.append(r[-1])
176    beta.append(solvent_sld)
177    r.append(total_radius)
178    beta.append(solvent_sld)
179
180    return np.asarray(r), np.asarray(beta)
181
182def ER(radius, n, thick_shell):
183    return np.sum(thick_shell[:n], axis=0) + core_radius
184
185def VR(radius, n, thick_shell):
186    return 1.0
187
188parameters = [["volfraction", "", 0.05, [0,1],"",
189               "volume fraction of spheres"],
190              ["sld", "1e-6/Ang^2", 1.0, [-inf, inf], "",
191               "Core scattering length density"],
192              ["radius", "Ang", 200., [0, inf], "",
193               "Radius of the core"],
194              ["sld_solvent", "1e-6/Ang^2", 6.4, [-inf, inf], "",
195               "Solvent scattering length density"],
196              ["n", "", 1, [0, 10], "volume",
197               "number of shells"],
198              ["sld_shell[n]", "1e-6/Ang^2", 1.7, [-inf, inf], "",
199               "scattering length density of shell k"],
200              ["thick_shell[n]", "Ang", 40., [0, inf], "volume",
201               "Thickness of shell k"],
202               ]
203
204demo = dict(volfraction = 1.0,
205            sld = 6.4,
206            radius = 60,
207            sld_solvent = 6.4,
208            n = 1,
209            sld_shell = [2.0],
210            thick_shell = [10])
211
212oldname = "CoreMultiShellModel"
213oldpars = dict(
214    sld="sld_core0",
215    radius="rad_core0",
216    sld_solvent="sld_solv",
217    n="n_shells",
218    sld_shell="sld_in_shell",
219    thick_shell="thick_shell",
220    # func_shell is always 2 in the user interface, so isn't included
221    )
Note: See TracBrowser for help on using the repository browser.