source: sasmodels/sasmodels/models/poly_gauss_coil.py @ ef07e95

core_shell_microgelsmagnetic_modelticket-1257-vesicle-productticket_1156ticket_1265_superballticket_822_more_unit_tests
Last change on this file since ef07e95 was 2d81cfe, checked in by Paul Kienzle <pkienzle@…>, 6 years ago

lint

  • Property mode set to 100644
File size: 4.0 KB
Line 
1#poly_gauss_coil model
2#conversion of Poly_GaussCoil.py
3#converted by Steve King, Mar 2016
4r"""
5This empirical model describes the scattering from *polydisperse* polymer
6chains in theta solvents or polymer melts, assuming a Schulz-Zimm type
7molecular weight distribution.
8
9To describe the scattering from *monodisperse* polymer chains, see the
10:ref:`mono-gauss-coil` model.
11
12Definition
13----------
14
15.. math::
16
17     I(q) = \text{scale} \cdot I_0 \cdot P(q) + \text{background}
18
19where
20
21.. math::
22
23     I_0 &= \phi_\text{poly} \cdot V \cdot (\rho_\text{poly}-\rho_\text{solv})^2 \\
24     P(q) &= 2 [(1 + UZ)^{-1/U} + Z - 1] / [(1 + U) Z^2] \\
25     Z &= [(q R_g)^2] / (1 + 2U) \\
26     U &= (Mw / Mn) - 1 = \text{polydispersity ratio} - 1 \\
27     V &= M / (N_A \delta)
28
29Here, $\phi_\text{poly}$, is the volume fraction of polymer, $V$ is the
30volume of a polymer coil, $M$ is the molecular weight of the polymer,
31$N_A$ is Avogadro's Number, $\delta$ is the bulk density of the polymer,
32$\rho_\text{poly}$ is the sld of the polymer, $\rho_\text{solv}$ is the
33sld of the solvent, and $R_g$ is the radius of gyration of the polymer coil.
34
35The 2D scattering intensity is calculated in the same way as the 1D,
36but where the $q$ vector is redefined as
37
38.. math::
39
40    q = \sqrt{q_x^2 + q_y^2}
41
42References
43----------
44
45O Glatter and O Kratky (editors), *Small Angle X-ray Scattering*,
46Academic Press, (1982) Page 404.
47
48J S Higgins, H C Benoit, *Polymers and Neutron Scattering*,
49Oxford Science Publications, (1996).
50
51S M King, *Small Angle Neutron Scattering* in *Modern Techniques for
52Polymer Characterisation*, Wiley, (1999).
53
54http://www.ncnr.nist.gov/staff/hammouda/distance_learning/chapter_28.pdf
55"""
56
57import numpy as np
58from numpy import inf, expm1, power
59
60name = "poly_gauss_coil"
61title = "Scattering from polydisperse polymer coils"
62
63description = """
64    Evaluates the scattering from
65    polydisperse polymer chains.
66    """
67category = "shape-independent"
68
69# pylint: disable=bad-whitespace, line-too-long
70#   ["name", "units", default, [lower, upper], "type", "description"],
71parameters = [
72    ["i_zero",          "1/cm", 70.0, [0.0, inf], "", "Intensity at q=0"],
73    ["rg",  "Ang", 75.0, [0.0, inf], "", "Radius of gyration"],
74    ["polydispersity",  "None",  2.0, [1.0, inf], "", "Polymer Mw/Mn"],
75    ]
76# pylint: enable=bad-whitespace, line-too-long
77
78# NB: Scale and Background are implicit parameters on every model
79def Iq(q, i_zero, rg, polydispersity):
80    # pylint: disable = missing-docstring
81    u = polydispersity - 1.0
82    z = q**2 * (rg**2 / (1.0 + 2.0*u))
83
84    # need to trap the case of the polydispersity being 1 (ie, monodisperse!)
85    if polydispersity == 1.0:
86        result = 2.0 * (expm1(-z) + z)
87        index = q != 0.
88        result[index] /= z[index]**2
89        result[~index] = 1.0
90    else:
91        # Taylor series around z=0 of (2*(1+uz)^(-1/u) + z - 1) / (z^2(u+1))
92        p = [
93            #(-1 - 20*u - 155*u**2 - 580*u**3 - 1044*u**4 - 720*u**5) / 2520.,
94            #(+1 + 14*u + 71*u**2 + 154*u**3 + 120*u**4) / 360.,
95            #(-1 - 9*u - 26*u**2 - 24*u**3) / 60.,
96            (+1 + 5*u + 6*u**2) / 12.,
97            (-1 - 2*u) / 3.,
98            (+1),
99            ]
100        result = 2.0 * (power(1.0 + u*z, -1.0/u) + z - 1.0) / (1.0 + u)
101        index = z > 1e-4
102        result[index] /= z[index]**2
103        result[~index] = np.polyval(p, z[~index])
104    return i_zero * result
105Iq.vectorized = True  # Iq accepts an array of q values
106
107def random():
108    rg = 10**np.random.uniform(0, 4)
109    #rg = 1e3
110    polydispersity = 10**np.random.uniform(0, 3)
111    pars = dict(
112        #scale=1, background=0,
113        i_zero=1e7, # i_zero is a simple scale
114        rg=rg,
115        polydispersity=polydispersity,
116    )
117    return pars
118
119demo = dict(scale=1.0,
120            i_zero=70.0,
121            rg=75.0,
122            polydispersity=2.0,
123            background=0.0)
124
125# these unit test values taken from SasView 3.1.2
126tests = [
127    [{'scale': 1.0, 'i_zero': 70.0, 'rg': 75.0,
128      'polydispersity': 2.0, 'background': 0.0},
129     [0.0106939, 0.469418], [57.6405, 0.169016]],
130    ]
Note: See TracBrowser for help on using the repository browser.