source: sasmodels/sasmodels/models/triaxial_ellipsoid.py @ 18d732c

core_shell_microgelscostrafo411magnetic_modelticket-1257-vesicle-productticket_1156ticket_1265_superballticket_822_more_unit_tests
Last change on this file since 18d732c was 18d732c, checked in by Paul Kienzle <pkienzle@…>, 7 years ago

Merge branch 'ticket-890' of github.com:sasview/sasmodels into ticket-890

  • Property mode set to 100644
File size: 6.7 KB
Line 
1# triaxial ellipsoid model
2# Note: model title and parameter table are inserted automatically
3r"""
4Definition
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
12Given an ellipsoid
13
14.. math::
15
16    \frac{X^2}{R_a^2} + \frac{Y^2}{R_b^2} + \frac{Z^2}{R_c^2} = 1
17
18the scattering for randomly oriented particles is defined by the average over
19all orientations $\Omega$ of:
20
21.. math::
22
23    P(q) = \text{scale}(\Delta\rho)^2\frac{V}{4 \pi}\int_\Omega\Phi^2(qr)\,d\Omega
24           + \text{background}
25
26where
27
28.. math::
29
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
33
34The $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
36axes, 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
45with $e = \cos\gamma \sin\phi$, $f = \cos\gamma \cos\phi$ and $g = \sin\gamma$.
46A 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
52for
53
54.. math::
55
56    p_a = \frac{a^2}{b^2} - 1 \text{ and } p_c = \frac{c^2}{b^2} - 1
57
58Due 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
60integral 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
68To provide easy access to the orientation of the triaxial ellipsoid,
69we define the axis of the cylinder using the angles $\theta$, $\phi$
70and $\psi$. These angles are defined analogously to the elliptical_cylinder below
71
72.. figure:: img/elliptical_cylinder_angle_definition.png
73
74    Definition of angles for oriented triaxial ellipsoid, where radii shown
75    here are $a < b << c$ and angle $\Psi$ is a rotation around the axis
76    of the particle.
77
78The angle $\psi$ is the rotational angle around its own $c$ axis
79against the $q$ plane. For example, $\psi = 0$ when the
80$a$ axis is parallel to the $x$ axis of the detector.
81
82.. _triaxial-ellipsoid-angles:
83
84.. figure:: img/triaxial_ellipsoid_angle_projection.png
85
86    Some example angles for oriented ellipsoid.
87
88The radius-of-gyration for this system is  $R_g^2 = (R_a R_b R_c)^2/5$.
89
90The contrast $\Delta\rho$ is defined as SLD(ellipsoid) - SLD(solvent).  In the
91parameters, $R_a$ is the minor equatorial radius, $R_b$ is the major
92equatorial radius, and $R_c$ is the polar radius of the ellipsoid.
93
94NB: The 2nd virial coefficient of the triaxial solid ellipsoid is
95calculated based on the polar radius $R_p = R_c$ and equatorial
96radius $R_e = \sqrt{R_a R_b}$, and used as the effective radius for
97$S(q)$ when $P(q) \cdot S(q)$ is applied.
98
99Validation
100----------
101
102Validation of our code was done by comparing the output of the
1031D calculation to the angular average of the output of 2D calculation
104over all possible angles.
105
106
107References
108----------
109
110[1] Finnigan, J.A., Jacobs, D.J., 1971.
111*Light scattering by ellipsoidal particles in solution*,
112J. Phys. D: Appl. Phys. 4, 72-77. doi:10.1088/0022-3727/4/1/310
113
114Authorship and Verification
115----------------------------
116
117* **Author:** NIST IGOR/DANSE **Date:** pre 2010
118* **Last Modified by:** Paul Kienzle (improved calculation) **Date:** April 4, 2017
119<<<<<<< HEAD
120* **Last Reviewed by:** Paul Kienzle &Richard Heenan **Date:**  April 4, 2017
121=======
122* **Last Reviewed by:** Paul Kienzle & Richard Heenan **Date:**  April 4, 2017
123>>>>>>> 3fd04991e2575b02401723d8534c376cd9b66305
124
125"""
126
127from numpy import inf, sin, cos, pi
128
129name = "triaxial_ellipsoid"
130title = "Ellipsoid of uniform scattering length density with three independent axes."
131
132description = """
133Note: During fitting ensure that the inequality ra<rb<rc is not
134        violated. Otherwise the calculation will
135        not be correct.
136"""
137category = "shape:ellipsoid"
138
139#             ["name", "units", default, [lower, upper], "type","description"],
140parameters = [["sld", "1e-6/Ang^2", 4, [-inf, inf], "sld",
141               "Ellipsoid scattering length density"],
142              ["sld_solvent", "1e-6/Ang^2", 1, [-inf, inf], "sld",
143               "Solvent scattering length density"],
144              ["radius_equat_minor", "Ang", 20, [0, inf], "volume",
145               "Minor equatorial radius, Ra"],
146              ["radius_equat_major", "Ang", 400, [0, inf], "volume",
147               "Major equatorial radius, Rb"],
148              ["radius_polar", "Ang", 10, [0, inf], "volume",
149               "Polar radius, Rc"],
150              ["theta", "degrees", 60, [-inf, inf], "orientation",
151               "In plane angle"],
152              ["phi", "degrees", 60, [-inf, inf], "orientation",
153               "Out of plane angle"],
154              ["psi", "degrees", 60, [-inf, inf], "orientation",
155               "Out of plane angle"],
156             ]
157
158source = ["lib/sas_3j1x_x.c", "lib/gauss76.c", "triaxial_ellipsoid.c"]
159
160def ER(radius_equat_minor, radius_equat_major, radius_polar):
161    """
162    Returns the effective radius used in the S*P calculation
163    """
164    import numpy as np
165    from .ellipsoid import ER as ellipsoid_ER
166
167    # now that radii can be in any size order, radii need sorting a,b,c
168    # where a~b and c is either much smaller or much larger
169    radii = np.vstack((radius_equat_major, radius_equat_minor, radius_polar))
170    radii = np.sort(radii, axis=0)
171    selector = (radii[1] - radii[0]) > (radii[2] - radii[1])
172    polar = np.where(selector, radii[0], radii[2])
173    equatorial = np.sqrt(np.where(~selector, radii[0]*radii[1], radii[1]*radii[2]))
174    return ellipsoid_ER(polar, equatorial)
175
176demo = dict(scale=1, background=0,
177            sld=6, sld_solvent=1,
178            theta=30, phi=15, psi=5,
179            radius_equat_minor=25, radius_equat_major=36, radius_polar=50,
180            radius_equat_minor_pd=0, radius_equat_minor_pd_n=1,
181            radius_equat_major_pd=0, radius_equat_major_pd_n=1,
182            radius_polar_pd=.2, radius_polar_pd_n=30,
183            theta_pd=15, theta_pd_n=45,
184            phi_pd=15, phi_pd_n=1,
185            psi_pd=15, psi_pd_n=1)
186
187q = 0.1
188# april 6 2017, rkh add unit tests
189#     NOT compared with any other calc method, assume correct!
190# add 2d test after pull #890
191qx = q*cos(pi/6.0)
192qy = q*sin(pi/6.0)
193tests = [[{}, 0.05, 24.8839548033],
194#        [{'theta':80., 'phi':10.}, (qx, qy), 9999. ],
195        ]
196del qx, qy  # not necessary to delete, but cleaner
Note: See TracBrowser for help on using the repository browser.