[c612162] | 1 | # pylint: disable=line-too-long |
---|
[a8b3cdb] | 2 | r""" |
---|
| 3 | Definition for 2D (orientated system) |
---|
| 4 | ------------------------------------- |
---|
| 5 | |
---|
[40a87fa] | 6 | The angles $\theta$ and $\phi$ define the orientation of the axis of the |
---|
| 7 | cylinder. The angle $\Psi$ is defined as the orientation of the major |
---|
| 8 | axis of the ellipse with respect to the vector $Q$. A gaussian polydispersity |
---|
| 9 | can be added to any of the orientation angles, and also for the minor |
---|
| 10 | radius and the ratio of the ellipse radii. |
---|
[a8b3cdb] | 11 | |
---|
[5111921] | 12 | .. figure:: img/elliptical_cylinder_geometry.png |
---|
[a8b3cdb] | 13 | |
---|
[40a87fa] | 14 | Elliptical cylinder geometry $a = r_\text{minor}$ |
---|
| 15 | and $\nu = r_\text{major} / r_\text{minor}$ is the *axis_ratio*. |
---|
[a8b3cdb] | 16 | |
---|
| 17 | The function calculated is |
---|
| 18 | |
---|
| 19 | .. math:: |
---|
[fa8011eb] | 20 | |
---|
[40a87fa] | 21 | I(\vec q)=\frac{1}{V_\text{cyl}}\int{d\psi}\int{d\phi}\int{ |
---|
[fcb33e4] | 22 | p(\theta,\phi,\psi)F^2(\vec q,\alpha,\psi)\sin(\alpha)d\alpha} |
---|
[a8b3cdb] | 23 | |
---|
| 24 | with the functions |
---|
| 25 | |
---|
| 26 | .. math:: |
---|
[fa8011eb] | 27 | |
---|
[fcb33e4] | 28 | F(q,\alpha,\psi) = 2\frac{J_1(a)\sin(b)}{ab} |
---|
[40a87fa] | 29 | |
---|
| 30 | where |
---|
| 31 | |
---|
| 32 | .. math:: |
---|
| 33 | |
---|
[fcb33e4] | 34 | a = qr'\sin(\alpha) |
---|
[404ebbd] | 35 | |
---|
[fcb33e4] | 36 | b = q\frac{L}{2}\cos(\alpha) |
---|
[404ebbd] | 37 | |
---|
[fcb33e4] | 38 | r'=\frac{r_{minor}}{\sqrt{2}}\sqrt{(1+\nu^{2}) + (1-\nu^{2})cos(\psi)} |
---|
[40a87fa] | 39 | |
---|
[a8b3cdb] | 40 | |
---|
[fcb33e4] | 41 | and the angle $\psi$ is defined as the orientation of the major axis of the |
---|
[40a87fa] | 42 | ellipse with respect to the vector $\vec q$. The angle $\alpha$ is the angle |
---|
| 43 | between the axis of the cylinder and $\vec q$. |
---|
[a8b3cdb] | 44 | |
---|
| 45 | |
---|
| 46 | Definition for 1D (no preferred orientation) |
---|
| 47 | -------------------------------------------- |
---|
| 48 | |
---|
[40a87fa] | 49 | The form factor is averaged over all possible orientation before normalized |
---|
| 50 | by the particle volume |
---|
[a8b3cdb] | 51 | |
---|
| 52 | .. math:: |
---|
| 53 | |
---|
[40a87fa] | 54 | P(q) = \text{scale} <F^2> / V |
---|
[a8b3cdb] | 55 | |
---|
[40a87fa] | 56 | To provide easy access to the orientation of the elliptical cylinder, we |
---|
| 57 | define the axis of the cylinder using two angles $\theta$, $\phi$ and $\Psi$ |
---|
| 58 | (see :ref:`cylinder orientation <cylinder-angle-definition>`). The angle |
---|
[404ebbd] | 59 | $\Psi$ is the rotational angle around its own long_c axis. |
---|
[40a87fa] | 60 | |
---|
| 61 | All angle parameters are valid and given only for 2D calculation; ie, an |
---|
| 62 | oriented system. |
---|
[a8b3cdb] | 63 | |
---|
[15a90c1] | 64 | .. figure:: img/elliptical_cylinder_angle_definition.png |
---|
[a8b3cdb] | 65 | |
---|
[9802ab3] | 66 | Definition of angles for oriented elliptical cylinder, where axis_ratio is drawn >1, |
---|
| 67 | and angle $\Psi$ is now a rotation around the axis of the cylinder. |
---|
[a8b3cdb] | 68 | |
---|
[15a90c1] | 69 | .. figure:: img/elliptical_cylinder_angle_projection.png |
---|
[a8b3cdb] | 70 | |
---|
[40a87fa] | 71 | Examples of the angles for oriented elliptical cylinders against the |
---|
[15a90c1] | 72 | detector plane, with $\Psi$ = 0. |
---|
[a8b3cdb] | 73 | |
---|
[404ebbd] | 74 | The $\theta$ and $\phi$ parameters to orient the cylinder only appear in the model when fitting 2d data. |
---|
[9802ab3] | 75 | On introducing "Orientational Distribution" in the angles, "distribution of theta" and "distribution of phi" parameters will |
---|
[404ebbd] | 76 | appear. These are actually rotations about the axes $\delta_1$ and $\delta_2$ of the cylinder, the $b$ and $a$ axes of the |
---|
| 77 | cylinder cross section. (When $\theta = \phi = 0$ these are parallel to the $Y$ and $X$ axes of the instrument.) |
---|
| 78 | The third orientation distribution, in $\psi$, is about the $c$ axis of the particle. Some experimentation may be required to |
---|
| 79 | understand the 2d patterns fully. (Earlier implementations had numerical integration issues in some circumstances when orientation |
---|
| 80 | distributions passed through 90 degrees, such situations, with very broad distributions, should still be approached with care.) |
---|
[9802ab3] | 81 | |
---|
[40a87fa] | 82 | NB: The 2nd virial coefficient of the cylinder is calculated based on the |
---|
| 83 | averaged radius $(=\sqrt{r_\text{minor}^2 * \text{axis ratio}})$ and length |
---|
| 84 | values, and used as the effective radius for $S(Q)$ when $P(Q)*S(Q)$ is applied. |
---|
[a8b3cdb] | 85 | |
---|
| 86 | |
---|
| 87 | Validation |
---|
| 88 | ---------- |
---|
| 89 | |
---|
[40a87fa] | 90 | Validation of our code was done by comparing the output of the 1D calculation |
---|
| 91 | to the angular average of the output of the 2D calculation over all possible |
---|
| 92 | angles. |
---|
[a8b3cdb] | 93 | |
---|
[40a87fa] | 94 | In the 2D average, more binning in the angle $\phi$ is necessary to get the |
---|
| 95 | proper result. The following figure shows the results of the averaging by |
---|
| 96 | varying the number of angular bins. |
---|
[a8b3cdb] | 97 | |
---|
[5111921] | 98 | .. figure:: img/elliptical_cylinder_averaging.png |
---|
[a8b3cdb] | 99 | |
---|
[fa8011eb] | 100 | The intensities averaged from 2D over different numbers of bins and angles. |
---|
[a8b3cdb] | 101 | |
---|
[e65a3e7] | 102 | References |
---|
| 103 | ---------- |
---|
[a8b3cdb] | 104 | |
---|
[40a87fa] | 105 | L A Feigin and D I Svergun, *Structure Analysis by Small-Angle X-Ray and |
---|
[fcb33e4] | 106 | Neutron Scattering*, Plenum, New York, (1987) [see table 3.4] |
---|
| 107 | |
---|
| 108 | Authorship and Verification |
---|
| 109 | ---------------------------- |
---|
| 110 | |
---|
| 111 | * **Author:** |
---|
[404ebbd] | 112 | * **Last Modified by:** |
---|
[fcb33e4] | 113 | * **Last Reviewed by:** Richard Heenan - corrected equation in docs **Date:** December 21, 2016 |
---|
| 114 | |
---|
[a8b3cdb] | 115 | """ |
---|
| 116 | |
---|
[0b56f38] | 117 | from numpy import pi, inf, sqrt, sin, cos |
---|
[a8b3cdb] | 118 | |
---|
| 119 | name = "elliptical_cylinder" |
---|
| 120 | title = "Form factor for an elliptical cylinder." |
---|
| 121 | description = """ |
---|
[c612162] | 122 | Form factor for an elliptical cylinder. |
---|
| 123 | See L A Feigin and D I Svergun, Structure Analysis by Small-Angle X-Ray and Neutron Scattering, Plenum, New York, (1987). |
---|
[a8b3cdb] | 124 | """ |
---|
| 125 | category = "shape:cylinder" |
---|
| 126 | |
---|
| 127 | # pylint: disable=bad-whitespace, line-too-long |
---|
| 128 | # ["name", "units", default, [lower, upper], "type","description"], |
---|
[a807206] | 129 | parameters = [["radius_minor", "Ang", 20.0, [0, inf], "volume", "Ellipse minor radius"], |
---|
[42356c8] | 130 | ["axis_ratio", "", 1.5, [1, inf], "volume", "Ratio of major radius over minor radius"], |
---|
[a8b3cdb] | 131 | ["length", "Ang", 400.0, [1, inf], "volume", "Length of the cylinder"], |
---|
[42356c8] | 132 | ["sld", "1e-6/Ang^2", 4.0, [-inf, inf], "sld", "Cylinder scattering length density"], |
---|
| 133 | ["sld_solvent", "1e-6/Ang^2", 1.0, [-inf, inf], "sld", "Solvent scattering length density"], |
---|
[9b79f29] | 134 | ["theta", "degrees", 90.0, [-360, 360], "orientation", "cylinder axis to beam angle"], |
---|
| 135 | ["phi", "degrees", 0, [-360, 360], "orientation", "rotation about beam"], |
---|
| 136 | ["psi", "degrees", 0, [-360, 360], "orientation", "rotation about cylinder axis"]] |
---|
[a8b3cdb] | 137 | |
---|
| 138 | # pylint: enable=bad-whitespace, line-too-long |
---|
| 139 | |
---|
[40a87fa] | 140 | source = ["lib/polevl.c", "lib/sas_J1.c", "lib/gauss76.c", "lib/gauss20.c", |
---|
| 141 | "elliptical_cylinder.c"] |
---|
[a8b3cdb] | 142 | |
---|
[a807206] | 143 | demo = dict(scale=1, background=0, radius_minor=100, axis_ratio=1.5, length=400.0, |
---|
[40a87fa] | 144 | sld=4.0, sld_solvent=1.0, theta=10.0, phi=20, psi=30, |
---|
| 145 | theta_pd=10, phi_pd=2, psi_pd=3) |
---|
[a8b3cdb] | 146 | |
---|
[a807206] | 147 | def ER(radius_minor, axis_ratio, length): |
---|
[a8b3cdb] | 148 | """ |
---|
| 149 | Equivalent radius |
---|
[a807206] | 150 | @param radius_minor: Ellipse minor radius |
---|
[74fd96f] | 151 | @param axis_ratio: Ratio of major radius over minor radius |
---|
[a8b3cdb] | 152 | @param length: Length of the cylinder |
---|
| 153 | """ |
---|
[a807206] | 154 | radius = sqrt(radius_minor * radius_minor * axis_ratio) |
---|
[40a87fa] | 155 | ddd = 0.75 * radius * (2 * radius * length |
---|
| 156 | + (length + radius) * (length + pi * radius)) |
---|
[a8b3cdb] | 157 | return 0.5 * (ddd) ** (1. / 3.) |
---|
[404ebbd] | 158 | |
---|
| 159 | def random(): |
---|
| 160 | import numpy as np |
---|
| 161 | # V = pi * radius_major * radius_minor * length; |
---|
| 162 | V = 10**np.random.uniform(3, 9) |
---|
| 163 | length = 10**np.random.uniform(1, 3) |
---|
[d9ec8f9] | 164 | axis_ratio = 10**np.random.uniform(0, 2) |
---|
[404ebbd] | 165 | radius_minor = np.sqrt(V/length/axis_ratio) |
---|
| 166 | Vf = 10**np.random.uniform(-4, -2) |
---|
| 167 | pars = dict( |
---|
| 168 | #background=0, sld=0, sld_solvent=1, |
---|
| 169 | scale=1e9*Vf/V, |
---|
| 170 | length=length, |
---|
| 171 | radius_minor=radius_minor, |
---|
| 172 | axis_ratio=axis_ratio, |
---|
| 173 | ) |
---|
| 174 | return pars |
---|
| 175 | |
---|
[0b56f38] | 176 | q = 0.1 |
---|
| 177 | # april 6 2017, rkh added a 2d unit test, NOT READY YET pull #890 branch assume correct! |
---|
| 178 | qx = q*cos(pi/6.0) |
---|
| 179 | qy = q*sin(pi/6.0) |
---|
[a8b3cdb] | 180 | |
---|
[40a87fa] | 181 | tests = [ |
---|
[a807206] | 182 | [{'radius_minor': 20.0, 'axis_ratio': 1.5, 'length':400.0}, 'ER', 79.89245454155024], |
---|
| 183 | [{'radius_minor': 20.0, 'axis_ratio': 1.2, 'length':300.0}, 'VR', 1], |
---|
[40a87fa] | 184 | |
---|
| 185 | # The SasView test result was 0.00169, with a background of 0.001 |
---|
[a807206] | 186 | [{'radius_minor': 20.0, 'axis_ratio': 1.5, 'sld': 4.0, 'length':400.0, |
---|
[40a87fa] | 187 | 'sld_solvent':1.0, 'background':0.0}, |
---|
| 188 | 0.001, 675.504402], |
---|
[0b56f38] | 189 | # [{'theta':80., 'phi':10.}, (qx, qy), 7.88866563001 ], |
---|
[40a87fa] | 190 | ] |
---|