source: sasmodels/sasmodels/models/squarewell.py @ 3330bb4

core_shell_microgelscostrafo411magnetic_modelticket-1257-vesicle-productticket_1156ticket_1265_superballticket_822_more_unit_tests
Last change on this file since 3330bb4 was 3330bb4, checked in by ajj, 7 years ago

Normalise line endings

  • Property mode set to 100644
File size: 4.4 KB
Line 
1# Note: model title and parameter table are inserted automatically
2r"""
3This calculates the interparticle structure factor for a square well fluid
4spherical particles. The mean spherical approximation (MSA) closure was
5used for this calculation, and is not the most appropriate closure for
6an attractive interparticle potential. This solution has been compared
7to Monte Carlo simulations for a square well fluid, showing this calculation
8to be limited in applicability to well depths $\epsilon < 1.5$ kT and
9volume 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 stickyhardsphere model may be a better choice in
14some circumstances. Computed values may behave badly at extremely small $qR$.
15
16The well width $(\lambda)$ is defined as multiples of the particle diameter
17$(2 R)$.
18
19The interaction potential is:
20
21  .. image:: img/squarewell.png
22
23.. math::
24
25    U(r) = \begin{cases}
26    \infty & r < 2R \\
27    -\epsilon & 2R \leq r < 2R\lambda \\
28    0 & r \geq 2R\lambda
29    \end{cases}
30
31where $r$ is the distance from the center of the sphere of a radius $R$.
32
33In sasview the effective radius may be calculated from the parameters
34used in the form factor $P(q)$ that this $S(q)$ is combined with.
35
36For 2D data: The 2D scattering intensity is calculated in the same way as 1D,
37where the $q$ vector is defined as
38
39.. math::
40
41    q = \sqrt{q_x^2 + q_y^2}
42
43References
44----------
45
46R V Sharma, K C Sharma, *Physica*, 89A (1977) 213.
47
48"""
49from numpy import inf
50
51name = "squarewell"
52title = "Square well structure factor, with MSA closure"
53description = """\
54    [Square well structure factor, with MSA closure]
55        Interparticle structure factor S(Q)for a hard sphere fluid with
56        a narrow attractive well. Fits are prone to deliver non-physical
57        parameters, use with care and read the references in the full manual.
58        In sasview the effective radius will be calculated from the
59        parameters used in P(Q).
60"""
61category = "structure-factor"
62structure_factor = True
63single = False
64
65#single = False
66#             ["name", "units", default, [lower, upper], "type","description"],
67parameters = [
68    #   [ "name", "units", default, [lower, upper], "type",
69    #     "description" ],
70    ["radius_effective", "Ang", 50.0, [0, inf], "volume",
71     "effective radius of hard sphere"],
72    ["volfraction", "", 0.04, [0, 0.08], "",
73     "volume fraction of spheres"],
74    ["welldepth", "kT", 1.5, [0.0, 1.5], "",
75     "depth of well, epsilon"],
76    ["wellwidth", "diameters", 1.2, [1.0, inf], "",
77     "width of well in diameters (=2R) units, must be > 1"],
78    ]
79
80# No volume normalization despite having a volume parameter
81# This should perhaps be volume normalized?
82form_volume = """
83    return 1.0;
84    """
85
86Iq = """
87// single precision is very poor at extreme small Q, would need a Taylor series
88        double req,phis,edibkb,lambda,struc;
89        double sigma,eta,eta2,eta3,eta4,etam1,etam14,alpha,beta,gamm;
90        double x,sk,sk2,sk3,sk4,t1,t2,t3,t4,ck;
91        double S,C,SL,CL;
92        x= q;
93       
94        req = radius_effective;
95        phis = volfraction;
96        edibkb = welldepth;
97        lambda = wellwidth;
98       
99        sigma = req*2.;
100        eta = phis;
101        eta2 = eta*eta;
102        eta3 = eta*eta2;
103        eta4 = eta*eta3;
104        etam1 = 1. - eta;
105        etam14 = etam1*etam1*etam1*etam1;
106        // temp borrow sk for an intermediate calc
107        sk = 1.0 +2.0*eta;
108        sk *= sk;
109        alpha = (  sk + eta3*( eta-4.0 )  )/etam14;
110        beta = -(eta/3.0) * ( 18. + 20.*eta - 12.*eta2 + eta4 )/etam14;
111        gamm = 0.5*eta*( sk + eta3*(eta-4.) )/etam14;
112       
113        //  calculate the structure factor
114       
115        sk = x*sigma;
116        sk2 = sk*sk;
117        sk3 = sk*sk2;
118        sk4 = sk3*sk;
119        SINCOS(sk,S,C);
120        SINCOS(lambda*sk,SL,CL);
121        t1 = alpha * sk3 * ( S - sk * C );
122        t2 = beta * sk2 * 2.0*( sk*S - (0.5*sk2 - 1.)*C - 1.0 );
123        t3 = gamm*( ( 4.0*sk3 - 24.*sk ) * S - ( sk4 - 12.0*sk2 + 24.0 )*C + 24.0 );
124        t4 = -edibkb*sk3*(SL +sk*(C - lambda*CL) - S );
125        ck =  -24.0*eta*( t1 + t2 + t3 + t4 )/sk3/sk3;
126        struc  = 1./(1.-ck);
127       
128        return(struc);
129"""
130
131# ER defaults to 0.0
132# VR defaults to 1.0
133
134demo = dict(radius_effective=50, volfraction=0.04, welldepth=1.5,
135            wellwidth=1.2, radius_effective_pd=0, radius_effective_pd_n=0)
136#
137tests = [
138    [{'scale': 1.0, 'background' : 0.0, 'radius_effective' : 50.0,
139      'volfraction' : 0.04,'welldepth' : 1.5, 'wellwidth' : 1.2,
140      'radius_effective_pd' : 0},
141     [0.001], [0.97665742]],
142    ]
143# ADDED by: converting from sasview RKH  ON: 16Mar2016
144
Note: See TracBrowser for help on using the repository browser.