[3330bb4] | 1 | # Note: model title and parameter table are inserted automatically |
---|
| 2 | r""" |
---|
[db1d9d5] | 3 | Calculates the interparticle structure factor for a hard sphere fluid |
---|
| 4 | with a narrow, attractive, square well potential. **The Mean Spherical |
---|
| 5 | Approximation (MSA) closure relationship is used, but it is not the most |
---|
| 6 | appropriate closure for an attractive interparticle potential.** However, |
---|
| 7 | the solution has been compared to Monte Carlo simulations for a square |
---|
| 8 | well fluid and these show the MSA calculation to be limited to well |
---|
| 9 | depths $\epsilon < 1.5$ kT and volume fractions $\phi < 0.08$. |
---|
[3330bb4] | 10 | |
---|
| 11 | Positive well depths correspond to an attractive potential well. Negative |
---|
| 12 | well depths correspond to a potential "shoulder", which may or may not be |
---|
[db1d9d5] | 13 | physically reasonable. The :ref:`stickyhardsphere` model may be a better |
---|
| 14 | choice in some circumstances. |
---|
| 15 | |
---|
| 16 | Computed 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. |
---|
[3330bb4] | 23 | |
---|
| 24 | The well width $(\lambda)$ is defined as multiples of the particle diameter |
---|
| 25 | $(2 R)$. |
---|
| 26 | |
---|
| 27 | The 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 | |
---|
[db1d9d5] | 37 | where $r$ is the distance from the center of a sphere of a radius $R$. |
---|
[3330bb4] | 38 | |
---|
[db1d9d5] | 39 | In SasView the effective radius may be calculated from the parameters |
---|
[3330bb4] | 40 | used in the form factor $P(q)$ that this $S(q)$ is combined with. |
---|
| 41 | |
---|
| 42 | For 2D data: The 2D scattering intensity is calculated in the same way as 1D, |
---|
| 43 | where the $q$ vector is defined as |
---|
| 44 | |
---|
| 45 | .. math:: |
---|
| 46 | |
---|
| 47 | q = \sqrt{q_x^2 + q_y^2} |
---|
| 48 | |
---|
| 49 | References |
---|
| 50 | ---------- |
---|
| 51 | |
---|
[0507e09] | 52 | .. [#] R V Sharma, K C Sharma, *Physica*, 89A (1977) 213 |
---|
| 53 | |
---|
[db1d9d5] | 54 | .. [#] M Kotlarchyk and S-H Chen, *J. Chem. Phys.*, 79 (1983) 2461-2469 |
---|
| 55 | |
---|
[0507e09] | 56 | Source |
---|
| 57 | ------ |
---|
| 58 | |
---|
| 59 | `squarewell.py <https://github.com/SasView/sasmodels/blob/master/sasmodels/models/squarewell.py>`_ |
---|
| 60 | |
---|
| 61 | Authorship and Verification |
---|
| 62 | ---------------------------- |
---|
| 63 | |
---|
[db1d9d5] | 64 | * **Author:** |
---|
| 65 | * **Last Modified by:** |
---|
| 66 | * **Last Reviewed by:** Steve King **Date:** March 27, 2019 |
---|
[0507e09] | 67 | * **Source added by :** Steve King **Date:** March 25, 2019 |
---|
[3330bb4] | 68 | """ |
---|
[2d81cfe] | 69 | |
---|
| 70 | import numpy as np |
---|
[3330bb4] | 71 | from numpy import inf |
---|
| 72 | |
---|
| 73 | name = "squarewell" |
---|
[db1d9d5] | 74 | title = "Square well structure factor with Mean Spherical Approximation closure" |
---|
[3330bb4] | 75 | description = """\ |
---|
| 76 | [Square well structure factor, with MSA closure] |
---|
[db1d9d5] | 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. |
---|
[3330bb4] | 82 | """ |
---|
| 83 | category = "structure-factor" |
---|
| 84 | structure_factor = True |
---|
| 85 | single = False |
---|
| 86 | |
---|
| 87 | #single = False |
---|
| 88 | # ["name", "units", default, [lower, upper], "type","description"], |
---|
| 89 | parameters = [ |
---|
| 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? |
---|
| 104 | form_volume = """ |
---|
| 105 | return 1.0; |
---|
| 106 | """ |
---|
| 107 | |
---|
| 108 | Iq = """ |
---|
| 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; |
---|
[8f04da4] | 115 | |
---|
[3330bb4] | 116 | req = radius_effective; |
---|
| 117 | phis = volfraction; |
---|
| 118 | edibkb = welldepth; |
---|
| 119 | lambda = wellwidth; |
---|
[8f04da4] | 120 | |
---|
[3330bb4] | 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; |
---|
[8f04da4] | 134 | |
---|
[3330bb4] | 135 | // calculate the structure factor |
---|
[8f04da4] | 136 | |
---|
[3330bb4] | 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); |
---|
[8f04da4] | 149 | |
---|
[3330bb4] | 150 | return(struc); |
---|
| 151 | """ |
---|
| 152 | |
---|
[8f04da4] | 153 | def random(): |
---|
[b297ba9] | 154 | """Return a random parameter set for the model.""" |
---|
[8f04da4] | 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 | |
---|
[3330bb4] | 164 | demo = dict(radius_effective=50, volfraction=0.04, welldepth=1.5, |
---|
| 165 | wellwidth=1.2, radius_effective_pd=0, radius_effective_pd_n=0) |
---|
| 166 | # |
---|
| 167 | tests = [ |
---|
[8f04da4] | 168 | [{'scale': 1.0, 'background': 0.0, 'radius_effective': 50.0, |
---|
[2d81cfe] | 169 | 'volfraction': 0.04, 'welldepth': 1.5, 'wellwidth': 1.2, |
---|
[8f04da4] | 170 | 'radius_effective_pd': 0}, [0.001], [0.97665742]], |
---|
[3330bb4] | 171 | ] |
---|
| 172 | # ADDED by: converting from sasview RKH ON: 16Mar2016 |
---|