[deb7ee0] | 1 | # rectangular_prism model |
---|
| 2 | # Note: model title and parameter table are inserted automatically |
---|
| 3 | r""" |
---|
| 4 | |
---|
[2941abf] | 5 | This model provides the form factor, $P(q)$, for a rectangular prism. |
---|
[deb7ee0] | 6 | |
---|
| 7 | Note that this model is almost totally equivalent to the existing |
---|
| 8 | :ref:`parallelepiped` model. |
---|
| 9 | The only difference is that the way the relevant |
---|
[2941abf] | 10 | parameters are defined here ($a$, $b/a$, $c/a$ instead of $a$, $b$, $c$) |
---|
[76e5041] | 11 | which allows use of polydispersity with this model while keeping the shape of |
---|
[2941abf] | 12 | the prism (e.g. setting $b/a = 1$ and $c/a = 1$ and applying polydispersity |
---|
[deb7ee0] | 13 | to *a* will generate a distribution of cubes of different sizes). |
---|
| 14 | |
---|
| 15 | |
---|
| 16 | Definition |
---|
| 17 | ---------- |
---|
| 18 | |
---|
| 19 | The 1D scattering intensity for this model was calculated by Mittelbach and |
---|
| 20 | Porod (Mittelbach, 1961), but the implementation here is closer to the |
---|
| 21 | equations given by Nayuk and Huber (Nayuk, 2012). |
---|
| 22 | Note also that the angle definitions used in the code and the present |
---|
| 23 | documentation correspond to those used in (Nayuk, 2012) (see Fig. 1 of |
---|
[2941abf] | 24 | that reference), with $\theta$ corresponding to $\alpha$ in that paper, |
---|
[deb7ee0] | 25 | and not to the usual convention used for example in the |
---|
[393facf] | 26 | :ref:`parallelepiped` model. |
---|
[deb7ee0] | 27 | |
---|
| 28 | In this model the scattering from a massive parallelepiped with an |
---|
[2941abf] | 29 | orientation with respect to the scattering vector given by $\theta$ |
---|
| 30 | and $\phi$ |
---|
[deb7ee0] | 31 | |
---|
| 32 | .. math:: |
---|
| 33 | |
---|
[2941abf] | 34 | A_P\,(q) = |
---|
| 35 | \frac{\sin \left( \tfrac{1}{2}qC \cos\theta \right) }{\tfrac{1}{2} qC \cos\theta} |
---|
| 36 | \,\times\, |
---|
| 37 | \frac{\sin \left( \tfrac{1}{2}qA \cos\theta \right) }{\tfrac{1}{2} qA \cos\theta} |
---|
| 38 | \,\times\ , |
---|
| 39 | \frac{\sin \left( \tfrac{1}{2}qB \cos\theta \right) }{\tfrac{1}{2} qB \cos\theta} |
---|
| 40 | |
---|
| 41 | where $A$, $B$ and $C$ are the sides of the parallelepiped and must fulfill |
---|
| 42 | $A \le B \le C$, $\theta$ is the angle between the $z$ axis and the |
---|
| 43 | longest axis of the parallelepiped $C$, and $\phi$ is the angle between the |
---|
| 44 | scattering vector (lying in the $xy$ plane) and the $y$ axis. |
---|
[deb7ee0] | 45 | |
---|
| 46 | The normalized form factor in 1D is obtained averaging over all possible |
---|
| 47 | orientations |
---|
| 48 | |
---|
| 49 | .. math:: |
---|
[2941abf] | 50 | P(q) = \frac{2}{\pi} \int_0^{\frac{\pi}{2}} \, |
---|
[deb7ee0] | 51 | \int_0^{\frac{\pi}{2}} A_P^2(q) \, \sin\theta \, d\theta \, d\phi |
---|
| 52 | |
---|
| 53 | And the 1D scattering intensity is calculated as |
---|
| 54 | |
---|
| 55 | .. math:: |
---|
[2941abf] | 56 | I(q) = \text{scale} \times V \times (\rho_\text{p} - |
---|
| 57 | \rho_\text{solvent})^2 \times P(q) |
---|
[deb7ee0] | 58 | |
---|
[2941abf] | 59 | where $V$ is the volume of the rectangular prism, $\rho_\text{p}$ |
---|
| 60 | is the scattering length of the parallelepiped, $\rho_\text{solvent}$ |
---|
[deb7ee0] | 61 | is the scattering length of the solvent, and (if the data are in absolute |
---|
| 62 | units) *scale* represents the volume fraction (which is unitless). |
---|
| 63 | |
---|
[393facf] | 64 | For 2d data the orientation of the particle is required, described using |
---|
| 65 | angles $\theta$, $\phi$ and $\Psi$ as in the diagrams below, for further details |
---|
| 66 | of the calculation and angular dispersions see :ref:`orientation` . |
---|
| 67 | The angle $\Psi$ is the rotational angle around the long *C* axis. For example, |
---|
| 68 | $\Psi = 0$ when the *B* axis is parallel to the *x*-axis of the detector. |
---|
| 69 | |
---|
| 70 | For 2d, constraints must be applied during fitting to ensure that the inequality |
---|
| 71 | $A < B < C$ is not violated, and hence the correct definition of angles is preserved. The calculation will not report an error, |
---|
| 72 | but the results may be not correct. |
---|
| 73 | |
---|
| 74 | .. figure:: img/parallelepiped_angle_definition.png |
---|
| 75 | |
---|
| 76 | Definition of the angles for oriented core-shell parallelepipeds. |
---|
| 77 | Note that rotation $\theta$, initially in the $xz$ plane, is carried out first, then |
---|
| 78 | rotation $\phi$ about the $z$ axis, finally rotation $\Psi$ is now around the axis of the cylinder. |
---|
| 79 | The neutron or X-ray beam is along the $z$ axis. |
---|
| 80 | |
---|
| 81 | .. figure:: img/parallelepiped_angle_projection.png |
---|
| 82 | |
---|
| 83 | Examples of the angles for oriented rectangular prisms against the |
---|
| 84 | detector plane. |
---|
| 85 | |
---|
[deb7ee0] | 86 | |
---|
| 87 | |
---|
| 88 | Validation |
---|
| 89 | ---------- |
---|
| 90 | |
---|
| 91 | Validation of the code was conducted by comparing the output of the 1D model |
---|
| 92 | to the output of the existing :ref:`parallelepiped` model. |
---|
| 93 | |
---|
[aa2edb2] | 94 | |
---|
| 95 | References |
---|
| 96 | ---------- |
---|
[deb7ee0] | 97 | |
---|
| 98 | P Mittelbach and G Porod, *Acta Physica Austriaca*, 14 (1961) 185-211 |
---|
| 99 | |
---|
| 100 | R Nayuk and K Huber, *Z. Phys. Chem.*, 226 (2012) 837-854 |
---|
| 101 | """ |
---|
| 102 | |
---|
[2d81cfe] | 103 | import numpy as np |
---|
[deb7ee0] | 104 | from numpy import pi, inf, sqrt |
---|
| 105 | |
---|
| 106 | name = "rectangular_prism" |
---|
| 107 | title = "Rectangular parallelepiped with uniform scattering length density." |
---|
| 108 | description = """ |
---|
[76e5041] | 109 | I(q)= scale*V*(sld - sld_solvent)^2*P(q,theta,phi)+background |
---|
[deb7ee0] | 110 | P(q,theta,phi) = (2/pi) * double integral from 0 to pi/2 of ... |
---|
| 111 | AP^2(q)*sin(theta)*dtheta*dphi |
---|
| 112 | AP = S(q*C*cos(theta)/2) * S(q*A*sin(theta)*sin(phi)/2) * S(q*B*sin(theta)*cos(phi)/2) |
---|
| 113 | S(x) = sin(x)/x |
---|
| 114 | """ |
---|
| 115 | category = "shape:parallelepiped" |
---|
| 116 | |
---|
| 117 | # ["name", "units", default, [lower, upper], "type","description"], |
---|
[42356c8] | 118 | parameters = [["sld", "1e-6/Ang^2", 6.3, [-inf, inf], "sld", |
---|
[deb7ee0] | 119 | "Parallelepiped scattering length density"], |
---|
[42356c8] | 120 | ["sld_solvent", "1e-6/Ang^2", 1, [-inf, inf], "sld", |
---|
[deb7ee0] | 121 | "Solvent scattering length density"], |
---|
[a807206] | 122 | ["length_a", "Ang", 35, [0, inf], "volume", |
---|
[deb7ee0] | 123 | "Shorter side of the parallelepiped"], |
---|
[31df0c9] | 124 | ["b2a_ratio", "", 1, [0, inf], "volume", |
---|
[deb7ee0] | 125 | "Ratio sides b/a"], |
---|
[31df0c9] | 126 | ["c2a_ratio", "", 1, [0, inf], "volume", |
---|
[deb7ee0] | 127 | "Ratio sides c/a"], |
---|
[8de1477] | 128 | ["theta", "degrees", 0, [-360, 360], "orientation", |
---|
| 129 | "c axis to beam angle"], |
---|
| 130 | ["phi", "degrees", 0, [-360, 360], "orientation", |
---|
| 131 | "rotation about beam"], |
---|
| 132 | ["psi", "degrees", 0, [-360, 360], "orientation", |
---|
| 133 | "rotation about c axis"], |
---|
[deb7ee0] | 134 | ] |
---|
| 135 | |
---|
[43b7eea] | 136 | source = ["lib/gauss76.c", "rectangular_prism.c"] |
---|
[deb7ee0] | 137 | |
---|
[a807206] | 138 | def ER(length_a, b2a_ratio, c2a_ratio): |
---|
[deb7ee0] | 139 | """ |
---|
| 140 | Return equivalent radius (ER) |
---|
| 141 | """ |
---|
[a807206] | 142 | b_side = length_a * b2a_ratio |
---|
| 143 | c_side = length_a * c2a_ratio |
---|
[deb7ee0] | 144 | |
---|
| 145 | # surface average radius (rough approximation) |
---|
[a807206] | 146 | surf_rad = sqrt(length_a * b_side / pi) |
---|
[deb7ee0] | 147 | |
---|
| 148 | ddd = 0.75 * surf_rad * (2 * surf_rad * c_side + (c_side + surf_rad) * (c_side + pi * surf_rad)) |
---|
| 149 | return 0.5 * (ddd) ** (1. / 3.) |
---|
| 150 | |
---|
[31df0c9] | 151 | def random(): |
---|
| 152 | a, b, c = 10**np.random.uniform(1, 4.7, size=3) |
---|
| 153 | pars = dict( |
---|
| 154 | length_a=a, |
---|
| 155 | b2a_ratio=b/a, |
---|
| 156 | c2a_ratio=c/a, |
---|
| 157 | ) |
---|
| 158 | return pars |
---|
[deb7ee0] | 159 | |
---|
| 160 | # parameters for demo |
---|
| 161 | demo = dict(scale=1, background=0, |
---|
[ab2aea8] | 162 | sld=6.3, sld_solvent=1.0, |
---|
[a807206] | 163 | length_a=35, b2a_ratio=1, c2a_ratio=1, |
---|
| 164 | length_a_pd=0.1, length_a_pd_n=10, |
---|
[deb7ee0] | 165 | b2a_ratio_pd=0.1, b2a_ratio_pd_n=1, |
---|
| 166 | c2a_ratio_pd=0.1, c2a_ratio_pd_n=1) |
---|
| 167 | |
---|
[6dd90c1] | 168 | tests = [[{}, 0.2, 0.375248406825], |
---|
| 169 | [{}, [0.2], [0.375248406825]], |
---|
[deb7ee0] | 170 | ] |
---|