source: sasmodels/sasmodels/models/superball.py @ 8b7ce55

ticket_1265_superball
Last change on this file since 8b7ce55 was 8b7ce55, checked in by DomiDre <homiedomi@…>, 5 years ago

Add superball form factor

  • Property mode set to 100644
File size: 6.5 KB
Line 
1# superball model
2# Note: model title and parameter table are inserted automatically
3r"""
4Definition
5----------
6
7.. figure:: img/superball_realSpace.png
8
9   Superball visualisation for varied values of the parameter p.
10
11This model calculates the scattering of a superball, which represents a cube
12with rounded edges. It can be used to describe nanoparticles that deviate from
13the perfect cube shape as it is often observed experimentally
14[#WetterskogSuperball]_. The shape is described by
15
16.. math::
17
18    x^{2p} + y^{2p} + z^{2p} \leq \biggl( \frac{a}{2} \biggr)^{2p}
19
20with $a$ the cube edge length of the superball and $p$ a parameter that
21describes the roundness of the edges. In the limiting cases $p=1$ the superball
22corresponds to a sphere with radius $R = a/2$ and for $p = \infty$ to a cube
23with edge length $a$. The exponent p is related to $a$ and the face diagonal
24$d$ via
25
26.. math::
27    p = \frac{1}{1 + 2 \mathrm{log}_2 (a/d)}.
28
29.. figure:: img/superball_geometry2d.png
30
31    Cross-sectional view of a superball showing the principal axis length $a$,
32    the face-diagonal $d$ and the superball radius $R$.
33
34The oriented form factor is determined by solving
35
36.. math::
37    p_o(\vec{q}) =& \int_{V} \mathrm{d} \vec{r} e^{i \vec{q} \cdot \vec{r}}\\
38        =& \frac{a^3}{8} \int_{-1}^{1} \mathrm{d} x \int_{-\gamma}^{\gamma}
39            \mathrm{d} y \int_{-\zeta}^{\zeta} \mathrm{d} z
40            e^{i a (q_x x + q_y y + q_z z) / 2}\\
41        =& \frac{a^2}{2 q_z} \int_{-1}^{1} \mathrm{d} x \int_{-\gamma}^{\gamma}
42            \mathrm{d} y  e^{i a(q_x x + q_y y)/2}
43            \mathrm{sin}(q_z a \zeta / 2),\\
44with
45
46.. math::
47    \gamma =& \sqrt[2p]{1-x^{2p}}, \\
48    \zeta =& \sqrt[2p]{1-x^{2p} -y^{2p}}.
49
50The integral can be transformed to
51
52.. math::
53    p_o(\vec{q}) = \frac{2 a^2}{q_z} \int_{0}^{1} \mathrm{d} x \, \mathrm{cos}
54        \biggl(\frac{a q_x x}{2} \biggr) \int_{0}^{\gamma} \mathrm{d} y \,
55        \mathrm{cos} \biggl( \frac{a q_y y}{2} \biggr) \mathrm{sin}
56        \biggl( \frac{a q_z \zeta}{2} \biggr),
57
58which can be solved numerically.
59
60The orientational average is then obtained by calculating
61
62.. math::
63    P(q) = \int_0^{\tfrac{\pi}{2}} \mathrm{d} \varphi \int_0^{\tfrac{\pi}{2}}
64        \mathrm{d} \theta \, \mathrm{sin} (\theta) | p_o(\vec{q}) |^2
65
66with
67
68.. math::
69    \vec{q} &= q \begin{pmatrix} \mathrm{cos} (\varphi) \mathrm{sin} (\theta)\\
70    \mathrm{sin} (\varphi) \mathrm{sin} (\theta)\\
71    \mathrm{cos} (\theta)\end{pmatrix}
72
73The implemented orientationally averaged superball model is then fully given by
74[#DresenSuperball]_
75
76.. math::
77    I(q) = \mathrm{scale} (\Delta \rho)^2 P(q) + \mathrm{background}.
78
79
80FITTING NOTES
81~~~~~~~~~~~~~
82
83Validation
84----------
85
86    The code is validated by reproducing the spherical form factor implemented
87    in SasView for p = 1 and the parallelepiped form factor with a = b = c for
88    p = 1000. The form factors match in the first order oscillation with a
89    precision in the order of $10^{-4}$. The agreement worsens for higher order
90    oscillations and beyond the third order oscillations a higher order Gauss
91    quadrature rule needs to be used to keep the agreement below $10^{-3}$.
92    This is however avoided in this implementation to keep the computation time
93    fast.
94
95References
96----------
97
98.. [#WetterskogSuperball] E. Wetterskog, A. Klapper, S. Disch, E. Josten, R. P. Hermann, U. RÌcker, T. BrÌckel, L. Bergström and G. Salazar-Alvarez, *Nanoscale*, 8 (2016) 15571
99
100.. [#DresenSuperball] A paper on the superball form factor is in preparation.
101
102Source
103------
104
105`superball.py <https://github.com/SasView/sasmodels/blob/master/sasmodels/models/superball.py>`_
106
107`superball.c <https://github.com/SasView/sasmodels/blob/master/sasmodels/models/superball.c>`_
108
109Authorship and Verification
110----------------------------
111
112* **Author:** Dominique Dresen **Date:** March 27, 2019
113* **Last Modified by:**  Dominique Dresen **Date:** March 27, 2019
114* **Last Reviewed by:**  **Date:**
115* **Source added by :** Dominique Dresen **Date:** March 27, 2019"""
116
117import numpy as np
118from numpy import inf
119
120name = "superball"
121title = "Superball with uniform scattering length density."
122description = """
123    I(q)= scale*V*(sld - sld_solvent)^2*P(q)+background
124        P(q) = (2/pi) * double integral from 0 to pi/2 of ...
125           AP^2(q)*sin(theta)*dtheta*dphi
126        AP = integral from -1 to 1 integral from -g to g of ...
127        cos(R qx x) cos(R qy y]) sin(R qz Ze)
128        g = (1 - x^(2p))^(1/(2p))
129        Ze = (1 - x^(2p) - y^(2p))^(1/(2p))
130"""
131category = "shape:superball"
132
133#             ["name", "units", default, [lower, upper], "type","description"],
134parameters = [["sld", "1e-6/Ang^2", 4, [-inf, inf], "sld",
135               "Superball scattering length density"],
136              ["sld_solvent", "1e-6/Ang^2", 1, [-inf, inf], "sld",
137               "Solvent scattering length density"],
138              ["length_a", "Ang", 50, [0, inf], "volume",
139               "Cube edge length of the superball"],
140              ["exponent_p", "", 2.5, [0, inf], "volume",
141               "Exponent describing the roundness of the superball"],
142              ["theta", "degrees", 0, [-360, 360], "orientation",
143               "c axis to beam angle"],
144              ["phi", "degrees", 0, [-360, 360], "orientation",
145               "rotation about beam"],
146              ["psi", "degrees", 0, [-360, 360], "orientation",
147               "rotation about c axis"],
148              ]
149# lib/gauss76.c
150# lib/gauss20.c
151source = ["lib/gauss20.c", "lib/sas_gamma.c", "superball.c"]
152
153have_Fq = True
154effective_radius_type = [
155    "radius of gyration",
156    "equivalent volume sphere",
157    "half length_a",
158]
159
160
161def random():
162    """Return a random parameter set for the model."""
163    length = np.random.uniform(10, 500)
164    exponent = np.random.uniform(1.5, 5)
165    pars = dict(
166        length_a=length,
167        exponent_p=exponent)
168    return pars
169
170
171# parameters for demo
172demo = dict(scale=1, background=0,
173            sld=6.3, sld_solvent=1.0,
174            length_a=100, exponent_p=2.5,
175            theta=45, phi=30, psi=15,
176            length_a_pd=0.1, length_a_pd_n=10,
177            theta_pd=10, theta_pd_n=1,
178            phi_pd=10, phi_pd_n=1,
179            psi_pd=10, psi_pd_n=1)
180
181
182tests = [
183    [{}, 0.2, 0.7683],
184    [{"length_a": 100., "exponent_p": 1, "sld": 6., "sld_solvent": 1.},
185     0.2, 0.7263],
186    [{"length_a": 100., "exponent_p": 1000, "sld": 6., "sld_solvent": 1.},
187     0.2, 0.2714],
188    [{"length_a": 100., "exponent_p": 2.5, "sld": 6., "sld_solvent": 1.},
189     0.2, 0.2810],
190    [{"length_a": 100., "exponent_p": 2.5, "sld": 6., "sld_solvent": 1.,
191      "length_a_pd": 0.1, "length_a_pd_n": 10},
192     0.2, 0.4955],
193]
Note: See TracBrowser for help on using the repository browser.