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

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

replace gifs so that we can build pdf

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