source: sasmodels/sasmodels/models/squarewell.py @ 0d5dc05

Last change on this file since 0d5dc05 was 0d5dc05, checked in by GitHub <noreply@…>, 5 years ago

Merge branch 'master' into ticket-1263-source-link

  • Property mode set to 100644
File size: 5.1 KB
Line 
1# Note: model title and parameter table are inserted automatically
2r"""
3Calculates the interparticle structure factor for a hard sphere fluid
4with a narrow, attractive, square well potential. **The Mean Spherical
5Approximation (MSA) closure relationship is used, but it is not the most
6appropriate closure for an attractive interparticle potential.** However,
7the solution has been compared to Monte Carlo simulations for a square
8well fluid and these show the MSA calculation to be limited to well
9depths $\epsilon < 1.5$ kT and volume fractions $\phi < 0.08$.
10
11Positive well depths correspond to an attractive potential well. Negative
12well depths correspond to a potential "shoulder", which may or may not be
13physically reasonable. The :ref:`stickyhardsphere` model may be a better
14choice in some circumstances.
15
16Computed values may behave badly at extremely small $qR$.
17
18.. note::
19
20   Earlier versions of SasView did not incorporate the so-called
21   $\beta(q)$ ("beta") correction [2] for polydispersity and non-sphericity.
22   This is only available in SasView versions 5.0 and higher.
23
24The well width $(\lambda)$ is defined as multiples of the particle diameter
25$(2 R)$.
26
27The interaction potential is:
28
29.. math::
30
31    U(r) = \begin{cases}
32    \infty & r < 2R \\
33    -\epsilon & 2R \leq r < 2R\lambda \\
34    0 & r \geq 2R\lambda
35    \end{cases}
36
37where $r$ is the distance from the center of a sphere of a radius $R$.
38
39In SasView the effective radius may be calculated from the parameters
40used in the form factor $P(q)$ that this $S(q)$ is combined with.
41
42For 2D data: The 2D scattering intensity is calculated in the same way as 1D,
43where the $q$ vector is defined as
44
45.. math::
46
47    q = \sqrt{q_x^2 + q_y^2}
48
49References
50----------
51
52.. [#] R V Sharma, K C Sharma, *Physica*, 89A (1977) 213
53
54.. [#] M Kotlarchyk and S-H Chen, *J. Chem. Phys.*, 79 (1983) 2461-2469
55
56Authorship and Verification
57----------------------------
58
59* **Author:**
60* **Last Modified by:**
61* **Last Reviewed by:** Steve King **Date:** March 27, 2019
62"""
63
64import numpy as np
65from numpy import inf
66
67name = "squarewell"
68title = "Square well structure factor with Mean Spherical Approximation closure"
69description = """\
70    [Square well structure factor, with MSA closure]
71        Interparticle structure factor S(Q) for a hard sphere fluid
72    with a narrow attractive well. Fits are prone to deliver non-
73    physical parameters; use with care and read the references in
74    the model documentation.The "beta(q)" correction is available
75    in versions 4.2.2 and higher.
76"""
77category = "structure-factor"
78structure_factor = True
79single = False
80
81#single = False
82#             ["name", "units", default, [lower, upper], "type","description"],
83parameters = [
84    #   [ "name", "units", default, [lower, upper], "type",
85    #     "description" ],
86    ["radius_effective", "Ang", 50.0, [0, inf], "volume",
87     "effective radius of hard sphere"],
88    ["volfraction", "", 0.04, [0, 0.08], "",
89     "volume fraction of spheres"],
90    ["welldepth", "kT", 1.5, [0.0, 1.5], "",
91     "depth of well, epsilon"],
92    ["wellwidth", "diameters", 1.2, [1.0, inf], "",
93     "width of well in diameters (=2R) units, must be > 1"],
94    ]
95
96# No volume normalization despite having a volume parameter
97# This should perhaps be volume normalized?
98form_volume = """
99    return 1.0;
100    """
101
102Iq = """
103// single precision is very poor at extreme small Q, would need a Taylor series
104        double req,phis,edibkb,lambda,struc;
105        double sigma,eta,eta2,eta3,eta4,etam1,etam14,alpha,beta,gamm;
106        double x,sk,sk2,sk3,sk4,t1,t2,t3,t4,ck;
107        double S,C,SL,CL;
108        x= q;
109
110        req = radius_effective;
111        phis = volfraction;
112        edibkb = welldepth;
113        lambda = wellwidth;
114
115        sigma = req*2.;
116        eta = phis;
117        eta2 = eta*eta;
118        eta3 = eta*eta2;
119        eta4 = eta*eta3;
120        etam1 = 1. - eta;
121        etam14 = etam1*etam1*etam1*etam1;
122        // temp borrow sk for an intermediate calc
123        sk = 1.0 +2.0*eta;
124        sk *= sk;
125        alpha = (  sk + eta3*( eta-4.0 )  )/etam14;
126        beta = -(eta/3.0) * ( 18. + 20.*eta - 12.*eta2 + eta4 )/etam14;
127        gamm = 0.5*eta*( sk + eta3*(eta-4.) )/etam14;
128
129        //  calculate the structure factor
130
131        sk = x*sigma;
132        sk2 = sk*sk;
133        sk3 = sk*sk2;
134        sk4 = sk3*sk;
135        SINCOS(sk,S,C);
136        SINCOS(lambda*sk,SL,CL);
137        t1 = alpha * sk3 * ( S - sk * C );
138        t2 = beta * sk2 * 2.0*( sk*S - (0.5*sk2 - 1.)*C - 1.0 );
139        t3 = gamm*( ( 4.0*sk3 - 24.*sk ) * S - ( sk4 - 12.0*sk2 + 24.0 )*C + 24.0 );
140        t4 = -edibkb*sk3*(SL +sk*(C - lambda*CL) - S );
141        ck =  -24.0*eta*( t1 + t2 + t3 + t4 )/sk3/sk3;
142        struc  = 1./(1.-ck);
143
144        return(struc);
145"""
146
147def random():
148    """Return a random parameter set for the model."""
149    pars = dict(
150        scale=1, background=0,
151        radius_effective=10**np.random.uniform(1, 4.7),
152        volfraction=np.random.uniform(0.00001, 0.08),
153        welldepth=np.random.uniform(0, 1.5),
154        wellwidth=np.random.uniform(1, 1.2),
155    )
156    return pars
157
158demo = dict(radius_effective=50, volfraction=0.04, welldepth=1.5,
159            wellwidth=1.2, radius_effective_pd=0, radius_effective_pd_n=0)
160#
161tests = [
162    [{'scale': 1.0, 'background': 0.0, 'radius_effective': 50.0,
163      'volfraction': 0.04, 'welldepth': 1.5, 'wellwidth': 1.2,
164      'radius_effective_pd': 0}, [0.001], [0.97665742]],
165    ]
166# ADDED by: converting from sasview RKH  ON: 16Mar2016
Note: See TracBrowser for help on using the repository browser.