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