Changes in / [0d5dc05:be0942c] in sasmodels


Ignore:
Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • doc/guide/fitting_sq.rst

    r694c6d0 re62c019  
    1414   This help document is under development 
    1515 
    16 **Product models**, or $P@S$ models for short, multiply the form factor 
    17 $P(Q)$ by the structure factor $S(Q)$, modulated by the **effective radius** 
    18 of the form factor. For the theory behind this, see :ref:`PStheory` later. 
     16.. figure:: p_and_s_buttons.png 
    1917 
    20 **If writing your own** $P@S$ **models, DO NOT give your model parameters** 
    21 **these names!** 
     18**Product models**, or $P@S$ models for short, multiply the structure factor 
     19$S(Q)$ by the form factor $P(Q)$, modulated by the **effective radius** of the 
     20form factor. 
    2221 
    23 Parameters 
    24 ^^^^^^^^^^ 
    25  
    26 Many parameters are common amongst $P@S$ models, but take on specific meanings: 
     22Many of the parameters in $P@S$ models take on specific meanings so that they 
     23can be handled correctly inside SasView: 
    2724 
    2825* *scale*: 
    2926 
    30     Overall model scale factor. 
     27  In simple $P(Q)$ models **scale** often represents the volume fraction of 
     28  material. 
    3129 
    32     To compute number density $n$ the volume fraction $V_f$ (parameterised as 
    33     **volfraction**) is needed.  In most $P(Q)$ models $V_f$ is not defined and 
    34     **scale** is used instead. Some $P(Q)$ models, such as the *vesicle*, do 
    35     define **volfraction** and so can leave **scale** at 1.0. 
    36  
    37     Structure factor models $S(Q)$ contain **volfraction**. In $P@S$ models 
    38     this is *also* used as the volume fraction for the form factor model 
    39     $P(Q)$, *replacing* any **volfraction** parameter in $P(Q)$. This means 
    40     that $P@S$ models can also leave **scale** at 1.0. 
    41  
    42     If the volume fraction required for $S(Q)$ is *not* the volume fraction 
    43     needed to compute the $n$ for $P(Q)$, then leave **volfraction** as the 
    44     $V_f$ for $S(Q)$ and use **scale** to define the $V_f$ for $P(Q)$ as 
    45     $V_f$ = **scale**  $\cdot$  **volfraction**.  This situation may occur in 
    46     a mixed phase system where the effective volume fraction needed to compute 
    47     the structure is much higher than the true volume fraction. 
     30  In $P@S$ models **scale** should be set to 1.0, as the $P@S$ model contains a 
     31  **volfraction** parameter. 
    4832 
    4933* *volfraction*: 
    5034 
    51     The volume fraction of material, $V_f$. 
     35  The volume fraction of material. 
    5236 
    53     For hollow shapes, **volfraction** still represents the volume fraction of 
    54     material but the $S(Q)$ calculation needs the volume fraction *enclosed by* 
    55     *the shape.*  To remedy this the user-specified **volfraction** is scaled 
    56     by the ratio form:shell computed from the average form volume and average 
    57     shell volume returned from the $P(Q)$ calculation when calculating $S(Q)$. 
    58     The original **volfraction** is divided by the shell volume to compute the 
    59     number density $n$ used in the $P@S$ model to get the absolute scaling on 
    60     the final $I(Q)$. 
     37  For hollow shapes, **volfraction** still represents the volume fraction of 
     38  material but the $S(Q)$ calculation needs the volume fraction *enclosed by* 
     39  *the shape.* SasView scales the user-specified volume fraction by the ratio 
     40  form:shell computed from the average form volume and average shell volume 
     41  returned from the $P(Q)$ calculation (the original volfraction is divided 
     42  by the shell volume to compute the number density, and then $P@S$ is scaled 
     43  by that to get the absolute scaling on the final $I(Q)$). 
    6144 
    6245* *radius_effective*: 
    6346 
    64     The radial distance determining the range of the $S(Q)$ interaction. 
     47  The radial distance determining the range of the $S(Q)$ interaction. 
    6548 
    66     This may be estimated from the "size" parameters $\mathbf \xi$ describing 
    67     the form of the shape.  For example, in a system containing freely-rotating 
    68     cylinders, the volume of space each cylinder requires to tumble will be 
    69     much larger than the volume of the cylinder itself. Thus the *effective* 
    70     radius of a cylinder will be larger than either its actual radius or half- 
    71     length. 
     49  This may, or may not, be the same as any "size" parameters describing the 
     50  form of the shape. For example, in a system containing freely-rotating 
     51  cylinders, the volume of space each cylinder requires to tumble will be 
     52  much larger than the volume of the cylinder itself. Thus the effective 
     53  radius will be larger than either the radius or half-length of the 
     54  cylinder. It may be sensible to tie or constrain **radius_effective** to one 
     55  or other of these "size" parameters. 
    7256 
    73     In use, it may be sensible to tie or constrain **radius_effective** 
    74     to one or other of the "size" parameters describing the form of the shape. 
    75  
    76     **radius_effective** may also be specified directly, independent of the 
    77     estimate from $P(Q)$. 
    78  
    79     If **radius_effective** is calculated by $P(Q)$, it will be the 
    80     weighted average of the effective radii computed for the polydisperse 
    81     shape parameters, and that average is used to compute $S(Q)$. When 
    82     specified directly, the value of **radius_effective** may be 
    83     polydisperse, and $S(Q)$ will be averaged over a range of effective 
    84     radii. Whether this makes any physical sense will depend on the system. 
    85  
    86 .. note:: 
    87  
    88    The following additional parameters are only available in SasView 5.0 and 
    89    later. 
    90  
    91  *radius_effective_mode*: 
    92  
    93     Defines how the effective radius (parameter **radius_effective**) should 
    94     be computed from the parameters of the shape. 
    95  
    96     When **radius_effective_mode = 0** then unconstrained **radius_effective** 
    97     parameter in the $S(Q)$ model is used. *This is the default in SasView* 
    98     *versions 4.x and earlier*. Otherwise, in SasView 5.0 and later, 
    99     **radius_effective_mode = k** represents an index in a list of alternative 
    100     **radius_effective** calculations which will appear in a drop-down box. 
    101  
    102     For example, the *ellipsoid* model defines the following 
    103     **radius_effective_modes**:: 
    104  
    105         1 => average curvature 
    106         2 => equivalent volume sphere 
    107         3 => min radius 
    108         4 => max radius 
    109  
    110     Note: **radius_effective_mode** will only appear in the parameter table if 
    111     the model defines the list of modes, otherwise it will be set permanently 
    112     to 0 for the user-defined effective radius. 
    113      
    114     **WARNING! If** $P(Q)$ **is multiplied by** $S(Q)$ **in the FitPage,** 
    115     **instead of being generated in the Sum|Multi dialog, the** 
    116     **radius_effective used is constrained (equivalent to** 
    117     **radius_effective_mode = 1)**. 
     57  If just part of the $S(Q)$ calculation, the value of **radius_effective** may 
     58  be polydisperse. If it is calculated by $P(Q)$, then it will be the weighted 
     59  average of the effective radii computed for the polydisperse shape 
     60  parameters. 
    11861 
    11962* *structure_factor_mode*: 
    12063 
    121     The type of structure factor calculation to use. 
     64  If the $P@S$ model supports the $\beta(Q)$ *decoupling correction* [1] then 
     65  **structure_factor_mode** will appear in the parameter table after the $S(Q)$ 
     66  parameters. 
    12267 
    123     If the $P@S$ model supports the $\beta(Q)$ *decoupling correction* [1] 
    124     then **structure_factor_mode** will appear in the parameter table after 
    125     the $S(Q)$ parameters. 
     68  If **structure_factor_mode = 0** then the *local monodisperse approximation* 
     69  will be used, i.e.: 
    12670 
    127     If **structure_factor_mode = 0** then the 
    128     *local monodisperse approximation* will be used, i.e.: 
     71    $I(Q)$ = $(scale$ / $volume)$ x $P(Q)$ x $S(Q)$ + $background$ 
    12972 
    130     .. math:: 
    131         I(Q) = \text{scale} \frac{V_f}{V} P(Q) S(Q) + \text{background} 
     73  If **structure_factor_mode = 1** then the $\beta(q)$ correction will be 
     74  used, i.e.: 
    13275 
    133     where $P(Q) = \langle F(Q)^2 \rangle$. *This is the default in SasView* 
    134     *versions 4.x and earlier*. 
     76    $I(Q)$ = $(scale$ x $volfraction$ / $volume)$ x $( <F(Q)^2>$ + $<F(Q)>^2$ x $(S(Q)$ - $1) )$ + $background$ 
    13577 
    136     If **structure_factor_mode = 1** then the $\beta(Q)$ correction will be 
    137     used, i.e.: 
     78    where $P(Q)$ = $<|F(Q)|^2>$. 
    13879 
    139     .. math:: 
    140         I(Q) = \text{scale} \frac{V_f}{V} P(Q) [ 1 + \beta(Q) (S(Q) - 1) ] 
    141         + \text{background} 
     80  This is equivalent to: 
    14281 
    143     The $\beta(Q)$ decoupling approximation has the effect of damping the 
    144     oscillations in the normal (local monodisperse) $S(Q)$. When $\beta(Q) = 1$ 
    145     the local monodisperse approximation is recovered. *This mode is only* 
    146     *available in SasView 5.0 and later*. 
     82    $I(Q)$ = $(scale$ / $volume)$ x $P(Q)$ x $( 1$ + $\beta(Q)$ x $(S(Q)$ - $1) )$ + $background$ 
    14783 
    148     More mode options may appear in future as more complicated operations are 
    149     added. 
     84  The $\beta(Q)$ decoupling approximation has the effect of damping the 
     85  oscillations in the normal (local monodisperse) $S(Q)$. When $\beta(Q)$ = 1 
     86  the local monodisperse approximation is recovered. 
    15087 
    151 .. _PStheory: 
    152  
    153 Theory 
    154 ^^^^^^ 
    155  
    156 Scattering at vector $\mathbf Q$ for an individual particle with 
    157 shape parameters $\mathbf\xi$ and contrast $\rho_c(\mathbf r, \mathbf\xi)$ 
    158 is computed from the square of the amplitude, $F(\mathbf Q, \mathbf\xi)$, as 
    159  
    160 .. math:: 
    161     I(\mathbf Q) = F(\mathbf Q, \mathbf\xi) F^*(\mathbf Q, \mathbf\xi) 
    162         \big/ V(\mathbf\xi) 
    163  
    164 with the particle volume $V(\mathbf \xi)$ and 
    165  
    166 .. math:: 
    167     F(\mathbf Q, \mathbf\xi) = \int_{\mathbb R^3} \rho_c(\mathbf r, \mathbf\xi) 
    168         e^{i \mathbf Q \cdot \mathbf r} \,\mathrm d \mathbf r = F 
    169  
    170 The 1-D scattering pattern for monodisperse particles uses the orientation 
    171 average in spherical coordinates, 
    172  
    173 .. math:: 
    174     I(Q) = n \langle F F^*\rangle = \frac{n}{4\pi} 
    175     \int_{\theta=0}^{\pi} \int_{\phi=0}^{2\pi} 
    176     F F^* \sin(\theta) \,\mathrm d\phi \mathrm d\theta 
    177  
    178 where $F(\mathbf Q,\mathbf\xi)$ uses 
    179 $\mathbf Q = [Q \sin\theta\cos\phi, Q \sin\theta\sin\phi, Q \cos\theta]^T$. 
    180 A $u$-substitution may be used, with $\alpha = \cos \theta$, 
    181 $\surd(1 - \alpha^2) = \sin \theta$, and 
    182 $\mathrm d\alpha = -\sin\theta\,\mathrm d\theta$. 
    183 Here, 
    184  
    185 .. math:: n = V_f/V(\mathbf\xi) 
    186  
    187 is the number density of scatterers estimated from the volume fraction $V_f$ 
    188 of particles in solution. In this formalism, each incoming 
    189 wave interacts with exactly one particle before being scattered into the 
    190 detector. All interference effects are within the particle itself. 
    191 The detector accumulates counts in proportion to the relative probability 
    192 at each pixel. The extension to heterogeneous systems is simply a matter of 
    193 adding the scattering patterns in proportion to the number density of each 
    194 particle. That is, given shape parameters $\mathbf\xi$ with probability 
    195 $P_\mathbf{\xi}$, 
    196  
    197 .. math:: 
    198  
    199     I(Q) = \int_\Xi n(\mathbf\xi) \langle F F^* \rangle \,\mathrm d\xi 
    200          = V_f\frac{\int_\Xi P_\mathbf{\xi} \langle F F^* \rangle 
    201          \,\mathrm d\mathbf\xi}{\int_\Xi P_\mathbf\xi V(\mathbf\xi)\,\mathrm d\mathbf\xi} 
    202  
    203 This approximation is valid in the dilute limit, where particles are 
    204 sufficiently far apart that the interaction between them can be ignored. 
    205  
    206 As concentration increases, a structure factor term $S(Q)$ can be included, 
    207 giving the monodisperse approximation for the interaction between particles, 
    208 with 
    209  
    210 .. math:: I(Q) = n \langle F F^* \rangle S(Q) 
    211  
    212 For particles without spherical symmetry, the decoupling approximation 
    213 is more accurate, with 
    214  
    215 .. math:: 
    216  
    217     I(Q) = n [\langle F F^* \rangle 
    218         + \langle F \rangle \langle F \rangle^* (S(Q) - 1)] 
    219  
    220 Or equivalently, 
    221  
    222 .. math:: I(Q) = P(Q)[1 + \beta\,(S(Q) - 1)] 
    223  
    224 with the form factor $P(Q) = n \langle F F^* \rangle$ and 
    225 $\beta = \langle F \rangle \langle F \rangle^* \big/ \langle F F^* \rangle$. 
    226 These approximations can be extended to heterogeneous systems using averages 
    227 over size, $\langle \cdot \rangle_\mathbf\xi = \int_\Xi P_\mathbf\xi \langle\cdot\rangle\,\mathrm d\mathbf\xi \big/ \int_\Xi P_\mathbf\xi \,\mathrm d\mathbf\xi$ and setting 
    228 $n = V_f\big/\langle V \rangle_\mathbf\xi$. 
    229  
    230 Further improvements can be made using the local monodisperse 
    231 approximation (LMA) or using partial structure factors [2]. 
     88  More mode options may appear in future as more complicated operations are 
     89  added. 
    23290 
    23391References 
     
    23694.. [#] Kotlarchyk, M.; Chen, S.-H. *J. Chem. Phys.*, 1983, 79, 2461 
    23795 
    238 .. [#] Bressler I., Kohlbrecher J., Thunemann A.F. *J. Appl. Crystallogr.* 
    239    48 (2015) 1587-1598 
    240  
    24196.. ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ 
    24297 
    24398*Document History* 
    24499 
    245 | 2019-03-31 Paul Kienzle, Steve King & Richard Heenan 
     100| 2019-03-30 Paul Kienzle & Steve King 
  • sasmodels/kernelcl.py

    r9fac5f5 ra34b811  
    158158ENV = None 
    159159def reset_environment(): 
    160     # type: () -> "GpuEnvironment" 
    161     """ 
    162     Return a new OpenCL context, such as after a change to SAS_OPENCL. 
     160    # type: () -> None 
     161    """ 
     162    Call to create a new OpenCL context, such as after a change to SAS_OPENCL. 
    163163    """ 
    164164    global ENV 
    165165    ENV = GpuEnvironment() if use_opencl() else None 
    166     return ENV 
     166 
    167167 
    168168def environment(): 
  • sasmodels/models/hardsphere.py

    r4d00de6 rc1e44e5  
    1616   Earlier versions of SasView did not incorporate the so-called 
    1717   $\beta(q)$ ("beta") correction [1] for polydispersity and non-sphericity. 
    18    This is only available in SasView versions 5.0 and higher. 
     18   This is only available in SasView versions 4.2.2 and higher. 
    1919 
    2020radius_effective is the effective hard sphere radius. 
  • sasmodels/models/hayter_msa.py

    r4d00de6 rc1e44e5  
    1818   Earlier versions of SasView did not incorporate the so-called 
    1919   $\beta(q)$ ("beta") correction [3] for polydispersity and non-sphericity. 
    20    This is only available in SasView versions 5.0 and higher. 
     20   This is only available in SasView versions 4.2.2 and higher. 
    2121 
    2222The salt concentration is used to compute the ionic strength of the solution 
  • sasmodels/models/squarewell.py

    r4d00de6 rc1e44e5  
    2020   Earlier versions of SasView did not incorporate the so-called 
    2121   $\beta(q)$ ("beta") correction [2] for polydispersity and non-sphericity. 
    22    This is only available in SasView versions 5.0 and higher. 
     22   This is only available in SasView versions 4.2.2 and higher. 
    2323 
    2424The well width $(\lambda)$ is defined as multiples of the particle diameter 
  • sasmodels/models/stickyhardsphere.py

    r4d00de6 rc1e44e5  
    5656   Earlier versions of SasView did not incorporate the so-called 
    5757   $\beta(q)$ ("beta") correction [3] for polydispersity and non-sphericity. 
    58    This is only available in SasView versions 5.0 and higher. 
     58   This is only available in SasView versions 4.2.2 and higher. 
    5959 
    6060In SasView the effective radius may be calculated from the parameters 
  • sasmodels/sesans.py

    rda33725 rb297ba9  
    1515from numpy import pi  # type: ignore 
    1616from scipy.special import j0 
    17  
    1817 
    1918class SesansTransform(object): 
     
    3938 
    4039    # transform arrays 
    41     _H = None   # type: np.ndarray 
    42     _H0 = None  # type: np.ndarray 
     40    _H = None  # type: np.ndarray 
     41    _H0 = None # type: np.ndarray 
    4342 
    44     def __init__(self, z, SElength, lam, zaccept, Rmax, log_spacing=1.0003): 
     43    def __init__(self, z, SElength, lam, zaccept, Rmax): 
    4544        # type: (np.ndarray, float, float) -> None 
     45        #import logging; logging.info("creating SESANS transform") 
    4646        self.q = z 
    47         self.log_spacing = log_spacing 
    4847        self._set_hankel(SElength, lam, zaccept, Rmax) 
    4948 
     
    6059    def _set_hankel(self, SElength, lam, zaccept, Rmax): 
    6160        # type: (np.ndarray, float, float) -> None 
    62         SElength = np.asarray(SElength) 
     61        # Force float32 arrays, otherwise run into memory problems on some machines 
     62        SElength = np.asarray(SElength, dtype='float32') 
     63 
     64        #Rmax = #value in text box somewhere in FitPage? 
    6365        q_max = 2*pi / (SElength[1] - SElength[0]) 
    6466        q_min = 0.1 * 2*pi / (np.size(SElength) * SElength[-1]) 
    65         q = np.exp(np.arange(np.log(q_min), np.log(q_max), 
    66                              np.log(self.log_spacing))) 
     67        q = np.arange(q_min, q_max, q_min, dtype='float32') 
     68        dq = q_min 
    6769 
    68         dq = np.diff(q) 
    69         dq = np.insert(dq, 0, dq[0]) 
     70        H0 = np.float32(dq/(2*pi)) * q 
    7071 
    71         H0 = dq/(2*pi) * q 
     72        repq = np.tile(q, (SElength.size, 1)).T 
     73        repSE = np.tile(SElength, (q.size, 1)) 
     74        H = np.float32(dq/(2*pi)) * j0(repSE*repq) * repq 
    7275 
    73         H = np.outer(q, SElength) 
    74         j0(H, out=H) 
    75         H *= (dq * q / (2*pi)).reshape((-1, 1)) 
    76  
    77         reptheta = np.outer(q, lam/(2*pi)) 
    78         np.arcsin(reptheta, out=reptheta) 
     76        replam = np.tile(lam, (q.size, 1)) 
     77        reptheta = np.arcsin(repq*replam/2*np.pi) 
    7978        mask = reptheta > zaccept 
    8079        H[mask] = 0 
Note: See TracChangeset for help on using the changeset viewer.