source: sasmodels/sasmodels/models/elliptical_cylinder.py @ a8b3cdb

core_shell_microgelscostrafo411magnetic_modelrelease_v0.94release_v0.95ticket-1257-vesicle-productticket_1156ticket_1265_superballticket_822_more_unit_tests
Last change on this file since a8b3cdb was a8b3cdb, checked in by Doucet, Mathieu <doucetm@…>, 8 years ago

Converted elliptical cylinder model

  • Property mode set to 100644
File size: 6.4 KB
Line 
1r"""
2This function calculates the scattering from an elliptical cylinder.
3
4Definition for 2D (orientated system)
5-------------------------------------
6
7The angles |theta| and |phi| define the orientation of the axis of the cylinder. The angle |bigpsi| is defined as the
8orientation of the major axis of the ellipse with respect to the vector *Q*\ . A gaussian polydispersity can be added
9to any of the orientation angles, and also for the minor radius and the ratio of the ellipse radii.
10
11.. image:: img/elliptical_cylinder_geometry.gif
12
13    *Figure.* *a* = *r_minor* and |nu|\ :sub:`n` = $r_ratio$ (i.e., $r_major / r_minor$).
14
15The function calculated is
16
17.. math::
18    I(\mathbf{q})=\frac{1}{V_{cyl}}\int{d\psi}\int{d\phi}\int{p(\theta,\phi,\psi)F^2(\mathbf{q},\alpha,\psi)\sin(\theta)d\theta}
19
20with the functions
21
22.. math::
23    F(\mathbf{q},\alpha,\psi)=2\frac{J_1(a)\sin(b)}{ab}
24    \\
25    a = \mathbf{q}\sin(\alpha)\left[ r^2_{major}\sin^2(\psi)+r^2_{minor}\cos(\psi) \right]^{1/2}
26    \\
27    b=\mathbf{q}\frac{L}{2}\cos(\alpha)
28
29and the angle |bigpsi| is defined as the orientation of the major axis of the ellipse with respect to the vector *q*\ .
30
31
32Definition for 1D (no preferred orientation)
33--------------------------------------------
34
35The form factor is averaged over all possible orientation before normalized by the particle volume
36
37.. math::
38    P(q) = scale  <F^2> / V
39
40The returned value is scaled to units of |cm^-1|.
41
42To provide easy access to the orientation of the elliptical cylinder, we define the axis of the cylinder using two
43angles |theta|, |phi| and |bigpsi|. As for the case of the cylinder, the angles |theta| and |phi| are defined on
44Figure 2 of CylinderModel. The angle |bigpsi| is the rotational angle around its own long_c axis against the *q* plane.
45For example, |bigpsi| = 0 when the *r_minor* axis is parallel to the *x*\ -axis of the detector.
46
47All angle parameters are valid and given only for 2D calculation; ie, an oriented system.
48
49.. image:: img/elliptical_cylinder_geometry_2d.jpg
50
51    *Figure. Definition of angles for 2D*
52
53.. image:: img/core_shell_bicelle_fig2.jpg
54
55    *Figure. Examples of the angles for oriented elliptical cylinders against the detector plane.*
56
57NB: The 2nd virial coefficient of the cylinder is calculated based on the averaged radius (= sqrt(*r_minor*\ :sup:`2` \* *r_ratio*))
58and length values, and used as the effective radius for *S(Q)* when *P(Q)* \* *S(Q)* is applied.
59
60
61.. image:: img/elliptical_cylinder_comparison_1d.jpg
62
63    *Figure. 1D plot using the default values (w/1000 data point).*
64
65Validation
66----------
67
68Validation of our code was done by comparing the output of the 1D calculation to the angular average of the output of
69the 2D calculation over all possible angles. The figure below shows the comparison where the solid dot refers to
70averaged 2D values while the line represents the result of the 1D calculation (for the 2D averaging, values of 76, 180,
71and 76 degrees are taken for the angles of |theta|, |phi|, and |bigpsi| respectively).
72
73.. image:: img/elliptical_cylinder_validation_1d.gif
74
75    *Figure. Comparison between 1D and averaged 2D.*
76
77In the 2D average, more binning in the angle |phi| is necessary to get the proper result. The following figure shows
78the results of the averaging by varying the number of angular bins.
79
80.. image:: img/elliptical_cylinder_averaging.gif
81
82    *Figure. The intensities averaged from 2D over different numbers of bins and angles.*
83
84Reference
85---------
86
87L A Feigin and D I Svergun, *Structure Analysis by Small-Angle X-Ray and Neutron Scattering*, Plenum,
88New York, (1987)
89"""
90
91import math
92from numpy import pi, inf
93
94name = "elliptical_cylinder"
95title = "Form factor for an elliptical cylinder."
96description = """
97    F^2(q) = The function calculated is
98
99.. math::
100    I(\mathbf{q})=\frac{1}{V_{cyl}}\int{d\psi}\int{d\phi}\int{p(\theta,\phi,\psi)F^2(\mathbf{q},\alpha,\psi)\sin(\theta)d\theta}
101
102with the functions
103
104.. math::
105    F(\mathbf{q},\alpha,\psi)=2\frac{J_1(a)\sin(b)}{ab}
106    \\
107    a = \mathbf{q}\sin(\alpha)\left[ r^2_{major}\sin^2(\psi)+r^2_{minor}\cos(\psi) \right]^{1/2}
108    \\
109    b=\mathbf{q}\frac{L}{2}\cos(\alpha)
110   
111In 1D we have
112
113.. math::
114    P(q) = scale  <F^2> / V
115"""
116category = "shape:cylinder"
117
118# pylint: disable=bad-whitespace, line-too-long
119#             ["name", "units", default, [lower, upper], "type","description"],
120parameters = [["r_minor",     "Ang",        20.0,  [0, inf],    "volume",      "Ellipse minor radius"],
121              ["r_ratio",     "",           1.5,   [1, inf],    "volume",      "Ratio of major radius over minor radius"],
122              ["length",      "Ang",        400.0, [1, inf],    "volume",      "Length of the cylinder"],
123              ["sld",         "1e-6/Ang^2", 4.0,   [-inf, inf], "",            "Cylinder scattering length density"],
124              ["solvent_sld", "1e-6/Ang^2", 1.0,   [-inf, inf], "",            "Solvent scattering length density"],
125              ["theta",       "degrees",    90.0,  [-360, 360], "orientation", "In plane angle"],
126              ["phi",         "degrees",    0,     [-360, 360], "orientation", "Out of plane angle"],
127              ["psi",         "degrees",    0,     [-360, 360], "orientation", "Major axis angle relative to Q"]]
128
129# pylint: enable=bad-whitespace, line-too-long
130
131source = ["lib/nr_bess_j1.c", "lib/gauss76.c", "lib/gauss20.c", "elliptical_cylinder.c"]
132
133demo = dict(scale=1, background=0, r_minor=100, r_ratio=1.5, length=400.0,
134            sld=4.0, solvent_sld=1.0, theta=10.0, phi=20, psi=30, theta_pd=10, phi_pd=2, psi_pd=3)
135
136oldname = 'EllipticalCylinderModel'
137oldpars = dict(theta='cyl_theta', phi='cyl_phi', psi='cyl_psi', sld='sldCyl', solvent_sld='sldSolv')
138
139def ER(r_minor, r_ratio, length):
140    """
141        Equivalent radius
142        @param r_minor: Ellipse minor radius
143        @param r_ratio: Ratio of major radius over minor radius
144        @param length: Length of the cylinder
145    """
146    r = math.sqrt(r_minor * r_minor * r_ratio )
147    ddd = 0.75 * r * (2 * r * length + (length + r) * (length + pi * r))
148    return 0.5 * (ddd) ** (1. / 3.)
149
150tests = [[{'r_minor': 20.0, 'r_ratio': 1.5, 'length':400.0}, 'ER', 79.89245454155024],
151         [{'r_minor': 20.0, 'r_ratio': 1.2, 'length':300.0}, 'VR', 1],
152
153         # The SasView test result was 0.00169, with a background of 0.001
154         [{'r_minor': 20.0,
155           'r_ratio': 1.5,
156           'sld': 4.0,
157           'length':400.0,
158           'solvent_sld':1.0,
159           'background':0.0
160          }, 0.001, 675.504402]]
Note: See TracBrowser for help on using the repository browser.