[c5b7d07] | 1 | # parallelepiped model |
---|
| 2 | # Note: model title and parameter table are inserted automatically |
---|
| 3 | r""" |
---|
| 4 | The form factor is normalized by the particle volume. |
---|
| 5 | |
---|
| 6 | Definition |
---|
| 7 | ---------- |
---|
| 8 | |
---|
[eb69cce] | 9 | This model provides the form factor, $P(q)$, for a rectangular parallelepiped |
---|
[33e91b1] | 10 | (below) where the form factor is normalized by the volume of the |
---|
[d138d43] | 11 | parallelepiped. If you need to apply polydispersity, see also |
---|
| 12 | rectangular_prism_. |
---|
[c5b7d07] | 13 | |
---|
| 14 | The calculated form factor is: |
---|
| 15 | |
---|
| 16 | .. math:: |
---|
| 17 | |
---|
[eb69cce] | 18 | P(q) = \frac{\text{scale}}{V} F^2(q) + \text{background} |
---|
[c5b7d07] | 19 | |
---|
[eb69cce] | 20 | where the volume $V = A B C$ and the averaging $\left<\ldots\right>$ is |
---|
| 21 | applied over all orientations for 1D. |
---|
[c5b7d07] | 22 | |
---|
[9fd094c] | 23 | .. figure:: img/parallelepiped.jpg |
---|
[c5b7d07] | 24 | |
---|
[9fd094c] | 25 | Parallelepiped with the corresponding definition of sides. |
---|
[c5b7d07] | 26 | |
---|
[eb69cce] | 27 | The edge of the solid must satisfy the condition that $A < B < C$. |
---|
| 28 | Then, assuming $a = A/B < 1$, $b = B /B = 1$, and $c = C/B > 1$, the |
---|
| 29 | form factor is |
---|
[c5b7d07] | 30 | |
---|
| 31 | .. math:: |
---|
| 32 | |
---|
[eb69cce] | 33 | P(q) = \frac{\text{scale}}{V}\int_0^1 |
---|
| 34 | \phi\left(\mu \sqrt{1-\sigma^2},a\right) |
---|
| 35 | \left[S(\mu c \sigma/2)\right]^2 d\sigma |
---|
[c5b7d07] | 36 | |
---|
| 37 | with |
---|
| 38 | |
---|
| 39 | .. math:: |
---|
| 40 | |
---|
[eb69cce] | 41 | \phi(\mu,a) = \int_0^1 |
---|
| 42 | \left\{S\left[\frac{\mu}{2}\cos(\frac{\pi}{2}u)\right] |
---|
| 43 | S\left[\frac{\mu a}{2}\sin(\frac{\pi}{2}u)\right] |
---|
| 44 | \right\}^2 du |
---|
[c5b7d07] | 45 | |
---|
| 46 | S(x) = \frac{\sin x}{x} |
---|
[33e91b1] | 47 | |
---|
[c5b7d07] | 48 | \mu = qB |
---|
| 49 | |
---|
| 50 | and the contrast is defined as |
---|
| 51 | |
---|
| 52 | .. math:: |
---|
| 53 | |
---|
| 54 | \Delta\rho = \rho_{\textstyle p} - \rho_{\textstyle solvent} |
---|
| 55 | |
---|
[33e91b1] | 56 | The scattering intensity per unit volume is returned in units of |cm^-1|; |
---|
[eb69cce] | 57 | i.e., $I(q) = \phi P(q)$. |
---|
[c5b7d07] | 58 | |
---|
[33e91b1] | 59 | NB: The 2nd virial coefficient of the parallelpiped is calculated based on |
---|
[eb69cce] | 60 | the averaged effective radius $(=\sqrt{A B / \pi})$ and |
---|
| 61 | length $(= C)$ values, and used as the effective radius for |
---|
| 62 | $S(q)$ when $P(q) \cdot S(q)$ is applied. |
---|
[c5b7d07] | 63 | |
---|
[33e91b1] | 64 | To provide easy access to the orientation of the parallelepiped, we define |
---|
[eb69cce] | 65 | three angles $\theta$, $\phi$ and $\Psi$. The definition of $\theta$ and |
---|
| 66 | $\phi$ is the same as for the cylinder model (see also figures below). |
---|
| 67 | The angle $\Psi$ is the rotational angle around the $C$ axis against |
---|
| 68 | the $q$ plane. For example, $\Psi = 0$ when the $B$ axis is parallel |
---|
| 69 | to the $x$-axis of the detector. |
---|
[c5b7d07] | 70 | |
---|
| 71 | |
---|
| 72 | .. _parallelepiped-orientation: |
---|
| 73 | |
---|
| 74 | .. figure:: img/orientation.jpg |
---|
| 75 | |
---|
| 76 | Definition of the angles for oriented parallelepipeds. |
---|
| 77 | |
---|
| 78 | .. figure:: img/orientation2.jpg |
---|
| 79 | |
---|
| 80 | Examples of the angles for oriented parallelepipeds against the detector plane. |
---|
| 81 | |
---|
| 82 | |
---|
| 83 | Validation |
---|
| 84 | ---------- |
---|
| 85 | |
---|
[33e91b1] | 86 | Validation of the code was done by comparing the output of the 1D calculation |
---|
| 87 | to the angular average of the output of a 2D calculation over all possible |
---|
| 88 | angles. The Figure below shows the comparison where the solid dot refers to |
---|
| 89 | averaged 2D while the line represents the result of the 1D calculation (for |
---|
[eb69cce] | 90 | the averaging, 76, 180, 76 points are taken for the angles of $\theta$, |
---|
| 91 | $\phi$, and $\Psi$ respectively). |
---|
[c5b7d07] | 92 | |
---|
| 93 | .. _parallelepiped-compare: |
---|
| 94 | |
---|
[eb69cce] | 95 | .. figure:: img/parallelepiped_compare.png |
---|
[c5b7d07] | 96 | |
---|
[9fd094c] | 97 | Comparison between 1D and averaged 2D. |
---|
[c5b7d07] | 98 | |
---|
[33e91b1] | 99 | This model reimplements the form factor calculations implemented in a c-library |
---|
[c5b7d07] | 100 | provided by the NIST Center for Neutron Research (Kline, 2006). |
---|
| 101 | |
---|
| 102 | """ |
---|
| 103 | |
---|
[33e91b1] | 104 | from numpy import pi, inf, sqrt |
---|
[c5b7d07] | 105 | |
---|
| 106 | name = "parallelepiped" |
---|
| 107 | title = "Rectangular parallelepiped with uniform scattering length density." |
---|
| 108 | description = """ |
---|
| 109 | P(q)= scale/V*integral from 0 to 1 of ... |
---|
| 110 | phi(mu*sqrt(1-sigma^2),a) * S(mu*c*sigma/2)^2 * dsigma |
---|
[33e91b1] | 111 | |
---|
[c5b7d07] | 112 | phi(mu,a) = integral from 0 to 1 of .. |
---|
[33e91b1] | 113 | (S((mu/2)*cos(pi*u/2))*S((mu*a/2)*sin(pi*u/2)))^2 * du |
---|
[c5b7d07] | 114 | S(x) = sin(x)/x |
---|
[33e91b1] | 115 | mu = q*B |
---|
[c5b7d07] | 116 | """ |
---|
[a5d0d00] | 117 | category = "shape:parallelpiped" |
---|
[c5b7d07] | 118 | |
---|
[3e428ec] | 119 | # ["name", "units", default, [lower, upper], "type","description"], |
---|
| 120 | parameters = [["sld", "1e-6/Ang^2", 4, [-inf, inf], "", |
---|
| 121 | "Parallelepiped scattering length density"], |
---|
| 122 | ["solvent_sld", "1e-6/Ang^2", 1, [-inf, inf], "", |
---|
| 123 | "Solvent scattering length density"], |
---|
| 124 | ["a_side", "Ang", 35, [0, inf], "volume", |
---|
| 125 | "Shorter side of the parallelepiped"], |
---|
| 126 | ["b_side", "Ang", 75, [0, inf], "volume", |
---|
| 127 | "Second side of the parallelepiped"], |
---|
| 128 | ["c_side", "Ang", 400, [0, inf], "volume", |
---|
| 129 | "Larger side of the parallelepiped"], |
---|
| 130 | ["theta", "degrees", 60, [-inf, inf], "orientation", |
---|
| 131 | "In plane angle"], |
---|
| 132 | ["phi", "degrees", 60, [-inf, inf], "orientation", |
---|
| 133 | "Out of plane angle"], |
---|
| 134 | ["psi", "degrees", 60, [-inf, inf], "orientation", |
---|
| 135 | "Rotation angle around its own c axis against q plane"], |
---|
| 136 | ] |
---|
[c5b7d07] | 137 | |
---|
[33e91b1] | 138 | source = ["lib/J1.c", "lib/gauss76.c", "parallelepiped.c"] |
---|
[c5b7d07] | 139 | |
---|
| 140 | def ER(a_side, b_side, c_side): |
---|
| 141 | |
---|
| 142 | # surface average radius (rough approximation) |
---|
| 143 | surf_rad = sqrt(a_side * b_side / pi) |
---|
| 144 | |
---|
| 145 | # DiamCyl recoded here (to check and possibly put in a library?) |
---|
| 146 | a = surf_rad |
---|
| 147 | b = 0.5 * c_side |
---|
| 148 | t1 = a * a * b |
---|
[33e91b1] | 149 | t2 = 1.0 + (b / a) * (1.0 + a / b / 2.0) * (1.0 + pi * a / b / 2.0) |
---|
[c5b7d07] | 150 | ddd = 3.0 * t1 * t2 |
---|
| 151 | |
---|
[33e91b1] | 152 | return 0.5 * (ddd) ** (1. / 3.) |
---|
[c5b7d07] | 153 | |
---|
| 154 | # parameters for demo |
---|
[3e428ec] | 155 | demo = dict(scale=1, background=0, |
---|
| 156 | sld=6.3e-6, solvent_sld=1.0e-6, |
---|
| 157 | a_side=35, b_side=75, c_side=400, |
---|
| 158 | theta=45, phi=30, psi=15, |
---|
| 159 | a_side_pd=0.1, a_side_pd_n=10, |
---|
| 160 | b_side_pd=0.1, b_side_pd_n=1, |
---|
[cd3dba0] | 161 | c_side_pd=0.1, c_side_pd_n=1, |
---|
[3e428ec] | 162 | theta_pd=10, theta_pd_n=1, |
---|
| 163 | phi_pd=10, phi_pd_n=1, |
---|
| 164 | psi_pd=10, psi_pd_n=10) |
---|
[c5b7d07] | 165 | |
---|
| 166 | # For testing against the old sasview models, include the converted parameter |
---|
| 167 | # names and the target sasview model name. |
---|
[33e91b1] | 168 | oldname = 'ParallelepipedModel' |
---|
| 169 | oldpars = dict(theta='parallel_theta', phi='parallel_phi', psi='parallel_psi', |
---|
| 170 | a_side='short_a', b_side='short_b', c_side='long_c', |
---|
| 171 | sld='sldPipe', solvent_sld='sldSolv') |
---|
[c5b7d07] | 172 | |
---|