source: sasmodels/sasmodels/models/cylinder.py @ 15a90c1

core_shell_microgelscostrafo411magnetic_modelticket-1257-vesicle-productticket_1156ticket_1265_superballticket_822_more_unit_tests
Last change on this file since 15a90c1 was 15a90c1, checked in by richardh, 7 years ago

more changes for new axes, and a bug in cylinder.py docs

  • Property mode set to 100644
File size: 5.8 KB
Line 
1# cylinder model
2# Note: model title and parameter table are inserted automatically
3r"""
4
5For information about polarised and magnetic scattering, see
6the :ref:`magnetism` documentation.
7
8Definition
9----------
10
11The output of the 2D scattering intensity function for oriented cylinders is
12given by (Guinier, 1955)
13
14.. math::
15
16    P(q,\alpha) = \frac{\text{scale}}{V} F^2(q,\alpha).sin(\alpha) + \text{background}
17
18where
19
20.. math::
21
22    F(q,\alpha) = 2 (\Delta \rho) V
23           \frac{\sin \left(\tfrac12 qL\cos\alpha \right)}
24                {\tfrac12 qL \cos \alpha}
25           \frac{J_1 \left(q R \sin \alpha\right)}{q R \sin \alpha}
26
27and $\alpha$ is the angle between the axis of the cylinder and $\vec q$, $V =\pi R^2L$
28is the volume of the cylinder, $L$ is the length of the cylinder, $R$ is the
29radius of the cylinder, and $\Delta\rho$ (contrast) is the scattering length
30density difference between the scatterer and the solvent. $J_1$ is the
31first order Bessel function.
32
33For randomly oriented particles:
34
35.. math::
36
37    F^2(q)=\int_{0}^{\pi/2}{F^2(q,\alpha)\sin(\alpha)d\alpha}=\int_{0}^{1}{F^2(q,u)du}
38
39
40Numerical integration is simplified by a change of variable to $u = cos(\alpha)$ with
41$sin(\alpha)=\sqrt{1-u^2}$.
42
43The output of the 1D scattering intensity function for randomly oriented
44cylinders is thus given by
45
46.. math::
47
48    P(q) = \frac{\text{scale}}{V}
49        \int_0^{\pi/2} F^2(q,\alpha) \sin \alpha\ d\alpha + \text{background}
50
51
52NB: The 2nd virial coefficient of the cylinder is calculated based on the
53radius and length values, and used as the effective radius for $S(q)$
54when $P(q) \cdot S(q)$ is applied.
55
56For oriented cylinders, we define the direction of the
57axis of the cylinder using two angles $\theta$ (note this is not the
58same as the scattering angle used in q) and $\phi$. Those angles
59are defined in :numref:`cylinder-angle-definition` .
60
61.. _cylinder-angle-definition:
62
63.. figure:: img/cylinder_angle_definition.jpg
64
65    Definition of the angles for oriented cylinders.
66
67.. figure:: img/cylinder_angle_projection.png
68
69    Examples for oriented cylinders.
70
71The $\theta$ and $\phi$ parameters only appear in the model when fitting 2d data.
72
73Validation
74----------
75
76Validation of the code was done by comparing the output of the 1D model
77to the output of the software provided by the NIST (Kline, 2006).
78The implementation of the intensity for fully oriented cylinders was done
79by averaging over a uniform distribution of orientations using
80
81.. math::
82
83    P(q) = \int_0^{\pi/2} d\phi
84        \int_0^\pi p(\theta) P_0(q,\theta) \sin \theta\ d\theta
85
86
87where $p(\theta,\phi) = 1$ is the probability distribution for the orientation
88and $P_0(q,\theta)$ is the scattering intensity for the fully oriented
89system, and then comparing to the 1D result.
90
91References
92----------
93
94J. S. Pedersen, Adv. Colloid Interface Sci. 70, 171-210 (1997).
95G. Fournet, Bull. Soc. Fr. Mineral. Cristallogr. 74, 39-113 (1951).
96"""
97
98import numpy as np  # type: ignore
99from numpy import pi, inf  # type: ignore
100
101name = "cylinder"
102title = "Right circular cylinder with uniform scattering length density."
103description = """
104     f(q,alpha) = 2*(sld - sld_solvent)*V*sin(qLcos(alpha)/2))
105                /[qLcos(alpha)/2]*J1(qRsin(alpha))/[qRsin(alpha)]
106
107            P(q,alpha)= scale/V*f(q,alpha)^(2)+background
108            V: Volume of the cylinder
109            R: Radius of the cylinder
110            L: Length of the cylinder
111            J1: The bessel function
112            alpha: angle between the axis of the
113            cylinder and the q-vector for 1D
114            :the ouput is P(q)=scale/V*integral
115            from pi/2 to zero of...
116            f(q,alpha)^(2)*sin(alpha)*dalpha + background
117"""
118category = "shape:cylinder"
119
120#             [ "name", "units", default, [lower, upper], "type", "description"],
121parameters = [["sld", "1e-6/Ang^2", 4, [-inf, inf], "sld",
122               "Cylinder scattering length density"],
123              ["sld_solvent", "1e-6/Ang^2", 1, [-inf, inf], "sld",
124               "Solvent scattering length density"],
125              ["radius", "Ang", 20, [0, inf], "volume",
126               "Cylinder radius"],
127              ["length", "Ang", 400, [0, inf], "volume",
128               "Cylinder length"],
129              ["theta", "degrees", 60, [-inf, inf], "orientation",
130               "latitude"],
131              ["phi", "degrees", 60, [-inf, inf], "orientation",
132               "longitude"],
133             ]
134
135source = ["lib/polevl.c", "lib/sas_J1.c", "lib/gauss76.c",  "cylinder.c"]
136
137def ER(radius, length):
138    """
139        Return equivalent radius (ER)
140    """
141    ddd = 0.75 * radius * (2 * radius * length + (length + radius) * (length + pi * radius))
142    return 0.5 * (ddd) ** (1. / 3.)
143
144# parameters for demo
145demo = dict(scale=1, background=0,
146            sld=6, sld_solvent=1,
147            radius=20, length=300,
148            theta=60, phi=60,
149            radius_pd=.2, radius_pd_n=9,
150            length_pd=.2, length_pd_n=10,
151            theta_pd=10, theta_pd_n=5,
152            phi_pd=10, phi_pd_n=5)
153
154qx, qy = 0.2 * np.cos(2.5), 0.2 * np.sin(2.5)
155# After redefinition of angles, find new tests values.  Was 10 10 in old coords
156tests = [[{}, 0.2, 0.042761386790780453],
157        [{}, [0.2], [0.042761386790780453]],
158#  new coords   
159        [{'theta':80.1534480601659, 'phi':10.1510817110481}, (qx, qy), 0.03514647218513852],
160        [{'theta':80.1534480601659, 'phi':10.1510817110481}, [(qx, qy)], [0.03514647218513852]],
161# old coords   [{'theta':10.0, 'phi':10.0}, (qx, qy), 0.03514647218513852],
162#              [{'theta':10.0, 'phi':10.0}, [(qx, qy)], [0.03514647218513852]],
163        ]
164del qx, qy  # not necessary to delete, but cleaner
165# ADDED by:  RKH  ON: 18Mar2016 renamed sld's etc
Note: See TracBrowser for help on using the repository browser.