source: sasmodels/sasmodels/models/hollow_cylinder.py @ c1e44e5

Last change on this file since c1e44e5 was c1e44e5, checked in by Paul Kienzle <pkienzle@…>, 5 years ago

Add local link to source files. Refs #1263.

  • Property mode set to 100644
File size: 6.3 KB
Line 
1r"""
2Definition
3----------
4
5This model provides the form factor, $P(q)$, for a monodisperse hollow right
6angle circular cylinder (rigid tube) where the The inside and outside of the
7hollow cylinder are assumed to have the same SLD and the form factor is thus
8normalized by the volume of the tube (i.e. not by the total cylinder volume).
9
10.. math::
11
12    P(q) = \text{scale} \left<F^2\right>/V_\text{shell} + \text{background}
13
14where the averaging $\left<\ldots\right>$ is applied only for the 1D
15calculation. If Intensity is given on an absolute scale, the scale factor here
16is the volume fraction of the shell.  This differs from
17the :ref:`core-shell-cylinder` in that, in that case, scale is the volume
18fraction of the entire cylinder (core+shell). The application might be for a
19bilayer which wraps into a hollow tube and the volume fraction of material is
20all in the shell, whereas the :ref:`core-shell-cylinder` model might be used for
21a cylindrical micelle where the tails in the core have a different SLD than the
22headgroups (in the shell) and the volume fraction of material comes fromm the
23whole cyclinder.  NOTE: the hollow_cylinder represents a tube whereas the
24core_shell_cylinder includes a shell layer covering the ends (end caps) as well.
25
26
27The 1D scattering intensity is calculated in the following way (Guinier, 1955)
28
29.. math::
30
31    P(q)           &= (\text{scale})V_\text{shell}\Delta\rho^2
32            \int_0^{1}\Psi^2
33            \left[q_z, R_\text{outer}(1-x^2)^{1/2},
34                       R_\text{core}(1-x^2)^{1/2}\right]
35            \left[\frac{\sin(qHx)}{qHx}\right]^2 dx \\
36    \Psi[q,y,z]    &= \frac{1}{1-\gamma^2}
37            \left[ \Lambda(qy) - \gamma^2\Lambda(qz) \right] \\
38    \Lambda(a)     &= 2 J_1(a) / a \\
39    \gamma         &= R_\text{core} / R_\text{outer} \\
40    V_\text{shell} &= \pi \left(R_\text{outer}^2 - R_\text{core}^2 \right)L \\
41    J_1(x)         &= (\sin(x)-x\cdot \cos(x)) / x^2
42
43where *scale* is a scale factor, $H = L/2$ and $J_1$ is the 1st order
44Bessel function.
45
46**NB**: The 2nd virial coefficient of the cylinder is calculated
47based on the outer radius and full length, which give an the effective radius
48for structure factor $S(q)$ when $P(q) \cdot S(q)$ is applied.
49
50In the parameters,the *radius* is $R_\text{core}$ while *thickness*
51is $R_\text{outer} - R_\text{core}$.
52
53To provide easy access to the orientation of the core-shell cylinder, we define
54the axis of the cylinder using two angles $\theta$ and $\phi$
55(see :ref:`cylinder model <cylinder-angle-definition>`).
56
57References
58----------
59
60.. [#] L A Feigin and D I Svergun, *Structure Analysis by Small-Angle X-Ray and
61   Neutron Scattering*, Plenum Press, New York, (1987)
62.. [#] L. Onsager, *Ann. New York Acad. Sci.*, 51 (1949) 627-659
63
64Authorship and Verification
65----------------------------
66
67* **Author:** NIST IGOR/DANSE **Date:** pre 2010
68* **Last Modified by:** Paul Butler **Date:** September 06, 2018
69   (corrected VR calculation)
70* **Last Reviewed by:** Paul Butler **Date:** September 06, 2018
71"""
72from __future__ import division
73
74import numpy as np
75from numpy import pi, inf, sin, cos
76
77name = "hollow_cylinder"
78title = ""
79description = """
80P(q) = scale*<f*f>/Vol + background, where f is the scattering amplitude.
81radius = the radius of core
82thickness = the thickness of shell
83length = the total length of the cylinder
84sld = SLD of the shell
85sld_solvent = SLD of the solvent
86background = incoherent background
87"""
88category = "shape:cylinder"
89# pylint: disable=bad-whitespace, line-too-long
90#   ["name", "units", default, [lower, upper], "type","description"],
91parameters = [
92    ["radius",      "Ang",     20.0, [0, inf],    "volume",      "Cylinder core radius"],
93    ["thickness",   "Ang",     10.0, [0, inf],    "volume",      "Cylinder wall thickness"],
94    ["length",      "Ang",    400.0, [0, inf],    "volume",      "Cylinder total length"],
95    ["sld",         "1e-6/Ang^2",  6.3, [-inf, inf], "sld",         "Cylinder sld"],
96    ["sld_solvent", "1e-6/Ang^2",  1,   [-inf, inf], "sld",         "Solvent sld"],
97    ["theta",       "degrees", 90,   [-360, 360], "orientation", "Cylinder axis to beam angle"],
98    ["phi",         "degrees",  0,   [-360, 360], "orientation", "Rotation about beam"],
99    ]
100# pylint: enable=bad-whitespace, line-too-long
101
102source = ["lib/polevl.c", "lib/sas_J1.c", "lib/gauss76.c", "hollow_cylinder.c"]
103have_Fq = True
104effective_radius_type = [
105    "excluded volume", "equivalent outer volume sphere",
106    "outer radius", "half length",
107    "half outer min dimension", "half outer max dimension",
108    "half outer diagonal",
109    ]
110
111def random():
112    """Return a random parameter set for the model."""
113    length = 10**np.random.uniform(1, 4.7)
114    outer_radius = 10**np.random.uniform(1, 4.7)
115    # Use a distribution with a preference for thin shell or thin core
116    # Avoid core,shell radii < 1
117    thickness = np.random.beta(0.5, 0.5)*(outer_radius-2) + 1
118    radius = outer_radius - thickness
119    pars = dict(
120        length=length,
121        radius=radius,
122        thickness=thickness,
123    )
124    return pars
125
126# parameters for demo
127demo = dict(scale=1.0, background=0.0, length=400.0, radius=20.0,
128            thickness=10, sld=6.3, sld_solvent=1, theta=90, phi=0,
129            thickness_pd=0.2, thickness_pd_n=9,
130            length_pd=.2, length_pd_n=10,
131            radius_pd=.2, radius_pd_n=9,
132            theta_pd=10, theta_pd_n=5,
133           )
134
135def r_eff(radius, thickness, length):
136    """R_eff from excluded volume"""
137    radius += thickness
138    return (0.5*(0.75*radius*(2.0*radius*length
139                              + (radius + length)*(pi*radius + length))
140                )**(1./3.))
141
142def shell_volume(radius, thickness, length):
143    """shell volume for parameter set"""
144    return pi*((radius+thickness)**2-radius**2)*length
145
146def form_shell_ratio(radius, thickness, length):
147    """form:shell ratio"""
148    return (radius+thickness)**2/((radius+thickness)**2 - radius**2)
149
150q = 0.1
151# april 6 2017, rkh added a 2d unit test, assume correct!
152qx = q*cos(pi/6.0)
153qy = q*sin(pi/6.0)
154test_pars = [
155    parameters[0][2], # radius
156    parameters[1][2], # thickness
157    parameters[2][2], # length
158]
159# Parameters for unit tests
160tests = [
161    [{}, 0.00005, 1764.926],
162    [{}, 0.1, None, None,
163     r_eff(*test_pars), shell_volume(*test_pars), form_shell_ratio(*test_pars),
164    ],
165    [{}, 0.001, 1756.76],
166    [{}, (qx, qy), 2.36885476192],
167]
168del qx, qy, test_pars  # not necessary to delete, but cleaner
Note: See TracBrowser for help on using the repository browser.