source: sasmodels/sasmodels/models/core_shell_cylinder.py @ ef07e95

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

lint

  • Property mode set to 100644
File size: 6.1 KB
Line 
1r"""
2Definition
3----------
4
5The output of the 2D scattering intensity function for oriented core-shell
6cylinders is given by (Kline, 2006 [#kline]_). The form factor is normalized
7by the particle volume.
8
9.. math::
10
11    I(q,\alpha) = \frac{\text{scale}}{V_s} F^2(q,\alpha).sin(\alpha) + \text{background}
12
13where
14
15.. math::
16
17    F(q,\alpha) = &\ (\rho_c - \rho_s) V_c
18           \frac{\sin \left( q \tfrac12 L\cos\alpha \right)}
19                {q \tfrac12 L\cos\alpha}
20           \frac{2 J_1 \left( qR\sin\alpha \right)}
21                {qR\sin\alpha} \\
22         &\ + (\rho_s - \rho_\text{solv}) V_s
23           \frac{\sin \left( q \left(\tfrac12 L+T\right) \cos\alpha \right)}
24                {q \left(\tfrac12 L +T \right) \cos\alpha}
25           \frac{ 2 J_1 \left( q(R+T)\sin\alpha \right)}
26                {q(R+T)\sin\alpha}
27
28and
29
30.. math::
31
32    V_s = \pi (R + T)^2 (L + 2T)
33
34and $\alpha$ is the angle between the axis of the cylinder and $\vec q$,
35$V_s$ is the volume of the outer shell (i.e. the total volume, including
36the shell), $V_c$ is the volume of the core, $L$ is the length of the core,
37$R$ is the radius of the core, $T$ is the thickness of the shell, $\rho_c$
38is the scattering length density of the core, $\rho_s$ is the scattering
39length density of the shell, $\rho_\text{solv}$ is the scattering length
40density of the solvent, and *background* is the background level.  The outer
41radius of the shell is given by $R+T$ and the total length of the outer
42shell is given by $L+2T$. $J1$ is the first order Bessel function.
43
44.. _core-shell-cylinder-geometry:
45
46.. figure:: img/core_shell_cylinder_geometry.jpg
47
48    Core shell cylinder schematic.
49
50To provide easy access to the orientation of the core-shell cylinder, we
51define the axis of the cylinder using two angles $\theta$ and $\phi$.
52(see :ref:`cylinder model <cylinder-angle-definition>`)
53
54NB: The 2nd virial coefficient of the cylinder is calculated based on
55the radius and 2 length values, and used as the effective radius for
56$S(q)$ when $P(q) \cdot S(q)$ is applied.
57
58The $\theta$ and $\phi$ parameters are not used for the 1D output.
59
60Reference
61---------
62
63.. [#] see, for example, Ian Livsey  J. Chem. Soc., Faraday Trans. 2, 1987,83,
64   1445-1452
65.. [#kline] S R Kline, *J Appl. Cryst.*, 39 (2006) 895
66
67Authorship and Verification
68----------------------------
69
70* **Author:** NIST IGOR/DANSE **Date:** pre 2010
71* **Last Modified by:** Paul Kienzle **Date:** Aug 8, 2016
72* **Last Reviewed by:** Richard Heenan **Date:** March 18, 2016
73"""
74
75import numpy as np
76from numpy import pi, inf, sin, cos
77
78name = "core_shell_cylinder"
79title = "Right circular cylinder with a core-shell scattering length density profile."
80description = """
81P(q,alpha)= scale/Vs*f(q)^(2) + background,
82      where: f(q)= 2(sld_core - solvant_sld)
83        * Vc*sin[qLcos(alpha/2)]
84        /[qLcos(alpha/2)]*J1(qRsin(alpha))
85        /[qRsin(alpha)]+2(sld_shell-sld_solvent)
86        *Vs*sin[q(L+T)cos(alpha/2)][[q(L+T)
87        *cos(alpha/2)]*J1(q(R+T)sin(alpha))
88        /q(R+T)sin(alpha)]
89
90    alpha:is the angle between the axis of
91        the cylinder and the q-vector
92    Vs: the volume of the outer shell
93    Vc: the volume of the core
94    L: the length of the core
95        sld_shell: the scattering length density of the shell
96    sld_solvent: the scattering length density of the solvent
97    background: the background
98    T: the thickness
99        R+T: is the outer radius
100     L+2T: The total length of the outershell
101    J1: the first order Bessel function
102     theta: axis_theta of the cylinder
103     phi: the axis_phi of the cylinder
104"""
105category = "shape:cylinder"
106
107#             ["name", "units", default, [lower, upper], "type", "description"],
108parameters = [["sld_core", "1e-6/Ang^2", 4, [-inf, inf], "sld",
109               "Cylinder core scattering length density"],
110              ["sld_shell", "1e-6/Ang^2", 4, [-inf, inf], "sld",
111               "Cylinder shell scattering length density"],
112              ["sld_solvent", "1e-6/Ang^2", 1, [-inf, inf], "sld",
113               "Solvent scattering length density"],
114              ["radius", "Ang", 20, [0, inf], "volume",
115               "Cylinder core radius"],
116              ["thickness", "Ang", 20, [0, inf], "volume",
117               "Cylinder shell thickness"],
118              ["length", "Ang", 400, [0, inf], "volume",
119               "Cylinder length"],
120              ["theta", "degrees", 60, [-360, 360], "orientation",
121               "cylinder axis to beam angle"],
122              ["phi", "degrees", 60, [-360, 360], "orientation",
123               "rotation about beam"],
124             ]
125
126source = ["lib/polevl.c", "lib/sas_J1.c", "lib/gauss76.c", "core_shell_cylinder.c"]
127
128def ER(radius, thickness, length):
129    """
130    Returns the effective radius used in the S*P calculation
131    """
132    radius = radius + thickness
133    length = length + 2 * thickness
134    ddd = 0.75 * radius * (2 * radius * length + (length + radius) * (length + pi * radius))
135    return 0.5 * (ddd) ** (1. / 3.)
136
137def VR(radius, thickness, length):
138    """
139    Returns volume ratio
140    """
141    whole = pi * (radius + thickness) ** 2 * (length + 2 * thickness)
142    core = pi * radius ** 2 * length
143    return whole, whole - core
144
145def random():
146    outer_radius = 10**np.random.uniform(1, 4.7)
147    # Use a distribution with a preference for thin shell or thin core
148    # Avoid core,shell radii < 1
149    radius = np.random.beta(0.5, 0.5)*(outer_radius-2) + 1
150    thickness = outer_radius - radius
151    length = np.random.uniform(1, 4.7)
152    pars = dict(
153        radius=radius,
154        thickness=thickness,
155        length=length,
156    )
157    return pars
158
159demo = dict(scale=1, background=0,
160            sld_core=6, sld_shell=8, sld_solvent=1,
161            radius=45, thickness=25, length=340,
162            theta=30, phi=15,
163            radius_pd=.2, radius_pd_n=1,
164            length_pd=.2, length_pd_n=10,
165            thickness_pd=.2, thickness_pd_n=10,
166            theta_pd=15, theta_pd_n=45,
167            phi_pd=15, phi_pd_n=1)
168q = 0.1
169# april 6 2017, rkh add unit tests, NOT compared with any other calc method, assume correct!
170qx = q*cos(pi/6.0)
171qy = q*sin(pi/6.0)
172tests = [
173    [{}, 0.075, 10.8552692237],
174    [{}, (qx, qy), 0.444618752741],
175]
176del qx, qy  # not necessary to delete, but cleaner
Note: See TracBrowser for help on using the repository browser.