[5933c7f] | 1 | # cylinder model |
---|
| 2 | # Note: model title and parameter table are inserted automatically |
---|
| 3 | r""" |
---|
| 4 | The form factor is normalized by the particle volume V = \piR^2L. |
---|
| 5 | |
---|
| 6 | Definition |
---|
| 7 | ---------- |
---|
| 8 | |
---|
| 9 | The output of the 2D scattering intensity function for oriented cylinders is |
---|
| 10 | given by (Guinier, 1955) |
---|
| 11 | |
---|
| 12 | .. math:: |
---|
| 13 | |
---|
| 14 | P(q,\alpha) = \frac{\text{scale}}{V} F^2(q) + \text{background} |
---|
| 15 | |
---|
| 16 | where |
---|
| 17 | |
---|
| 18 | .. math:: |
---|
| 19 | |
---|
| 20 | F(q) = 2 (\Delta \rho) V |
---|
| 21 | \frac{\sin \left(\tfrac12 qL\cos\alpha \right)} |
---|
| 22 | {\tfrac12 qL \cos \alpha} |
---|
| 23 | \frac{J_1 \left(q R \sin \alpha\right)}{q R \sin \alpha} |
---|
| 24 | |
---|
| 25 | and $\alpha$ is the angle between the axis of the cylinder and $\vec q$, $V$ |
---|
| 26 | is the volume of the cylinder, $L$ is the length of the cylinder, $R$ is the |
---|
| 27 | radius of the cylinder, and $\Delta\rho$ (contrast) is the scattering length |
---|
| 28 | density difference between the scatterer and the solvent. $J_1$ is the |
---|
| 29 | first order Bessel function. |
---|
| 30 | |
---|
| 31 | To provide easy access to the orientation of the cylinder, we define the |
---|
| 32 | axis of the cylinder using two angles $\theta$ and $\phi$. Those angles |
---|
[6ef4293] | 33 | are defined in :numref:`cylinder-angle-definition`. |
---|
[5933c7f] | 34 | |
---|
| 35 | .. _cylinder-angle-definition: |
---|
| 36 | |
---|
| 37 | .. figure:: img/cylinder_angle_definition.jpg |
---|
| 38 | |
---|
| 39 | Definition of the angles for oriented cylinders. |
---|
| 40 | |
---|
| 41 | .. figure:: img/cylinder_angle_projection.jpg |
---|
| 42 | |
---|
| 43 | Examples of the angles for oriented cylinders against the detector plane. |
---|
| 44 | |
---|
| 45 | NB: The 2nd virial coefficient of the cylinder is calculated based on the |
---|
| 46 | radius and length values, and used as the effective radius for $S(q)$ |
---|
| 47 | when $P(q) \cdot S(q)$ is applied. |
---|
| 48 | |
---|
| 49 | The output of the 1D scattering intensity function for randomly oriented |
---|
| 50 | cylinders is then given by |
---|
| 51 | |
---|
| 52 | .. math:: |
---|
| 53 | |
---|
| 54 | P(q) = \frac{\text{scale}}{V} |
---|
| 55 | \int_0^{\pi/2} F^2(q,\alpha) \sin \alpha\ d\alpha + \text{background} |
---|
| 56 | |
---|
| 57 | The $\theta$ and $\phi$ parameters are not used for the 1D output. |
---|
| 58 | |
---|
| 59 | Validation |
---|
| 60 | ---------- |
---|
| 61 | |
---|
| 62 | Validation of the code was done by comparing the output of the 1D model |
---|
| 63 | to the output of the software provided by the NIST (Kline, 2006). |
---|
| 64 | The implementation of the intensity for fully oriented cylinders was done |
---|
| 65 | by averaging over a uniform distribution of orientations using |
---|
| 66 | |
---|
| 67 | .. math:: |
---|
| 68 | |
---|
| 69 | P(q) = \int_0^{\pi/2} d\phi |
---|
| 70 | \int_0^\pi p(\theta, \phi) P_0(q,\alpha) \sin \theta\ d\theta |
---|
| 71 | |
---|
| 72 | |
---|
| 73 | where $p(\theta,\phi)$ is the probability distribution for the orientation |
---|
| 74 | and $P_0(q,\alpha)$ is the scattering intensity for the fully oriented |
---|
| 75 | system, and then comparing to the 1D result. |
---|
| 76 | |
---|
| 77 | References |
---|
| 78 | ---------- |
---|
| 79 | |
---|
| 80 | None |
---|
| 81 | |
---|
| 82 | """ |
---|
| 83 | |
---|
[7ae2b7f] | 84 | import numpy as np # type: ignore |
---|
| 85 | from numpy import pi, inf # type: ignore |
---|
[5933c7f] | 86 | |
---|
| 87 | name = "cylinder" |
---|
| 88 | title = "Right circular cylinder with uniform scattering length density." |
---|
| 89 | description = """ |
---|
| 90 | f(q,alpha) = 2*(sld - sld_solvent)*V*sin(qLcos(alpha)/2)) |
---|
| 91 | /[qLcos(alpha)/2]*J1(qRsin(alpha))/[qRsin(alpha)] |
---|
| 92 | |
---|
| 93 | P(q,alpha)= scale/V*f(q,alpha)^(2)+background |
---|
| 94 | V: Volume of the cylinder |
---|
| 95 | R: Radius of the cylinder |
---|
| 96 | L: Length of the cylinder |
---|
| 97 | J1: The bessel function |
---|
| 98 | alpha: angle between the axis of the |
---|
| 99 | cylinder and the q-vector for 1D |
---|
| 100 | :the ouput is P(q)=scale/V*integral |
---|
| 101 | from pi/2 to zero of... |
---|
| 102 | f(q,alpha)^(2)*sin(alpha)*dalpha + background |
---|
| 103 | """ |
---|
| 104 | category = "shape:cylinder" |
---|
| 105 | |
---|
| 106 | # [ "name", "units", default, [lower, upper], "type", "description"], |
---|
[42356c8] | 107 | parameters = [["sld", "4e-6/Ang^2", 4, [-inf, inf], "sld", |
---|
[5933c7f] | 108 | "Cylinder scattering length density"], |
---|
[42356c8] | 109 | ["sld_solvent", "1e-6/Ang^2", 1, [-inf, inf], "sld", |
---|
[5933c7f] | 110 | "Solvent scattering length density"], |
---|
| 111 | ["radius", "Ang", 20, [0, inf], "volume", |
---|
| 112 | "Cylinder radius"], |
---|
| 113 | ["length", "Ang", 400, [0, inf], "volume", |
---|
| 114 | "Cylinder length"], |
---|
| 115 | ["theta", "degrees", 60, [-inf, inf], "orientation", |
---|
| 116 | "In plane angle"], |
---|
| 117 | ["phi", "degrees", 60, [-inf, inf], "orientation", |
---|
| 118 | "Out of plane angle"], |
---|
| 119 | ] |
---|
| 120 | |
---|
| 121 | source = ["lib/polevl.c","lib/sas_J1.c", "lib/gauss76.c", "cylinder.c"] |
---|
| 122 | |
---|
| 123 | def ER(radius, length): |
---|
| 124 | """ |
---|
| 125 | Return equivalent radius (ER) |
---|
| 126 | """ |
---|
| 127 | ddd = 0.75 * radius * (2 * radius * length + (length + radius) * (length + pi * radius)) |
---|
| 128 | return 0.5 * (ddd) ** (1. / 3.) |
---|
| 129 | |
---|
| 130 | # parameters for demo |
---|
| 131 | demo = dict(scale=1, background=0, |
---|
| 132 | sld=6, sld_solvent=1, |
---|
| 133 | radius=20, length=300, |
---|
| 134 | theta=60, phi=60, |
---|
| 135 | radius_pd=.2, radius_pd_n=9, |
---|
| 136 | length_pd=.2, length_pd_n=10, |
---|
| 137 | theta_pd=10, theta_pd_n=5, |
---|
| 138 | phi_pd=10, phi_pd_n=5) |
---|
| 139 | |
---|
| 140 | qx, qy = 0.2 * np.cos(2.5), 0.2 * np.sin(2.5) |
---|
| 141 | tests = [[{}, 0.2, 0.042761386790780453], |
---|
| 142 | [{}, [0.2], [0.042761386790780453]], |
---|
| 143 | [{'theta':10.0, 'phi':10.0}, (qx, qy), 0.03514647218513852], |
---|
| 144 | [{'theta':10.0, 'phi':10.0}, [(qx, qy)], [0.03514647218513852]], |
---|
| 145 | ] |
---|
| 146 | del qx, qy # not necessary to delete, but cleaner |
---|
| 147 | # ADDED by: RKH ON: 18Mar2016 renamed sld's etc |
---|