source: sasmodels/sasmodels/models/gauss_lorentz_gel.py @ 168052c

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

pylint prettification

  • Property mode set to 100644
File size: 5.1 KB
Line 
1r"""
2This model calculates the scattering from a gel structure,
3but typically a physical rather than chemical network.
4It is modeled as a sum of a low-q exponential decay plus
5a lorentzian at higher-q values.
6
7Definition
8----------
9
10The scattering intensity I(q) is calculated as (Eqn. 5 from the reference)
11
12.. math::
13
14    I(q) = I_G(0)exp(-q^2\Xi ^2/2) + I_L(0)/(1+q^2\xi^2)
15
16$\Xi$ is the length scale of the static correlations in the gel,
17which can be attributed to the "frozen-in" crosslinks.
18$\xi is the dynamic correlation length, which can be attributed to the
19fluctuating polymer chains between crosslinks.
20$IG(0)$ and $IL(0)$ are the scaling factors for each of these structures.
21Think carefully about how these map to your particular system!
22
23.. note::
24    The peaked structure at higher $q$ values (Figure 2 from the reference)
25    is not reproduced by the model. Peaks can be introduced into the model
26    by summing this model with the PeakGaussModel function.
27
28For 2D data the scattering intensity is calculated in the same way as 1D,
29where the $q$ vector is defined as
30
31.. math::
32
33    q = \sqrt{q_x^2 + q_y^2}
34
35
36.. figure:: img/gauss_lorentz_gel_1d.jpg
37
38    1D plot using the default values (w/500 data point).
39
40
41References
42----------
43
44G Evmenenko, E Theunissen, K Mortensen, H Reynaers, *Polymer*,
4542 (2001) 2907-2913
46
47"""
48
49from numpy import inf, sqrt, exp
50
51name = "gauss_lorentz_gel"
52title = "Gauss Lorentz Gel model of scattering from a gel structure"
53description = """
54            Class that evaluates a GaussLorentzGel model.
55
56            I(q) = scale_g*exp(- q^2*Z^2 / 2)+scale_l/(1+q^2*z^2)
57                    + background
58            List of default parameters:
59                scale_g = Gauss scale factor
60                Z = Static correlation length
61                scale_l = Lorentzian scale factor
62                z = Dynamic correlation length
63                background = Incoherent background
64            """
65category = "shape-independent"
66# pylint: disable=bad-whitespace, line-too-long
67#            ["name", "units", default, [lower, upper], "type", "description"],
68parameters = [["gauss_scale_factor",   "",    100.0,  [-inf, inf], "", "Gauss scale factor"],
69              ["static_cor_length",    "Ang", 100.0,  [0, inf],    "", "Static correlation length"],
70              ["lorentz_scale_factor", "",     50.0,  [-inf, inf], "", "Lorentzian scale factor"],
71              ["dynamic_cor_length",   "Ang",  20.0,  [0, inf],    "", "Dynamic correlation length"],
72             ]
73# pylint: enable=bad-whitespace, line-too-long
74
75def Iq(q,
76       gauss_scale_factor=100.0,
77       static_cor_length=100.0,
78       lorentz_scale_factor=50.0,
79       dynamic_cor_length=20.0):
80    """
81
82    :param q:                    Input q-value
83    :param gauss_scale_factor:   Gauss scale factor
84    :param static_cor_length:    Static correlation length
85    :param lorentz_scale_factor: Lorentzian scale factor
86    :param dynamic_cor_length:   Dynamic correlation length
87    :return:                     1-D intensity
88    """
89
90    term1 = gauss_scale_factor *\
91            exp(-1.0*q*q*static_cor_length*static_cor_length/2.0)
92    term2 = lorentz_scale_factor /\
93            (1.0+(q*dynamic_cor_length)*(q*dynamic_cor_length))
94
95    return term1 + term2
96
97Iq.vectorized = True  # Iq accepts an array of q values
98
99
100def Iqxy(qx, qy, *args):
101    """
102    :param qx:   Input q_x-value
103    :param qy:   Input q_y-value
104    :param args: Remaining aruments
105    :return:     2-D intensity
106    """
107
108    return Iq(sqrt(qx**2 + qy**2), *args)
109
110Iqxy.vectorized = True  # Iqxy accepts an array of qx, qy values
111
112
113demo = dict(scale=1, background=0.1,
114            gauss_scale_factor=100.0,
115            static_cor_length=100.0,
116            lorentz_scale_factor=50.0,
117            dynamic_cor_length=20.0)
118
119oldname = "GaussLorentzGelModel"
120
121oldpars = dict(background='background',
122               gauss_scale_factor='scale_g',
123               static_cor_length='stat_colength',
124               lorentz_scale_factor='scale_l',
125               dynamic_cor_length='dyn_colength')
126
127tests = [
128
129    # Accuracy tests based on content in test/utest_extra_models.py
130    [{'gauss_scale_factor':  100.0,
131      'static_cor_length':   100.0,
132      'lorentz_scale_factor': 50.0,
133      'dynamic_cor_length':   20.0,
134     }, 0.001, 149.481],
135
136    [{'gauss_scale_factor':  100.0,
137      'static_cor_length':   100.0,
138      'lorentz_scale_factor': 50.0,
139      'dynamic_cor_length':   20.0,
140     }, 0.105363, 9.1903],
141
142    [{'gauss_scale_factor':  100.0,
143      'static_cor_length':   100.0,
144      'lorentz_scale_factor': 50.0,
145      'dynamic_cor_length':   20.0,
146     }, 0.441623, 0.632811],
147
148    # Additional tests with larger range of parameters
149    [{'gauss_scale_factor':  10.0,
150      'static_cor_length':  100.0,
151      'lorentz_scale_factor': 3.0,
152      'dynamic_cor_length':   1.0,
153     }, 0.1, 2.9702970297],
154
155    [{'gauss_scale_factor':  10.0,
156      'static_cor_length':  100.0,
157      'lorentz_scale_factor': 3.0,
158      'dynamic_cor_length':   1.0,
159      'background':         100.0
160     }, 5.0, 100.115384615],
161
162    [{'gauss_scale_factor':  10.0,
163      'static_cor_length':  100.0,
164      'lorentz_scale_factor': 3.0,
165      'dynamic_cor_length':   1.0,
166     }, 200., 7.49981250469e-05],
167    ]
Note: See TracBrowser for help on using the repository browser.