source: sasmodels/example/weights/maier_saupe.py @ 01dba26

Last change on this file since 01dba26 was 55e82f0, checked in by Paul Kienzle <pkienzle@…>, 6 years ago

add some weights examples and update docs

  • Property mode set to 100644
File size: 1.6 KB
Line 
1from __future__ import print_function
2import numpy as np
3from numpy import exp, sin, degrees, radians, pi, sqrt
4
5from sasmodels.weights import Dispersion as BaseDispersion
6
7class Dispersion(BaseDispersion):
8    r"""
9    Maier-Saupe dispersion on orientation.
10
11    .. math:
12
13        w(\theta) = e^{P_2{\cos^2 \theta}}
14
15    This provides a close match to the gaussian distribution for
16    low angles, but the tails are limited to $\pm 90^\circ$.  For $P_2 \ll 1$
17    the distribution is approximately uniform.  The usual polar coordinate
18    projection applies, with $\theta$ weights scaled by $\cos \theta$
19    and $\phi$ weights unscaled.
20
21    This is equivalent to a cyclic gaussian distribution
22    $w(\theta) = e^{-sin^2(\theta)/(2\P_2^2)}.
23    """
24    type = "maier_saupe"
25    default = dict(npts=35, width=1, nsigmas=None)
26
27    # Note: center is always zero for orientation distributions
28    def _weights(self, center, sigma, lb, ub):
29        # use the width parameter as the value for Maier-Saupe P_2
30        # and find the equivalent width sigma
31        P2 = sigma
32        sigma = 1./sqrt(2.*P2)
33
34        # Limit width to +/- 90 degrees
35        width = min(self.nsigmas*sigma, pi/2)
36        x = np.linspace(-width, width, self.npts)
37
38        # Truncate the distribution in case the parameter value is limited
39        x[(x >= radians(lb)) & (x <= radians(ub))]
40
41        # Return orientation in degrees with Maier-Saupe weights
42        # Note: weights are normalized to sum to 1, so we can scale
43        # by an arbitrary scale factor c = exp(m) to get:
44        #     w = exp(m*cos(x)**2)/c = exp(-m*sin(x)**2)
45        return degrees(x), exp(-P2*sin(x)**2)
Note: See TracBrowser for help on using the repository browser.