File: stacked_disks.py

package info (click to toggle)
mccode 3.5.19%2Bds5-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,113,256 kB
  • sloc: ansic: 40,697; python: 25,137; yacc: 8,438; sh: 5,405; javascript: 4,596; lex: 1,632; cpp: 742; perl: 296; lisp: 273; makefile: 226; fortran: 132
file content (302 lines) | stat: -rw-r--r-- 10,770 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
r"""
Definition
----------

This model provides the form factor, $P(q)$, for stacked discs (tactoids)
with a core/layer structure which is constructed itself as $P(q) S(Q)$
multiplying a $P(q)$ for individual core/layer disks by a structure factor
$S(q)$ proposed by Kratky and Porod in 1949\ [#Kratky1949]_ assuming the next
neighbor distance (d-spacing) in the stack of parallel discs obeys a Gaussian
distribution. As such the normalization of this "composite" form factor is
relative to the individual disk volume, not the volume of the stack of disks.
This model is appropriate for example for non non exfoliated clay particles
such as Laponite.

.. figure:: img/stacked_disks_geometry.png

   Geometry of a single core/layer disk

The scattered intensity $I(q)$ is calculated as

.. math::

    I(q) = N\int_{0}^{\pi /2}\left[ \Delta \rho_t
    \left( V_t f_t(q,\alpha) - V_c f_c(q,\alpha)\right) + \Delta
    \rho_c V_c f_c(q,\alpha)\right]^2 S(q,\alpha)\sin{\alpha}\ d\alpha
    + \text{background}

where the contrast

.. math::

    \Delta \rho_i = \rho_i - \rho_\text{solvent}

and $N$ is the number of individual (single) discs per unit volume, $\alpha$
is the angle between the axis of the disc and $q$, and $V_t$ and $V_c$ are the
total volume and the core volume of a single disc, respectively, and

.. math::

    f_t(q,\alpha) =
    \left(\frac{\sin(q(d+h)\cos{\alpha})}{q(d+h)\cos{\alpha}}\right)
    \left(\frac{2J_1(qR\sin{\alpha})}{qR\sin{\alpha}} \right)

    f_c(q,\alpha) =
    \left(\frac{\sin(qh)\cos{\alpha})}{qh\cos{\alpha}}\right)
    \left(\frac{2J_1(qR\sin{\alpha})}{qR\sin{\alpha}}\right)

where $d$ = thickness of the layer (*thick_layer*),
$2h$ = core thickness (*thick_core*), and $R$ = radius of the disc (*radius*).

.. math::

    S(q,\alpha) = 1 + \frac{1}{2}\sum_{k=1}^n(n-k)\cos{(kDq\cos{\alpha})}
    \exp\left[ -k(q)^2(D\cos{\alpha}~\sigma_d)^2/2\right]

where $n$ is the total number of the disc stacked (*n_stacking*),
$D = 2(d+h)$ is the next neighbor center-to-center distance (d-spacing),
and $\sigma_d$ = the Gaussian standard deviation of the d-spacing (*sigma_d*).
Note that $D\cos(\alpha)$ is the component of $D$ parallel to $q$ and the last
term in the equation above is effectively a Debye-Waller factor term.

.. note::

    1. Each assembly in the stack is layer/core/layer, so the spacing of the
    cores is core plus two layers. The 2nd virial coefficient of the cylinder
    is calculated based on the *radius* and *length*
    = *n_stacking* * (*thick_core* + 2 * *thick_layer*)
    values, and used as the effective radius for $S(Q)$ when $P(Q) * S(Q)$
    is applied.

    2. the resolution smearing calculation uses 76 Gaussian quadrature points
    to properly smear the model since the function is HIGHLY oscillatory,
    especially around the q-values that correspond to the repeat distance of
    the layers.

2d scattering from oriented stacks is calculated in the same way as for
cylinders, for further details of the calculation and angular dispersions
see :ref:`orientation`.

.. figure:: img/cylinder_angle_definition.png

    Angles $\theta$ and $\phi$ orient the stack of discs relative
    to the beam line coordinates, where the beam is along the $z$ axis.
    Rotation $\theta$, initially in the $xz$ plane, is carried out first,
    then rotation $\phi$ about the $z$ axis. Orientation distributions are
    described as rotations about two perpendicular axes $\delta_1$ and
    $\delta_2$ in the frame of the cylinder itself, which when
    $\theta = \phi = 0$ are parallel to the $Y$ and $X$ axes.


Our model is derived from the form factor calculations implemented in a
C-library provided by the NIST Center for Neutron Research\ [#Kline2006]_

References
----------

See also Higgins and Benoit [#Higgins1994]_ and Guinier and
Fournet [#Guinier1955]_.

.. [#Kratky1949] O Kratky and G Porod, *J. Colloid Science*, 4, (1949) 35
.. [#Kline2006] S R Kline, *J Appl. Cryst.*, 39 (2006) 895
.. [#Higgins1994] J S Higgins and H C Benoit, *Polymers and Neutron Scattering*,
   Clarendon, Oxford, 1994
.. [#Guinier1955] A Guinier and G Fournet, *Small-Angle Scattering of X-Rays*,
   John Wiley and Sons, New York, 1955

Authorship and Verification
----------------------------

* **Author:** NIST IGOR/DANSE **Date:** pre 2010
* **Last Modified by:** Paul Butler and Paul Kienzle **Date:** November 26, 2016
* **Last Reviewed by:** Paul Butler and Paul Kienzle **Date:** November 26, 2016
"""

