source: sasmodels/sasmodels/models/binary_hard_sphere.py @ 115d0f0

core_shell_microgelscostrafo411magnetic_modelrelease_v0.94release_v0.95ticket-1257-vesicle-productticket_1156ticket_1265_superballticket_822_more_unit_tests
Last change on this file since 115d0f0 was 115d0f0, checked in by butler, 8 years ago

conversion of binary hard sphere model. Note that the model is badly
behaved at low (and sometimes high) qr. It may be possible to improve
on this by working on the calculations of the partial structure factors
sf11, sf12, sf22 which are a mass of arithmatic at present. However the
instability is outside the normal useful range. SasView? sasmodels and
samsmodels package do not agree well (delta of 1 or 2) outside the
"good" range.

  • Property mode set to 100644
File size: 4.7 KB
Line 
1r"""
2
3The binary hard sphere model provides the scattering intensity, for binary
4mixture of hard spheres including hard sphere interaction between those
5particles, using rhw Percus-Yevick closure. The calculation is an exact
6multi-component solution that properly accounts for the 3 partial structure
7factors.
8
9Definition
10----------
11
12.. math::
13
14    \begin{eqnarray}
15    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) + \\
16    x\,f_2^2(q)S_{22}(q) \\
17    \end{eqnarray}
18
19where $S_{ij}$ are the partial structure factors and $f_i$ are the scattering
20amplitudes of the particles. The subscript 1 is for the smaller particle and 2
21is for the larger. The number fraction of the larger particle,
22($x = n2/(n1+n2)$, where $n$ = the number density) is internally calculated
23based on the diameter ratio and the volume fractions.
24
25.. math::
26
27    \begin{eqnarray}
28    x &=& \frac{(\phi_2 / \phi)\alpha^3}{(1-(\phi_2/\phi) + (\phi_2/\phi) \\
29    \alpha^3)} \phi &=& \phi_1 + \phi_2 = \text{total volume fraction} \\
30    \alpha &=& R_1/R_2 = \text{size ratio}
31    \end{eqnarray}
32
33The 2D scattering intensity is the same as 1D, regardless of the orientation of
34the *q* vector which is defined as
35
36.. math::
37
38    q = \sqrt{q_x^2 + q_y^2}
39
40
41**NOTE 1:** The volume fractions and the scattering contrasts are loosely
42correlated, so holding as many parameters fixed to known values during fitting
43will improve the robustness of the fit.
44
45**NOTE 2:** Since the calculation uses the Percus-Yevick closure, all of the
46limitations of that closure relation apply here. Specifically, one should be
47wary of results for (total) volume fractions greater than approximately 40%.
48Depending on the size ratios or number fractions, the limit on total volume
49fraction may be lower.
50
51**NOTE 3:** The heavy arithmatic operations also mean that at present the
52function is poorly behaved at very low qr.  In some cases very large qr may
53also be poorly behaved.  These should however be outside any useful region of
54qr.
55
56The code for this model is based originally on a c-library implementation by the
57NIST Center for Neutron Research (Kline, 2006).
58
59See the references for details.
60
61References
62----------
63
64N W Ashcroft and D C Langreth, *Physical Review*, 156 (1967) 685-692
65[Errata found in *Phys. Rev.* 166 (1968) 934]
66
67S R Kline, *J Appl. Cryst.*, 39 (2006) 895
68
69**Author:** N/A **on:**
70
71**Modified by:** Paul Butler **on:** March 18, 2016
72
73**Reviewed by:** Paul Butler **on:** March 18, 2016
74"""
75
76import numpy as np
77from numpy import pi, inf
78
79name = "binary_hard_sphere"
80title = "binary mixture of hard spheres with hard sphere interactions."
81description = """Describes the scattering from a mixture of two distinct
82monodisperse, hard sphere particles.
83        [Parameters];
84        radius_lg: large radius of binary hard sphere,
85        radius_sm: small radius of binary hard sphere,
86        volfraction_lg: volume fraction of large spheres,
87        volfraction_sm: volume fraction of small spheres,
88        sld_lg: large sphere  scattering length density,
89        sld_sm: small sphere scattering length density,
90        sld_solvent: solvent scattering length density.
91"""
92category = "shape:sphere"
93
94#             ["name", "units", default, [lower, upper], "type", "description"],
95parameters = [["radius_lg", "Ang", 100, [0, inf], "",
96               "radius of large particle"],
97              ["radius_sm", "Ang", 25, [0, inf], "",
98               "radius of small particle"],
99              ["volfraction_lg", "", 0.1, [0, 1], "",
100               "volume fraction of large particle"],
101              ["volfraction_sm", "", 0.2, [0, 1], "",
102               "volume fraction of small particle"],
103              ["sld_lg", "1e-6/Ang^2", 3.5, [-inf, inf], "",
104               "scattering length density of large particle"],
105              ["sld_sm", "1e-6/Ang^2", 0.5, [-inf, inf], "",
106               "scattering length density of small particle"],
107              ["sld_solvent", "1e-6/Ang^2", 6.36, [-inf, inf], "",
108               "Solvent scattering length density"],
109             ]
110
111source = ["lib/sph_j1c.c", "binary_hard_sphere.c"]
112
113# parameters for demo and documentation
114demo = dict(scale=1, background=0,
115            sld_lg=3.5, sld_sm=0.5, sld_solvent=6.36,
116            radius_lg=100, radius_sm=20,
117            volfraction_lg=0.1, volfraction_sm=0.2)
118
119# For testing against the old sasview models, include the converted parameter
120# names and the target sasview model name.
121oldname = 'BinaryHSModel'
122oldpars = dict(volfraction_lg='vol_frac_ls', volfraction_sm='vol_frac_ss',
123               sld_lg='ls_sld', sld_sm='ss_sld', sld_solvent='solvent_sld',
124               radius_lg='l_radius', radius_sm='s_radius')
125
126# NOTE: test results taken from values returned by SasView 3.1.2
127tests = [[{'scale':1.0}, 0.001, 25.8927262013]]
128
Note: See TracBrowser for help on using the repository browser.