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