source: sasmodels/sasmodels/models/unified_power_Rg.py @ 58c3367

core_shell_microgelscostrafo411magnetic_modelrelease_v0.94release_v0.95ticket-1257-vesicle-productticket_1156ticket_1265_superballticket_822_more_unit_tests
Last change on this file since 58c3367 was eb574d7, checked in by ajj, 8 years ago

Fixed docstring for unified_power_Rg

Closes #631

  • Property mode set to 100644
File size: 3.1 KB
RevLine 
[263daec]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
[948db69]10.. math::
[263daec]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
[948db69]18The empirical fit function is:
[263daec]19
[948db69]20.. math::
[263daec]21
22    I(q) = \text{background}
[eb574d7]23    + \sum_{i=1}^N \Bigl[
24        G_i \exp\Bigl(-\frac{q^2R_{gi}^2}{3}\Bigr)
25       + B_i \exp\Bigl(-\frac{q^2R_{g(i+1)}^2}{3}\Bigr)
26             \Bigl(\frac{1}{q_i^*}\Bigr)^{P_i} \Bigr]
[263daec]27
28where
29
[948db69]30.. math::
[263daec]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
[40a87fa]39For example, to approximate the scattering from random coils (Debye equation),
[263daec]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
[948db69]47.. math::
[263daec]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
[2c74c11]64from numpy import inf, exp, sqrt, errstate
[263daec]65from scipy.special import erf
66
[40a87fa]67category = "shape-independent"
[948db69]68name = "unified_power_Rg"
69title = "Unified Power Rg"
70description = """
71        The Beaucage model employs the empirical multiple level unified
72        Exponential/Power-law fit method developed by G. Beaucage. Four functions
73        are included so that 1, 2, 3, or 4 levels can be used.
74        """
[40a87fa]75
76# pylint: disable=bad-whitespace, line-too-long
[263daec]77parameters = [
78    ["level",     "",     1,      [0, 6], "", "Level number"],
[42356c8]79    ["rg[level]", "Ang",  15.8,   [0, inf], "", "Radius of gyration"],
[263daec]80    ["power[level]", "",  4,      [-inf, inf], "", "Power"],
81    ["B[level]",  "1/cm", 4.5e-6, [-inf, inf], "", ""],
82    ["G[level]",  "1/cm", 400,    [0, inf], "", ""],
83    ]
[40a87fa]84# pylint: enable=bad-whitespace, line-too-long
[263daec]85
[42356c8]86def Iq(q, level, rg, power, B, G):
[263daec]87    ilevel = int(level)
88    if ilevel == 0:
[2c74c11]89        with errstate(divide='ignore'):
90            return 1./q
91
92    with errstate(divide='ignore', invalid='ignore'):
[ec77322]93        result = np.zeros(q.shape, 'd')
[2c74c11]94        for i in range(ilevel):
95            exp_now = exp(-(q*rg[i])**2/3.)
96            pow_now = (erf(q*rg[i]/sqrt(6.))**3/q)**power[i]
97            exp_next = exp(-(q*rg[i+1])**2/3.) if i < ilevel-1 else 1.
98            result += G[i]*exp_now + B[i]*exp_next*pow_now
[40a87fa]99    result[q == 0] = np.sum(G[:ilevel])
[263daec]100    return result
[2c74c11]101
[263daec]102Iq.vectorized = True
103
104demo = dict(
105    level=2,
[42356c8]106    rg=[15.8, 21],
[263daec]107    power=[4, 2],
108    B=[4.5e-6, 0.0006],
109    G=[400, 3],
110    scale=1.,
111    background=0.,
[40a87fa]112)
Note: See TracBrowser for help on using the repository browser.