[5d4777d] | 1 | # cylinder model |
---|
[a7684e5] | 2 | # Note: model title and parameter table are inserted automatically |
---|
[32c160a] | 3 | r""" |
---|
[a7684e5] | 4 | The form factor is normalized by the particle volume. |
---|
[32c160a] | 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 | |
---|
[19dcb933] | 14 | P(Q,\alpha) = {\text{scale} \over V} F^2(Q) + \text{background} |
---|
[32c160a] | 15 | |
---|
| 16 | where |
---|
| 17 | |
---|
| 18 | .. math:: |
---|
| 19 | |
---|
[19dcb933] | 20 | F(Q) = 2 (\Delta \rho) V |
---|
| 21 | {\sin \left(Q\tfrac12 L\cos\alpha \right) |
---|
| 22 | \over Q\tfrac12 L \cos \alpha} |
---|
| 23 | {J_1 \left(Q R \sin \alpha\right) \over Q R \sin \alpha} |
---|
[32c160a] | 24 | |
---|
| 25 | and $\alpha$ is the angle between the axis of the cylinder and $\vec q$, $V$ |
---|
[19dcb933] | 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. |
---|
[32c160a] | 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 |
---|
[19dcb933] | 33 | are defined in :num:`figure #cylinder-orientation`. |
---|
[32c160a] | 34 | |
---|
[5d4777d] | 35 | .. _cylinder-orientation: |
---|
[32c160a] | 36 | |
---|
[19dcb933] | 37 | .. figure:: img/orientation.jpg |
---|
[32c160a] | 38 | |
---|
| 39 | Definition of the angles for oriented cylinders. |
---|
| 40 | |
---|
[19dcb933] | 41 | .. figure:: img/orientation2.jpg |
---|
[32c160a] | 42 | |
---|
[9474dda] | 43 | Examples of the angles for oriented cylinders against the detector plane. |
---|
[32c160a] | 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 | |
---|
[19dcb933] | 54 | P(Q) = {\text{scale} \over V} |
---|
| 55 | \int_0^{\pi/2} F^2(Q,\alpha) \sin \alpha\ d\alpha + \text{background} |
---|
[32c160a] | 56 | |
---|
| 57 | The *theta* and *phi* parameters are not used for the 1D output. Our |
---|
| 58 | implementation of the scattering kernel and the 1D scattering intensity |
---|
| 59 | use the c-library from NIST. |
---|
| 60 | |
---|
[a7684e5] | 61 | Validation |
---|
| 62 | ---------- |
---|
[32c160a] | 63 | |
---|
| 64 | Validation of our code was done by comparing the output of the 1D model |
---|
| 65 | to the output of the software provided by the NIST (Kline, 2006). |
---|
[19dcb933] | 66 | :num:`Figure #cylinder-compare` shows a comparison of |
---|
[32c160a] | 67 | the 1D output of our model and the output of the NIST software. |
---|
| 68 | |
---|
[5d4777d] | 69 | .. _cylinder-compare: |
---|
[32c160a] | 70 | |
---|
[19dcb933] | 71 | .. figure:: img/cylinder_compare.jpg |
---|
[32c160a] | 72 | |
---|
| 73 | Comparison of the SasView scattering intensity for a cylinder with the |
---|
| 74 | output of the NIST SANS analysis software. |
---|
[19dcb933] | 75 | The parameters were set to: *scale* = 1.0, *radius* = 20 |Ang|, |
---|
| 76 | *length* = 400 |Ang|, *contrast* = 3e-6 |Ang^-2|, and |
---|
| 77 | *background* = 0.01 |cm^-1|. |
---|
[32c160a] | 78 | |
---|
| 79 | In general, averaging over a distribution of orientations is done by |
---|
| 80 | evaluating the following |
---|
| 81 | |
---|
| 82 | .. math:: |
---|
| 83 | |
---|
[19dcb933] | 84 | P(Q) = \int_0^{\pi/2} d\phi |
---|
| 85 | \int_0^\pi p(\theta, \phi) P_0(Q,\alpha) \sin \theta\ d\theta |
---|
[32c160a] | 86 | |
---|
| 87 | |
---|
| 88 | where $p(\theta,\phi)$ is the probability distribution for the orientation |
---|
[19dcb933] | 89 | and $P_0(Q,\alpha)$ is the scattering intensity for the fully oriented |
---|
[32c160a] | 90 | system. Since we have no other software to compare the implementation of |
---|
| 91 | the intensity for fully oriented cylinders, we can compare the result of |
---|
| 92 | averaging our 2D output using a uniform distribution $p(\theta, \phi) = 1.0$. |
---|
[19dcb933] | 93 | :num:`Figure #cylinder-crosscheck` shows the result of |
---|
[32c160a] | 94 | such a cross-check. |
---|
| 95 | |
---|
[5d4777d] | 96 | .. _cylinder-crosscheck: |
---|
[32c160a] | 97 | |
---|
[19dcb933] | 98 | .. figure:: img/cylinder_crosscheck.jpg |
---|
[32c160a] | 99 | |
---|
| 100 | Comparison of the intensity for uniformly distributed cylinders |
---|
| 101 | calculated from our 2D model and the intensity from the NIST SANS |
---|
| 102 | analysis software. |
---|
[19dcb933] | 103 | The parameters used were: *scale* = 1.0, *radius* = 20 |Ang|, |
---|
| 104 | *length* = 400 |Ang|, *contrast* = 3e-6 |Ang^-2|, and |
---|
| 105 | *background* = 0.0 |cm^-1|. |
---|
[32c160a] | 106 | """ |
---|
| 107 | |
---|
[143e2f7] | 108 | import numpy as np |
---|
[32c160a] | 109 | from numpy import pi, inf |
---|
| 110 | |
---|
[a7684e5] | 111 | name = "cylinder" |
---|
| 112 | title = "Right circular cylinder with uniform scattering length density." |
---|
| 113 | description = """ |
---|
[9474dda] | 114 | f(q,alpha) = 2*(sld - solvent_sld)*V*sin(qLcos(alpha/2)) |
---|
| 115 | /[qLcos(alpha/2)]*J1(qRsin(alpha/2))/[qRsin(alpha)] |
---|
[a7684e5] | 116 | |
---|
[9474dda] | 117 | P(q,alpha)= scale/V*f(q,alpha)^(2)+background |
---|
[a7684e5] | 118 | V: Volume of the cylinder |
---|
| 119 | R: Radius of the cylinder |
---|
| 120 | L: Length of the cylinder |
---|
| 121 | J1: The bessel function |
---|
[5d4777d] | 122 | alpha: angle between the axis of the |
---|
[a7684e5] | 123 | cylinder and the q-vector for 1D |
---|
| 124 | :the ouput is P(q)=scale/V*integral |
---|
| 125 | from pi/2 to zero of... |
---|
[9474dda] | 126 | f(q,alpha)^(2)*sin(alpha)*dalpha + background |
---|
[5d4777d] | 127 | """ |
---|
[a5d0d00] | 128 | category = "shape:cylinder" |
---|
[a7684e5] | 129 | |
---|
[3e428ec] | 130 | # [ "name", "units", default, [lower, upper], "type", "description"], |
---|
| 131 | parameters = [["sld", "1e-6/Ang^2", 4, [-inf, inf], "", |
---|
| 132 | "Cylinder scattering length density"], |
---|
| 133 | ["solvent_sld", "1e-6/Ang^2", 1, [-inf, inf], "", |
---|
| 134 | "Solvent scattering length density"], |
---|
| 135 | ["radius", "Ang", 20, [0, inf], "volume", |
---|
| 136 | "Cylinder radius"], |
---|
| 137 | ["length", "Ang", 400, [0, inf], "volume", |
---|
| 138 | "Cylinder length"], |
---|
| 139 | ["theta", "degrees", 60, [-inf, inf], "orientation", |
---|
| 140 | "In plane angle"], |
---|
| 141 | ["phi", "degrees", 60, [-inf, inf], "orientation", |
---|
| 142 | "Out of plane angle"], |
---|
| 143 | ] |
---|
| 144 | |
---|
| 145 | source = ["lib/J1.c", "lib/gauss76.c", "cylinder.c"] |
---|
[a7684e5] | 146 | |
---|
[32c160a] | 147 | def ER(radius, length): |
---|
[3e428ec] | 148 | ddd = 0.75 * radius * (2 * radius * length + (length + radius) * (length + pi * radius)) |
---|
| 149 | return 0.5 * (ddd) ** (1. / 3.) |
---|
[32c160a] | 150 | |
---|
[d547f16] | 151 | # parameters for demo |
---|
[3e428ec] | 152 | demo = dict(scale=1, background=0, |
---|
| 153 | sld=6, solvent_sld=1, |
---|
| 154 | radius=20, length=300, |
---|
| 155 | theta=60, phi=60, |
---|
| 156 | radius_pd=.2, radius_pd_n=9, |
---|
| 157 | length_pd=.2, length_pd_n=10, |
---|
| 158 | theta_pd=10, theta_pd_n=5, |
---|
| 159 | phi_pd=10, phi_pd_n=5) |
---|
[d547f16] | 160 | |
---|
[a503bfd] | 161 | # For testing against the old sasview models, include the converted parameter |
---|
| 162 | # names and the target sasview model name. |
---|
[3e428ec] | 163 | oldname = 'CylinderModel' |
---|
| 164 | oldpars = dict(theta='cyl_theta', phi='cyl_phi', sld='sldCyl', solvent_sld='sldSolv') |
---|
| 165 | |
---|
| 166 | |
---|
| 167 | qx, qy = 0.2 * np.cos(2.5), 0.2 * np.sin(2.5) |
---|
| 168 | tests = [[{}, 0.2, 0.041761386790780453], |
---|
| 169 | [{}, [0.2], [0.041761386790780453]], |
---|
| 170 | [{'theta':10.0, 'phi':10.0}, (qx, qy), 0.03414647218513852], |
---|
| 171 | [{'theta':10.0, 'phi':10.0}, [(qx, qy)], [0.03414647218513852]], |
---|
| 172 | ] |
---|
| 173 | del qx, qy # not necessary to delete, but cleaner |
---|