source: sasmodels/sasmodels/models/gauss_lorentz_gel.py @ e481a39

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

Removing hardcoded figures to be replaced by autogenerated ones

  • 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
36References
37----------
38
39G Evmenenko, E Theunissen, K Mortensen, H Reynaers, *Polymer*,
4042 (2001) 2907-2913
41
42"""
43
44from numpy import inf, sqrt, exp
45
46name = "gauss_lorentz_gel"
47title = "Gauss Lorentz Gel model of scattering from a gel structure"
48description = """
49            Class that evaluates a GaussLorentzGel model.
50
51            I(q) = scale_g*exp(- q^2*Z^2 / 2)+scale_l/(1+q^2*z^2)
52                    + background
53            List of default parameters:
54                scale_g = Gauss scale factor
55                Z = Static correlation length
56                scale_l = Lorentzian scale factor
57                z = Dynamic correlation length
58                background = Incoherent background
59            """
60category = "shape-independent"
61# pylint: disable=bad-whitespace, line-too-long
62#            ["name", "units", default, [lower, upper], "type", "description"],
63parameters = [["gauss_scale_factor",   "",    100.0,  [-inf, inf], "", "Gauss scale factor"],
64              ["static_cor_length",    "Ang", 100.0,  [0, inf],    "", "Static correlation length"],
65              ["lorentz_scale_factor", "",     50.0,  [-inf, inf], "", "Lorentzian scale factor"],
66              ["dynamic_cor_length",   "Ang",  20.0,  [0, inf],    "", "Dynamic correlation length"],
67             ]
68# pylint: enable=bad-whitespace, line-too-long
69
70def Iq(q,
71       gauss_scale_factor=100.0,
72       static_cor_length=100.0,
73       lorentz_scale_factor=50.0,
74       dynamic_cor_length=20.0):
75    """
76
77    :param q:                    Input q-value
78    :param gauss_scale_factor:   Gauss scale factor
79    :param static_cor_length:    Static correlation length
80    :param lorentz_scale_factor: Lorentzian scale factor
81    :param dynamic_cor_length:   Dynamic correlation length
82    :return:                     1-D intensity
83    """
84
85    term1 = gauss_scale_factor *\
86            exp(-1.0*q*q*static_cor_length*static_cor_length/2.0)
87    term2 = lorentz_scale_factor /\
88            (1.0+(q*dynamic_cor_length)*(q*dynamic_cor_length))
89
90    return term1 + term2
91
92Iq.vectorized = True  # Iq accepts an array of q values
93
94
95def Iqxy(qx, qy, *args):
96    """
97    :param qx:   Input q_x-value
98    :param qy:   Input q_y-value
99    :param args: Remaining aruments
100    :return:     2-D intensity
101    """
102
103    return Iq(sqrt(qx**2 + qy**2), *args)
104
105Iqxy.vectorized = True  # Iqxy accepts an array of qx, qy values
106
107
108demo = dict(scale=1, background=0.1,
109            gauss_scale_factor=100.0,
110            static_cor_length=100.0,
111            lorentz_scale_factor=50.0,
112            dynamic_cor_length=20.0)
113
114oldname = "GaussLorentzGelModel"
115
116oldpars = dict(background='background',
117               gauss_scale_factor='scale_g',
118               static_cor_length='stat_colength',
119               lorentz_scale_factor='scale_l',
120               dynamic_cor_length='dyn_colength')
121
122tests = [
123
124    # Accuracy tests based on content in test/utest_extra_models.py
125    [{'gauss_scale_factor':  100.0,
126      'static_cor_length':   100.0,
127      'lorentz_scale_factor': 50.0,
128      'dynamic_cor_length':   20.0,
129     }, 0.001, 149.482],
130
131    [{'gauss_scale_factor':  100.0,
132      'static_cor_length':   100.0,
133      'lorentz_scale_factor': 50.0,
134      'dynamic_cor_length':   20.0,
135     }, 0.105363, 9.1913],
136
137    [{'gauss_scale_factor':  100.0,
138      'static_cor_length':   100.0,
139      'lorentz_scale_factor': 50.0,
140      'dynamic_cor_length':   20.0,
141     }, 0.441623, 0.633811],
142
143    # Additional tests with larger range of parameters
144    [{'gauss_scale_factor':  10.0,
145      'static_cor_length':  100.0,
146      'lorentz_scale_factor': 3.0,
147      'dynamic_cor_length':   1.0,
148     }, 0.1, 2.9712970297],
149
150    [{'gauss_scale_factor':  10.0,
151      'static_cor_length':  100.0,
152      'lorentz_scale_factor': 3.0,
153      'dynamic_cor_length':   1.0,
154      'background':         100.0
155     }, 5.0, 100.116384615],
156
157    [{'gauss_scale_factor':  10.0,
158      'static_cor_length':  100.0,
159      'lorentz_scale_factor': 3.0,
160      'dynamic_cor_length':   1.0,
161      'background':           0.0,
162     }, 200., 7.49981250469e-05],
163    ]
Note: See TracBrowser for help on using the repository browser.