source: sasmodels/sasmodels/models/ellipsoid.py @ 3c56da87

core_shell_microgelscostrafo411magnetic_modelrelease_v0.94release_v0.95ticket-1257-vesicle-productticket_1156ticket_1265_superballticket_822_more_unit_tests
Last change on this file since 3c56da87 was 3c56da87, checked in by Paul Kienzle <pkienzle@…>, 9 years ago

lint cleanup

  • Property mode set to 100644
File size: 6.4 KB
Line 
1# ellipsoid model
2# Note: model title and parameter table are inserted automatically
3r"""
4The form factor is normalized by the particle volume.
5
6Definition
7----------
8
9The output of the 2D scattering intensity function for oriented ellipsoids
10is given by (Feigin, 1987)
11
12.. math::
13
14    P(Q,\alpha) = {\text{scale} \over V} F^2(Q) + \text{background}
15
16where
17
18.. math::
19
20    F(Q) = {3 (\Delta rho)) V (\sin[Qr(R_p,R_e,\alpha)]
21                - \cos[Qr(R_p,R_e,\alpha)])
22            \over [Qr(R_p,R_e,\alpha)]^3 }
23
24and
25
26.. math::
27
28    r(R_p,R_e,\alpha) = \left[ R_e^2 \sin^2 \alpha
29        + R_p^2 \cos^2 \alpha \right]^{1/2}
30
31
32$\alpha$ is the angle between the axis of the ellipsoid and $\vec q$,
33$V$ is the volume of the ellipsoid, $R_p$ is the polar radius along the
34rotational axis of the ellipsoid, $R_e$ is the equatorial radius perpendicular
35to the rotational axis of the ellipsoid and $\Delta \rho$ (contrast) is the
36scattering length density difference between the scatterer and the solvent.
37
38To provide easy access to the orientation of the ellipsoid, we define
39the rotation axis of the ellipsoid using two angles $\theta$ and $\phi$.
40These angles are defined in the
41:ref:`cylinder orientation figure <cylinder-orientation>`.
42For the ellipsoid, $\theta$ is the angle between the rotational axis
43and the $z$-axis.
44
45NB: The 2nd virial coefficient of the solid ellipsoid is calculated based
46on the $R_p$ and $R_e$ values, and used as the effective radius for
47$S(Q)$ when $P(Q) \cdot S(Q)$ is applied.
48
49.. _ellipsoid-1d:
50
51.. figure:: img/ellipsoid_1d.JPG
52
53    The output of the 1D scattering intensity function for randomly oriented
54    ellipsoids given by the equation above.
55
56
57The $\theta$ and $\phi$ parameters are not used for the 1D output. Our
58implementation of the scattering kernel and the 1D scattering intensity
59use the c-library from NIST.
60
61.. _ellipsoid-geometry:
62
63.. figure:: img/ellipsoid_geometry.JPG
64
65    The angles for oriented ellipsoid.
66
67Validation
68----------
69
70Validation of our code was done by comparing the output of the 1D model
71to the output of the software provided by the NIST (Kline, 2006).
72:num:`Figure ellipsoid-comparison-1d` below shows a comparison of
73the 1D output of our model and the output of the NIST software.
74
75.. _ellipsoid-comparison-1d:
76
77.. figure:: img/ellipsoid_comparison_1d.jpg
78
79    Comparison of the SasView scattering intensity for an ellipsoid
80    with the output of the NIST SANS analysis software.  The parameters
81    were set to: *scale* = 1.0, *rpolar* = 20 |Ang|,
82    *requatorial* =400 |Ang|, *contrast* = 3e-6 |Ang^-2|,
83    and *background* = 0.01 |cm^-1|.
84
85Averaging over a distribution of orientation is done by evaluating the
86equation above. Since we have no other software to compare the
87implementation of the intensity for fully oriented ellipsoids, we can
88compare the result of averaging our 2D output using a uniform distribution
89$p(\theta,\phi) = 1.0$.  :num:`Figure #ellipsoid-comparison-2d`
90shows the result of such a cross-check.
91
92.. _ellipsoid-comparison-2d:
93
94.. figure:: img/ellipsoid_comparison_2d.jpg
95
96    Comparison of the intensity for uniformly distributed ellipsoids
97    calculated from our 2D model and the intensity from the NIST SANS
98    analysis software. The parameters used were: *scale* = 1.0,
99    *rpolar* = 20 |Ang|, *requatorial* = 400 |Ang|,
100    *contrast* = 3e-6 |Ang^-2|, and *background* = 0.0 |cm^-1|.
101
102The discrepancy above *q* = 0.3 |cm^-1| is due to the way the form factors
103are calculated in the c-library provided by NIST. A numerical integration
104has to be performed to obtain $P(Q)$ for randomly oriented particles.
105The NIST software performs that integration with a 76-point Gaussian
106quadrature rule, which will become imprecise at high $Q$ where the amplitude
107varies quickly as a function of $Q$. The SasView result shown has been
108obtained by summing over 501 equidistant points. Our result was found
109to be stable over the range of $Q$ shown for a number of points higher
110than 500.
111
112REFERENCE
113
114L A Feigin and D I Svergun. *Structure Analysis by Small-Angle X-Ray and Neutron Scattering*, Plenum,
115New York, 1987.
116"""
117
118from numpy import inf
119
120name = "ellipsoid"
121title = "Ellipsoid of revolution with uniform scattering length density."
122
123description = """\
124P(q.alpha)= scale*f(q)^2 + background, where f(q)= 3*(sld
125                - solvent_sld)*V*[sin(q*r(Rp,Re,alpha))
126                -q*r*cos(qr(Rp,Re,alpha))]
127                /[qr(Rp,Re,alpha)]^3"
128
129     r(Rp,Re,alpha)= [Re^(2)*(sin(alpha))^2
130                + Rp^(2)*(cos(alpha))^2]^(1/2)
131
132                sld: SLD of the ellipsoid
133                solvent_sld: SLD of the solvent
134                V: volume of the ellipsoid
135                Rp: polar radius of the ellipsoid
136                Re: equatorial radius of the ellipsoid
137"""
138category = "shape:ellipsoid"
139
140parameters = [
141#   [ "name", "units", default, [lower, upper], "type",
142#     "description" ],
143    [ "sld", "1e-6/Ang^2", 4, [-inf,inf], "",
144      "Ellipsoid scattering length density" ],
145    [ "solvent_sld", "1e-6/Ang^2", 1, [-inf,inf], "",
146      "Solvent scattering length density" ],
147    [ "rpolar", "Ang",  20, [0, inf], "volume",
148      "Polar radius" ],
149    [ "requatorial", "Ang",  400, [0, inf], "volume",
150      "Equatorial radius" ],
151    [ "theta", "degrees", 60, [-inf, inf], "orientation",
152      "In plane angle" ],
153    [ "phi", "degrees", 60, [-inf, inf], "orientation",
154      "Out of plane angle" ],
155    ]
156
157source = [ "lib/J1.c", "lib/gauss76.c", "ellipsoid.c"]
158
159def ER(rpolar, requatorial):
160    import numpy as np
161
162    ee = np.empty_like(rpolar)
163    idx = rpolar > requatorial
164    ee[idx] = (rpolar[idx]**2 - requatorial[idx]**2)/rpolar[idx]**2
165    idx = rpolar < requatorial
166    ee[idx] = (requatorial[idx]**2 - rpolar[idx]**2)/requatorial[idx]**2
167    idx = rpolar == requatorial
168    ee[idx] = 2*rpolar[idx]
169    valid = (rpolar*requatorial != 0)
170    bd = 1.0-ee[valid]
171    e1 = np.sqrt(ee[valid])
172    b1 = 1.0 + np.arcsin(e1)/(e1*np.sqrt(bd))
173    bL = (1.0+e1)/(1.0-e1)
174    b2 = 1.0 + bd/2/e1*np.log(bL)
175    delta = 0.75*b1*b2
176
177    ddd = np.zeros_like(rpolar)
178    ddd[valid] = 2.0*(delta+1.0)*rpolar*requatorial**2
179    return 0.5*ddd**(1.0/3.0)
180
181
182demo = dict(
183        scale=1, background=0,
184        sld=6, solvent_sld=1,
185        rpolar=50, requatorial=30,
186        theta=30, phi=15,
187        rpolar_pd=.2, rpolar_pd_n=15,
188        requatorial_pd=.2, requatorial_pd_n=15,
189        theta_pd=15, theta_pd_n=45,
190        phi_pd=15, phi_pd_n=1,
191        )
192oldname = 'EllipsoidModel'
193oldpars = dict(theta='axis_theta', phi='axis_phi',
194               sld='sldEll', solvent_sld='sldSolv',
195               rpolar='radius_a', requatorial='radius_b')
Note: See TracBrowser for help on using the repository browser.