import numpy as np
from numpy import inf, sin, cos, pi

name = "stacked_disks"
title = "Form factor for a stacked set of non exfoliated core/shell disks"
description = """\
    One layer of disk consists of a core, a top layer, and a bottom layer.
    radius =  the radius of the disk
    thick_core = thickness of the core
    thick_layer = thickness of a layer
    sld_core = the SLD of the core
    sld_layer = the SLD of the layers
    n_stacking = the number of the disks
    sigma_d =  Gaussian STD of d-spacing
    sld_solvent = the SLD of the solvent
    """
category = "shape:cylinder"

# pylint: disable=bad-whitespace, line-too-long
#   ["name", "units", default, [lower, upper], "type","description"],
parameters = [
    ["thick_core",  "Ang",        10.0, [0, inf],    "volume",      "Thickness of the core disk"],
    ["thick_layer", "Ang",        10.0, [0, inf],    "volume",      "Thickness of layer each side of core"],
    ["radius",      "Ang",        15.0, [0, inf],    "volume",      "Radius of the stacked disk"],
    ["n_stacking",  "",            1.0, [1, inf],    "volume",      "Number of stacked layer/core/layer disks"],
    ["sigma_d",     "Ang",         0,   [0, inf],    "",            "Sigma of nearest neighbor spacing"],
    ["sld_core",    "1e-6/Ang^2",  4,   [-inf, inf], "sld",         "Core scattering length density"],
    ["sld_layer",   "1e-6/Ang^2",  0.0, [-inf, inf], "sld",         "Layer scattering length density"],
    ["sld_solvent", "1e-6/Ang^2",  5.0, [-inf, inf], "sld",         "Solvent scattering length density"],
    ["theta",       "degrees",     0,   [-360, 360], "orientation", "Orientation of the stacked disk axis w/respect incoming beam"],
    ["phi",         "degrees",     0,   [-360, 360], "orientation", "Rotation about beam"],
    ]
# pylint: enable=bad-whitespace, line-too-long

source = ["lib/polevl.c", "lib/sas_J1.c", "lib/gauss76.c", "stacked_disks.c"]

def random():
    """Return a random parameter set for the model."""
    radius = 10**np.random.uniform(1, 4.7)
    total_stack = 10**np.random.uniform(1, 4.7)
    n_stacking = int(10**np.random.uniform(0, np.log10(total_stack)-1) + 0.5)
    d = total_stack/n_stacking
    thick_core = np.random.uniform(0, d-2)  # at least 1 A for each layer
    thick_layer = (d - thick_core)/2
    # Let polydispersity peak around 15%; 95% < 0.4; max=100%
    sigma_d = d * np.random.beta(1.5, 7)
    pars = dict(
        thick_core=thick_core,
        thick_layer=thick_layer,
        radius=radius,
        n_stacking=n_stacking,
        sigma_d=sigma_d,
    )
    return pars

