source: sasmodels/sasmodels/models/cylinder.py @ 4cdd0cc

core_shell_microgelscostrafo411magnetic_modelticket-1257-vesicle-productticket_1156ticket_1265_superballticket_822_more_unit_tests
Last change on this file since 4cdd0cc was 4cdd0cc, checked in by krzywon, 7 years ago

Fix unit typo for SLD

  • Property mode set to 100644
File size: 5.3 KB
Line 
1# cylinder model
2# Note: model title and parameter table are inserted automatically
3r"""
4The form factor is normalized by the particle volume V = \piR^2L.
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) + \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$
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,\theta)\sin(\theta)d\theta}
38
39
40To provide easy access to the orientation of the cylinder, we define the
41axis of the cylinder using two angles $\theta$ and $\phi$. Those angles
42are defined in :numref:`cylinder-angle-definition` .
43
44.. _cylinder-angle-definition:
45
46.. figure:: img/cylinder_angle_definition.jpg
47
48    Definition of the angles for oriented cylinders.
49
50
51NB: The 2nd virial coefficient of the cylinder is calculated based on the
52radius and length values, and used as the effective radius for $S(q)$
53when $P(q) \cdot S(q)$ is applied.
54
55The output of the 1D scattering intensity function for randomly oriented
56cylinders is then given by
57
58.. math::
59
60    P(q) = \frac{\text{scale}}{V}
61        \int_0^{\pi/2} F^2(q,\alpha) \sin \alpha\ d\alpha + \text{background}
62
63The $\theta$ and $\phi$ parameters are not used for the 1D output.
64
65Validation
66----------
67
68Validation of the code was done by comparing the output of the 1D model
69to the output of the software provided by the NIST (Kline, 2006).
70The implementation of the intensity for fully oriented cylinders was done
71by averaging over a uniform distribution of orientations using
72
73.. math::
74
75    P(q) = \int_0^{\pi/2} d\phi
76        \int_0^\pi p(\alpha) P_0(q,\alpha) \sin \alpha\ d\alpha
77
78
79where $p(\theta,\phi) = 1$ is the probability distribution for the orientation
80and $P_0(q,\alpha)$ is the scattering intensity for the fully oriented
81system, and then comparing to the 1D result.
82
83References
84----------
85
86J. S. Pedersen, Adv. Colloid Interface Sci. 70, 171-210 (1997).
87G. Fournet, Bull. Soc. Fr. Mineral. Cristallogr. 74, 39-113 (1951).
88"""
89
90import numpy as np  # type: ignore
91from numpy import pi, inf  # type: ignore
92
93name = "cylinder"
94title = "Right circular cylinder with uniform scattering length density."
95description = """
96     f(q,alpha) = 2*(sld - sld_solvent)*V*sin(qLcos(alpha)/2))
97                /[qLcos(alpha)/2]*J1(qRsin(alpha))/[qRsin(alpha)]
98
99            P(q,alpha)= scale/V*f(q,alpha)^(2)+background
100            V: Volume of the cylinder
101            R: Radius of the cylinder
102            L: Length of the cylinder
103            J1: The bessel function
104            alpha: angle between the axis of the
105            cylinder and the q-vector for 1D
106            :the ouput is P(q)=scale/V*integral
107            from pi/2 to zero of...
108            f(q,alpha)^(2)*sin(alpha)*dalpha + background
109"""
110category = "shape:cylinder"
111
112#             [ "name", "units", default, [lower, upper], "type", "description"],
113parameters = [["sld", "1e-6/Ang^2", 4, [-inf, inf], "sld",
114               "Cylinder scattering length density"],
115              ["sld_solvent", "1e-6/Ang^2", 1, [-inf, inf], "sld",
116               "Solvent scattering length density"],
117              ["radius", "Ang", 20, [0, inf], "volume",
118               "Cylinder radius"],
119              ["length", "Ang", 400, [0, inf], "volume",
120               "Cylinder length"],
121              ["theta", "degrees", 60, [-inf, inf], "orientation",
122               "latitude"],
123              ["phi", "degrees", 60, [-inf, inf], "orientation",
124               "longitude"],
125             ]
126
127source = ["lib/polevl.c", "lib/sas_J1.c", "lib/gauss76.c",  "cylinder.c"]
128
129def ER(radius, length):
130    """
131        Return equivalent radius (ER)
132    """
133    ddd = 0.75 * radius * (2 * radius * length + (length + radius) * (length + pi * radius))
134    return 0.5 * (ddd) ** (1. / 3.)
135
136# parameters for demo
137demo = dict(scale=1, background=0,
138            sld=6, sld_solvent=1,
139            radius=20, length=300,
140            theta=60, phi=60,
141            radius_pd=.2, radius_pd_n=9,
142            length_pd=.2, length_pd_n=10,
143            theta_pd=10, theta_pd_n=5,
144            phi_pd=10, phi_pd_n=5)
145
146qx, qy = 0.2 * np.cos(2.5), 0.2 * np.sin(2.5)
147# After redefinition of angles, find new tests values
148#tests = [[{}, 0.2, 0.042761386790780453],
149#         [{}, [0.2], [0.042761386790780453]],
150#         [{'theta':10.0, 'phi':10.0}, (qx, qy), 0.03514647218513852],
151#         [{'theta':10.0, 'phi':10.0}, [(qx, qy)], [0.03514647218513852]],
152#        ]
153del qx, qy  # not necessary to delete, but cleaner
154# ADDED by:  RKH  ON: 18Mar2016 renamed sld's etc
Note: See TracBrowser for help on using the repository browser.