# source:sasmodels/sasmodels/models/guinier.py@0507e09

core_shell_microgelsmagnetic_modelticket-1257-vesicle-productticket_1156ticket_1265_superballticket_822_more_unit_tests
Last change on this file since 0507e09 was 0507e09, checked in by smk78, 6 months ago

Added link to source code to each model. Closes #883

• Property mode set to 100644
File size: 3.3 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
48.. [#] A Guinier and G Fournet, *Small-Angle Scattering of X-Rays*, John Wiley & Sons, New York (1955)
49
50Source
51------
52
53guinier.py <https://github.com/SasView/sasmodels/blob/master/sasmodels/models/guinier.py>_
54
55Authorship and Verification
56----------------------------
57
58* **Author:**
60* **Last Reviewed by:**
61* **Source added by :** Steve King **Date:** March 25, 2019
62"""
63
64import numpy as np
65from numpy import inf
66
67name = "guinier"
68title = ""
69description = """
70 I(q) = scale.exp ( - rg^2 q^2 / 3.0 )
71
72    List of default parameters:
73    scale = scale
74    rg = Radius of gyration
75"""
76category = "shape-independent"
77
78#             ["name", "units", default, [lower, upper], "type","description"],
79parameters = [["rg", "Ang", 60.0, [-inf, inf], "", "Radius of Gyration"]]
80
81Iq = """
82    double exponent = fabs(rg)*rg*q*q/3.0;
83    double value = exp(-exponent);
84    return value;
85"""
86
87def random():
88    """Return a random parameter set for the model."""
89    scale = 10**np.random.uniform(1, 4)
90    # Note: compare.py has Rg cutoff of 1e-30 at q=1 for guinier, so use that
91    # log_10 Ae^(-(q Rg)^2/3) = log_10(A) - (q Rg)^2/ (3 ln 10) > -30
92    #   => log_10(A) > Rg^2/(3 ln 10) - 30
93    q_max = 1.0
94    rg_max = np.sqrt(90*np.log(10) + 3*np.log(scale))/q_max
95    rg = 10**np.random.uniform(0, np.log10(rg_max))
96    pars = dict(
97        #background=0,
98        scale=scale,
99        rg=rg,
100    )
101    return pars
102
103# parameters for demo
104demo = dict(scale=1.0, background=0.001, rg=60.0)
105
106# parameters for unit tests
107tests = [[{'rg' : 31.5}, 0.005, 0.992756]]
Note: See TracBrowser for help on using the repository browser.