source: sasmodels/sasmodels/models/gauss_lorentz_gel.py @ 07a6700

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

More unit tests for converted models.

  • Property mode set to 100644
File size: 4.8 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*, 42 (2001) 2907-2913
45
46"""
47
48from numpy import inf, pi, sqrt, exp
49
50name = "gauss_lorentz_gel"
51title = "Gauss Lorentz Gel model of scattering from a gel structure"
52description = """
53            Class that evaluates a GaussLorentzGel model.
54
55            I(q) = scale_g*exp(- q^2*Z^2 / 2)+scale_l/(1+q^2*z^2)
56                    + background
57            List of default parameters:
58                scale_g = Gauss scale factor
59                Z = Static correlation length
60                scale_l = Lorentzian scale factor
61                z = Dynamic correlation length
62                background = Incoherent background
63            """
64category = "shape-independent"
65
66#            ["name", "units", default, [lower, upper], "type", "description"],
67parameters = [["gauss_scale_factor",   "",    100.0,  [-inf, inf], "", "Gauss scale factor"],
68              ["static_cor_length",    "Ang", 100.0,  [0, inf],    "", "Static correlation length"],
69              ["lorentz_scale_factor", "",     50.0,  [-inf, inf], "", "Lorentzian scale factor"],
70              ["dynamic_cor_length",   "Ang",  20.0,  [0, inf],    "", "Dynamic correlation length"],
71              ]
72
73
74def Iq(q,
75       gauss_scale_factor,
76       static_cor_length,
77       lorentz_scale_factor,
78       dynamic_cor_length):
79
80        term1 = gauss_scale_factor *\
81                exp(-1.0*q*q*static_cor_length*static_cor_length/2.0)
82        term2 = lorentz_scale_factor /\
83                (1.0+(q*dynamic_cor_length)*(q*dynamic_cor_length))
84
85        return term1 + term2
86
87Iq.vectorized = True  # Iq accepts an array of q values
88
89
90def Iqxy(qx, qy, *args):
91        iq = Iq(sqrt(qx**2 + qy**2), *args)
92
93        return iq
94
95Iqxy.vectorized = True  # Iqxy accepts an array of qx, qy values
96
97
98demo = dict(scale=1, background=0.1,
99            gauss_scale_factor=100.0,
100            static_cor_length=100.0,
101            lorentz_scale_factor=50.0,
102            dynamic_cor_length=20.0)
103
104oldname = "GaussLorentzGelModel"
105
106oldpars = dict(background='background',
107               gauss_scale_factor='scale_g',
108               static_cor_length='stat_colength',
109               lorentz_scale_factor='scale_l',
110               dynamic_cor_length='dyn_colength')
111
112tests = [
113         # Accuracy tests based on content in test/utest_extra_models.py
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           }, 0.001, 149.481],
119
120         [{'gauss_scale_factor':  100.0,
121           'static_cor_length':   100.0,
122           'lorentz_scale_factor': 50.0,
123           'dynamic_cor_length':   20.0,
124           }, 0.105363, 9.1903],
125
126         [{'gauss_scale_factor':  100.0,
127           'static_cor_length':   100.0,
128           'lorentz_scale_factor': 50.0,
129           'dynamic_cor_length':   20.0,
130           }, 0.441623, 0.632811],
131
132         # Additional tests with larger range of parameters
133         [{'gauss_scale_factor':  10.0,
134           'static_cor_length':  100.0,
135           'lorentz_scale_factor': 3.0,
136           'dynamic_cor_length':   1.0,
137           }, 0.1, 2.9702970297],
138
139         [{'gauss_scale_factor':  10.0,
140           'static_cor_length':  100.0,
141           'lorentz_scale_factor': 3.0,
142           'dynamic_cor_length':   1.0,
143           'background':         100.0
144           }, 5.0, 100.115384615],
145
146         [{'gauss_scale_factor':  10.0,
147           'static_cor_length':  100.0,
148           'lorentz_scale_factor': 3.0,
149           'dynamic_cor_length':   1.0,
150           }, 200., 7.49981250469e-05],
151         ]
Note: See TracBrowser for help on using the repository browser.