1 | # pylint: disable=line-too-long |
---|
2 | r""" |
---|
3 | |
---|
4 | .. figure:: img/elliptical_cylinder_geometry.png |
---|
5 | |
---|
6 | Elliptical cylinder geometry $a = r_\text{minor}$ |
---|
7 | and $\nu = r_\text{major} / r_\text{minor}$ is the *axis_ratio*. |
---|
8 | |
---|
9 | The function calculated is |
---|
10 | |
---|
11 | .. math:: |
---|
12 | |
---|
13 | I(\vec q)=\frac{1}{V_\text{cyl}}\int{d\psi}\int{d\phi}\int{ |
---|
14 | p(\theta,\phi,\psi)F^2(\vec q,\alpha,\psi)\sin(\alpha)d\alpha} |
---|
15 | |
---|
16 | with the functions |
---|
17 | |
---|
18 | .. math:: |
---|
19 | |
---|
20 | F(q,\alpha,\psi) = 2\frac{J_1(a)\sin(b)}{ab} |
---|
21 | |
---|
22 | where |
---|
23 | |
---|
24 | .. math:: |
---|
25 | |
---|
26 | a = qr'\sin(\alpha) |
---|
27 | |
---|
28 | b = q\frac{L}{2}\cos(\alpha) |
---|
29 | |
---|
30 | r'=\frac{r_{minor}}{\sqrt{2}}\sqrt{(1+\nu^{2}) + (1-\nu^{2})cos(\psi)} |
---|
31 | |
---|
32 | |
---|
33 | and the angle $\psi$ is defined as the orientation of the major axis of the |
---|
34 | ellipse with respect to the vector $\vec q$. The angle $\alpha$ is the angle |
---|
35 | between the axis of the cylinder and $\vec q$. |
---|
36 | |
---|
37 | |
---|
38 | For 1D scattering, with no preferred orientation, the form factor is averaged over all possible orientations and normalized |
---|
39 | by the particle volume |
---|
40 | |
---|
41 | .. math:: |
---|
42 | |
---|
43 | P(q) = \text{scale} <F^2> / V |
---|
44 | |
---|
45 | For 2d data the orientation of the particle is required, described using a different set |
---|
46 | of angles as in the diagrams below, for further details of the calculation and angular |
---|
47 | dispersions see :ref:`orientation` . |
---|
48 | |
---|
49 | |
---|
50 | .. figure:: img/elliptical_cylinder_angle_definition.png |
---|
51 | |
---|
52 | Note that the angles here are not the same as in the equations for the scattering function. |
---|
53 | Rotation $\theta$, initially in the $xz$ plane, is carried out first, then |
---|
54 | rotation $\phi$ about the $z$ axis, finally rotation $\Psi$ is now around the axis of the cylinder. |
---|
55 | The neutron or X-ray beam is along the $z$ axis. |
---|
56 | |
---|
57 | .. figure:: img/elliptical_cylinder_angle_projection.png |
---|
58 | |
---|
59 | Examples of the angles for oriented elliptical cylinders against the |
---|
60 | detector plane, with $\Psi$ = 0. |
---|
61 | |
---|
62 | The $\theta$ and $\phi$ parameters to orient the cylinder only appear in the model when fitting 2d data. |
---|
63 | |
---|
64 | |
---|
65 | NB: The 2nd virial coefficient of the cylinder is calculated based on the |
---|
66 | averaged radius $(=\sqrt{r_\text{minor}^2 * \text{axis ratio}})$ and length |
---|
67 | values, and used as the effective radius for $S(Q)$ when $P(Q)*S(Q)$ is applied. |
---|
68 | |
---|
69 | |
---|
70 | Validation |
---|
71 | ---------- |
---|
72 | |
---|
73 | Validation of our code was done by comparing the output of the 1D calculation |
---|
74 | to the angular average of the output of the 2D calculation over all possible |
---|
75 | angles. |
---|
76 | |
---|
77 | In the 2D average, more binning in the angle $\phi$ is necessary to get the |
---|
78 | proper result. The following figure shows the results of the averaging by |
---|
79 | varying the number of angular bins. |
---|
80 | |
---|
81 | .. figure:: img/elliptical_cylinder_averaging.png |
---|
82 | |
---|
83 | The intensities averaged from 2D over different numbers of bins and angles. |
---|
84 | |
---|
85 | References |
---|
86 | ---------- |
---|
87 | |
---|
88 | L A Feigin and D I Svergun, *Structure Analysis by Small-Angle X-Ray and |
---|
89 | Neutron Scattering*, Plenum, New York, (1987) [see table 3.4] |
---|
90 | |
---|
91 | Authorship and Verification |
---|
92 | ---------------------------- |
---|
93 | |
---|
94 | * **Author:** |
---|
95 | * **Last Modified by:** |
---|
96 | * **Last Reviewed by:** Richard Heenan - corrected equation in docs **Date:** December 21, 2016 |
---|
97 | |
---|
98 | """ |
---|
99 | |
---|
100 | from numpy import pi, inf, sqrt, sin, cos |
---|
101 | |
---|
102 | name = "elliptical_cylinder" |
---|
103 | title = "Form factor for an elliptical cylinder." |
---|
104 | description = """ |
---|
105 | Form factor for an elliptical cylinder. |
---|
106 | See L A Feigin and D I Svergun, Structure Analysis by Small-Angle X-Ray and Neutron Scattering, Plenum, New York, (1987). |
---|
107 | """ |
---|
108 | category = "shape:cylinder" |
---|
109 | |
---|
110 | # pylint: disable=bad-whitespace, line-too-long |
---|
111 | # ["name", "units", default, [lower, upper], "type","description"], |
---|
112 | parameters = [["radius_minor", "Ang", 20.0, [0, inf], "volume", "Ellipse minor radius"], |
---|
113 | ["axis_ratio", "", 1.5, [1, inf], "volume", "Ratio of major radius over minor radius"], |
---|
114 | ["length", "Ang", 400.0, [1, inf], "volume", "Length of the cylinder"], |
---|
115 | ["sld", "1e-6/Ang^2", 4.0, [-inf, inf], "sld", "Cylinder scattering length density"], |
---|
116 | ["sld_solvent", "1e-6/Ang^2", 1.0, [-inf, inf], "sld", "Solvent scattering length density"], |
---|
117 | ["theta", "degrees", 90.0, [-360, 360], "orientation", "cylinder axis to beam angle"], |
---|
118 | ["phi", "degrees", 0, [-360, 360], "orientation", "rotation about beam"], |
---|
119 | ["psi", "degrees", 0, [-360, 360], "orientation", "rotation about cylinder axis"]] |
---|
120 | |
---|
121 | # pylint: enable=bad-whitespace, line-too-long |
---|
122 | |
---|
123 | source = ["lib/polevl.c", "lib/sas_J1.c", "lib/gauss76.c", "lib/gauss20.c", |
---|
124 | "elliptical_cylinder.c"] |
---|
125 | |
---|
126 | demo = dict(scale=1, background=0, radius_minor=100, axis_ratio=1.5, length=400.0, |
---|
127 | sld=4.0, sld_solvent=1.0, theta=10.0, phi=20, psi=30, |
---|
128 | theta_pd=10, phi_pd=2, psi_pd=3) |
---|
129 | |
---|
130 | def ER(radius_minor, axis_ratio, length): |
---|
131 | """ |
---|
132 | Equivalent radius |
---|
133 | @param radius_minor: Ellipse minor radius |
---|
134 | @param axis_ratio: Ratio of major radius over minor radius |
---|
135 | @param length: Length of the cylinder |
---|
136 | """ |
---|
137 | radius = sqrt(radius_minor * radius_minor * axis_ratio) |
---|
138 | ddd = 0.75 * radius * (2 * radius * length |
---|
139 | + (length + radius) * (length + pi * radius)) |
---|
140 | return 0.5 * (ddd) ** (1. / 3.) |
---|
141 | |
---|
142 | def random(): |
---|
143 | import numpy as np |
---|
144 | # V = pi * radius_major * radius_minor * length; |
---|
145 | V = 10**np.random.uniform(3, 9) |
---|
146 | length = 10**np.random.uniform(1, 3) |
---|
147 | axis_ratio = 10**np.random.uniform(0, 2) |
---|
148 | radius_minor = np.sqrt(V/length/axis_ratio) |
---|
149 | Vf = 10**np.random.uniform(-4, -2) |
---|
150 | pars = dict( |
---|
151 | #background=0, sld=0, sld_solvent=1, |
---|
152 | scale=1e9*Vf/V, |
---|
153 | length=length, |
---|
154 | radius_minor=radius_minor, |
---|
155 | axis_ratio=axis_ratio, |
---|
156 | ) |
---|
157 | return pars |
---|
158 | |
---|
159 | q = 0.1 |
---|
160 | # april 6 2017, rkh added a 2d unit test, NOT READY YET pull #890 branch assume correct! |
---|
161 | qx = q*cos(pi/6.0) |
---|
162 | qy = q*sin(pi/6.0) |
---|
163 | |
---|
164 | tests = [ |
---|
165 | [{'radius_minor': 20.0, 'axis_ratio': 1.5, 'length':400.0}, 'ER', 79.89245454155024], |
---|
166 | [{'radius_minor': 20.0, 'axis_ratio': 1.2, 'length':300.0}, 'VR', 1], |
---|
167 | |
---|
168 | # The SasView test result was 0.00169, with a background of 0.001 |
---|
169 | [{'radius_minor': 20.0, 'axis_ratio': 1.5, 'sld': 4.0, 'length':400.0, |
---|
170 | 'sld_solvent':1.0, 'background':0.0}, |
---|
171 | 0.001, 675.504402], |
---|
172 | # [{'theta':80., 'phi':10.}, (qx, qy), 7.88866563001 ], |
---|
173 | ] |
---|