Changes in sasmodels/models/triaxial_ellipsoid.py [3330bb4:34a9e4e] in sasmodels
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/models/triaxial_ellipsoid.py
r3330bb4 r34a9e4e 2 2 # Note: model title and parameter table are inserted automatically 3 3 r""" 4 All three axes are of different lengths with $R_a \leq R_b \leq R_c$ 5 **Users should maintain this inequality for all calculations**. 4 Definition 5 ---------- 6 7 .. figure:: img/triaxial_ellipsoid_geometry.jpg 8 9 Ellipsoid with $R_a$ as *radius_equat_minor*, $R_b$ as *radius_equat_major* 10 and $R_c$ as *radius_polar*. 11 12 Given an ellipsoid 6 13 7 14 .. math:: 8 15 9 P(q) = \text{scale} V \left< F^2(q) \right> + \text{background}16 \frac{X^2}{R_a^2} + \frac{Y^2}{R_b^2} + \frac{Z^2}{R_c^2} = 1 10 17 11 where the volume $V = 4/3 \pi R_a R_b R_c$, and the averaging 12 $\left<\ldots\right>$ is applied over all orientations for 1D. 13 14 .. figure:: img/triaxial_ellipsoid_geometry.jpg 15 16 Ellipsoid schematic. 17 18 Definition 19 ---------- 20 21 The form factor calculated is 18 the scattering for randomly oriented particles is defined by the average over 19 all orientations $\Omega$ of: 22 20 23 21 .. math:: 24 22 25 P(q) = \frac{\text{scale}}{V}\int_0^1\int_0^1 26 \Phi^2(qR_a^2\cos^2( \pi x/2) + qR_b^2\sin^2(\pi y/2)(1-y^2) + R_c^2y^2) 27 dx dy 23 P(q) = \text{scale}(\Delta\rho)^2\frac{V}{4 \pi}\int_\Omega\Phi^2(qr)\,d\Omega 24 + \text{background} 28 25 29 26 where … … 31 28 .. math:: 32 29 33 \Phi(u) = 3 u^{-3} (\sin u - u \cos u) 30 \Phi(qr) &= 3 j_1(qr)/qr = 3 (\sin qr - qr \cos qr)/(qr)^3 \\ 31 r^2 &= R_a^2e^2 + R_b^2f^2 + R_c^2g^2 \\ 32 V &= \tfrac{4}{3} \pi R_a R_b R_c 34 33 34 The $e$, $f$ and $g$ terms are the projections of the orientation vector on $X$, 35 $Y$ and $Z$ respectively. Keeping the orientation fixed at the canonical 36 axes, we can integrate over the incident direction using polar angle 37 $-\pi/2 \le \gamma \le \pi/2$ and equatorial angle $0 \le \phi \le 2\pi$ 38 (as defined in ref [1]), 39 40 .. math:: 41 42 \langle\Phi^2\rangle = \int_0^{2\pi} \int_{-\pi/2}^{\pi/2} \Phi^2(qr) 43 \cos \gamma\,d\gamma d\phi 44 45 with $e = \cos\gamma \sin\phi$, $f = \cos\gamma \cos\phi$ and $g = \sin\gamma$. 46 A little algebra yields 47 48 .. math:: 49 50 r^2 = b^2(p_a \sin^2 \phi \cos^2 \gamma + 1 + p_c \sin^2 \gamma) 51 52 for 53 54 .. math:: 55 56 p_a = \frac{a^2}{b^2} - 1 \text{ and } p_c = \frac{c^2}{b^2} - 1 57 58 Due to symmetry, the ranges can be restricted to a single quadrant 59 $0 \le \gamma \le \pi/2$ and $0 \le \phi \le \pi/2$, scaling the resulting 60 integral by 8. The computation is done using the substitution $u = \sin\gamma$, 61 $du = \cos\gamma\,d\gamma$, giving 62 63 .. math:: 64 65 \langle\Phi^2\rangle &= 8 \int_0^{\pi/2} \int_0^1 \Phi^2(qr) du d\phi \\ 66 r^2 &= b^2(p_a \sin^2(\phi)(1 - u^2) + 1 + p_c u^2) 67 68 Though for convenience we describe the three radii of the ellipsoid as equatorial 69 and polar, they may be given in $any$ size order. To avoid multiple solutions, especially 70 with Monte-Carlo fit methods, it may be advisable to restrict their ranges. For typical 71 small angle diffraction situations there may be a number of closely similar "best fits", 72 so some trial and error, or fixing of some radii at expected values, may help. 73 35 74 To provide easy access to the orientation of the triaxial ellipsoid, 36 75 we define the axis of the cylinder using the angles $\theta$, $\phi$ 37 and $\psi$. These angles are defined on 38 :numref:`triaxial-ellipsoid-angles` . 39 The angle $\psi$ is the rotational angle around its own $c$ axis 40 against the $q$ plane. For example, $\psi = 0$ when the 41 $a$ axis is parallel to the $x$ axis of the detector. 76 and $\psi$. These angles are defined analogously to the elliptical_cylinder below, note that 77 angle $\phi$ is now NOT the same as in the equations above. 78 79 .. figure:: img/elliptical_cylinder_angle_definition.png 80 81 Definition of angles for oriented triaxial ellipsoid, where radii are for illustration here 82 $a < b << c$ and angle $\Psi$ is a rotation around the axis of the particle. 83 84 For oriented ellipsoids the *theta*, *phi* and *psi* orientation parameters will appear when fitting 2D data, 85 see the :ref:`elliptical-cylinder` model for further information. 42 86 43 87 .. _triaxial-ellipsoid-angles: 44 88 45 .. figure:: img/triaxial_ellipsoid_angle_projection. jpg89 .. figure:: img/triaxial_ellipsoid_angle_projection.png 46 90 47 The angles for orientedellipsoid.91 Some examples for an oriented triaxial ellipsoid. 48 92 49 93 The radius-of-gyration for this system is $R_g^2 = (R_a R_b R_c)^2/5$. 50 94 51 The contrast is defined as SLD(ellipsoid) - SLD(solvent). In the95 The contrast $\Delta\rho$ is defined as SLD(ellipsoid) - SLD(solvent). In the 52 96 parameters, $R_a$ is the minor equatorial radius, $R_b$ is the major 53 97 equatorial radius, and $R_c$ is the polar radius of the ellipsoid. 54 98 55 99 NB: The 2nd virial coefficient of the triaxial solid ellipsoid is 56 calculated based on the polar radius $R_p = R_c$ and equatorial 57 radius $R_e = \sqrt{R_a R_b}$, and used as the effective radius for 100 calculated after sorting the three radii to give the most appropriate 101 prolate or oblate form, from the new polar radius $R_p = R_c$ and effective equatorial 102 radius, $R_e = \sqrt{R_a R_b}$, to then be used as the effective radius for 58 103 $S(q)$ when $P(q) \cdot S(q)$ is applied. 59 104 … … 69 114 ---------- 70 115 71 L A Feigin and D I Svergun, *Structure Analysis by Small-Angle X-Ray 72 and Neutron Scattering*, Plenum, New York, 1987. 116 [1] Finnigan, J.A., Jacobs, D.J., 1971. 117 *Light scattering by ellipsoidal particles in solution*, 118 J. Phys. D: Appl. Phys. 4, 72-77. doi:10.1088/0022-3727/4/1/310 119 120 Authorship and Verification 121 ---------------------------- 122 123 * **Author:** NIST IGOR/DANSE **Date:** pre 2010 124 * **Last Modified by:** Paul Kienzle (improved calculation) **Date:** April 4, 2017 125 * **Last Reviewed by:** Paul Kienzle & Richard Heenan **Date:** April 4, 2017 73 126 """ 74 127 75 from numpy import inf 128 from numpy import inf, sin, cos, pi 76 129 77 130 name = "triaxial_ellipsoid" 78 131 title = "Ellipsoid of uniform scattering length density with three independent axes." 79 132 80 description = """\ 81 Note: During fitting ensure that the inequality ra<rb<rc is not 82 violated. Otherwise the calculation will 83 not be correct. 133 description = """ 134 Triaxial ellipsoid - see main documentation. 84 135 """ 85 136 category = "shape:ellipsoid" … … 91 142 "Solvent scattering length density"], 92 143 ["radius_equat_minor", "Ang", 20, [0, inf], "volume", 93 "Minor equatorial radius "],144 "Minor equatorial radius, Ra"], 94 145 ["radius_equat_major", "Ang", 400, [0, inf], "volume", 95 "Major equatorial radius "],146 "Major equatorial radius, Rb"], 96 147 ["radius_polar", "Ang", 10, [0, inf], "volume", 97 "Polar radius "],98 ["theta", "degrees", 60, [- inf, inf], "orientation",99 " In planeangle"],100 ["phi", "degrees", 60, [- inf, inf], "orientation",101 " Out of plane angle"],102 ["psi", "degrees", 60, [- inf, inf], "orientation",103 " Out of plane angle"],148 "Polar radius, Rc"], 149 ["theta", "degrees", 60, [-360, 360], "orientation", 150 "polar axis to beam angle"], 151 ["phi", "degrees", 60, [-360, 360], "orientation", 152 "rotation about beam"], 153 ["psi", "degrees", 60, [-360, 360], "orientation", 154 "rotation about polar axis"], 104 155 ] 105 156 … … 108 159 def ER(radius_equat_minor, radius_equat_major, radius_polar): 109 160 """ 110 161 Returns the effective radius used in the S*P calculation 111 162 """ 112 163 import numpy as np 113 164 from .ellipsoid import ER as ellipsoid_ER 114 return ellipsoid_ER(radius_polar, np.sqrt(radius_equat_minor * radius_equat_major)) 165 166 # now that radii can be in any size order, radii need sorting a,b,c 167 # where a~b and c is either much smaller or much larger 168 radii = np.vstack((radius_equat_major, radius_equat_minor, radius_polar)) 169 radii = np.sort(radii, axis=0) 170 selector = (radii[1] - radii[0]) > (radii[2] - radii[1]) 171 polar = np.where(selector, radii[0], radii[2]) 172 equatorial = np.sqrt(np.where(~selector, radii[0]*radii[1], radii[1]*radii[2])) 173 return ellipsoid_ER(polar, equatorial) 115 174 116 175 demo = dict(scale=1, background=0, … … 124 183 phi_pd=15, phi_pd_n=1, 125 184 psi_pd=15, psi_pd_n=1) 185 186 q = 0.1 187 # april 6 2017, rkh add unit tests 188 # NOT compared with any other calc method, assume correct! 189 # check 2d test after pull #890 190 qx = q*cos(pi/6.0) 191 qy = q*sin(pi/6.0) 192 tests = [[{}, 0.05, 24.8839548033], 193 [{'theta':80., 'phi':10.}, (qx, qy), 166.712060266 ], 194 ] 195 del qx, qy # not necessary to delete, but cleaner
Note: See TracChangeset
for help on using the changeset viewer.