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