source: sasmodels/sasmodels/models/spherical_sld.py @ 4a82d4d

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

Spherical SLD working expect low q region

  • Property mode set to 100644
File size: 13.8 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).
10Unlike the OnionExpShellModel (using an analytical integration),
11the interfacial layers here are sub-divided and numerically integrated assuming each of the sub-layers are described
12by a line function. The number of the sub-layer can be given by users by setting the integer values of npts_inter
13in the GUI. The form factor is normalized by the total volume of the sphere.
14
15Definition
16----------
17
18The scattering intensity $I(q)$ in 1D is calculated as:
19
20.. math::
21
22    P(q) = \frac{f^2}{V_\text{particle}}
23    f = f_\text{core} + \sum_{\text{inter}_i=0}^N f_text{inter}_i +
24    \sum_{\text{flat}_i=0}^N f_text{flat}_i +f_\text{solvent}
25
26where, for a spherically symmetric particle with a particle density \rho(r)
27
28
29The scaling of the second power law region (coefficent C) is then automatically scaled to
30match the first by following formula
31
32.. math::
33    C = \frac{A}{qc^{-m1} qc^{-m2}}
34
35.. note::
36    Be sure to enter the power law exponents as positive values!
37
38For 2D data the scattering intensity is calculated in the same way as 1D,
39where the $q$ vector is defined as
40
41.. math::
42
43    q = \sqrt{q_x^2 + q_y^2}
44
45
46.. figure:: img/two_power_law_1d.jpg
47
48    1D plot using the default values (w/500 data point).
49
50References
51----------
52L A Feigin and D I Svergun, Structure Analysis by Small-Angle X-Ray and Neutron Scattering, Plenum Press, New York, (1987)
53
54"""
55
56from numpy import inf
57
58name = "spherical_sld"
59title = "Sperical SLD intensity calculation"
60description = """
61            I(q) =
62               background = Incoherent background [1/cm]
63        """
64category = "shere-based"
65
66
67# pylint: disable=bad-whitespace, line-too-long
68#            ["name", "units", default, [lower, upper], "type", "description"],
69parameters = [["n_shells",       "",         1, [0, 9], "", "number of shells"],
70              ["thick_inter_0",       "Ang",         50, [-inf, inf], "", "intern layer thickness"],
71              ["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"],
72              ["sld_core_0",       "1/Ang^2",         2.07E-6, [-inf, inf],"", "sld function flat"],
73              ["sld_solv",     "1/Ang^2",    1E-6,[-inf, inf], "","sld function solvent"],
74              ["sld_flat_1",       "1/Ang^2",         4.06E-6, [-inf, inf],"", "sld function flat"],
75              ["sld_flat_2",       "1/Ang^2",         3.5E-6, [-inf, inf],"", "sld function flat"],
76              ["sld_flat_3",       "1/Ang^2",         4.06E-6, [-inf, inf],"", "sld function flat"],
77              ["sld_flat_4",       "1/Ang^2",         3.5E-6, [-inf, inf],"", "sld function flat"],
78              ["sld_flat_5",       "1/Ang^2",         4.06E-6, [-inf, inf],"", "sld function flat"],
79              ["sld_flat_6",       "1/Ang^2",         3.5E-6, [-inf, inf],"", "sld function flat"],
80              ["sld_flat_7",       "1/Ang^2",         4.06E-6, [-inf, inf],"", "sld function flat"],
81              ["sld_flat_8",       "1/Ang^2",         3.5E-6, [-inf, inf],"", "sld function flat"],
82              ["sld_flat_9",       "1/Ang^2",         4.06E-6, [-inf, inf],"", "sld function flat"],
83              ["sld_flat_10",      "1/Ang^2",         3.5E-6, [-inf, inf],"", "sld function flat"],
84              ["thick_inter_1",       "Ang",         50.0, [-inf, inf], "", "intern layer thickness"],
85              ["thick_inter_2",       "Ang",         50.0, [-inf, inf], "", "intern layer thickness"],
86              ["thick_inter_3",       "Ang",         50.0, [-inf, inf], "", "intern layer thickness"],
87              ["thick_inter_4",       "Ang",         50.0, [-inf, inf], "", "intern layer thickness"],
88              ["thick_inter_5",       "Ang",         50.0, [-inf, inf], "", "intern layer thickness"],
89              ["thick_inter_6",       "Ang",         50.0, [-inf, inf], "", "intern layer thickness"],
90              ["thick_inter_7",       "Ang",         50.0, [-inf, inf], "", "intern layer thickness"],
91              ["thick_inter_8",       "Ang",         50.0, [-inf, inf], "", "intern layer thickness"],
92              ["thick_inter_9",       "Ang",         50.0, [-inf, inf], "", "intern layer thickness"],
93              ["thick_inter_10",       "Ang",         50.0, [-inf, inf], "", "intern layer thickness"],
94              ["thick_flat_1",       "Ang",         100.0, [-inf, inf], "", "flat layer_thickness"],
95              ["thick_flat_2",       "Ang",         100.0, [-inf, inf], "", "flat layer_thickness"],
96              ["thick_flat_3",       "Ang",         100.0, [-inf, inf], "", "flat layer_thickness"],
97              ["thick_flat_4",       "Ang",         100.0, [-inf, inf], "", "flat layer_thickness"],
98              ["thick_flat_5",       "Ang",         100.0, [-inf, inf], "", "flat layer_thickness"],
99              ["thick_flat_6",       "Ang",         100.0, [-inf, inf], "", "flat layer_thickness"],
100              ["thick_flat_7",       "Ang",         100.0, [-inf, inf], "", "flat layer_thickness"],
101              ["thick_flat_8",       "Ang",         100.0, [-inf, inf], "", "flat layer_thickness"],
102              ["thick_flat_9",       "Ang",         100.0, [-inf, inf], "", "flat layer_thickness"],
103              ["thick_flat_10",       "Ang",         100.0, [-inf, inf], "", "flat layer_thickness"],
104              ["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"],
105              ["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"],
106              ["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"],
107              ["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"],
108              ["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"],
109              ["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"],
110              ["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"],
111              ["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"],
112              ["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"],
113              ["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"],
114              ["nu_inter_1",       "",         2.5, [-inf, inf], "", "steepness parameter"],
115              ["nu_inter_2",       "",         2.5, [-inf, inf], "", "steepness parameter"],
116              ["nu_inter_3",       "",         2.5, [-inf, inf], "", "steepness parameter"],
117              ["nu_inter_4",       "",         2.5, [-inf, inf], "", "steepness parameter"],
118              ["nu_inter_5",       "",         2.5, [-inf, inf], "", "steepness parameter"],
119              ["nu_inter_6",       "",         2.5, [-inf, inf], "", "steepness parameter"],
120              ["nu_inter_7",       "",         2.5, [-inf, inf], "", "steepness parameter"],
121              ["nu_inter_8",       "",         2.5, [-inf, inf], "", "steepness parameter"],
122              ["nu_inter_9",       "",         2.5, [-inf, inf], "", "steepness parameter"],
123              ["nu_inter_10",       "",         2.5, [-inf, inf], "", "steepness parameter"],
124              ["npts_inter",  "",         35, [0, inf], "", "number of points in each sublayer"],
125              ["nu_inter_0",       "",         2.5, [-inf, inf], "", "steepness parameter"],
126              ["rad_core_0",       "Ang",         50.0, [-inf, inf], "", "intern layer thickness"],
127              ]
128# pylint: enable=bad-whitespace, line-too-long
129source = ["lib/librefl.c", "spherical_sld.c"]
130
131
132#TODO: Not clear if dispersion function is needed
133#def _set_dispersion(self):
134#        """
135#        Setting dispersion for all shells
136#        """
137#        ##set dispersion from model
138#        for name , value in self.model.dispersion.iteritems():
139#
140#            nshell = -1
141#            if name.split('_')[0] == 'thick':
142#                while nshell < 1:
143#                    nshell += 1
144#                    if name.split('_')[1] == 'inter%s' % str(nshell):
145#                        self.dispersion[name] = value
146#                    else:
147#                        continue
148#            else:
149#                self.dispersion[name] = value
150
151
152def ER(radius):
153        """
154        Calculate the effective radius for P(q)*S(q)
155        Tale different radius values from corresponding shells
156
157        :return: the value of the effective radius
158        """
159
160        return radius
161
162demo = dict(scale=1, background=0.0,
163        n_shells=10,
164        sld_solv=1E-6,
165        npts_inter=35,
166        func_inter_0=0,
167        nu_inter_0=2.5,
168        rad_core_0=50.0,
169        sld_core_0=2.07E-6,
170        thick_inter_0=50,
171        func_inter_1=0,
172        nu_inter_1=2.5,
173        thick_inter_1=50,
174        sld_flat_1=4E-6,
175        thick_flat_1=100,
176        func_inter_2=0,
177        nu_inter_2=2.5,
178        thick_inter_2=50,
179        sld_flat_2=3.5E-6,
180        thick_flat_2=100,
181        func_inter_3=0,
182        nu_inter_3=2.5,
183        thick_inter_3=50,
184        sld_flat_3=4E-6,
185        thick_flat_3=100,
186        func_inter_4=0,
187        nu_inter_4=2.5,
188        thick_inter_4=50,
189        sld_flat_4=3.5E-6,
190        thick_flat_4=100,
191        func_inter_5=0,
192        nu_inter_5=2.5,
193        thick_inter_5=50,
194        sld_flat_5=4E-6,
195        thick_flat_5=100,
196        func_inter_6=0,
197        nu_inter_6=2.5,
198        thick_inter_6=50,
199        sld_flat_6=3.5E-6,
200        thick_flat_6=100,
201        func_inter_7=0,
202        nu_inter_7=2.5,
203        thick_inter_7=50,
204        sld_flat_7=4E-6,
205        thick_flat_7=100,
206        func_inter_8=0,
207        nu_inter_8=2.5,
208        thick_inter_8=50,
209        sld_flat_8=3.5E-6,
210        thick_flat_8=100,
211        func_inter_9=0,
212        nu_inter_9=2.5,
213        thick_inter_9=50,
214        sld_flat_9=4E-6,
215        thick_flat_9=100,
216        func_inter_10=0,
217        nu_inter_10=2.5,
218        thick_inter_10=50,
219        sld_flat_10=3.5E-6,
220        thick_flat_10=100
221        )
222
223oldname = "SphereSLDModel"
224oldpars = dict(
225        scale="scale",
226        background="background",
227        n_shells="n_shells",
228        npts_inter='npts_inter',
229        sld_solv='sld_solv',
230        func_inter_0='func_inter0',
231        nu_inter_0='nu_inter0',
232        rad_core_0='rad_core0',
233        sld_core_0='sld_core0',
234        thick_inter_0='thick_inter0',
235        func_inter_1='func_inter1',
236        nu_inter_1='nu_inter1',
237        thick_inter_1='thick_inter1',
238        sld_flat_1='sld_flat1',
239        thick_flat_1='thick_flat1',
240        func_inter_2='func_inter2',
241        nu_inter_2='nu_inter2',
242        thick_inter_2='thick_inter2',
243        sld_flat_2='sld_flat2',
244        thick_flat_2='thick_flat2',
245        func_inter_3='func_inter3',
246        nu_inter_3='nu_inter3',
247        thick_inter_3='thick_inter3',
248        sld_flat_3='sld_flat3',
249        thick_flat_3='thick_flat3',
250        func_inter_4='func_inter4',
251        nu_inter_4='nu_inter4',
252        thick_inter_4='thick_inter4',
253        sld_flat_4='sld_flat4',
254        thick_flat_4='thick_flat4',
255        func_inter_5='func_inter5',
256        nu_inter_5='nu_inter5',
257        thick_inter_5='thick_inter5',
258        sld_flat_5='sld_flat5',
259        thick_flat_5='thick_flat5',
260        func_inter_6='func_inter6',
261        nu_inter_6='nu_inter6',
262        thick_inter_6='thick_inter6',
263        sld_flat_6='sld_flat6',
264        thick_flat_6='thick_flat6',
265        func_inter_7='func_inter7',
266        nu_inter_7='nu_inter7',
267        thick_inter_7='thick_inter7',
268        sld_flat_7='sld_flat7',
269        thick_flat_7='thick_flat7',
270        func_inter_8='func_inter8',
271        nu_inter_8='nu_inter8',
272        thick_inter_8='thick_inter8',
273        sld_flat_8='sld_flat8',
274        thick_flat_8='thick_flat8',
275        func_inter_9='func_inter9',
276        nu_inter_9='nu_inter9',
277        thick_inter_9='thick_inter9',
278        sld_flat_9='sld_flat9',
279        thick_flat_9='thick_flat9',
280        func_inter_10='func_inter10',
281        nu_inter_10='nu_inter10',
282        thick_inter_10='thick_inter10',
283        sld_flat_10='sld_flat10',
284        thick_flat_10='thick_flat10')
285
286tests = [
287    # Accuracy tests based on content in test/utest_extra_models.py
288    [{'npts_iter':35,
289        'sld_solv':1E-6,
290        'func_inter_1':0.0,
291        'nu_inter':2.5,
292        'thick_inter_1':50,
293        'sld_flat_1':4E-6,
294        'thick_flat_1':100,
295        'func_inter_0':0.0,
296        'nu_inter_0':2.5,
297        'rad_core_0':50.0,
298        'sld_core_0':2.07E-6,
299        'thick_inter_0':50,
300        'background': 0.0,
301    }, 0.001, 1000],
302]
Note: See TracBrowser for help on using the repository browser.