source:sasmodels/sasmodels/models/guinier.py@b297ba9

core_shell_microgelsmagnetic_modelticket-1257-vesicle-productticket_1156ticket_1265_superballticket_822_more_unit_tests
Last change on this file since b297ba9 was b297ba9, checked in by Paul Kienzle <pkienzle@…>, 15 months ago

lint

• Property mode set to 100644
File size: 3.0 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
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
22In scattering, the radius of gyration $R_g$ quantifies the objects's
23distribution of SLD (not mass density, as in mechanics) from the objects's
24SLD centre of mass. It is defined by
25
26.. math:: R_g^2 = \frac{\sum_i\rho_i\left(r_i-r_0\right)^2}{\sum_i\rho_i}
27
28where $r_0$ denotes the object's SLD centre of mass and $\rho_i$ is the SLD at
29a point $i$.
30
31Notice that $R_g^2$ may be negative (since SLD can be negative), which happens
32when a form factor $P(Q)$ is increasing with $Q$ rather than decreasing. This
33can occur for core/shell particles, hollow particles, or for composite
34particles with domains of different SLDs in a solvent with an SLD close to the
35average match point. (Alternatively, this might be regarded as there being an
36internal inter-domain "structure factor" within a single particle which gives
37rise to a peak in the scattering).
38
39To specify a negative value of $R_g^2$ in SasView, simply give $R_g$ a negative
40value ($R_g^2$ will be evaluated as $R_g |R_g|$). Note that the physical radius
41of gyration, of the exterior of the particle, will still be large and positive.
42It is only the apparent size from the small $Q$ data that will give a small or
43negative value of $R_g^2$.
44
45References
46----------
47
48A Guinier and G Fournet, *Small-Angle Scattering of X-Rays*,
49John Wiley & Sons, New York (1955)
50"""
51
52import numpy as np
53from numpy import inf
54
55name = "guinier"
56title = ""
57description = """
58 I(q) = scale.exp ( - rg^2 q^2 / 3.0 )
59
60    List of default parameters:
61    scale = scale
62    rg = Radius of gyration
63"""
64category = "shape-independent"
65
66#             ["name", "units", default, [lower, upper], "type","description"],
67parameters = [["rg", "Ang", 60.0, [-inf, inf], "", "Radius of Gyration"]]
68
69Iq = """
70    double exponent = fabs(rg)*rg*q*q/3.0;
71    double value = exp(-exponent);
72    return value;
73"""
74
75def random():
76    """Return a random parameter set for the model."""
77    scale = 10**np.random.uniform(1, 4)
78    # Note: compare.py has Rg cutoff of 1e-30 at q=1 for guinier, so use that
79    # log_10 Ae^(-(q Rg)^2/3) = log_10(A) - (q Rg)^2/ (3 ln 10) > -30
80    #   => log_10(A) > Rg^2/(3 ln 10) - 30
81    q_max = 1.0
82    rg_max = np.sqrt(90*np.log(10) + 3*np.log(scale))/q_max
83    rg = 10**np.random.uniform(0, np.log10(rg_max))
84    pars = dict(
85        #background=0,
86        scale=scale,
87        rg=rg,
88    )
89    return pars
90
91# parameters for demo
92demo = dict(scale=1.0, background=0.001, rg=60.0)
93
94# parameters for unit tests
95tests = [[{'rg' : 31.5}, 0.005, 0.992756]]
Note: See TracBrowser for help on using the repository browser.