Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/models/parallelepiped.py

    r3330bb4 r34a9e4e  
    99---------- 
    1010 
    11 | This model calculates the scattering from a rectangular parallelepiped 
    12 | (\:numref:`parallelepiped-image`\). 
    13 | If you need to apply polydispersity, see also :ref:`rectangular-prism`. 
     11 This model calculates the scattering from a rectangular parallelepiped 
     12 (\:numref:`parallelepiped-image`\). 
     13 If you need to apply polydispersity, see also :ref:`rectangular-prism`. 
    1414 
    1515.. _parallelepiped-image: 
    1616 
     17 
    1718.. figure:: img/parallelepiped_geometry.jpg 
    1819 
     
    2122.. note:: 
    2223 
    23    The edge of the solid must satisfy the condition that $A < B < C$. 
    24    This requirement is not enforced in the model, so it is up to the 
    25    user to check this during the analysis. 
     24The three dimensions of the parallelepiped (strictly here a cuboid) may be given in  
     25$any$ size order. To avoid multiple fit solutions, especially 
     26with Monte-Carlo fit methods, it may be advisable to restrict their ranges. There may  
     27be a number of closely similar "best fits", so some trial and error, or fixing of some  
     28dimensions at expected values, may help. 
    2629 
    2730The 1D scattering intensity $I(q)$ is calculated as: 
     
    6770    \mu &= qB 
    6871 
    69  
    7072The scattering intensity per unit volume is returned in units of |cm^-1|. 
    7173 
    7274NB: The 2nd virial coefficient of the parallelepiped is calculated based on 
    73 the averaged effective radius $(=\sqrt{A B / \pi})$ and 
     75the averaged effective radius, after appropriately sorting the three 
     76dimensions, to give an oblate or prolate particle, $(=\sqrt{AB/\pi})$ and 
    7477length $(= C)$ values, and used as the effective radius for 
    7578$S(q)$ when $P(q) \cdot S(q)$ is applied. 
     
    102105.. _parallelepiped-orientation: 
    103106 
    104 .. figure:: img/parallelepiped_angle_definition.jpg 
    105  
    106     Definition of the angles for oriented parallelepipeds. 
    107  
    108 .. figure:: img/parallelepiped_angle_projection.jpg 
    109  
    110     Examples of the angles for oriented parallelepipeds against the 
     107.. figure:: img/parallelepiped_angle_definition.png 
     108 
     109    Definition of the angles for oriented parallelepiped, shown with $A<B<C$. 
     110 
     111.. figure:: img/parallelepiped_angle_projection.png 
     112 
     113    Examples of the angles for an oriented parallelepiped against the 
    111114    detector plane. 
    112115 
     116On introducing "Orientational Distribution" in the angles, "distribution of theta" and "distribution of phi" parameters will 
     117appear. These are actually rotations about axes $\delta_1$ and $\delta_2$ of the parallelepiped, perpendicular to the $a$ x $c$ and $b$ x $c$ faces.  
     118(When $\theta = \phi = 0$ these are parallel to the $Y$ and $X$ axes of the instrument.) The third orientation distribution, in $\psi$, is  
     119about the $c$ axis of the particle, perpendicular to the $a$ x $b$ face. Some experimentation may be required to  
     120understand the 2d patterns fully. (Earlier implementations had numerical integration issues in some circumstances when orientation  
     121distributions passed through 90 degrees, such situations, with very broad distributions, should still be approached with care.)  
     122 
     123     
    113124For a given orientation of the parallelepiped, the 2D form factor is 
    114125calculated as 
     
    116127.. math:: 
    117128 
    118     P(q_x, q_y) = \left[\frac{\sin(qA\cos\alpha/2)}{(qA\cos\alpha/2)}\right]^2 
    119                   \left[\frac{\sin(qB\cos\beta/2)}{(qB\cos\beta/2)}\right]^2 
    120                   \left[\frac{\sin(qC\cos\gamma/2)}{(qC\cos\gamma/2)}\right]^2 
     129    P(q_x, q_y) = \left[\frac{\sin(\tfrac{1}{2}qA\cos\alpha)}{(\tfrac{1}{2}qA\cos\alpha)}\right]^2 
     130                  \left[\frac{\sin(\tfrac{1}{2}qB\cos\beta)}{(\tfrac{1}{2}qB\cos\beta)}\right]^2 
     131                  \left[\frac{\sin(\tfrac{1}{2}qC\cos\gamma)}{(\tfrac{1}{2}qC\cos\gamma)}\right]^2 
    121132 
    122133with 
     
    154165angles. 
    155166 
    156 This model is based on form factor calculations implemented in a c-library 
    157 provided by the NIST Center for Neutron Research (Kline, 2006). 
    158167 
    159168References 
     
    163172 
    164173R Nayuk and K Huber, *Z. Phys. Chem.*, 226 (2012) 837-854 
     174 
     175Authorship and Verification 
     176---------------------------- 
     177 
     178* **Author:** This model is based on form factor calculations implemented 
     179    in a c-library provided by the NIST Center for Neutron Research (Kline, 2006). 
     180* **Last Modified by:**  Paul Kienzle **Date:** April 05, 2017 
     181* **Last Reviewed by:**  Richard Heenan **Date:** April 06, 2017 
     182 
    165183""" 
    166184 
    167185import numpy as np 
    168 from numpy import pi, inf, sqrt 
     186from numpy import pi, inf, sqrt, sin, cos 
    169187 
    170188name = "parallelepiped" 
     
    180198            mu = q*B 
    181199        V: Volume of the rectangular parallelepiped 
    182         alpha: angle between the long axis of the  
     200        alpha: angle between the long axis of the 
    183201            parallelepiped and the q-vector for 1D 
    184202""" 
     
    196214              ["length_c", "Ang", 400, [0, inf], "volume", 
    197215               "Larger side of the parallelepiped"], 
    198               ["theta", "degrees", 60, [-inf, inf], "orientation", 
    199                "In plane angle"], 
    200               ["phi", "degrees", 60, [-inf, inf], "orientation", 
    201                "Out of plane angle"], 
    202               ["psi", "degrees", 60, [-inf, inf], "orientation", 
    203                "Rotation angle around its own c axis against q plane"], 
     216              ["theta", "degrees", 60, [-360, 360], "orientation", 
     217               "c axis to beam angle"], 
     218              ["phi", "degrees", 60, [-360, 360], "orientation", 
     219               "rotation about beam"], 
     220              ["psi", "degrees", 60, [-360, 360], "orientation", 
     221               "rotation about c axis"], 
    204222             ] 
    205223 
     
    208226def ER(length_a, length_b, length_c): 
    209227    """ 
    210         Return effective radius (ER) for P(q)*S(q) 
     228    Return effective radius (ER) for P(q)*S(q) 
    211229    """ 
    212  
     230    # now that axes can be in any size order, need to sort a,b,c where a~b and c is either much smaller 
     231    # or much larger 
     232    abc = np.vstack((length_a, length_b, length_c)) 
     233    abc = np.sort(abc, axis=0) 
     234    selector = (abc[1] - abc[0]) > (abc[2] - abc[1]) 
     235    length = np.where(selector, abc[0], abc[2]) 
    213236    # surface average radius (rough approximation) 
    214     surf_rad = sqrt(length_a * length_b / pi) 
    215  
    216     ddd = 0.75 * surf_rad * (2 * surf_rad * length_c + (length_c + surf_rad) * (length_c + pi * surf_rad)) 
     237    radius = np.sqrt(np.where(~selector, abc[0]*abc[1], abc[1]*abc[2]) / pi) 
     238 
     239    ddd = 0.75 * radius * (2*radius*length + (length + radius)*(length + pi*radius)) 
    217240    return 0.5 * (ddd) ** (1. / 3.) 
    218241 
     
    230253            phi_pd=10, phi_pd_n=1, 
    231254            psi_pd=10, psi_pd_n=10) 
    232  
    233 qx, qy = 0.2 * np.cos(2.5), 0.2 * np.sin(2.5) 
     255# rkh 7/4/17 add random unit test for 2d, note make all params different, 2d values not tested against other codes or models 
     256qx, qy = 0.2 * cos(pi/6.), 0.2 * sin(pi/6.) 
    234257tests = [[{}, 0.2, 0.17758004974], 
    235258         [{}, [0.2], [0.17758004974]], 
    236          [{'theta':10.0, 'phi':10.0}, (qx, qy), 0.00560296014], 
    237          [{'theta':10.0, 'phi':10.0}, [(qx, qy)], [0.00560296014]], 
     259         [{'theta':10.0, 'phi':20.0}, (qx, qy), 0.0089517140475], 
     260         [{'theta':10.0, 'phi':20.0}, [(qx, qy)], [0.0089517140475]], 
    238261        ] 
    239262del qx, qy  # not necessary to delete, but cleaner 
Note: See TracChangeset for help on using the changeset viewer.