source: sasmodels/sasmodels/models/core_multi_shell.py @ 4e28511

core_shell_microgelsmagnetic_modelticket-1257-vesicle-productticket_1156ticket_1265_superballticket_822_more_unit_tests
Last change on this file since 4e28511 was b297ba9, checked in by Paul Kienzle <pkienzle@…>, 5 years ago

lint

  • Property mode set to 100644
File size: 4.8 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 $\vec 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, see
28the :ref:`magnetism` documentation.
29
30Our model uses the form factor calculations implemented in a c-library provided
31by the NIST Center for Neutron Research (Kline, 2006) [#kline]_.
32
33References
34----------
35
36.. [#] See the :ref:`core-shell-sphere` model documentation.
37.. [#kline] S R Kline, *J Appl. Cryst.*, 39 (2006) 895
38.. [#] L A Feigin and D I Svergun, *Structure Analysis by Small-Angle X-Ray and
39   Neutron Scattering*, Plenum Press, New York, 1987.
40
41Authorship and Verification
42----------------------------
43
44* **Author:** NIST IGOR/DANSE **Date:** pre 2010
45* **Last Modified by:** Paul Kienzle **Date:** September 12, 2016
46* **Last Reviewed by:** Paul Kienzle **Date:** September 12, 2016
47"""
48from __future__ import division
49
50import numpy as np
51from numpy import inf
52
53name = "core_multi_shell"
54title = "This model provides the scattering from a spherical core with 1 to 4 \
55 concentric shell structures. The SLDs of the core and each shell are \
56 individually specified."
57
58description = """\
59Form factor for a core muti-shell (up to 4) sphere normalized by the volume.
60Each shell can have a unique thickness and sld.
61
62        background:background,
63        rad_core0: radius of sphere(core)
64        thick_shell#:the thickness of the shell#
65        sld_core0: the SLD of the sphere
66        sld_solv: the SLD of the solvent
67        sld_shell: the SLD of the shell#
68        A_shell#: the coefficient in the exponential function
69
70
71    scale: 1.0 if data is on absolute scale
72    volfraction: volume fraction of spheres
73    radius: the radius of the core
74    sld: the SLD of the core
75    thick_shelli: the thickness of the i'th shell from the core
76    sld_shelli: the SLD of the i'th shell from the core
77    sld_solvent: the SLD of the solvent
78    background: incoherent background
79
80"""
81
82category = "shape:sphere"
83
84
85#             ["name", "units", default, [lower, upper], "type","description"],
86parameters = [["sld_core", "1e-6/Ang^2", 1.0, [-inf, inf], "sld",
87               "Core scattering length density"],
88              ["radius", "Ang", 200., [0, inf], "volume",
89               "Radius of the core"],
90              ["sld_solvent", "1e-6/Ang^2", 6.4, [-inf, inf], "sld",
91               "Solvent scattering length density"],
92              ["n", "", 1, [0, 10], "volume",
93               "number of shells"],
94              ["sld[n]", "1e-6/Ang^2", 1.7, [-inf, inf], "sld",
95               "scattering length density of shell k"],
96              ["thickness[n]", "Ang", 40., [0, inf], "volume",
97               "Thickness of shell k"],
98             ]
99
100source = ["lib/sas_3j1x_x.c", "core_multi_shell.c"]
101have_Fq = True
102effective_radius_type = ["outer radius", "core radius"]
103
104def random():
105    """Return a random parameter set for the model."""
106    num_shells = np.minimum(np.random.poisson(3)+1, 10)
107    total_radius = 10**np.random.uniform(1.7, 4)
108    thickness = np.random.exponential(size=num_shells+1)
109    thickness *= total_radius/np.sum(thickness)
110    pars = dict(
111        #background=0,
112        n=num_shells,
113        radius=thickness[0],
114    )
115    for k, v in enumerate(thickness[1:]):
116        pars['thickness%d'%(k+1)] = v
117    return pars
118
119def profile(sld_core, radius, sld_solvent, n, sld, thickness):
120    """
121    Returns the SLD profile *r* (Ang), and *rho* (1e-6/Ang^2).
122    """
123    n = int(n+0.5)
124    z = []
125    rho = []
126
127    # add in the core
128    z.append(0)
129    rho.append(sld_core)
130    z.append(radius)
131    rho.append(sld_core)
132
133    # add in the shells
134    for k in range(int(n)):
135        # Left side of each shells
136        z.append(z[-1])
137        rho.append(sld[k])
138        z.append(z[-1] + thickness[k])
139        rho.append(sld[k])
140    # add in the solvent
141    z.append(z[-1])
142    rho.append(sld_solvent)
143    z.append(z[-1]*1.25)
144    rho.append(sld_solvent)
145
146    return np.asarray(z), np.asarray(rho)
147
148demo = dict(sld_core=6.4,
149            radius=60,
150            sld_solvent=6.4,
151            n=2,
152            sld=[2.0, 3.0],
153            thickness=20,
154            thickness1_pd=0.3,
155            thickness2_pd=0.3,
156            thickness1_pd_n=10,
157            thickness2_pd_n=10,
158           )
Note: See TracBrowser for help on using the repository browser.