# source:sasmodels/sasmodels/models/binary_hard_sphere.py@0507e09

core_shell_microgelsmagnetic_modelticket-1257-vesicle-productticket_1156ticket_1265_superballticket_822_more_unit_tests
Last change on this file since 0507e09 was 0507e09, checked in by smk78, 6 months ago

• Property mode set to 100644
File size: 5.5 KB
Line
1r"""
2Definition
3----------
4
5The binary hard sphere model provides the scattering intensity, for binary
6mixture of hard spheres including hard sphere interaction between those
7particles, using rhw Percus-Yevick closure. The calculation is an exact
8multi-component solution that properly accounts for the 3 partial structure
9factors as follows:
10
11.. math::
12
13    I(q) = (1-x)f_1^2(q) S_{11}(q) + 2[x(1-x)]^{1/2} f_1(q)f_2(q)S_{12}(q) +
14    x\,f_2^2(q)S_{22}(q)
15
16where $S_{ij}$ are the partial structure factors and $f_i$ are the scattering
17amplitudes of the particles. The subscript 1 is for the smaller particle and 2
18is for the larger. The number fraction of the larger particle,
19($x = n2/(n1+n2)$, where $n$ = the number density) is internally calculated
20based on the diameter ratio and the volume fractions.
21
22.. math::
23    :nowrap:
24
25    \begin{align*}
26    x &= \frac{(\phi_2 / \phi)\alpha^3}{(1-(\phi_2/\phi) + (\phi_2/\phi)
27    \alpha^3)} \\
28    \phi &= \phi_1 + \phi_2 = \text{total volume fraction} \\
29    \alpha &= R_1/R_2 = \text{size ratio}
30    \end{align*}
31
32The 2D scattering intensity is the same as 1D, regardless of the orientation of
33the *q* vector which is defined as
34
35.. math::
36
37    q = \sqrt{q_x^2 + q_y^2}
38
39
40**NOTE 1:** The volume fractions and the scattering contrasts are loosely
41correlated, so holding as many parameters fixed to known values during fitting
42will improve the robustness of the fit.
43
44**NOTE 2:** Since the calculation uses the Percus-Yevick closure, all of the
45limitations of that closure relation apply here. Specifically, one should be
46wary of results for (total) volume fractions greater than approximately 40%.
47Depending on the size ratios or number fractions, the limit on total volume
48fraction may be lower.
49
50**NOTE 3:** The heavy arithmatic operations also mean that at present the
51function is poorly behaved at very low qr.  In some cases very large qr may
52also be poorly behaved.  These should however be outside any useful region of
53qr.
54
55The code for this model is based originally on a c-library implementation by the
56NIST Center for Neutron Research (Kline, 2006).
57
58See the references for details.
59
60References
61----------
62
63.. [#] N W Ashcroft and D C Langreth, *Physical Review*, 156 (1967) 685-692
64   [Errata found in *Phys. Rev.* 166 (1968) 934]
65.. [#] S R Kline, *J Appl. Cryst.*, 39 (2006) 895
66
67Source
68------
69
70binary_hard_sphere.py <https://github.com/SasView/sasmodels/blob/master/sasmodels/models/binary_hard_sphere.py>_
71
72binary_hard_sphere.c <https://github.com/SasView/sasmodels/blob/master/sasmodels/models/binary_hard_sphere.c>_
73
74Authorship and Verification
75----------------------------
76
77* **Author:** NIST IGOR/DANSE **Date:** pre 2010
79* **Last Reviewed by:** Paul Butler **Date:** March 20, 2016
80* **Source added by :** Steve King **Date:** March 25, 2019
81"""
82
83import numpy as np
84from numpy import inf
85
86category = "shape:sphere"
87single = False  # double precision only!
88
89name = "binary_hard_sphere"
90title = "binary mixture of hard spheres with hard sphere interactions."
91description = """Describes the scattering from a mixture of two distinct
92monodisperse, hard sphere particles.
93        [Parameters];
96        volfraction_lg: volume fraction of large spheres,
97        volfraction_sm: volume fraction of small spheres,
98        sld_lg: large sphere  scattering length density,
99        sld_sm: small sphere scattering length density,
100        sld_solvent: solvent scattering length density.
101"""
102#             ["name", "units", default, [lower, upper], "type", "description"],
103parameters = [["radius_lg", "Ang", 100, [0, inf], "",
105              ["radius_sm", "Ang", 25, [0, inf], "",
107              ["volfraction_lg", "", 0.1, [0, 1], "",
108               "volume fraction of large particle"],
109              ["volfraction_sm", "", 0.2, [0, 1], "",
110               "volume fraction of small particle"],
111              ["sld_lg", "1e-6/Ang^2", 3.5, [-inf, inf], "sld",
112               "scattering length density of large particle"],
113              ["sld_sm", "1e-6/Ang^2", 0.5, [-inf, inf], "sld",
114               "scattering length density of small particle"],
115              ["sld_solvent", "1e-6/Ang^2", 6.36, [-inf, inf], "sld",
116               "Solvent scattering length density"],
117             ]
118
119source = ["lib/sas_3j1x_x.c", "binary_hard_sphere.c"]
120
121def random():
122    """Return a random parameter set for the model."""
123    # TODO: binary_hard_sphere fails at low qr
126    volfraction_lg = 10**np.random.uniform(-3, -0.3)
127    volfraction_sm = 10**np.random.uniform(-3, -0.3)
128    # TODO: Get slightly different results if large and small are swapped
129    # modify the model so it doesn't care which is which
132        volfraction_lg, volfraction_sm = volfraction_sm, volfraction_lg
133    pars = dict(