source: sasmodels/sasmodels/models/fuzzy_sphere.py @ 71b751d

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

update remaining form factors to use Fq interface

  • Property mode set to 100644
File size: 4.3 KB
Line 
1r"""
2For information about polarised and magnetic scattering, see
3the :ref:`magnetism` documentation.
4
5Definition
6----------
7
8The scattering intensity $I(q)$ is calculated as:
9
10.. math::
11
12    I(q) = \frac{\text{scale}}{V}(\Delta \rho)^2 A^2(q) S(q)
13           + \text{background}
14
15
16where the amplitude $A(q)$ is given as the typical sphere scattering convoluted
17with a Gaussian to get a gradual drop-off in the scattering length density:
18
19.. math::
20
21    A(q) = \frac{3\left[\sin(qR) - qR \cos(qR)\right]}{(qR)^3}
22           \exp\left(\frac{-(\sigma_\text{fuzzy}q)^2}{2}\right)
23
24Here $A(q)^2$ is the form factor, $P(q)$. The scale is equivalent to the
25volume fraction of spheres, each of volume, $V$. Contrast $(\Delta \rho)$
26is the difference of scattering length densities of the sphere and the
27surrounding solvent.
28
29Poly-dispersion in radius and in fuzziness is provided for, though the
30fuzziness must be kept much smaller than the sphere radius for meaningful
31results.
32
33From the reference:
34
35  The "fuzziness" of the interface is defined by the parameter
36  $\sigma_\text{fuzzy}$. The particle radius $R$ represents the radius of the
37  particle where the scattering length density profile decreased to 1/2 of the
38  core density. $\sigma_\text{fuzzy}$ is the width of the smeared particle
39  surface; i.e., the standard deviation from the average height of the fuzzy
40  interface. The inner regions of the microgel that display a higher density
41  are described by the radial box profile extending to a radius of
42  approximately $R_\text{box} \sim R - 2 \sigma$. The profile approaches
43  zero as $R_\text{sans} \sim R + 2\sigma$.
44
45For 2D data: The 2D scattering intensity is calculated in the same way as 1D,
46where the $q$ vector is defined as
47
48.. math:: q = \sqrt{{q_x}^2 + {q_y}^2}
49
50References
51----------
52
53M Stieger, J. S Pedersen, P Lindner, W Richtering, *Langmuir*,
5420 (2004) 7283-7292
55"""
56
57import numpy as np
58from numpy import inf
59
60name = "fuzzy_sphere"
61title = "Scattering from spherical particles with a fuzzy surface."
62description = """\
63scale: scale factor times volume fraction,
64or just volume fraction for absolute scale data
65radius: radius of the solid sphere
66fuzziness = the standard deviation of the fuzzy interfacial
67thickness (ie., so-called interfacial roughness)
68sld: the SLD of the sphere
69solvend_sld: the SLD of the solvent
70background: incoherent background
71Note: By definition, this function works only when fuzziness << radius.
72"""
73category = "shape:sphere"
74
75# pylint: disable=bad-whitespace,line-too-long
76# ["name", "units", default, [lower, upper], "type","description"],
77parameters = [["sld",         "1e-6/Ang^2",  1, [-inf, inf], "sld",    "Particle scattering length density"],
78              ["sld_solvent", "1e-6/Ang^2",  3, [-inf, inf], "sld",    "Solvent scattering length density"],
79              ["radius",      "Ang",        60, [0, inf],    "volume", "Sphere radius"],
80              ["fuzziness",   "Ang",        10, [0, inf],    "",       "std deviation of Gaussian convolution for interface (must be << radius)"],
81             ]
82# pylint: enable=bad-whitespace,line-too-long
83
84source = ["lib/sas_3j1x_x.c"]
85have_Fq = True
86
87c_code = """
88static double form_volume(double radius)
89{
90    return M_4PI_3*cube(radius);
91}
92
93static void Fq(double q, double *F1, double *F2, double sld, double sld_solvent,
94               double radius, double fuzziness)
95{
96    const double qr = q*radius;
97    const double bes = sas_3j1x_x(qr);
98    const double qf = exp(-0.5*square(q*fuzziness));
99    const double contrast = (sld - sld_solvent);
100    const double form = contrast * form_volume(radius) * bes * qf;
101    *F1 = 1.0e-2*form;
102    *F2 = 1.0e-4*form*form;
103}
104"""
105
106def ER(radius):
107    """
108    Return radius
109    """
110    return radius
111
112# VR defaults to 1.0
113
114def random():
115    radius = 10**np.random.uniform(1, 4.7)
116    fuzziness = 10**np.random.uniform(-2, -0.5)*radius  # 1% to 31% fuzziness
117    pars = dict(
118        radius=radius,
119        fuzziness=fuzziness,
120    )
121    return pars
122
123demo = dict(scale=1, background=0.001,
124            sld=1, sld_solvent=3,
125            radius=60,
126            fuzziness=10,
127            radius_pd=.2, radius_pd_n=45,
128            fuzziness_pd=.2, fuzziness_pd_n=0)
129
130tests = [
131    # Accuracy tests based on content in test/utest_models_new1_3.py
132    #[{'background': 0.001}, 1.0, 0.001],
133
134    [{}, 0.00301005, 359.2315],
135
136    ]
Note: See TracBrowser for help on using the repository browser.