source: sasmodels/sasmodels/models/stickyhardsphere.py @ 3c56da87

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

lint cleanup

  • Property mode set to 100644
File size: 5.9 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. The returned value is a dimensionless
7structure factor, *S(q)*.
8
9The perturb (perturbation parameter), |epsilon|, should be held between 0.01
10and 0.1. It is best to hold the perturbation parameter fixed and let
11the "stickiness" vary to adjust the interaction strength. The stickiness,
12|tau|, is defined in the equation below and is a function of both the
13perturbation parameter and the interaction strength. |tau| and |epsilon|
14are defined in terms of the hard sphere diameter (|sigma| = 2\*\ *R*\ ), the
15width of the square well, |bigdelta| (same units as *R*), and the depth of
16the well, *Uo*, in units of kT. From the definition, it is clear that
17smaller |tau| means stronger attraction.
18
19.. image:: img/stickyhardsphere_228.PNG
20
21where the interaction potential is
22
23.. image:: img/stickyhardsphere_229.PNG
24
25The Percus-Yevick (PY) closure was used for this calculation, and is an
26adequate closure for an attractive interparticle potential. This solution
27has been compared to Monte Carlo simulations for a square well fluid, with
28good agreement.
29
30The true particle volume fraction, |phi|, is not equal to *h*, which appears
31in most of the reference. The two are related in equation (24) of the
32reference. The reference also describes the relationship between this
33perturbation solution and the original sticky hard sphere (or adhesive
34sphere) model by Baxter.
35
36NB: The calculation can go haywire for certain combinations of the input
37parameters, producing unphysical solutions - in this case errors are
38reported to the command window and the *S(q)* is set to -1 (so it will
39disappear on a log-log plot). Use tight bounds to keep the parameters to
40values that you know are physical (test them) and keep nudging them until
41the optimization does not hit the constraints.
42
43In sasview the effective radius will be calculated from the parameters
44used in the form factor P(Q) that this S(Q) is combined with.
45
46For 2D data: The 2D scattering intensity is calculated in the same way
47as 1D, where the *q* vector is defined as
48
49.. math::
50
51    Q = \sqrt{Q_x^2 + Q_y^2}
52
53==============  ========  =============
54Parameter name  Units     Default value
55==============  ========  =============
56effect_radius   |Ang|     50
57perturb         None      0.05
58volfraction     None      0.1
59stickiness      K         0.2
60==============  ========  =============
61
62.. image:: img/stickyhardsphere_230.jpg
63
64*Figure. 1D plot using the default values (in linear scale).*
65
66REFERENCE
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
87parameters = [
88    #   [ "name", "units", default, [lower, upper], "type",
89    #     "description" ],
90    ["effect_radius", "Ang", 50.0, [0, inf], "volume",
91     "effective radius of hard sphere"],
92    ["volfraction", "", 0.2, [0, 0.74], "",
93     "volume fraction of hard spheres"],
94    ["perturb", "", 0.05, [0.01, 0.1], "",
95     "perturbation parameter, epsilon"],
96    ["stickiness", "", 0.20, [-inf, inf], "",
97     "stickiness, tau"],
98    ]
99
100# No volume normalization despite having a volume parameter
101# This should perhaps be volume normalized?
102form_volume = """
103    return 1.0;
104    """
105
106Iq = """
107    double onemineps,eta;
108    double sig,aa,etam1,etam1sq,qa,qb,qc,radic;
109    double lam,lam2,test,mu,alpha,beta;
110    double kk,k2,k3,ds,dc,aq1,aq2,aq3,aq,bq1,bq2,bq3,bq,sq;
111
112    onemineps = 1.0-perturb;
113    eta = volfraction/onemineps/onemineps/onemineps;
114
115    sig = 2.0 * effect_radius;
116    aa = sig/onemineps;
117    etam1 = 1.0 - eta;
118    etam1sq=etam1*etam1;
119    //C
120    //C  SOLVE QUADRATIC FOR LAMBDA
121    //C
122    qa = eta/12.0;
123    qb = -1.0*(stickiness + eta/etam1);
124    qc = (1.0 + eta/2.0)/etam1sq;
125    radic = qb*qb - 4.0*qa*qc;
126    if(radic<0) {
127        //if(x>0.01 && x<0.015)
128        //      Print "Lambda unphysical - both roots imaginary"
129        //endif
130        return(-1.0);
131    }
132    //C   KEEP THE SMALLER ROOT, THE LARGER ONE IS UNPHYSICAL
133    lam = (-1.0*qb-sqrt(radic))/(2.0*qa);
134    lam2 = (-1.0*qb+sqrt(radic))/(2.0*qa);
135    if(lam2<lam) {
136        lam = lam2;
137    }
138    test = 1.0 + 2.0*eta;
139    mu = lam*eta*etam1;
140    if(mu>test) {
141        //if(x>0.01 && x<0.015)
142        // Print "Lambda unphysical mu>test"
143        //endif
144        return(-1.0);
145    }
146    alpha = (1.0 + 2.0*eta - mu)/etam1sq;
147    beta = (mu - 3.0*eta)/(2.0*etam1sq);
148    //C
149    //C   CALCULATE THE STRUCTURE FACTOR
150    //C
151    kk = q*aa;
152    k2 = kk*kk;
153    k3 = kk*k2;
154    SINCOS(kk,ds,dc);
155    //ds = sin(kk);
156    //dc = cos(kk);
157    aq1 = ((ds - kk*dc)*alpha)/k3;
158    aq2 = (beta*(1.0-dc))/k2;
159    aq3 = (lam*ds)/(12.0*kk);
160    aq = 1.0 + 12.0*eta*(aq1+aq2-aq3);
161    //
162    bq1 = alpha*(0.5/kk - ds/k2 + (1.0 - dc)/k3);
163    bq2 = beta*(1.0/kk - ds/k2);
164    bq3 = (lam/12.0)*((1.0 - dc)/kk);
165    bq = 12.0*eta*(bq1+bq2-bq3);
166    //
167    sq = 1.0/(aq*aq +bq*bq);
168
169    return(sq);
170"""
171
172Iqxy = """
173    return Iq(sqrt(qx*qx+qy*qy), IQ_PARAMETERS);
174    """
175
176# ER defaults to 0.0
177# VR defaults to 1.0
178
179oldname = 'StickyHSStructure'
180oldpars = dict()
181demo = dict(effect_radius=200, volfraction=0.2, perturb=0.05,
182            stickiness=0.2, effect_radius_pd=0.1, effect_radius_pd_n=40)
183
Note: See TracBrowser for help on using the repository browser.