source: sasmodels/sasmodels/models/unified_power_Rg.py @ 40a87fa

core_shell_microgelscostrafo411magnetic_modelrelease_v0.94release_v0.95ticket-1257-vesicle-productticket_1156ticket_1265_superballticket_822_more_unit_tests
Last change on this file since 40a87fa was 40a87fa, checked in by Paul Kienzle <pkienzle@…>, 8 years ago

lint and latex cleanup

  • Property mode set to 100644
File size: 2.8 KB
Line 
1r"""
2Definition
3----------
4
5The Beaucage model employs the empirical multiple level unified
6Exponential/Power-law fit method developed by G. Beaucage. Four functions
7are included so that 1, 2, 3, or 4 levels can be used. In addition a 0 level
8has been added which simply calculates
9
10.. math:
11
12    I(q) = \text{scale} / q + \text{background}
13
14The Beaucage method is able to reasonably approximate the scattering from
15many different types of particles, including fractal clusters, random coils
16(Debye equation), ellipsoidal particles, etc.
17
18The empirical fit function is (eq 9'):
19
20.. math:
21
22    I(q) = \text{background}
23    + \Sum_{i=1}^N \left[
24        G_i \exp\left(-\frac{q^2R_{gi}^2}{3}\right)
25       + B_i \exp\left(-\frac{q^2R_{g(i+1)}^2}{3}\right)
26             \left(\frac{1}{q_i^*}\right)^{P_i}
27
28where
29
30.. math:
31
32    q_i^* = \frac{q}{\operatorname{erf}^3(q R_{gi}/\sqrt{6}}
33
34
35For each level, the four parameters $G_i$, $R_{gi}$, $B_i$ and $P_i$ must
36be chosen.  Beaucage has an additional factor $k$ in the definition of
37$q_i^*$ which is ignored here.
38
39For example, to approximate the scattering from random coils (Debye equation),
40set $R_{gi}$ as the Guinier radius, $P_i = 2$, and $B_i = 2 G_i / R_{gi}$
41
42See the references for further information on choosing the parameters.
43
44For 2D data: The 2D scattering intensity is calculated in the same way as 1D,
45where the $q$ vector is defined as
46
47.. math:
48
49    q = \sqrt{q_x^2 + q_y^2}
50
51
52References
53----------
54
55G Beaucage, *J. Appl. Cryst.*, 28 (1995) 717-728
56
57G Beaucage, *J. Appl. Cryst.*, 29 (1996) 134-146
58
59"""
60
61from __future__ import division
62
63import numpy as np
64from numpy import inf, exp, sqrt, errstate
65from scipy.special import erf
66
67category = "shape-independent"
68
69# pylint: disable=bad-whitespace, line-too-long
70parameters = [
71    ["level",     "",     1,      [0, 6], "", "Level number"],
72    ["rg[level]", "Ang",  15.8,   [0, inf], "", "Radius of gyration"],
73    ["power[level]", "",  4,      [-inf, inf], "", "Power"],
74    ["B[level]",  "1/cm", 4.5e-6, [-inf, inf], "", ""],
75    ["G[level]",  "1/cm", 400,    [0, inf], "", ""],
76    ]
77# pylint: enable=bad-whitespace, line-too-long
78
79def Iq(q, level, rg, power, B, G):
80    ilevel = int(level)
81    if ilevel == 0:
82        with errstate(divide='ignore'):
83            return 1./q
84
85    with errstate(divide='ignore', invalid='ignore'):
86        result = np.zeros(q.shape, 'd')
87        for i in range(ilevel):
88            exp_now = exp(-(q*rg[i])**2/3.)
89            pow_now = (erf(q*rg[i]/sqrt(6.))**3/q)**power[i]
90            exp_next = exp(-(q*rg[i+1])**2/3.) if i < ilevel-1 else 1.
91            result += G[i]*exp_now + B[i]*exp_next*pow_now
92    result[q == 0] = np.sum(G[:ilevel])
93    return result
94
95Iq.vectorized = True
96
97demo = dict(
98    level=2,
99    rg=[15.8, 21],
100    power=[4, 2],
101    B=[4.5e-6, 0.0006],
102    G=[400, 3],
103    scale=1.,
104    background=0.,
105)
Note: See TracBrowser for help on using the repository browser.