Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/models/parallelepiped.py

    r3330bb4 rafd4692  
    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. 
     24   The edge of the solid used to have to satisfy the condition that $A < B < C$. 
     25   After some improvements to the effective radius calculation, used with 
     26   an S(Q), it is beleived that this is no longer the case. 
    2627 
    2728The 1D scattering intensity $I(q)$ is calculated as: 
     
    7172 
    7273NB: The 2nd virial coefficient of the parallelepiped is calculated based on 
    73 the averaged effective radius $(=\sqrt{A B / \pi})$ and 
     74the averaged effective radius, after appropriately sorting the three 
     75dimensions, to give an oblate or prolate particle, $(=\sqrt{AB/\pi})$ and 
    7476length $(= C)$ values, and used as the effective radius for 
    7577$S(q)$ when $P(q) \cdot S(q)$ is applied. 
     
    102104.. _parallelepiped-orientation: 
    103105 
    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 
     106.. figure:: img/parallelepiped_angle_definition.png 
     107 
     108    Definition of the angles for oriented parallelepiped, shown with $A<B<C$. 
     109 
     110.. figure:: img/parallelepiped_angle_projection.png 
     111 
     112    Examples of the angles for an oriented parallelepiped against the 
    111113    detector plane. 
    112114 
     
    116118.. math:: 
    117119 
    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 
     120    P(q_x, q_y) = \left[\frac{\sin(\tfrac{1}{2}qA\cos\alpha)}{(\tfrac{1}{2}qA\cos\alpha)}\right]^2 
     121                  \left[\frac{\sin(\tfrac{1}{2}qB\cos\beta)}{(\tfrac{1}{2}qB\cos\beta)}\right]^2 
     122                  \left[\frac{\sin(\tfrac{1}{2}qC\cos\gamma)}{(\tfrac{1}{2}qC\cos\gamma)}\right]^2 
    121123 
    122124with 
     
    154156angles. 
    155157 
    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). 
    158158 
    159159References 
     
    163163 
    164164R Nayuk and K Huber, *Z. Phys. Chem.*, 226 (2012) 837-854 
     165 
     166Authorship and Verification 
     167---------------------------- 
     168 
     169* **Author:** This model is based on form factor calculations implemented 
     170in a c-library provided by the NIST Center for Neutron Research (Kline, 2006). 
     171* **Last Modified by:**  Paul Kienzle **Date:** April 05, 2017 
     172* **Last Reviewed by:**  Richard Heenan **Date:** April 06, 2017 
     173 
    165174""" 
    166175 
    167176import numpy as np 
    168 from numpy import pi, inf, sqrt 
     177from numpy import pi, inf, sqrt, sin, cos 
    169178 
    170179name = "parallelepiped" 
     
    180189            mu = q*B 
    181190        V: Volume of the rectangular parallelepiped 
    182         alpha: angle between the long axis of the  
     191        alpha: angle between the long axis of the 
    183192            parallelepiped and the q-vector for 1D 
    184193""" 
     
    208217def ER(length_a, length_b, length_c): 
    209218    """ 
    210         Return effective radius (ER) for P(q)*S(q) 
     219    Return effective radius (ER) for P(q)*S(q) 
    211220    """ 
    212  
     221    # now that axes can be in any size order, need to sort a,b,c where a~b and c is either much smaller 
     222    # or much larger 
     223    abc = np.vstack((length_a, length_b, length_c)) 
     224    abc = np.sort(abc, axis=0) 
     225    selector = (abc[1] - abc[0]) > (abc[2] - abc[1]) 
     226    length = np.where(selector, abc[0], abc[2]) 
    213227    # 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)) 
     228    radius = np.sqrt(np.where(~selector, abc[0]*abc[1], abc[1]*abc[2]) / pi) 
     229 
     230    ddd = 0.75 * radius * (2*radius*length + (length + radius)*(length + pi*radius)) 
    217231    return 0.5 * (ddd) ** (1. / 3.) 
    218232 
     
    230244            phi_pd=10, phi_pd_n=1, 
    231245            psi_pd=10, psi_pd_n=10) 
    232  
    233 qx, qy = 0.2 * np.cos(2.5), 0.2 * np.sin(2.5) 
     246# rkh 7/4/17 add random unit test for 2d, note make all params different, 2d values not tested against other codes or models 
     247qx, qy = 0.2 * cos(pi/6.), 0.2 * sin(pi/6.) 
    234248tests = [[{}, 0.2, 0.17758004974], 
    235249         [{}, [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]], 
     250         [{'theta':10.0, 'phi':20.0}, (qx, qy), 0.0089517140475], 
     251         [{'theta':10.0, 'phi':20.0}, [(qx, qy)], [0.0089517140475]], 
    238252        ] 
    239253del qx, qy  # not necessary to delete, but cleaner 
Note: See TracChangeset for help on using the changeset viewer.