[5d4777d] | 1 | # ellipsoid model |
---|
| 2 | # Note: model title and parameter table are inserted automatically |
---|
| 3 | r""" |
---|
[404ebbd] | 4 | The form factor is normalized by the particle volume |
---|
[5d4777d] | 5 | |
---|
| 6 | Definition |
---|
| 7 | ---------- |
---|
| 8 | |
---|
| 9 | The output of the 2D scattering intensity function for oriented ellipsoids |
---|
| 10 | is given by (Feigin, 1987) |
---|
| 11 | |
---|
| 12 | .. math:: |
---|
| 13 | |
---|
[cade620] | 14 | P(q,\alpha) = \frac{\text{scale}}{V} F^2(q,\alpha) + \text{background} |
---|
[5d4777d] | 15 | |
---|
| 16 | where |
---|
| 17 | |
---|
| 18 | .. math:: |
---|
| 19 | |
---|
[3b571ae] | 20 | F(q,\alpha) = \Delta \rho V \frac{3(\sin qr - qr \cos qr)}{(qr)^3} |
---|
[5d4777d] | 21 | |
---|
[3b571ae] | 22 | for |
---|
[5d4777d] | 23 | |
---|
| 24 | .. math:: |
---|
| 25 | |
---|
[3b571ae] | 26 | r = \left[ R_e^2 \sin^2 \alpha + R_p^2 \cos^2 \alpha \right]^{1/2} |
---|
[5d4777d] | 27 | |
---|
| 28 | |
---|
| 29 | $\alpha$ is the angle between the axis of the ellipsoid and $\vec q$, |
---|
[3b571ae] | 30 | $V = (4/3)\pi R_pR_e^2$ is the volume of the ellipsoid, $R_p$ is the polar |
---|
| 31 | radius along the rotational axis of the ellipsoid, $R_e$ is the equatorial |
---|
| 32 | radius perpendicular to the rotational axis of the ellipsoid and |
---|
| 33 | $\Delta \rho$ (contrast) is the scattering length density difference between |
---|
| 34 | the scatterer and the solvent. |
---|
[5d4777d] | 35 | |
---|
[3b571ae] | 36 | For randomly oriented particles use the orientational average, |
---|
[416f5c7] | 37 | |
---|
| 38 | .. math:: |
---|
| 39 | |
---|
[3b571ae] | 40 | \langle F^2(q) \rangle = \int_{0}^{\pi/2}{F^2(q,\alpha)\sin(\alpha)\,d\alpha} |
---|
[416f5c7] | 41 | |
---|
| 42 | |
---|
[3b571ae] | 43 | computed via substitution of $u=\sin(\alpha)$, $du=\cos(\alpha)\,d\alpha$ as |
---|
| 44 | |
---|
| 45 | .. math:: |
---|
| 46 | |
---|
| 47 | \langle F^2(q) \rangle = \int_0^1{F^2(q, u)\,du} |
---|
| 48 | |
---|
| 49 | with |
---|
| 50 | |
---|
| 51 | .. math:: |
---|
| 52 | |
---|
| 53 | r = R_e \left[ 1 + u^2\left(R_p^2/R_e^2 - 1\right)\right]^{1/2} |
---|
| 54 | |
---|
[eda8b30] | 55 | For 2d data from oriented ellipsoids the direction of the rotation axis of |
---|
| 56 | the ellipsoid is defined using two angles $\theta$ and $\phi$ as for the |
---|
[0a7eec11] | 57 | :ref:`cylinder orientation figure <cylinder-angle-definition>`. |
---|
[5d4777d] | 58 | For the ellipsoid, $\theta$ is the angle between the rotational axis |
---|
[3b571ae] | 59 | and the $z$ -axis in the $xz$ plane followed by a rotation by $\phi$ |
---|
[eda8b30] | 60 | in the $xy$ plane, for further details of the calculation and angular |
---|
| 61 | dispersions see :ref:`orientation` . |
---|
[5d4777d] | 62 | |
---|
| 63 | NB: The 2nd virial coefficient of the solid ellipsoid is calculated based |
---|
| 64 | on the $R_p$ and $R_e$ values, and used as the effective radius for |
---|
[eb69cce] | 65 | $S(q)$ when $P(q) \cdot S(q)$ is applied. |
---|
[5d4777d] | 66 | |
---|
| 67 | |
---|
[eb69cce] | 68 | The $\theta$ and $\phi$ parameters are not used for the 1D output. |
---|
[5d4777d] | 69 | |
---|
[19dcb933] | 70 | |
---|
[5d4777d] | 71 | |
---|
| 72 | Validation |
---|
| 73 | ---------- |
---|
| 74 | |
---|
[aa2edb2] | 75 | Validation of the code was done by comparing the output of the 1D model |
---|
[5d4777d] | 76 | to the output of the software provided by the NIST (Kline, 2006). |
---|
| 77 | |
---|
[aa2edb2] | 78 | The implementation of the intensity for fully oriented ellipsoids was |
---|
| 79 | validated by averaging the 2D output using a uniform distribution |
---|
| 80 | $p(\theta,\phi) = 1.0$ and comparing with the output of the 1D calculation. |
---|
[5d4777d] | 81 | |
---|
| 82 | |
---|
| 83 | .. _ellipsoid-comparison-2d: |
---|
| 84 | |
---|
[19dcb933] | 85 | .. figure:: img/ellipsoid_comparison_2d.jpg |
---|
[5d4777d] | 86 | |
---|
| 87 | Comparison of the intensity for uniformly distributed ellipsoids |
---|
| 88 | calculated from our 2D model and the intensity from the NIST SANS |
---|
[19dcb933] | 89 | analysis software. The parameters used were: *scale* = 1.0, |
---|
[a807206] | 90 | *radius_polar* = 20 |Ang|, *radius_equatorial* = 400 |Ang|, |
---|
[19dcb933] | 91 | *contrast* = 3e-6 |Ang^-2|, and *background* = 0.0 |cm^-1|. |
---|
[5d4777d] | 92 | |
---|
[eb69cce] | 93 | The discrepancy above $q$ = 0.3 |cm^-1| is due to the way the form factors |
---|
[5d4777d] | 94 | are calculated in the c-library provided by NIST. A numerical integration |
---|
[eb69cce] | 95 | has to be performed to obtain $P(q)$ for randomly oriented particles. |
---|
[5d4777d] | 96 | The NIST software performs that integration with a 76-point Gaussian |
---|
[eb69cce] | 97 | quadrature rule, which will become imprecise at high $q$ where the amplitude |
---|
| 98 | varies quickly as a function of $q$. The SasView result shown has been |
---|
[5d4777d] | 99 | obtained by summing over 501 equidistant points. Our result was found |
---|
[eb69cce] | 100 | to be stable over the range of $q$ shown for a number of points higher |
---|
[5d4777d] | 101 | than 500. |
---|
| 102 | |
---|
[3b571ae] | 103 | Model was also tested against the triaxial ellipsoid model with equal major |
---|
| 104 | and minor equatorial radii. It is also consistent with the cyclinder model |
---|
| 105 | with polar radius equal to length and equatorial radius equal to radius. |
---|
| 106 | |
---|
[eb69cce] | 107 | References |
---|
| 108 | ---------- |
---|
[5d4777d] | 109 | |
---|
[431caae] | 110 | L A Feigin and D I Svergun. |
---|
| 111 | *Structure Analysis by Small-Angle X-Ray and Neutron Scattering*, |
---|
| 112 | Plenum Press, New York, 1987. |
---|
[3b571ae] | 113 | |
---|
[bb39b4a] | 114 | A. Isihara. J. Chem. Phys. 18(1950) 1446-1449 |
---|
| 115 | |
---|
[3b571ae] | 116 | Authorship and Verification |
---|
| 117 | ---------------------------- |
---|
| 118 | |
---|
| 119 | * **Author:** NIST IGOR/DANSE **Date:** pre 2010 |
---|
| 120 | * **Converted to sasmodels by:** Helen Park **Date:** July 9, 2014 |
---|
| 121 | * **Last Modified by:** Paul Kienzle **Date:** March 22, 2017 |
---|
[5d4777d] | 122 | """ |
---|
[404ebbd] | 123 | from __future__ import division |
---|
[5d4777d] | 124 | |
---|
[0b56f38] | 125 | from numpy import inf, sin, cos, pi |
---|
[5d4777d] | 126 | |
---|
| 127 | name = "ellipsoid" |
---|
| 128 | title = "Ellipsoid of revolution with uniform scattering length density." |
---|
| 129 | |
---|
| 130 | description = """\ |
---|
| 131 | P(q.alpha)= scale*f(q)^2 + background, where f(q)= 3*(sld |
---|
[3556ad7] | 132 | - sld_solvent)*V*[sin(q*r(Rp,Re,alpha)) |
---|
[3e428ec] | 133 | -q*r*cos(qr(Rp,Re,alpha))] |
---|
| 134 | /[qr(Rp,Re,alpha)]^3" |
---|
[5d4777d] | 135 | |
---|
| 136 | r(Rp,Re,alpha)= [Re^(2)*(sin(alpha))^2 |
---|
[3e428ec] | 137 | + Rp^(2)*(cos(alpha))^2]^(1/2) |
---|
[5d4777d] | 138 | |
---|
[3e428ec] | 139 | sld: SLD of the ellipsoid |
---|
[3556ad7] | 140 | sld_solvent: SLD of the solvent |
---|
[3e428ec] | 141 | V: volume of the ellipsoid |
---|
| 142 | Rp: polar radius of the ellipsoid |
---|
| 143 | Re: equatorial radius of the ellipsoid |
---|
[5d4777d] | 144 | """ |
---|
[a5d0d00] | 145 | category = "shape:ellipsoid" |
---|
[5d4777d] | 146 | |
---|
[3e428ec] | 147 | # ["name", "units", default, [lower, upper], "type","description"], |
---|
[42356c8] | 148 | parameters = [["sld", "1e-6/Ang^2", 4, [-inf, inf], "sld", |
---|
[3e428ec] | 149 | "Ellipsoid scattering length density"], |
---|
[42356c8] | 150 | ["sld_solvent", "1e-6/Ang^2", 1, [-inf, inf], "sld", |
---|
[3e428ec] | 151 | "Solvent scattering length density"], |
---|
[a807206] | 152 | ["radius_polar", "Ang", 20, [0, inf], "volume", |
---|
[3e428ec] | 153 | "Polar radius"], |
---|
[a807206] | 154 | ["radius_equatorial", "Ang", 400, [0, inf], "volume", |
---|
[3e428ec] | 155 | "Equatorial radius"], |
---|
[9b79f29] | 156 | ["theta", "degrees", 60, [-360, 360], "orientation", |
---|
| 157 | "ellipsoid axis to beam angle"], |
---|
| 158 | ["phi", "degrees", 60, [-360, 360], "orientation", |
---|
| 159 | "rotation about beam"], |
---|
[3e428ec] | 160 | ] |
---|
| 161 | |
---|
[925ad6e] | 162 | source = ["lib/sas_3j1x_x.c", "lib/gauss76.c", "ellipsoid.c"] |
---|
[5d4777d] | 163 | |
---|
[a807206] | 164 | def ER(radius_polar, radius_equatorial): |
---|
[5d4777d] | 165 | import numpy as np |
---|
[bb39b4a] | 166 | # see equation (26) in A.Isihara, J.Chem.Phys. 18(1950)1446-1449 |
---|
[a807206] | 167 | ee = np.empty_like(radius_polar) |
---|
| 168 | idx = radius_polar > radius_equatorial |
---|
| 169 | ee[idx] = (radius_polar[idx] ** 2 - radius_equatorial[idx] ** 2) / radius_polar[idx] ** 2 |
---|
| 170 | idx = radius_polar < radius_equatorial |
---|
| 171 | ee[idx] = (radius_equatorial[idx] ** 2 - radius_polar[idx] ** 2) / radius_equatorial[idx] ** 2 |
---|
| 172 | idx = radius_polar == radius_equatorial |
---|
| 173 | ee[idx] = 2 * radius_polar[idx] |
---|
| 174 | valid = (radius_polar * radius_equatorial != 0) |
---|
[3e428ec] | 175 | bd = 1.0 - ee[valid] |
---|
[5d4777d] | 176 | e1 = np.sqrt(ee[valid]) |
---|
[3e428ec] | 177 | b1 = 1.0 + np.arcsin(e1) / (e1 * np.sqrt(bd)) |
---|
| 178 | bL = (1.0 + e1) / (1.0 - e1) |
---|
| 179 | b2 = 1.0 + bd / 2 / e1 * np.log(bL) |
---|
| 180 | delta = 0.75 * b1 * b2 |
---|
[5d4777d] | 181 | |
---|
[92708d8] | 182 | ddd = np.zeros_like(radius_polar) |
---|
[a807206] | 183 | ddd[valid] = 2.0 * (delta + 1.0) * radius_polar * radius_equatorial ** 2 |
---|
[3e428ec] | 184 | return 0.5 * ddd ** (1.0 / 3.0) |
---|
| 185 | |
---|
[404ebbd] | 186 | def random(): |
---|
| 187 | import numpy as np |
---|
[31df0c9] | 188 | V = 10**np.random.uniform(5, 12) |
---|
[404ebbd] | 189 | radius_polar = 10**np.random.uniform(1.3, 4) |
---|
| 190 | radius_equatorial = np.sqrt(V/radius_polar) # ignore 4/3 pi |
---|
| 191 | pars = dict( |
---|
| 192 | #background=0, sld=0, sld_solvent=1, |
---|
| 193 | radius_polar=radius_polar, |
---|
| 194 | radius_equatorial=radius_equatorial, |
---|
| 195 | ) |
---|
| 196 | return pars |
---|
[3e428ec] | 197 | |
---|
| 198 | demo = dict(scale=1, background=0, |
---|
[3556ad7] | 199 | sld=6, sld_solvent=1, |
---|
[a807206] | 200 | radius_polar=50, radius_equatorial=30, |
---|
[3e428ec] | 201 | theta=30, phi=15, |
---|
[a807206] | 202 | radius_polar_pd=.2, radius_polar_pd_n=15, |
---|
| 203 | radius_equatorial_pd=.2, radius_equatorial_pd_n=15, |
---|
[3e428ec] | 204 | theta_pd=15, theta_pd_n=45, |
---|
| 205 | phi_pd=15, phi_pd_n=1) |
---|
[0b56f38] | 206 | q = 0.1 |
---|
| 207 | # april 6 2017, rkh add unit tests, NOT compared with any other calc method, assume correct! |
---|
| 208 | qx = q*cos(pi/6.0) |
---|
| 209 | qy = q*sin(pi/6.0) |
---|
| 210 | tests = [[{}, 0.05, 54.8525847025], |
---|
| 211 | [{'theta':80., 'phi':10.}, (qx, qy), 1.74134670026 ], |
---|
| 212 | ] |
---|
| 213 | del qx, qy # not necessary to delete, but cleaner |
---|