source: sasmodels/sasmodels/models/unified_power_Rg.py @ 3f853beb

core_shell_microgelscostrafo411magnetic_modelticket-1257-vesicle-productticket_1156ticket_1265_superballticket_822_more_unit_tests
Last change on this file since 3f853beb was c3ccaec, checked in by GitHub <noreply@…>, 7 years ago

Merge branch 'master' into ticket-815

  • Property mode set to 100644
File size: 3.7 KB
RevLine 
[263daec]1r"""
2Definition
3----------
4
[6431056]5This model employs the empirical multiple level unified Exponential/Power-law
6fit method developed by Beaucage. Four functions are included so that 1, 2, 3,
7or 4 levels can be used. In addition a 0 level has been added which simply
8calculates
[263daec]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
[cdcebf1]18The model works best for mass fractal systems characterized by Porod exponents
19between 5/3 and 3. It should not be used for surface fractal systems. Hammouda
[6431056]20(2010) has pointed out a deficiency in the way this model handles the
21transitioning between the Guinier and Porod regimes and which can create
22artefacts that appear as kinks in the fitted model function.
23
24Also see the Guinier_Porod model.
25
[948db69]26The empirical fit function is:
[263daec]27
[948db69]28.. math::
[263daec]29
30    I(q) = \text{background}
[eb574d7]31    + \sum_{i=1}^N \Bigl[
32        G_i \exp\Bigl(-\frac{q^2R_{gi}^2}{3}\Bigr)
33       + B_i \exp\Bigl(-\frac{q^2R_{g(i+1)}^2}{3}\Bigr)
34             \Bigl(\frac{1}{q_i^*}\Bigr)^{P_i} \Bigr]
[263daec]35
36where
37
[948db69]38.. math::
[263daec]39
[66ca2a6]40    q_i^* = q \left[\operatorname{erf}
41            \left(\frac{q R_{gi}}{\sqrt{6}}\right)
42        \right]^{-3}
[263daec]43
44
45For each level, the four parameters $G_i$, $R_{gi}$, $B_i$ and $P_i$ must
46be chosen.  Beaucage has an additional factor $k$ in the definition of
47$q_i^*$ which is ignored here.
48
[40a87fa]49For example, to approximate the scattering from random coils (Debye equation),
[263daec]50set $R_{gi}$ as the Guinier radius, $P_i = 2$, and $B_i = 2 G_i / R_{gi}$
51
52See the references for further information on choosing the parameters.
53
54For 2D data: The 2D scattering intensity is calculated in the same way as 1D,
55where the $q$ vector is defined as
56
[948db69]57.. math::
[263daec]58
59    q = \sqrt{q_x^2 + q_y^2}
60
61
62References
63----------
64
65G Beaucage, *J. Appl. Cryst.*, 28 (1995) 717-728
66
67G Beaucage, *J. Appl. Cryst.*, 29 (1996) 134-146
68
[cdcebf1]69B Hammouda, *Analysis of the Beaucage model, J. Appl. Cryst.*, (2010), 43, 1474-1478
[6431056]70
[263daec]71"""
72
73from __future__ import division
74
75import numpy as np
[2c74c11]76from numpy import inf, exp, sqrt, errstate
[263daec]77from scipy.special import erf
78
[40a87fa]79category = "shape-independent"
[948db69]80name = "unified_power_Rg"
81title = "Unified Power Rg"
82description = """
83        The Beaucage model employs the empirical multiple level unified
84        Exponential/Power-law fit method developed by G. Beaucage. Four functions
85        are included so that 1, 2, 3, or 4 levels can be used.
86        """
[40a87fa]87
88# pylint: disable=bad-whitespace, line-too-long
[263daec]89parameters = [
90    ["level",     "",     1,      [0, 6], "", "Level number"],
[42356c8]91    ["rg[level]", "Ang",  15.8,   [0, inf], "", "Radius of gyration"],
[263daec]92    ["power[level]", "",  4,      [-inf, inf], "", "Power"],
93    ["B[level]",  "1/cm", 4.5e-6, [-inf, inf], "", ""],
94    ["G[level]",  "1/cm", 400,    [0, inf], "", ""],
95    ]
[40a87fa]96# pylint: enable=bad-whitespace, line-too-long
[263daec]97
[42356c8]98def Iq(q, level, rg, power, B, G):
[0542fe1]99    level = int(level + 0.5)
100    if level == 0:
[2c74c11]101        with errstate(divide='ignore'):
102            return 1./q
103
104    with errstate(divide='ignore', invalid='ignore'):
[ec77322]105        result = np.zeros(q.shape, 'd')
[0542fe1]106        for i in range(level):
[2c74c11]107            exp_now = exp(-(q*rg[i])**2/3.)
108            pow_now = (erf(q*rg[i]/sqrt(6.))**3/q)**power[i]
[0542fe1]109            if i < level-1:
[b3f2a24]110                exp_next = exp(-(q*rg[i+1])**2/3.)
111            else:
112                exp_next = 1
[2c74c11]113            result += G[i]*exp_now + B[i]*exp_next*pow_now
[b3f2a24]114
[0542fe1]115    result[q == 0] = np.sum(G[:level])
[263daec]116    return result
[2c74c11]117
[263daec]118Iq.vectorized = True
119
120demo = dict(
121    level=2,
[42356c8]122    rg=[15.8, 21],
[263daec]123    power=[4, 2],
124    B=[4.5e-6, 0.0006],
125    G=[400, 3],
126    scale=1.,
127    background=0.,
[40a87fa]128)
Note: See TracBrowser for help on using the repository browser.