source: sasmodels/sasmodels/models/spherical_sld.py @ 8ad9619

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

Spherical SLD model added

  • Property mode set to 100644
File size: 18.0 KB
Line 
1r"""
2This model calculates an empirical functional form for SAS data using SpericalSLD profile
3
4Similarly to the OnionExpShellModel, this model provides the form factor, P(q), for a multi-shell sphere,
5where the interface between the each neighboring shells can be described by one of a number of functions
6including error, power-law, and exponential functions. This model is to calculate the scattering intensity
7by building a continuous custom SLD profile against the radius of the particle. The SLD profile is composed
8of a flat core, a flat solvent, a number (up to 9 ) flat shells, and the interfacial layers between
9the adjacent flat shells (or core, and solvent) (see below).
10
11.. figure:: img/spherical_sld_profile.gif
12
13    Exemplary SLD profile
14
15Unlike the OnionExpShellModel (using an analytical integration),
16the interfacial layers here are sub-divided and numerically integrated assuming each of the sub-layers are described
17by a line function. The number of the sub-layer can be given by users by setting the integer values of npts_inter.
18The form factor is normalized by the total volume of the sphere.
19
20Definition
21----------
22
23The form factor $P(q)$ in 1D is calculated by:
24
25.. math::
26
27    P(q) = \frac{f^2}{V_\text{particle}} \text{ where }
28    f = f_\text{core} + \sum_{\text{inter}_i=0}^N f_{\text{inter}_i} +
29    \sum_{\text{flat}_i=0}^N f_{\text{flat}_i} +f_\text{solvent}
30
31For a spherically symmetric particle with a particle density $\rho_x(r)$ the sld function can be defined as:
32
33.. math::
34
35    f_x = 4 \pi \int_{0}^{\infty} \rho_x(r)  \frac{\sin(qr)} {qr^2} r^2 dr
36
37
38so that individual terms can be calcualted as follows:
39
40.. math::
41    f_\text{core} = 4 \pi \int_{0}^{r_\text{core}} \rho_\text{core} \frac{\sin(qr)} {qr} r^2 dr =
42    3 \rho_\text{core} V(r_\text{core})
43    \Big[ \frac{\sin(qr_\text{core}) - qr_\text{core} \cos(qr_\text{core})} {qr_\text{core}^3} \Big]
44
45    f_{\text{inter}_i} = 4 \pi \int_{\Delta t_{ \text{inter}_i } } \rho_{ \text{inter}_i } \frac{\sin(qr)} {qr} r^2 dr
46
47    f_{\text{shell}_i} = 4 \pi \int_{\Delta t_{ \text{inter}_i } } \rho_{ \text{flat}_i } \frac{\sin(qr)} {qr} r^2 dr =
48    3 \rho_{ \text{flat}_i } V ( r_{ \text{inter}_i } + \Delta t_{ \text{inter}_i } )
49    \Big[ \frac{\sin(qr_{\text{inter}_i} + \Delta t_{ \text{inter}_i } ) - q (r_{\text{inter}_i} +
50    \Delta t_{ \text{inter}_i }) \cos(q( r_{\text{inter}_i} + \Delta t_{ \text{inter}_i } ) ) }
51    {q ( r_{\text{inter}_i} + \Delta t_{ \text{inter}_i } )^3 }  \Big]
52    -3 \rho_{ \text{flat}_i } V(r_{ \text{inter}_i })
53    \Big[ \frac{\sin(qr_{\text{inter}_i}) - qr_{\text{flat}_i} \cos(qr_{\text{inter}_i}) } {qr_{\text{inter}_i}^3} \Big]
54
55    f_\text{solvent} = 4 \pi \int_{r_N}^{\infty} \rho_\text{solvent} \frac{\sin(qr)} {qr} r^2 dr =
56    3 \rho_\text{solvent} V(r_N)
57    \Big[ \frac{\sin(qr_N) - qr_N \cos(qr_N)} {qr_N^3} \Big]
58
59
60Here we assumed that the SLDs of the core and solvent are constant against $r$.
61The SLD at the interface between shells, $\rho_{\text {inter}_i}$
62is calculated with a function chosen by an user, where the functions are
63
64Exp:
65
66.. math::
67    \rho_{{inter}_i} (r) = \begin{cases}
68    B \exp\Big( \frac {\pm A(r - r_{\text{flat}_i})} {\Delta t_{ \text{inter}_i }} \Big) +C  & \text{for} A \neq 0 \\
69    B \Big( \frac {(r - r_{\text{flat}_i})} {\Delta t_{ \text{inter}_i }} \Big) +C  & \text{for} A = 0 \\
70    \end{cases}
71
72Power-Law
73
74.. math::
75    \rho_{{inter}_i} (r) = \begin{cases}
76    \pm B \Big( \frac {(r - r_{\text{flat}_i} )} {\Delta t_{ \text{inter}_i }} \Big) ^A  +C  & \text{for} A \neq 0 \\
77    \rho_{\text{flat}_{i+1}}  & \text{for} A = 0 \\
78    \end{cases}
79
80Erf:
81
82.. math::
83    \rho_{{inter}_i} (r) = \begin{cases}
84    B \text{erf} \Big( \frac { A(r - r_{\text{flat}_i})} {\sqrt{2} \Delta t_{ \text{inter}_i }} \Big) +C  & \text{for} A \neq 0 \\
85    B \Big( \frac {(r - r_{\text{flat}_i} )} {\Delta t_{ \text{inter}_i }} \Big)  +C  & \text{for} A = 0 \\
86    \end{cases}
87
88The functions are normalized so that they vary between 0 and 1, and they are constrained such that the SLD
89is continuous at the boundaries of the interface as well as each sub-layers. Thus B and C are determined.
90
91Once $\rho_{\text{inter}_i}$ is found at the boundary of the sub-layer of the interface, we can find its contribution
92to the form factor $P(q)$
93
94.. math::
95    f_{\text{inter}_i} = 4 \pi \int_{\Delta t_{ \text{inter}_i } } \rho_{ \text{inter}_i } \frac{\sin(qr)} {qr} r^2 dr =
96    4 \pi \sum_{j=0}^{npts_{\text{inter}_i} -1 }
97    \int_{r_j}^{r_{j+1}} \rho_{ \text{inter}_i } (r_j) \frac{\sin(qr)} {qr} r^2 dr \approx
98
99    4 \pi \sum_{j=0}^{npts_{\text{inter}_i} -1 } \Big[
100    3 ( \rho_{ \text{inter}_i } ( r_{j+1} ) - \rho_{ \text{inter}_i } ( r_{j} ) V ( r_{ \text{sublayer}_j } )
101    \Big[ \frac {r_j^2 \beta_\text{out}^2 \sin(\beta_\text{out}) - (\beta_\text{out}^2-2) \cos(\beta_\text{out}) }
102    {\beta_\text{out}^4 } \Big]
103
104    - 3 ( \rho_{ \text{inter}_i } ( r_{j+1} ) - \rho_{ \text{inter}_i } ( r_{j} ) V ( r_{ \text{sublayer}_j-1 } )
105    \Big[ \frac {r_{j-1}^2 \sin(\beta_\text{in}) - (\beta_\text{in}^2-2) \cos(\beta_\text{in}) }
106    {\beta_\text{in}^4 } \Big]
107
108    + 3 \rho_{ \text{inter}_i } ( r_{j+1} )  V ( r_j )
109    \Big[ \frac {\sin(\beta_\text{out}) - \cos(\beta_\text{out}) }
110    {\beta_\text{out}^4 } \Big]
111
112    - 3 \rho_{ \text{inter}_i } ( r_{j} )  V ( r_j )
113    \Big[ \frac {\sin(\beta_\text{in}) - \cos(\beta_\text{in}) }
114    {\beta_\text{in}^4 } \Big]
115    \Big]
116
117where
118
119.. math::
120    V(a) = \frac {4\pi}{3}a^3
121
122    a_\text{in} ~ \frac{r_j}{r_{j+1} -r_j} \text{, } a_\text{out} ~ \frac{r_{j+1}}{r_{j+1} -r_j}
123
124    \beta_\text{in} = qr_j \text{, } \beta_\text{out} = qr_{j+1}
125
126
127We assume the $\rho_{\text{inter}_i} (r)$ can be approximately linear within a sub-layer $j$
128
129Finally form factor can be calculated by
130
131.. math::
132
133    P(q) = \frac{[f]^2} {V_\text{particle}} \text{where} V_\text{particle} = V(r_{\text{shell}_N})
134
135For 2D data the scattering intensity is calculated in the same way as 1D,
136where the $q$ vector is defined as
137
138.. math::
139
140    q = \sqrt{q_x^2 + q_y^2}
141
142
143.. figure:: img/spherical_sld_1d.jpg
144
145    1D plot using the default values (w/400 data point).
146
147.. figure:: img/spherical_sld_default_profile.jpg
148
149    SLD profile from the default values.
150
151.. note::
152    The outer most radius is used as the effective radius for S(Q) when $P(Q) * S(Q)$ is applied.
153
154References
155----------
156L A Feigin and D I Svergun, Structure Analysis by Small-Angle X-Ray and Neutron Scattering, Plenum Press, New York, (1987)
157
158"""
159
160from numpy import inf
161
162name = "spherical_sld"
163title = "Sperical SLD intensity calculation"
164description = """
165            I(q) =
166               background = Incoherent background [1/cm]
167        """
168category = "sphere-based"
169
170# pylint: disable=bad-whitespace, line-too-long
171#            ["name", "units", default, [lower, upper], "type", "description"],
172parameters = [["n_shells",        "",               1,      [0, 9],         "", "number of shells"],
173              ["thick_inter_0",   "Ang",            50,     [-inf, inf],    "", "intern layer thickness"],
174              ["func_inter_0",    "",               0,      [0, 4],         "", "'Erf(|nu|*z)':0, 'RPower(z^|nu|)':1, 'LPower(z^|nu|)':2, 'RExp(-|nu|*z)':3, 'LExp(-|nu|*z)':4"],
175              ["core0_sld",       "1e-6/Ang^2",     2.07,   [-inf, inf],    "", "sld function flat"],
176              ["solvent_sld",     "1e-6/Ang^2",     1.0,    [-inf, inf],    "", "sld function solvent"],
177              ["flat1_sld",       "1e-6/Ang^2",     4.06,   [-inf, inf],    "", "sld function flat"],
178              ["flat2_sld",       "1e-6/Ang^2",     3.5,    [-inf, inf],    "", "sld function flat"],
179              ["flat3_sld",       "1e-6/Ang^2",     4.06,   [-inf, inf],    "", "sld function flat"],
180              ["flat4_sld",       "1e-6/Ang^2",     3.5,    [-inf, inf],    "", "sld function flat"],
181              ["flat5_sld",       "1e-6/Ang^2",     4.06,   [-inf, inf],    "", "sld function flat"],
182              ["flat6_sld",       "1e-6/Ang^2",     3.5,    [-inf, inf],    "", "sld function flat"],
183              ["flat7_sld",       "1e-6/Ang^2",     4.06,   [-inf, inf],    "", "sld function flat"],
184              ["flat8_sld",       "1e-6/Ang^2",     3.5,    [-inf, inf],    "", "sld function flat"],
185              ["flat9_sld",       "1e-6/Ang^2",     4.06,   [-inf, inf],    "", "sld function flat"],
186              ["flat10_sld",      "1e-6/Ang^2",     3.5,    [-inf, inf],    "", "sld function flat"],
187              ["thick_inter_1",    "Ang",           50.0,   [0, inf],    "", "intern layer thickness"],
188              ["thick_inter_2",    "Ang",           50.0,   [0, inf],    "", "intern layer thickness"],
189              ["thick_inter_3",    "Ang",           50.0,   [0, inf],    "", "intern layer thickness"],
190              ["thick_inter_4",    "Ang",           50.0,   [0, inf],    "", "intern layer thickness"],
191              ["thick_inter_5",    "Ang",           50.0,   [0, inf],    "", "intern layer thickness"],
192              ["thick_inter_6",    "Ang",           50.0,   [0, inf],    "", "intern layer thickness"],
193              ["thick_inter_7",    "Ang",           50.0,   [0, inf],    "", "intern layer thickness"],
194              ["thick_inter_8",    "Ang",           50.0,   [0, inf],    "", "intern layer thickness"],
195              ["thick_inter_9",    "Ang",           50.0,   [0, inf],    "", "intern layer thickness"],
196              ["thick_inter_10",   "Ang",           50.0,   [0, inf],    "", "intern layer thickness"],
197              ["thick_flat_1",     "Ang",           100.0,  [0, inf],    "", "flat layer_thickness"],
198              ["thick_flat_2",     "Ang",           100.0,  [0, inf],    "", "flat layer_thickness"],
199              ["thick_flat_3",     "Ang",           100.0,  [0, inf],    "", "flat layer_thickness"],
200              ["thick_flat_4",     "Ang",           100.0,  [0, inf],    "", "flat layer_thickness"],
201              ["thick_flat_5",     "Ang",           100.0,  [0, inf],    "", "flat layer_thickness"],
202              ["thick_flat_6",     "Ang",           100.0,  [0, inf],    "", "flat layer_thickness"],
203              ["thick_flat_7",     "Ang",           100.0,  [0, inf],    "", "flat layer_thickness"],
204              ["thick_flat_8",     "Ang",           100.0,  [0, inf],    "", "flat layer_thickness"],
205              ["thick_flat_9",     "Ang",           100.0,  [0, inf],    "", "flat layer_thickness"],
206              ["thick_flat_10",    "Ang",           100.0,  [0, inf],    "", "flat layer_thickness"],
207              ["func_inter_1",      "",             0,      [0, 4],         "", "'Erf(|nu|*z)':0, 'RPower(z^|nu|)':1, 'LPower(z^|nu|)':2, 'RExp(-|nu|*z)':3, 'LExp(-|nu|*z)':4"],
208              ["func_inter_2",      "",             0,      [0, 4],         "", "'Erf(|nu|*z)':0, 'RPower(z^|nu|)':1, 'LPower(z^|nu|)':2, 'RExp(-|nu|*z)':3, 'LExp(-|nu|*z)':4"],
209              ["func_inter_3",      "",             0,      [0, 4],         "", "'Erf(|nu|*z)':0, 'RPower(z^|nu|)':1, 'LPower(z^|nu|)':2, 'RExp(-|nu|*z)':3, 'LExp(-|nu|*z)':4"],
210              ["func_inter_4",      "",             0,      [0, 4],         "", "'Erf(|nu|*z)':0, 'RPower(z^|nu|)':1, 'LPower(z^|nu|)':2, 'RExp(-|nu|*z)':3, 'LExp(-|nu|*z)':4"],
211              ["func_inter_5",      "",             0,      [0, 4],         "", "'Erf(|nu|*z)':0, 'RPower(z^|nu|)':1, 'LPower(z^|nu|)':2, 'RExp(-|nu|*z)':3, 'LExp(-|nu|*z)':4"],
212              ["func_inter_6",      "",             0,      [0, 4],         "", "'Erf(|nu|*z)':0, 'RPower(z^|nu|)':1, 'LPower(z^|nu|)':2, 'RExp(-|nu|*z)':3, 'LExp(-|nu|*z)':4"],
213              ["func_inter_7",      "",             0,      [0, 4],         "", "'Erf(|nu|*z)':0, 'RPower(z^|nu|)':1, 'LPower(z^|nu|)':2, 'RExp(-|nu|*z)':3, 'LExp(-|nu|*z)':4"],
214              ["func_inter_8",      "",             0,      [0, 4],         "", "'Erf(|nu|*z)':0, 'RPower(z^|nu|)':1, 'LPower(z^|nu|)':2, 'RExp(-|nu|*z)':3, 'LExp(-|nu|*z)':4"],
215              ["func_inter_9",      "",             0,      [0, 4],         "", "'Erf(|nu|*z)':0, 'RPower(z^|nu|)':1, 'LPower(z^|nu|)':2, 'RExp(-|nu|*z)':3, 'LExp(-|nu|*z)':4"],
216              ["func_inter_10",     "",             0,      [0, 4],         "", "'Erf(|nu|*z)':0, 'RPower(z^|nu|)':1, 'LPower(z^|nu|)':2, 'RExp(-|nu|*z)':3, 'LExp(-|nu|*z)':4"],
217              ["nu_inter_1",        "",             2.5,    [-inf, inf],    "", "steepness parameter"],
218              ["nu_inter_2",        "",             2.5,    [-inf, inf],    "", "steepness parameter"],
219              ["nu_inter_3",        "",             2.5,    [-inf, inf],    "", "steepness parameter"],
220              ["nu_inter_4",        "",             2.5,    [-inf, inf],    "", "steepness parameter"],
221              ["nu_inter_5",        "",             2.5,    [-inf, inf],    "", "steepness parameter"],
222              ["nu_inter_6",        "",             2.5,    [-inf, inf],   "", "steepness parameter"],
223              ["nu_inter_7",        "",             2.5,    [-inf, inf],    "", "steepness parameter"],
224              ["nu_inter_8",        "",             2.5,    [-inf, inf],    "", "steepness parameter"],
225              ["nu_inter_9",        "",             2.5,    [-inf, inf],    "", "steepness parameter"],
226              ["nu_inter_10",       "",             2.5,    [-inf, inf],    "", "steepness parameter"],
227              ["npts_inter",        "",             35,     [0, 35],        "", "number of points in each sublayer Must be odd number"],
228              ["nu_inter_0",        "",             2.5,    [-inf, inf],    "", "steepness parameter"],
229              ["rad_core_0",        "Ang",          50.0,   [0, inf],    "", "intern layer thickness"],
230              ]
231# pylint: enable=bad-whitespace, line-too-long
232#source = ["lib/librefl.c",  "lib/sph_j1c.c", "spherical_sld.c"]
233
234Iq = """
235    return q;
236    """
237
238Iqxy = """
239    // never called since no orientation or magnetic parameters.
240    //return -1.0;
241    """
242
243demo = dict(
244        n_shells=4,
245        scale=1.0,
246        solvent_sld=1.0,
247        background=0.0,
248        npts_inter=35.0,
249        func_inter_0=0,
250        nu_inter_0=2.5,
251        rad_core_0=50.0,
252        core0_sld=2.07,
253        thick_inter_0=50.0,
254        func_inter_1=0,
255        nu_inter_1=2.5,
256        thick_inter_1=50.0,
257        flat1_sld=4.0,
258        thick_flat_1=100.0,
259        func_inter_2=0,
260        nu_inter_2=2.5,
261        thick_inter_2=50.0,
262        flat2_sld=3.5,
263        thick_flat_2=100.0,
264        func_inter_3=0,
265        nu_inter_3=2.5,
266        thick_inter_3=50.0,
267        flat3_sld=4.0,
268        thick_flat_3=100.0,
269        func_inter_4=0,
270        nu_inter_4=2.5,
271        thick_inter_4=50.0,
272        flat4_sld=3.5,
273        thick_flat_4=100.0,
274        func_inter_5=0,
275        nu_inter_5=2.5,
276        thick_inter_5=50.0,
277        flat5_sld=4.0,
278        thick_flat_5=100.0,
279        func_inter_6=0,
280        nu_inter_6=2.5,
281        thick_inter_6=50.0,
282        flat6_sld=3.5,
283        thick_flat_6=100.0,
284        func_inter_7=0,
285        nu_inter_7=2.5,
286        thick_inter_7=50.0,
287        flat7_sld=4.0,
288        thick_flat_7=100.0,
289        func_inter_8=0,
290        nu_inter_8=2.5,
291        thick_inter_8=50.0,
292        flat8_sld=3.5,
293        thick_flat_8=100.0,
294        func_inter_9=0,
295        nu_inter_9=2.5,
296        thick_inter_9=50.0,
297        flat9_sld=4.0,
298        thick_flat_9=100.0,
299        func_inter_10=0,
300        nu_inter_10=2.5,
301        thick_inter_10=50.0,
302        flat10_sld=3.5,
303        thick_flat_10=100.0
304        )
305
306oldname = "SphereSLDModel"
307oldpars = dict(
308        n_shells="n_shells",
309        scale="scale",
310        npts_inter='npts_inter',
311        solvent_sld='sld_solv',
312        func_inter_0='func_inter0',
313        nu_inter_0='nu_inter0',
314        background='background',
315        rad_core_0='rad_core0',
316        core0_sld='sld_core0',
317        thick_inter_0='thick_inter0',
318        func_inter_1='func_inter1',
319        nu_inter_1='nu_inter1',
320        thick_inter_1='thick_inter1',
321        flat1_sld='sld_flat1',
322        thick_flat_1='thick_flat1',
323        func_inter_2='func_inter2',
324        nu_inter_2='nu_inter2',
325        thick_inter_2='thick_inter2',
326        flat2_sld='sld_flat2',
327        thick_flat_2='thick_flat2',
328        func_inter_3='func_inter3',
329        nu_inter_3='nu_inter3',
330        thick_inter_3='thick_inter3',
331        flat3_sld='sld_flat3',
332        thick_flat_3='thick_flat3',
333        func_inter_4='func_inter4',
334        nu_inter_4='nu_inter4',
335        thick_inter_4='thick_inter4',
336        flat4_sld='sld_flat4',
337        thick_flat_4='thick_flat4',
338        func_inter_5='func_inter5',
339        nu_inter_5='nu_inter5',
340        thick_inter_5='thick_inter5',
341        flat5_sld='sld_flat5',
342        thick_flat_5='thick_flat5',
343        func_inter_6='func_inter6',
344        nu_inter_6='nu_inter6',
345        thick_inter_6='thick_inter6',
346        flat6_sld='sld_flat6',
347        thick_flat_6='thick_flat6',
348        func_inter_7='func_inter7',
349        nu_inter_7='nu_inter7',
350        thick_inter_7='thick_inter7',
351        flat7_sld='sld_flat7',
352        thick_flat_7='thick_flat7',
353        func_inter_8='func_inter8',
354        nu_inter_8='nu_inter8',
355        thick_inter_8='thick_inter8',
356        flat8_sld='sld_flat8',
357        thick_flat_8='thick_flat8',
358        func_inter_9='func_inter9',
359        nu_inter_9='nu_inter9',
360        thick_inter_9='thick_inter9',
361        flat9_sld='sld_flat9',
362        thick_flat_9='thick_flat9',
363        func_inter_10='func_inter10',
364        nu_inter_10='nu_inter10',
365        thick_inter_10='thick_inter10',
366        flat10_sld='sld_flat10',
367        thick_flat_10='thick_flat10')
368
369#TODO: Not working yet
370tests = [
371    # Accuracy tests based on content in test/utest_extra_models.py
372    [{'npts_iter':35,
373        'sld_solv':1,
374        'func_inter_1':0.0,
375        'nu_inter':2.5,
376        'thick_inter_1':50,
377        'sld_flat_1':4,
378        'thick_flat_1':100,
379        'func_inter_0':0.0,
380        'nu_inter_0':2.5,
381        'rad_core_0':50.0,
382        'sld_core_0':2.07,
383        'thick_inter_0':50,
384        'background': 0.0,
385    }, 0.001, 1000],
386]
Note: See TracBrowser for help on using the repository browser.