source: sasmodels/sasmodels/models/squarewell.py @ 830cf6b

ticket-1257-vesicle-productticket_1156ticket_822_more_unit_tests
Last change on this file since 830cf6b was db1d9d5, checked in by Paul Kienzle <pkienzle@…>, 5 years ago

merge with master

  • Property mode set to 100644
File size: 5.3 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 4.2.2 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
56Source
57------
58
59`squarewell.py <https://github.com/SasView/sasmodels/blob/master/sasmodels/models/squarewell.py>`_
60
61Authorship and Verification
62----------------------------
63
64* **Author:**
65* **Last Modified by:**
66* **Last Reviewed by:** Steve King **Date:** March 27, 2019
67* **Source added by :** Steve King **Date:** March 25, 2019
68"""
69
70import numpy as np
71from numpy import inf
72
73name = "squarewell"
74title = "Square well structure factor with Mean Spherical Approximation closure"
75description = """\
76    [Square well structure factor, with MSA closure]
77        Interparticle structure factor S(Q) for a hard sphere fluid
78    with a narrow attractive well. Fits are prone to deliver non-
79    physical parameters; use with care and read the references in
80    the model documentation.The "beta(q)" correction is available
81    in versions 4.2.2 and higher.
82"""
83category = "structure-factor"
84structure_factor = True
85single = False
86
87#single = False
88#             ["name", "units", default, [lower, upper], "type","description"],
89parameters = [
90    #   [ "name", "units", default, [lower, upper], "type",
91    #     "description" ],
92    ["radius_effective", "Ang", 50.0, [0, inf], "volume",
93     "effective radius of hard sphere"],
94    ["volfraction", "", 0.04, [0, 0.08], "",
95     "volume fraction of spheres"],
96    ["welldepth", "kT", 1.5, [0.0, 1.5], "",
97     "depth of well, epsilon"],
98    ["wellwidth", "diameters", 1.2, [1.0, inf], "",
99     "width of well in diameters (=2R) units, must be > 1"],
100    ]
101
102# No volume normalization despite having a volume parameter
103# This should perhaps be volume normalized?
104form_volume = """
105    return 1.0;
106    """
107
108Iq = """
109// single precision is very poor at extreme small Q, would need a Taylor series
110        double req,phis,edibkb,lambda,struc;
111        double sigma,eta,eta2,eta3,eta4,etam1,etam14,alpha,beta,gamm;
112        double x,sk,sk2,sk3,sk4,t1,t2,t3,t4,ck;
113        double S,C,SL,CL;
114        x= q;
115
116        req = radius_effective;
117        phis = volfraction;
118        edibkb = welldepth;
119        lambda = wellwidth;
120
121        sigma = req*2.;
122        eta = phis;
123        eta2 = eta*eta;
124        eta3 = eta*eta2;
125        eta4 = eta*eta3;
126        etam1 = 1. - eta;
127        etam14 = etam1*etam1*etam1*etam1;
128        // temp borrow sk for an intermediate calc
129        sk = 1.0 +2.0*eta;
130        sk *= sk;
131        alpha = (  sk + eta3*( eta-4.0 )  )/etam14;
132        beta = -(eta/3.0) * ( 18. + 20.*eta - 12.*eta2 + eta4 )/etam14;
133        gamm = 0.5*eta*( sk + eta3*(eta-4.) )/etam14;
134
135        //  calculate the structure factor
136
137        sk = x*sigma;
138        sk2 = sk*sk;
139        sk3 = sk*sk2;
140        sk4 = sk3*sk;
141        SINCOS(sk,S,C);
142        SINCOS(lambda*sk,SL,CL);
143        t1 = alpha * sk3 * ( S - sk * C );
144        t2 = beta * sk2 * 2.0*( sk*S - (0.5*sk2 - 1.)*C - 1.0 );
145        t3 = gamm*( ( 4.0*sk3 - 24.*sk ) * S - ( sk4 - 12.0*sk2 + 24.0 )*C + 24.0 );
146        t4 = -edibkb*sk3*(SL +sk*(C - lambda*CL) - S );
147        ck =  -24.0*eta*( t1 + t2 + t3 + t4 )/sk3/sk3;
148        struc  = 1./(1.-ck);
149
150        return(struc);
151"""
152
153def random():
154    """Return a random parameter set for the model."""
155    pars = dict(
156        scale=1, background=0,
157        radius_effective=10**np.random.uniform(1, 4.7),
158        volfraction=np.random.uniform(0.00001, 0.08),
159        welldepth=np.random.uniform(0, 1.5),
160        wellwidth=np.random.uniform(1, 1.2),
161    )
162    return pars
163
164demo = dict(radius_effective=50, volfraction=0.04, welldepth=1.5,
165            wellwidth=1.2, radius_effective_pd=0, radius_effective_pd_n=0)
166#
167tests = [
168    [{'scale': 1.0, 'background': 0.0, 'radius_effective': 50.0,
169      'volfraction': 0.04, 'welldepth': 1.5, 'wellwidth': 1.2,
170      'radius_effective_pd': 0}, [0.001], [0.97665742]],
171    ]
172# ADDED by: converting from sasview RKH  ON: 16Mar2016
Note: See TracBrowser for help on using the repository browser.