# After redefinition of spherical coordinates -
# tests had in old coords theta=0, phi=0; new coords theta=90, phi=0
q = 0.1
# april 6 2017, rkh added a 2d unit test, assume correct!
qx = q*cos(pi/6.0)
qy = q*sin(pi/6.0)
# Accuracy tests based on content in test/utest_extra_models.py.
# Added 2 tests with n_stacked = 5 using SasView 3.1.2 - PDB;
# for which alas q=0.001 values seem closer to n_stacked=1 not 5,
# changed assuming my 4.1 code OK, RKH
tests = [
    [{'thick_core': 10.0,
      'thick_layer': 15.0,
      'radius': 3000.0,
      'n_stacking': 1.0,
      'sigma_d': 0.0,
      'sld_core': 4.0,
      'sld_layer': -0.4,
      'sld_solvent': 5.0,
      'theta': 90.0,
      'phi': 0.0,
      'scale': 0.01,
      'background': 0.001,
     }, 0.001, 5075.12],
    [{'thick_core': 10.0,
      'thick_layer': 15.0,
      'radius': 3000.0,
      'n_stacking': 5,
      'sigma_d': 0.0,
      'sld_core': 4.0,
      'sld_layer': -0.4,
      'sld_solvent': 5.0,
      'theta': 90.0,
      'phi': 0.0,
      'scale': 0.01,
      'background': 0.001,
      # n_stacking=1 not 5 ? slight change in value here 11jan2017,
      # check other cpu types
      #}, 0.001, 5065.12793824],
      #}, 0.001, 5075.11570493],
     }, 0.001, 25325.635693],
    [{'thick_core': 10.0,
      'thick_layer': 15.0,
      'radius': 100.0,
      'n_stacking': 5,
      'sigma_d': 0.0,
      'sld_core': 4.0,
      'sld_layer': -0.4,
      'sld_solvent': 5.0,
      'theta': 90.0,
      'phi': 20.0,
      'scale': 0.01,
      'background': 0.001,
     }, (qx, qy), 0.0491167089952],
    [{'thick_core': 10.0,
      'thick_layer': 15.0,
      'radius': 3000.0,
      'n_stacking': 5,
      'sigma_d': 0.0,
      'sld_core': 4.0,
      'sld_layer': -0.4,
      'sld_solvent': 5.0,
      'theta': 90.0,
      'phi': 0.0,
      'scale': 0.01,
      'background': 0.001,
      # n_stacking=1 not 5 ?  slight change in value here 11jan2017,
      # check other cpu types
      #}, 0.164, 0.0127673597265],
      #}, 0.164, 0.01480812968],
     }, 0.164, 0.0598367986509],

    [{'thick_core': 10.0,
      'thick_layer': 15.0,
      'radius': 3000.0,
      'n_stacking': 1.0,
      'sigma_d': 0.0,
      'sld_core': 4.0,
      'sld_layer': -0.4,
      'sld_solvent': 5.0,
      'theta': 90.0,
      'phi': 0.0,
      'scale': 0.01,
      'background': 0.001,
      # second test here was at q=90, changed it to q=5,
      # note I(q) is then just value of flat background
     }, [0.001, 5.0], [5075.12, 0.001]],

    [{'thick_core': 10.0,
      'thick_layer': 15.0,
      'radius': 3000.0,
      'n_stacking': 1.0,
      'sigma_d': 0.0,
      'sld_core': 4.0,
      'sld_layer': -0.4,
      'sld_solvent': 5.0,
      'theta': 90.0,
      'phi': 0.0,
      'scale': 0.01,
      'background': 0.001,
     }, ([0.4, 0.5]), [0.00105074, 0.00121761]],
    #[{'thick_core': 10.0,
    #  'thick_layer': 15.0,
    #  'radius': 3000.0,
    #  'n_stacking': 1.0,
    #  'sigma_d': 0.0,
    #  'sld_core': 4.0,
    #  'sld_layer': -0.4,
    #  'sld_solvent': 5.0,
    #  'theta': 90.0,
    #  'phi': 20.0,
    #  'scale': 0.01,
    #  'background': 0.001,
    # 2017-05-18 PAK temporarily suppress output of qx,qy test; j1 is
    #     not accurate for large qr
    # }, (qx, qy), 0.0341738733124],
    # }, (qx, qy), None],

    [{'thick_core': 10.0,
      'thick_layer': 15.0,
      'radius': 3000.0,
      'n_stacking': 1.0,
      'sigma_d': 0.0,
      'sld_core': 4.0,
      'sld_layer': -0.4,
      'sld_solvent': 5.0,
      'theta': 90.0,
      'phi': 0.0,
      'scale': 0.01,
      'background': 0.001,
     }, ([1.3, 1.57]), [0.0010039, 0.0010038]],
    ]
# 11Jan2017   RKH checking unit test again, note they are all 1D, no 2D