source: sasmodels/sasmodels/models/stickyhardsphere.py @ 13ed84c

core_shell_microgelscostrafo411magnetic_modelrelease_v0.94release_v0.95ticket-1257-vesicle-productticket_1156ticket_1265_superballticket_822_more_unit_tests
Last change on this file since 13ed84c was 13ed84c, checked in by Paul Kienzle <pkienzle@…>, 8 years ago

set single=False on all models that fail the single precision tests

  • Property mode set to 100644
File size: 6.1 KB
Line 
1# Note: model title and parameter table are inserted automatically
2r"""
3This calculates the interparticle structure factor for a hard sphere fluid
4with a narrow attractive well. A perturbative solution of the Percus-Yevick
5closure is used. The strength of the attractive well is described in terms
6of "stickiness" as defined below.
7
8The perturb (perturbation parameter), $\epsilon$, should be held between 0.01
9and 0.1. It is best to hold the perturbation parameter fixed and let
10the "stickiness" vary to adjust the interaction strength. The stickiness,
11$\tau$, is defined in the equation below and is a function of both the
12perturbation parameter and the interaction strength. $\tau$ and $\epsilon$
13are defined in terms of the hard sphere diameter $(\sigma = 2 R)$, the
14width of the square well, $\Delta$ (same units as $R$\ ), and the depth of
15the well, $U_o$, in units of $kT$. From the definition, it is clear that
16smaller $\tau$ means stronger attraction.
17
18.. math::
19
20    \tau     &= \frac{1}{12\epsilon} \exp(u_o / kT) \\
21    \epsilon &= \Delta / (\sigma + \Delta)
22
23where the interaction potential is
24
25.. math::
26
27    U(r) = \begin{cases}
28        \infty & r < \sigma \\
29        -U_o   & \sigma \leq r \leq \sigma + \Delta \\
30        0      & r > \sigma + \Delta
31        \end{cases}
32
33The Percus-Yevick (PY) closure was used for this calculation, and is an
34adequate closure for an attractive interparticle potential. This solution
35has been compared to Monte Carlo simulations for a square well fluid, with
36good agreement.
37
38The true particle volume fraction, $\phi$, is not equal to $h$, which appears
39in most of the reference. The two are related in equation (24) of the
40reference. The reference also describes the relationship between this
41perturbation solution and the original sticky hard sphere (or adhesive
42sphere) model by Baxter.
43
44**NB**: The calculation can go haywire for certain combinations of the input
45parameters, producing unphysical solutions - in this case errors are
46reported to the command window and the $S(q)$ is set to -1 (so it will
47disappear on a log-log plot). Use tight bounds to keep the parameters to
48values that you know are physical (test them) and keep nudging them until
49the optimization does not hit the constraints.
50
51In sasview the effective radius will be calculated from the parameters
52used in the form factor $P(q)$ that this $S(q)$ is combined with.
53
54For 2D data the scattering intensity is calculated in the same way
55as 1D, where the $q$ vector is defined as
56
57.. math::
58
59    q = \sqrt{q_x^2 + q_y^2}
60
61.. figure:: img/stickyhardsphere_1d.jpg
62
63    1D plot using the default values (in linear scale).
64
65References
66----------
67
68S V G Menon, C Manohar, and K S Rao, *J. Chem. Phys.*, 95(12) (1991) 9186-9190
69"""
70
71# TODO: refactor so that we pull in the old sansmodels.c_extensions
72
73from numpy import inf
74
75name = "stickyhardsphere"
76title = "Sticky hard sphere structure factor, with Percus-Yevick closure"
77description = """\
78    [Sticky hard sphere structure factor, with Percus-Yevick closure]
79        Interparticle structure factor S(Q)for a hard sphere fluid with
80        a narrow attractive well. Fits are prone to deliver non-physical
81        parameters, use with care and read the references in the full manual.
82        In sasview the effective radius will be calculated from the
83        parameters used in P(Q).
84"""
85category = "structure-factor"
86
87single = False
88#             ["name", "units", default, [lower, upper], "type","description"],
89parameters = [
90    #   [ "name", "units", default, [lower, upper], "type",
91    #     "description" ],
92    ["effect_radius", "Ang", 50.0, [0, inf], "volume",
93     "effective radius of hard sphere"],
94    ["volfraction", "", 0.2, [0, 0.74], "",
95     "volume fraction of hard spheres"],
96    ["perturb", "", 0.05, [0.01, 0.1], "",
97     "perturbation parameter, epsilon"],
98    ["stickiness", "", 0.20, [-inf, inf], "",
99     "stickiness, tau"],
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    double onemineps,eta;
110    double sig,aa,etam1,etam1sq,qa,qb,qc,radic;
111    double lam,lam2,test,mu,alpha,beta;
112    double kk,k2,k3,ds,dc,aq1,aq2,aq3,aq,bq1,bq2,bq3,bq,sq;
113
114    onemineps = 1.0-perturb;
115    eta = volfraction/onemineps/onemineps/onemineps;
116
117    sig = 2.0 * effect_radius;
118    aa = sig/onemineps;
119    etam1 = 1.0 - eta;
120    etam1sq=etam1*etam1;
121    //C
122    //C  SOLVE QUADRATIC FOR LAMBDA
123    //C
124    qa = eta/12.0;
125    qb = -1.0*(stickiness + eta/etam1);
126    qc = (1.0 + eta/2.0)/etam1sq;
127    radic = qb*qb - 4.0*qa*qc;
128    if(radic<0) {
129        //if(x>0.01 && x<0.015)
130        //    Print "Lambda unphysical - both roots imaginary"
131        //endif
132        return(-1.0);
133    }
134    //C   KEEP THE SMALLER ROOT, THE LARGER ONE IS UNPHYSICAL
135    lam = (-1.0*qb-sqrt(radic))/(2.0*qa);
136    lam2 = (-1.0*qb+sqrt(radic))/(2.0*qa);
137    if(lam2<lam) {
138        lam = lam2;
139    }
140    test = 1.0 + 2.0*eta;
141    mu = lam*eta*etam1;
142    if(mu>test) {
143        //if(x>0.01 && x<0.015)
144        // Print "Lambda unphysical mu>test"
145        //endif
146        return(-1.0);
147    }
148    alpha = (1.0 + 2.0*eta - mu)/etam1sq;
149    beta = (mu - 3.0*eta)/(2.0*etam1sq);
150    //C
151    //C   CALCULATE THE STRUCTURE FACTOR
152    //C
153    kk = q*aa;
154    k2 = kk*kk;
155    k3 = kk*k2;
156    SINCOS(kk,ds,dc);
157    //ds = sin(kk);
158    //dc = cos(kk);
159    aq1 = ((ds - kk*dc)*alpha)/k3;
160    aq2 = (beta*(1.0-dc))/k2;
161    aq3 = (lam*ds)/(12.0*kk);
162    aq = 1.0 + 12.0*eta*(aq1+aq2-aq3);
163    //
164    bq1 = alpha*(0.5/kk - ds/k2 + (1.0 - dc)/k3);
165    bq2 = beta*(1.0/kk - ds/k2);
166    bq3 = (lam/12.0)*((1.0 - dc)/kk);
167    bq = 12.0*eta*(bq1+bq2-bq3);
168    //
169    sq = 1.0/(aq*aq +bq*bq);
170
171    return(sq);
172"""
173
174Iqxy = """
175    return Iq(sqrt(qx*qx+qy*qy), IQ_PARAMETERS);
176    """
177
178# ER defaults to 0.0
179# VR defaults to 1.0
180
181oldname = 'StickyHSStructure'
182oldpars = dict()
183demo = dict(effect_radius=200, volfraction=0.2, perturb=0.05,
184            stickiness=0.2, effect_radius_pd=0.1, effect_radius_pd_n=40)
185#
186tests = [
187        [ {'scale': 1.0, 'background' : 0.0, 'effect_radius' : 50.0, 'perturb' : 0.05, 'stickiness' : 0.2, 'volfraction' : 0.1,
188           'effect_radius_pd' : 0}, [0.001], [1.09718]]
189        ]
190
191
Note: See TracBrowser for help on using the repository browser.