source: sasmodels/sasmodels/models/stacked_disks.py @ eda8b30

core_shell_microgelsmagnetic_modelticket-1257-vesicle-productticket_1156ticket_1265_superballticket_822_more_unit_tests
Last change on this file since eda8b30 was eda8b30, checked in by richardh, 6 years ago

further changes to model docs for orientation calcs

  • Property mode set to 100644
File size: 10.6 KB
Line 
1r"""
2Definition
3----------
4
5This model provides the form factor, $P(q)$, for stacked discs (tactoids)
6with a core/layer structure which is constructed itself as $P(q) S(Q)$
7multiplying a $P(q)$ for individual core/layer disks by a structure factor
8$S(q)$ proposed by Kratky and Porod in 1949\ [#CIT1949]_ assuming the next
9neighbor distance (d-spacing) in the stack of parallel discs obeys a Gaussian
10distribution. As such the normalization of this "composite" form factor is
11relative to the individual disk volume, not the volume of the stack of disks.
12This model is appropriate for example for non non exfoliated clay particles such
13as Laponite.
14
15.. figure:: img/stacked_disks_geometry.png
16
17   Geometry of a single core/layer disk
18
19The scattered intensity $I(q)$ is calculated as
20
21.. math::
22
23    I(q) = N\int_{0}^{\pi /2}\left[ \Delta \rho_t
24    \left( V_t f_t(q,\alpha) - V_c f_c(q,\alpha)\right) + \Delta
25    \rho_c V_c f_c(q,\alpha)\right]^2 S(q,\alpha)\sin{\alpha}\ d\alpha
26    + \text{background}
27
28where the contrast
29
30.. math::
31
32    \Delta \rho_i = \rho_i - \rho_\text{solvent}
33
34and $N$ is the number of individual (single) discs per unit volume, $\alpha$ is
35the angle between the axis of the disc and $q$, and $V_t$ and $V_c$ are the
36total volume and the core volume of a single disc, respectively, and
37
38.. math::
39
40    f_t(q,\alpha) =
41    \left(\frac{\sin(q(d+h)\cos{\alpha})}{q(d+h)\cos{\alpha}}\right)
42    \left(\frac{2J_1(qR\sin{\alpha})}{qR\sin{\alpha}} \right)
43
44    f_c(q,\alpha) =
45    \left(\frac{\sin(qh)\cos{\alpha})}{qh\cos{\alpha}}\right)
46    \left(\frac{2J_1(qR\sin{\alpha})}{qR\sin{\alpha}}\right)
47
48where $d$ = thickness of the layer (*thick_layer*),
49$2h$ = core thickness (*thick_core*), and $R$ = radius of the disc (*radius*).
50
51.. math::
52
53    S(q,\alpha) = 1 + \frac{1}{2}\sum_{k=1}^n(n-k)\cos{(kDq\cos{\alpha})}
54    \exp\left[ -k(q)^2(D\cos{\alpha}~\sigma_d)^2/2\right]
55
56where $n$ is the total number of the disc stacked (*n_stacking*),
57$D = 2(d+h)$ is the next neighbor center-to-center distance (d-spacing),
58and $\sigma_d$ = the Gaussian standard deviation of the d-spacing (*sigma_d*).
59Note that $D\cos(\alpha)$ is the component of $D$ parallel to $q$ and the last
60term in the equation above is effectively a Debye-Waller factor term.
61
62.. note::
63
64    1. Each assembly in the stack is layer/core/layer, so the spacing of the
65    cores is core plus two layers. The 2nd virial coefficient of the cylinder
66    is calculated based on the *radius* and *length*
67    = *n_stacking* * (*thick_core* + 2 * *thick_layer*)
68    values, and used as the effective radius for $S(Q)$ when $P(Q) * S(Q)$
69    is applied.
70
71    2. the resolution smearing calculation uses 76 Gaussian quadrature points
72    to properly smear the model since the function is HIGHLY oscillatory,
73    especially around the q-values that correspond to the repeat distance of
74    the layers.
75
762d scattering from oriented stacks is calculated in the same way as for cylinders,
77for further details of the calculation and angular dispersions see :ref:`orientation` .
78
79.. figure:: img/cylinder_angle_definition.png
80
81    Angles $\theta$ and $\phi$ orient the stack of discs relative
82    to the beam line coordinates, where the beam is along the $z$ axis. Rotation $\theta$, initially
83    in the $xz$ plane, is carried out first, then rotation $\phi$ about the $z$ axis. Orientation distributions
84    are described as rotations about two perpendicular axes $\delta_1$ and $\delta_2$
85    in the frame of the cylinder itself, which when $\theta = \phi = 0$ are parallel to the $Y$ and $X$ axes.
86
87
88Our model is derived from the form factor calculations implemented in a
89c-library provided by the NIST Center for Neutron Research\ [#CIT_Kline]_
90
91References
92----------
93
94.. [#CIT1949] O Kratky and G Porod, *J. Colloid Science*, 4, (1949) 35
95.. [#CIT_Kline] S R Kline, *J Appl. Cryst.*, 39 (2006) 895
96.. [#] J S Higgins and H C Benoit, *Polymers and Neutron Scattering*,
97   Clarendon, Oxford, 1994
98.. [#] A Guinier and G Fournet, *Small-Angle Scattering of X-Rays*,
99   John Wiley and Sons, New York, 1955
100
101Authorship and Verification
102----------------------------
103
104* **Author:** NIST IGOR/DANSE **Date:** pre 2010
105* **Last Modified by:** Paul Butler and Paul Kienzle **on:** November 26, 2016
106* **Last Reviewed by:** Paul Butler and Paul Kienzle **on:** November 26, 2016
107"""
108
109from numpy import inf, sin, cos, pi
110
111name = "stacked_disks"
112title = "Form factor for a stacked set of non exfoliated core/shell disks"
113description = """\
114    One layer of disk consists of a core, a top layer, and a bottom layer.
115    radius =  the radius of the disk
116    thick_core = thickness of the core
117    thick_layer = thickness of a layer
118    sld_core = the SLD of the core
119    sld_layer = the SLD of the layers
120    n_stacking = the number of the disks
121    sigma_d =  Gaussian STD of d-spacing
122    sld_solvent = the SLD of the solvent
123    """
124category = "shape:cylinder"
125
126# pylint: disable=bad-whitespace, line-too-long
127#   ["name", "units", default, [lower, upper], "type","description"],
128parameters = [
129    ["thick_core",  "Ang",        10.0, [0, inf],    "volume",      "Thickness of the core disk"],
130    ["thick_layer", "Ang",        10.0, [0, inf],    "volume",      "Thickness of layer each side of core"],
131    ["radius",      "Ang",        15.0, [0, inf],    "volume",      "Radius of the stacked disk"],
132    ["n_stacking",  "",            1.0, [1, inf],    "volume",      "Number of stacked layer/core/layer disks"],
133    ["sigma_d",     "Ang",         0,   [0, inf],    "",            "Sigma of nearest neighbor spacing"],
134    ["sld_core",    "1e-6/Ang^2",  4,   [-inf, inf], "sld",         "Core scattering length density"],
135    ["sld_layer",   "1e-6/Ang^2",  0.0, [-inf, inf], "sld",         "Layer scattering length density"],
136    ["sld_solvent", "1e-6/Ang^2",  5.0, [-inf, inf], "sld",         "Solvent scattering length density"],
137    ["theta",       "degrees",     0,   [-360, 360], "orientation", "Orientation of the stacked disk axis w/respect incoming beam"],
138    ["phi",         "degrees",     0,   [-360, 360], "orientation", "Rotation about beam"],
139    ]
140# pylint: enable=bad-whitespace, line-too-long
141
142source = ["lib/polevl.c", "lib/sas_J1.c", "lib/gauss76.c", "stacked_disks.c"]
143
144def random():
145    import numpy as np
146    radius = 10**np.random.uniform(1, 4.7)
147    total_stack = 10**np.random.uniform(1, 4.7)
148    n_stacking = int(10**np.random.uniform(0, np.log10(total_stack)-1) + 0.5)
149    d = total_stack/n_stacking
150    thick_core = np.random.uniform(0, d-2)  # at least 1 A for each layer
151    thick_layer = (d - thick_core)/2
152    # Let polydispersity peak around 15%; 95% < 0.4; max=100%
153    sigma_d = d * np.random.beta(1.5, 7)
154    pars = dict(
155        thick_core=thick_core,
156        thick_layer=thick_layer,
157        radius=radius,
158        n_stacking=n_stacking,
159        sigma_d=sigma_d,
160    )
161    return pars
162
163demo = dict(background=0.001,
164            scale=0.01,
165            thick_core=10.0,
166            thick_layer=10.0,
167            radius=15.0,
168            n_stacking=1,
169            sigma_d=0,
170            sld_core=4,
171            sld_layer=0.0,
172            sld_solvent=5.0,
173            theta=90,
174            phi=0)
175# After redefinition of spherical coordinates -
176# tests had in old coords theta=0, phi=0; new coords theta=90, phi=0
177q = 0.1
178# april 6 2017, rkh added a 2d unit test, assume correct!
179qx = q*cos(pi/6.0)
180qy = q*sin(pi/6.0)
181# Accuracy tests based on content in test/utest_extra_models.py.
182# Added 2 tests with n_stacked = 5 using SasView 3.1.2 - PDB;
183# for which alas q=0.001 values seem closer to n_stacked=1 not 5,
184# changed assuming my 4.1 code OK, RKH
185tests = [
186    [{'thick_core': 10.0,
187      'thick_layer': 15.0,
188      'radius': 3000.0,
189      'n_stacking': 1.0,
190      'sigma_d': 0.0,
191      'sld_core': 4.0,
192      'sld_layer': -0.4,
193      'sld_solvent': 5.0,
194      'theta': 90.0,
195      'phi': 0.0,
196      'scale': 0.01,
197      'background': 0.001,
198     }, 0.001, 5075.12],
199    [{'thick_core': 10.0,
200      'thick_layer': 15.0,
201      'radius': 3000.0,
202      'n_stacking': 5,
203      'sigma_d': 0.0,
204      'sld_core': 4.0,
205      'sld_layer': -0.4,
206      'sld_solvent': 5.0,
207      'theta': 90.0,
208      'phi': 0.0,
209      'scale': 0.01,
210      'background': 0.001,
211#     }, 0.001, 5065.12793824],    n_stacking=1 not 5 ? slight change in value here 11jan2017, check other cpu types
212#     }, 0.001, 5075.11570493],
213     }, 0.001, 25325.635693],
214    [{'thick_core': 10.0,
215      'thick_layer': 15.0,
216      'radius': 100.0,
217      'n_stacking': 5,
218      'sigma_d': 0.0,
219      'sld_core': 4.0,
220      'sld_layer': -0.4,
221      'sld_solvent': 5.0,
222      'theta': 90.0,
223      'phi': 20.0,
224      'scale': 0.01,
225      'background': 0.001,
226     }, (qx, qy), 0.0491167089952],
227    [{'thick_core': 10.0,
228      'thick_layer': 15.0,
229      'radius': 3000.0,
230      'n_stacking': 5,
231      'sigma_d': 0.0,
232      'sld_core': 4.0,
233      'sld_layer': -0.4,
234      'sld_solvent': 5.0,
235      'theta': 90.0,
236      'phi': 0.0,
237      'scale': 0.01,
238      'background': 0.001,
239#     }, 0.164, 0.0127673597265],    n_stacking=1 not 5 ?  slight change in value here 11jan2017, check other cpu types
240#     }, 0.164, 0.01480812968],
241     }, 0.164, 0.0598367986509],
242
243    [{'thick_core': 10.0,
244      'thick_layer': 15.0,
245      'radius': 3000.0,
246      'n_stacking': 1.0,
247      'sigma_d': 0.0,
248      'sld_core': 4.0,
249      'sld_layer': -0.4,
250      'sld_solvent': 5.0,
251      'theta': 90.0,
252      'phi': 0.0,
253      'scale': 0.01,
254      'background': 0.001,
255# second test here was at q=90, changed it to q=5, note I(q) is then just value of flat background
256     }, [0.001, 5.0], [5075.12, 0.001]],
257
258    [{'thick_core': 10.0,
259      'thick_layer': 15.0,
260      'radius': 3000.0,
261      'n_stacking': 1.0,
262      'sigma_d': 0.0,
263      'sld_core': 4.0,
264      'sld_layer': -0.4,
265      'sld_solvent': 5.0,
266      'theta': 90.0,
267      'phi': 0.0,
268      'scale': 0.01,
269      'background': 0.001,
270     }, ([0.4, 0.5]), [0.00105074, 0.00121761]],
271#    [{'thick_core': 10.0,
272#      'thick_layer': 15.0,
273#      'radius': 3000.0,
274#      'n_stacking': 1.0,
275#      'sigma_d': 0.0,
276#      'sld_core': 4.0,
277#      'sld_layer': -0.4,
278#      'sld_solvent': 5.0,
279#      'theta': 90.0,
280#      'phi': 20.0,
281#      'scale': 0.01,
282#      'background': 0.001,
283# 2017-05-18 PAK temporarily suppress output of qx,qy test; j1 is not accurate for large qr
284#     }, (qx, qy), 0.0341738733124],
285#     }, (qx, qy), None],
286
287    [{'thick_core': 10.0,
288      'thick_layer': 15.0,
289      'radius': 3000.0,
290      'n_stacking': 1.0,
291      'sigma_d': 0.0,
292      'sld_core': 4.0,
293      'sld_layer': -0.4,
294      'sld_solvent': 5.0,
295      'theta': 90.0,
296      'phi': 0.0,
297      'scale': 0.01,
298      'background': 0.001,
299     }, ([1.3, 1.57]), [0.0010039, 0.0010038]],
300    ]
301# 11Jan2017   RKH checking unit test again, note they are all 1D, no 2D
Note: See TracBrowser for help on using the repository browser.