source: sasmodels/sasmodels/models/core_shell_parallelepiped.py @ 5810f00

core_shell_microgelscostrafo411magnetic_modelticket-1257-vesicle-productticket_1156ticket_1265_superballticket_822_more_unit_tests
Last change on this file since 5810f00 was 5810f00, checked in by butler, 7 years ago

updating documentation to meet standards. Addresses #646

  • Property mode set to 100644
File size: 7.6 KB
Line 
1r"""
2Definition
3----------
4
5Calculates the form factor for a rectangular solid with a core-shell structure.
6**The thickness and the scattering length density of the shell or "rim"
7can be different on all three (pairs) of faces.**
8
9The form factor is normalized by the particle volume $V$ such that
10
11.. math::
12
13    I(q) = \text{scale}\frac{\langle f^2 \rangle}{V} + \text{background}
14
15where $\langle \ldots \rangle$ is an average over all possible orientations
16of the rectangular solid.
17
18
19The function calculated is the form factor of the rectangular solid below.
20The core of the solid is defined by the dimensions $A$, $B$, $C$ such that
21$A < B < C$.
22
23.. image:: img/core_shell_parallelepiped_geometry.jpg
24
25There are rectangular "slabs" of thickness $t_A$ that add to the $A$ dimension
26(on the $BC$ faces). There are similar slabs on the $AC$ $(=t_B)$ and $AB$
27$(=t_C)$ faces. The projection in the $AB$ plane is then
28
29.. image:: img/core_shell_parallelepiped_projection.jpg
30
31The volume of the solid is
32
33.. math::
34
35    V = ABC + 2t_ABC + 2t_BAC + 2t_CAB
36
37**meaning that there are "gaps" at the corners of the solid.**
38
39The intensity calculated follows the :ref:`parallelepiped` model, with the
40core-shell intensity being calculated as the square of the sum of the
41amplitudes of the core and shell, in the same manner as a core-shell model.
42
43.. math::
44
45    F_{a}(Q,\alpha,\beta)=
46    \Bigg(\frac{sin(Q(L_A+2t_A)/2sin\alpha sin\beta)}{Q(L_A+2t_A)/2sin\alpha
47    sin\beta)}
48    - \frac{sin(QL_A/2sin\alpha sin\beta)}{QL_A/2sin\alpha sin\beta)} \Bigg)
49    + \frac{sin(QL_B/2sin\alpha sin\beta)}{QL_B/2sin\alpha sin\beta)}
50    + \frac{sin(QL_C/2sin\alpha sin\beta)}{QL_C/2sin\alpha sin\beta)}
51
52.. note::
53
54    For the calculation of the form factor to be valid, the sides of the solid
55    MUST be chosen such that** $A < B < C$.
56    If this inequality is not satisfied, the model will not report an error,
57    but the calculation will not be correct and thus the result wrong.
58
59FITTING NOTES
60If the scale is set equal to the particle volume fraction, |phi|, the returned
61value is the scattered intensity per unit volume, $I(q) = \phi P(q)$.
62However, **no interparticle interference effects are included in this
63calculation.**
64
65There are many parameters in this model. Hold as many fixed as possible with
66known values, or you will certainly end up at a solution that is unphysical.
67
68Constraints must be applied during fitting to ensure that the inequality
69$A < B < C$ is not violated. The calculation will not report an error,
70but the results will not be correct.
71
72The returned value is in units of |cm^-1|, on absolute scale.
73
74NB: The 2nd virial coefficient of the core_shell_parallelepiped is calculated
75based on the the averaged effective radius $(=\sqrt{(A+2t_A)(B+2t_B)/\pi})$
76and length $(C+2t_C)$ values, and used as the effective radius
77for $S(Q)$ when $P(Q) * S(Q)$ is applied.
78
79To provide easy access to the orientation of the parallelepiped, we define the
80axis of the cylinder using three angles $\theta$, $\phi$ and $\Psi$.
81(see :ref:`cylinder orientation <cylinder-angle-definition>`).
82The angle $\Psi$ is the rotational angle around the *long_c* axis against the
83$q$ plane. For example, $\Psi = 0$ when the *short_b* axis is parallel to the
84*x*-axis of the detector.
85
86.. figure:: img/parallelepiped_angle_definition.jpg
87
88    Definition of the angles for oriented core-shell parallelepipeds.
89
90.. figure:: img/parallelepiped_angle_projection.jpg
91
92    Examples of the angles for oriented core-shell parallelepipeds against the
93    detector plane.
94
95Validation
96----------
97
98The model uses the form factor calculations implemented in a c-library provided
99by the NIST Center for Neutron Research (Kline, 2006).
100
101References
102----------
103
104.. [#] P Mittelbach and G Porod, *Acta Physica Austriaca*, 14 (1961) 185-211
105    Equations (1), (13-14). (in German)
106.. [#] D Singh (2009). *Small angle scattering studies of self assembly in
107   lipid mixtures*, John's Hopkins University Thesis (2009) 223-225. `Available
108   from Proquest <http://search.proquest.com/docview/304915826?accountid
109   =26379>`_
110
111Authorship and Verification
112----------------------------
113
114* **Author:** NIST IGOR/DANSE **Date:** pre 2010
115* **Last Modified by:** Paul Butler **Date:** September 30, 2016
116* **Last Reviewed by:** Miguel Gonzales **Date:** March 21, 2016
117"""
118
119import numpy as np
120from numpy import pi, inf, sqrt
121
122name = "core_shell_parallelepiped"
123title = "Rectangular solid with a core-shell structure."
124description = """
125     P(q)=
126"""
127category = "shape:parallelepiped"
128
129#             ["name", "units", default, [lower, upper], "type","description"],
130parameters = [["sld_core", "1e-6/Ang^2", 1, [-inf, inf], "sld",
131               "Parallelepiped core scattering length density"],
132              ["sld_a", "1e-6/Ang^2", 2, [-inf, inf], "sld",
133               "Parallelepiped A rim scattering length density"],
134              ["sld_b", "1e-6/Ang^2", 4, [-inf, inf], "sld",
135               "Parallelepiped B rim scattering length density"],
136              ["sld_c", "1e-6/Ang^2", 2, [-inf, inf], "sld",
137               "Parallelepiped C rim scattering length density"],
138              ["sld_solvent", "1e-6/Ang^2", 6, [-inf, inf], "sld",
139               "Solvent scattering length density"],
140              ["length_a", "Ang", 35, [0, inf], "volume",
141               "Shorter side of the parallelepiped"],
142              ["length_b", "Ang", 75, [0, inf], "volume",
143               "Second side of the parallelepiped"],
144              ["length_c", "Ang", 400, [0, inf], "volume",
145               "Larger side of the parallelepiped"],
146              ["thick_rim_a", "Ang", 10, [0, inf], "volume",
147               "Thickness of A rim"],
148              ["thick_rim_b", "Ang", 10, [0, inf], "volume",
149               "Thickness of B rim"],
150              ["thick_rim_c", "Ang", 10, [0, inf], "volume",
151               "Thickness of C rim"],
152              ["theta", "degrees", 0, [-inf, inf], "orientation",
153               "In plane angle"],
154              ["phi", "degrees", 0, [-inf, inf], "orientation",
155               "Out of plane angle"],
156              ["psi", "degrees", 0, [-inf, inf], "orientation",
157               "Rotation angle around its own c axis against q plane"],
158             ]
159
160source = ["lib/gauss76.c", "core_shell_parallelepiped.c"]
161
162
163def ER(length_a, length_b, length_c, thick_rim_a, thick_rim_b, thick_rim_c):
164    """
165        Return equivalent radius (ER)
166    """
167
168    # surface average radius (rough approximation)
169    surf_rad = sqrt((length_a + 2.0*thick_rim_a) * (length_b + 2.0*thick_rim_b) / pi)
170
171    height = length_c + 2.0*thick_rim_c
172
173    ddd = 0.75 * surf_rad * (2 * surf_rad * height + (height + surf_rad) * (height + pi * surf_rad))
174    return 0.5 * (ddd) ** (1. / 3.)
175
176# VR defaults to 1.0
177
178# parameters for demo
179demo = dict(scale=1, background=0.0,
180            sld_core=1e-6, sld_a=2e-6, sld_b=4e-6,
181            sld_c=2e-6, sld_solvent=6e-6,
182            length_a=35, length_b=75, length_c=400,
183            thick_rim_a=10, thick_rim_b=10, thick_rim_c=10,
184            theta=0, phi=0, psi=0,
185            length_a_pd=0.1, length_a_pd_n=1,
186            length_b_pd=0.1, length_b_pd_n=1,
187            length_c_pd=0.1, length_c_pd_n=1,
188            thick_rim_a_pd=0.1, thick_rim_a_pd_n=1,
189            thick_rim_b_pd=0.1, thick_rim_b_pd_n=1,
190            thick_rim_c_pd=0.1, thick_rim_c_pd_n=1,
191            theta_pd=10, theta_pd_n=1,
192            phi_pd=10, phi_pd_n=1,
193            psi_pd=10, psi_pd_n=10)
194
195qx, qy = 0.2 * np.cos(2.5), 0.2 * np.sin(2.5)
196tests = [[{}, 0.2, 0.533149288477],
197         [{}, [0.2], [0.533149288477]],
198         [{'theta':10.0, 'phi':10.0}, (qx, qy), 0.032102135569],
199         [{'theta':10.0, 'phi':10.0}, [(qx, qy)], [0.032102135569]],
200        ]
201del qx, qy  # not necessary to delete, but cleaner
Note: See TracBrowser for help on using the repository browser.