source: sasmodels/sasmodels/models/unified_power_Rg.py @ 42356c8

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

label all sld parameters

  • Property mode set to 100644
File size: 2.5 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
65from scipy.special import erf
66
67parameters = [
68    ["level",     "",     1,      [0, 6], "", "Level number"],
69    ["rg[level]", "Ang",  15.8,   [0, inf], "", "Radius of gyration"],
70    ["power[level]", "",  4,      [-inf, inf], "", "Power"],
71    ["B[level]",  "1/cm", 4.5e-6, [-inf, inf], "", ""],
72    ["G[level]",  "1/cm", 400,    [0, inf], "", ""],
73    ]
74
75def Iq(q, level, rg, power, B, G):
76    ilevel = int(level)
77    if ilevel == 0:
78        return 1./q
79
80    result = np.zeros_like(q)
81    for i in range(ilevel):
82        exp_now = exp(-(q*rg[i])**2/3.)
83        pow_now = (erf(q*rg[i]/sqrt(6.))**3/q)**power[i]
84        exp_next = exp(-(q*rg[i+1])**2/3.) if i < ilevel-1 else 1.
85        result += G[i]*exp_now + B[i]*exp_next*pow_now
86    result[q==0] = np.sum(G[:ilevel])
87    return result
88Iq.vectorized = True
89
90demo = dict(
91    level=2,
92    rg=[15.8, 21],
93    power=[4, 2],
94    B=[4.5e-6, 0.0006],
95    G=[400, 3],
96    scale=1.,
97    background=0.,
98)
Note: See TracBrowser for help on using the repository browser.