source: sasmodels/sasmodels/models/guinier.py @ 05cd67f

core_shell_microgelsmagnetic_modelticket-1257-vesicle-productticket_1156ticket_1265_superballticket_822_more_unit_tests
Last change on this file since 05cd67f was 05cd67f, checked in by Torin Cooper-Bennun <torin.cooper-bennun@…>, 6 years ago

use floating point routine fabs (breaks in openCL otherwise)

  • Property mode set to 100644
File size: 2.6 KB
Line 
1r"""
2Definition
3----------
4
5This model fits the Guinier function
6
7.. math::
8
9    I(q) = \text{scale} \cdot \exp{\left[ \frac{-Q^2 R_g^2 }{3} \right]}
10            + \text{background}
11
12to the data directly without any need for linearisation (*cf*. the usual
13plot of $\ln I(q)$ vs $q^2$\ ). Note that you may have to restrict the data
14range to include small q only, where the Guinier approximation actually
15applies. See also the guinier_porod model.
16
17For 2D data the scattering intensity is calculated in the same way as 1D,
18where the $q$ vector is defined as
19
20.. math:: q = \sqrt{q_x^2 + q_y^2}
21
22Note that $R_g^2$ may be negative, which happens when a form factor $P(Q)$ is
23increasing with $Q$ rather than decreasing. This can occur for core/shell
24particles, hollow particles, or for composite particles with domains of
25different SLDs in a solvent with an SLD close to the average match point.
26(Alternatively, this might be regarded as there being an internal inter-domain
27"structure factor" within a single particle which gives rise to a peak in the
28scattering).
29
30To specify a negative value of $R_g^2$ in SasView, simply give $R_g$ a negative
31value ($R_g^2$ will be evaluated as $R_g |R_g|$). Note that the physical radius
32of gyration, of the exterior of the particle, will still be large and positive.
33It is only the apparent size from the small $Q$ data that will give a small or
34negative value of $R_g^2$.
35
36References
37----------
38
39A Guinier and G Fournet, *Small-Angle Scattering of X-Rays*,
40John Wiley & Sons, New York (1955)
41"""
42
43import numpy as np
44from numpy import inf
45
46name = "guinier"
47title = ""
48description = """
49 I(q) = scale.exp ( - rg^2 q^2 / 3.0 )
50
51    List of default parameters:
52    scale = scale
53    rg = Radius of gyration
54"""
55category = "shape-independent"
56
57#             ["name", "units", default, [lower, upper], "type","description"],
58parameters = [["rg", "Ang", 60.0, [-inf, inf], "", "Radius of Gyration"]]
59
60Iq = """
61    double exponent = fabs(rg)*rg*q*q/3.0;
62    double value = exp(-exponent);
63    return value;
64"""
65
66def random():
67    scale = 10**np.random.uniform(1, 4)
68    # Note: compare.py has Rg cutoff of 1e-30 at q=1 for guinier, so use that
69    # log_10 Ae^(-(q Rg)^2/3) = log_10(A) - (q Rg)^2/ (3 ln 10) > -30
70    #   => log_10(A) > Rg^2/(3 ln 10) - 30
71    q_max = 1.0
72    rg_max = np.sqrt(90*np.log(10) + 3*np.log(scale))/q_max
73    rg = 10**np.random.uniform(0, np.log10(rg_max))
74    pars = dict(
75        #background=0,
76        scale=scale,
77        rg=rg,
78    )
79    return pars
80
81# parameters for demo
82demo = dict(scale=1.0,  background=0.001, rg=60.0 )
83
84# parameters for unit tests
85tests = [[{'rg' : 31.5}, 0.005, 0.992756]]
Note: See TracBrowser for help on using the repository browser.