source: sasmodels/sasmodels/models/cylinder.py @ 38d8774

core_shell_microgelscostrafo411magnetic_modelrelease_v0.94release_v0.95ticket-1257-vesicle-productticket_1156ticket_1265_superballticket_822_more_unit_tests
Last change on this file since 38d8774 was 3e428ec, checked in by Doucet, Mathieu <doucetm@…>, 9 years ago

Cleaning up

  • Property mode set to 100644
File size: 6.1 KB
RevLine 
[5d4777d]1# cylinder model
[a7684e5]2# Note: model title and parameter table are inserted automatically
[32c160a]3r"""
[a7684e5]4The form factor is normalized by the particle volume.
[32c160a]5
6For information about polarised and magnetic scattering, click here_.
7
8Definition
9----------
10
11The output of the 2D scattering intensity function for oriented cylinders is
12given by (Guinier, 1955)
13
14.. math::
15
[19dcb933]16    P(Q,\alpha) = {\text{scale} \over V} F^2(Q) + \text{background}
[32c160a]17
18where
19
20.. math::
21
[19dcb933]22    F(Q) = 2 (\Delta \rho) V
23           {\sin \left(Q\tfrac12 L\cos\alpha \right)
24               \over Q\tfrac12 L \cos \alpha}
25           {J_1 \left(Q R \sin \alpha\right) \over Q R \sin \alpha}
[32c160a]26
27and $\alpha$ is the angle between the axis of the cylinder and $\vec q$, $V$
[19dcb933]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.
[32c160a]32
33To provide easy access to the orientation of the cylinder, we define the
34axis of the cylinder using two angles $\theta$ and $\phi$. Those angles
[19dcb933]35are defined in :num:`figure #cylinder-orientation`.
[32c160a]36
[5d4777d]37.. _cylinder-orientation:
[32c160a]38
[19dcb933]39.. figure:: img/orientation.jpg
[32c160a]40
41    Definition of the angles for oriented cylinders.
42
[19dcb933]43.. figure:: img/orientation2.jpg
[32c160a]44
[9474dda]45    Examples of the angles for oriented cylinders against the detector plane.
[32c160a]46
47NB: The 2nd virial coefficient of the cylinder is calculated based on the
48radius and length values, and used as the effective radius for $S(Q)$
49when $P(Q) \cdot S(Q)$ is applied.
50
51The output of the 1D scattering intensity function for randomly oriented
52cylinders is then given by
53
54.. math::
55
[19dcb933]56    P(Q) = {\text{scale} \over V}
57        \int_0^{\pi/2} F^2(Q,\alpha) \sin \alpha\ d\alpha + \text{background}
[32c160a]58
59The *theta* and *phi* parameters are not used for the 1D output. Our
60implementation of the scattering kernel and the 1D scattering intensity
61use the c-library from NIST.
62
[a7684e5]63Validation
64----------
[32c160a]65
66Validation of our code was done by comparing the output of the 1D model
67to the output of the software provided by the NIST (Kline, 2006).
[19dcb933]68:num:`Figure #cylinder-compare` shows a comparison of
[32c160a]69the 1D output of our model and the output of the NIST software.
70
[5d4777d]71.. _cylinder-compare:
[32c160a]72
[19dcb933]73.. figure:: img/cylinder_compare.jpg
[32c160a]74
75    Comparison of the SasView scattering intensity for a cylinder with the
76    output of the NIST SANS analysis software.
[19dcb933]77    The parameters were set to: *scale* = 1.0, *radius* = 20 |Ang|,
78    *length* = 400 |Ang|, *contrast* = 3e-6 |Ang^-2|, and
79    *background* = 0.01 |cm^-1|.
[32c160a]80
81In general, averaging over a distribution of orientations is done by
82evaluating the following
83
84.. math::
85
[19dcb933]86    P(Q) = \int_0^{\pi/2} d\phi
87        \int_0^\pi p(\theta, \phi) P_0(Q,\alpha) \sin \theta\ d\theta
[32c160a]88
89
90where $p(\theta,\phi)$ is the probability distribution for the orientation
[19dcb933]91and $P_0(Q,\alpha)$ is the scattering intensity for the fully oriented
[32c160a]92system. Since we have no other software to compare the implementation of
93the intensity for fully oriented cylinders, we can compare the result of
94averaging our 2D output using a uniform distribution $p(\theta, \phi) = 1.0$.
[19dcb933]95:num:`Figure #cylinder-crosscheck` shows the result of
[32c160a]96such a cross-check.
97
[5d4777d]98.. _cylinder-crosscheck:
[32c160a]99
[19dcb933]100.. figure:: img/cylinder_crosscheck.jpg
[32c160a]101
102    Comparison of the intensity for uniformly distributed cylinders
103    calculated from our 2D model and the intensity from the NIST SANS
104    analysis software.
[19dcb933]105    The parameters used were: *scale* = 1.0, *radius* = 20 |Ang|,
106    *length* = 400 |Ang|, *contrast* = 3e-6 |Ang^-2|, and
107    *background* = 0.0 |cm^-1|.
[32c160a]108"""
109
[143e2f7]110import numpy as np
[32c160a]111from numpy import pi, inf
112
[a7684e5]113name = "cylinder"
114title = "Right circular cylinder with uniform scattering length density."
115description = """
[9474dda]116     f(q,alpha) = 2*(sld - solvent_sld)*V*sin(qLcos(alpha/2))
117                /[qLcos(alpha/2)]*J1(qRsin(alpha/2))/[qRsin(alpha)]
[a7684e5]118
[9474dda]119            P(q,alpha)= scale/V*f(q,alpha)^(2)+background
[a7684e5]120            V: Volume of the cylinder
121            R: Radius of the cylinder
122            L: Length of the cylinder
123            J1: The bessel function
[5d4777d]124            alpha: angle between the axis of the
[a7684e5]125            cylinder and the q-vector for 1D
126            :the ouput is P(q)=scale/V*integral
127            from pi/2 to zero of...
[9474dda]128            f(q,alpha)^(2)*sin(alpha)*dalpha + background
[5d4777d]129"""
[a5d0d00]130category = "shape:cylinder"
[a7684e5]131
[3e428ec]132#             [ "name", "units", default, [lower, upper], "type", "description"],
133parameters = [["sld", "1e-6/Ang^2", 4, [-inf, inf], "",
134               "Cylinder scattering length density"],
135              ["solvent_sld", "1e-6/Ang^2", 1, [-inf, inf], "",
136               "Solvent scattering length density"],
137              ["radius", "Ang", 20, [0, inf], "volume",
138               "Cylinder radius"],
139              ["length", "Ang", 400, [0, inf], "volume",
140               "Cylinder length"],
141              ["theta", "degrees", 60, [-inf, inf], "orientation",
142               "In plane angle"],
143              ["phi", "degrees", 60, [-inf, inf], "orientation",
144               "Out of plane angle"],
145             ]
146
147source = ["lib/J1.c", "lib/gauss76.c", "cylinder.c"]
[a7684e5]148
[32c160a]149def ER(radius, length):
[3e428ec]150    ddd = 0.75 * radius * (2 * radius * length + (length + radius) * (length + pi * radius))
151    return 0.5 * (ddd) ** (1. / 3.)
[32c160a]152
[d547f16]153# parameters for demo
[3e428ec]154demo = dict(scale=1, background=0,
155            sld=6, solvent_sld=1,
156            radius=20, length=300,
157            theta=60, phi=60,
158            radius_pd=.2, radius_pd_n=9,
159            length_pd=.2, length_pd_n=10,
160            theta_pd=10, theta_pd_n=5,
161            phi_pd=10, phi_pd_n=5)
[d547f16]162
[a503bfd]163# For testing against the old sasview models, include the converted parameter
164# names and the target sasview model name.
[3e428ec]165oldname = 'CylinderModel'
166oldpars = dict(theta='cyl_theta', phi='cyl_phi', sld='sldCyl', solvent_sld='sldSolv')
167
168
169qx, qy = 0.2 * np.cos(2.5), 0.2 * np.sin(2.5)
170tests = [[{}, 0.2, 0.041761386790780453],
171         [{}, [0.2], [0.041761386790780453]],
172         [{'theta':10.0, 'phi':10.0}, (qx, qy), 0.03414647218513852],
173         [{'theta':10.0, 'phi':10.0}, [(qx, qy)], [0.03414647218513852]],
174        ]
175del qx, qy  # not necessary to delete, but cleaner
Note: See TracBrowser for help on using the repository browser.