source: sasmodels/sasmodels/models/capped_cylinder.py @ 71b751d

core_shell_microgelsmagnetic_modelticket-1257-vesicle-productticket_1156ticket_1265_superballticket_822_more_unit_tests
Last change on this file since 71b751d was 71b751d, checked in by Paul Kienzle <pkienzle@…>, 6 years ago

update remaining form factors to use Fq interface

  • Property mode set to 100644
File size: 6.7 KB
Line 
1r"""
2Definitions
3-----------
4
5Calculates the scattering from a cylinder with spherical section end-caps.
6Like :ref:`barbell`, this is a sphereocylinder with end caps that have a
7radius larger than that of the cylinder, but with the center of the end cap
8radius lying within the cylinder. This model simply becomes a convex
9lens when the length of the cylinder $L=0$. See the diagram for the details
10of the geometry and restrictions on parameter values.
11
12.. figure:: img/capped_cylinder_geometry.jpg
13
14    Capped cylinder geometry, where $r$ is *radius*, $R$ is *bell_radius* and
15    $L$ is *length*. Since the end cap radius $R \geq r$ and by definition
16    for this geometry $h < 0$, $h$ is then defined by $r$ and $R$ as
17    $h = - \sqrt{R^2 - r^2}$
18
19The scattered intensity $I(q)$ is calculated as
20
21.. math::
22
23    I(q) = \frac{\Delta \rho^2}{V} \left<A^2(q,\alpha).sin(\alpha)\right>
24
25where the amplitude $A(q,\alpha)$ with the rod axis at angle $\alpha$ to $q$ is given as
26
27.. math::
28
29    A(q) =&\ \pi r^2L
30        \frac{\sin\left(\tfrac12 qL\cos\alpha\right)}
31            {\tfrac12 qL\cos\alpha}
32        \frac{2 J_1(qr\sin\alpha)}{qr\sin\alpha} \\
33        &\ + 4 \pi R^3 \int_{-h/R}^1 dt
34        \cos\left[ q\cos\alpha
35            \left(Rt + h + {\tfrac12} L\right)\right]
36        \times (1-t^2)
37        \frac{J_1\left[qR\sin\alpha \left(1-t^2\right)^{1/2}\right]}
38             {qR\sin\alpha \left(1-t^2\right)^{1/2}}
39
40The $\left<\ldots\right>$ brackets denote an average of the structure over
41all orientations. $\left< A^2(q)\right>$ is then the form factor, $P(q)$.
42The scale factor is equivalent to the volume fraction of cylinders, each of
43volume, $V$. Contrast $\Delta\rho$ is the difference of scattering length
44densities of the cylinder and the surrounding solvent.
45
46The volume of the capped cylinder is (with $h$ as a positive value here)
47
48.. math::
49
50    V = \pi r_c^2 L + \tfrac{2\pi}{3}(R-h)^2(2R + h)
51
52
53and its radius of gyration is
54
55.. math::
56
57    R_g^2 =&\ \left[ \tfrac{12}{5}R^5
58        + R^4\left(6h+\tfrac32 L\right)
59        + R^2\left(4h^2 + L^2 + 4Lh\right)
60        + R^2\left(3Lh^2 + \tfrac32 L^2h\right) \right. \\
61        &\ \left. + \tfrac25 h^5 - \tfrac12 Lh^4 - \tfrac12 L^2h^3
62        + \tfrac14 L^3r^2 + \tfrac32 Lr^4 \right]
63        \left( 4R^3 6R^2h - 2h^3 + 3r^2L \right)^{-1}
64
65
66.. note::
67
68    The requirement that $R \geq r$ is not enforced in the model!
69    It is up to you to restrict this during analysis.
70
71The 2D scattering intensity is calculated similar to the 2D cylinder model.
72
73.. figure:: img/cylinder_angle_definition.png
74
75    Definition of the angles for oriented 2D cylinders.
76
77
78References
79----------
80
81.. [#] H Kaya, *J. Appl. Cryst.*, 37 (2004) 223-230
82.. [#] H Kaya and N-R deSouza, *J. Appl. Cryst.*, 37 (2004) 508-509 (addenda
83   and errata)
84
85Authorship and Verification
86----------------------------
87
88* **Author:** NIST IGOR/DANSE **Date:** pre 2010
89* **Last Modified by:** Paul Butler **Date:** September 30, 2016
90* **Last Reviewed by:** Richard Heenan **Date:** January 4, 2017
91"""
92
93import numpy as np
94from numpy import inf, sin, cos, pi
95
96name = "capped_cylinder"
97title = "Right circular cylinder with spherical end caps and uniform SLD"
98description = """That is, a sphereocylinder
99    with end caps that have a radius larger than
100    that of the cylinder and the center of the
101    end cap radius lies within the cylinder.
102    Note: As the length of cylinder -->0,
103    it becomes a Convex Lens.
104    It must be that radius <(=) radius_cap.
105    [Parameters];
106    scale: volume fraction of spheres,
107    background:incoherent background,
108    radius: radius of the cylinder,
109    length: length of the cylinder,
110    radius_cap: radius of the semi-spherical cap,
111    sld: SLD of the capped cylinder,
112    sld_solvent: SLD of the solvent.
113"""
114category = "shape:cylinder"
115# pylint: disable=bad-whitespace, line-too-long
116#             ["name", "units", default, [lower, upper], "type", "description"],
117parameters = [["sld",         "1e-6/Ang^2", 4, [-inf, inf], "sld",    "Cylinder scattering length density"],
118              ["sld_solvent", "1e-6/Ang^2", 1, [-inf, inf], "sld",    "Solvent scattering length density"],
119              ["radius",      "Ang",       20, [0, inf],    "volume", "Cylinder radius"],
120
121              # TODO: use an expression for cap radius with fixed bounds.
122              # The current form requires cap radius R bigger than cylinder radius r.
123              # Could instead use R/r in [1,inf], r/R in [0,1], or the angle between
124              # cylinder and cap in [0,90].  The problem is similar for the barbell
125              # model.  Propose r/R in [0,1] in both cases, with the model specifying
126              # cylinder radius in the capped cylinder model and sphere radius in the
127              # barbell model.  This leads to the natural value of zero for no cap
128              # in the capped cylinder, and zero for no bar in the barbell model.  In
129              # both models, one would be a pill.
130              ["radius_cap", "Ang",     20, [0, inf],    "volume", "Cap radius"],
131              ["length",     "Ang",    400, [0, inf],    "volume", "Cylinder length"],
132              ["theta",      "degrees", 60, [-360, 360], "orientation", "cylinder axis to beam angle"],
133              ["phi",        "degrees", 60, [-360, 360], "orientation", "rotation about beam"],
134             ]
135# pylint: enable=bad-whitespace, line-too-long
136
137source = ["lib/polevl.c", "lib/sas_J1.c", "lib/gauss76.c", "capped_cylinder.c"]
138have_Fq = True
139
140def random():
141    # TODO: increase volume range once problem with bell radius is fixed
142    # The issue is that bell radii of more than about 200 fail at high q
143    volume = 10**np.random.uniform(7, 9)
144    bar_volume = 10**np.random.uniform(-4, -1)*volume
145    bell_volume = volume - bar_volume
146    bell_radius = (bell_volume/6)**0.3333  # approximate
147    min_bar = bar_volume/np.pi/bell_radius**2
148    bar_length = 10**np.random.uniform(0, 3)*min_bar
149    bar_radius = np.sqrt(bar_volume/bar_length/np.pi)
150    if bar_radius > bell_radius:
151        bell_radius, bar_radius = bar_radius, bell_radius
152    pars = dict(
153        #background=0,
154        radius_cap=bell_radius,
155        radius=bar_radius,
156        length=bar_length,
157    )
158    return pars
159
160
161demo = dict(scale=1, background=0,
162            sld=6, sld_solvent=1,
163            radius=260, radius_cap=290, length=290,
164            theta=30, phi=15,
165            radius_pd=.2, radius_pd_n=1,
166            radius_cap_pd=.2, radius_cap_pd_n=1,
167            length_pd=.2, length_pd_n=10,
168            theta_pd=15, theta_pd_n=45,
169            phi_pd=15, phi_pd_n=1)
170q = 0.1
171# april 6 2017, rkh add unit tests, NOT compared with any other calc method, assume correct!
172qx = q*cos(pi/6.0)
173qy = q*sin(pi/6.0)
174tests = [
175    [{}, 0.075, 26.0698570695],
176    [{'theta':80., 'phi':10.}, (qx, qy), 0.561811990502],
177]
178del qx, qy  # not necessary to delete, but cleaner
Note: See TracBrowser for help on using the repository browser.