source: sasmodels/sasmodels/models/parallelepiped.py @ d138d43

core_shell_microgelscostrafo411magnetic_modelrelease_v0.94release_v0.95ticket-1257-vesicle-productticket_1156ticket_1265_superballticket_822_more_unit_tests
Last change on this file since d138d43 was d138d43, checked in by Paul Kienzle <pkienzle@…>, 8 years ago

remove documentation build errors

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