Changeset 19dcb933 in sasmodels


Ignore:
Timestamp:
Sep 3, 2014 3:16:10 AM (10 years ago)
Author:
Paul Kienzle <pkienzle@…>
Branches:
master, core_shell_microgels, costrafo411, magnetic_model, release_v0.94, release_v0.95, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
Children:
1c7ffdc
Parents:
87985ca
Message:

build docs for models

Files:
20 added
10 edited
1 moved

Legend:

Unmodified
Added
Removed
  • README.rst

    r5d4777d r19dcb933  
     1Sasmodels 
     2========= 
     3 
     4Theory models for small angle scattering. 
     5 
     6The models provided are usable directly in the bumps fitting package and 
     7in the sasview analysis package.  If OpenCL is available, the models will 
     8run much faster.  If not, then precompiled versions will be included with 
     9the distributed package.  New models can be added if OpenCL or a C compiler 
     10is available. 
     11 
    112cylinder.c + cylinder.py is the cylinder model with renamed variables and 
    213sld scaled by 1e6 so the numbers are nicer.  The model name is "cylinder" 
     
    1021 
    1122Note: may want to rename form_volume to calc_volume and Iq/Iqxy to 
    12 calc_Iq/calc_Iqxy. Similarly ER/VR go to calc_ER/calc_VR. 
     23calc_Iq/calc_Iqxy in model interface. Similarly ER/VR go to calc_ER/calc_VR. 
    1324 
    1425Note: It is possible to translate python code automatically to opencl, using 
    1526something like numba, clyther, shedskin or pypy, so maybe the kernel functions 
    1627could be implemented without any C syntax. 
     28 
     29Note: angular dispersion in theta is probably not calculated correctly, but 
     30is left this way for compatibility with sasview. 
    1731 
    1832Magnetism hasn't been implemented yet.  We may want a separate Imagnetic 
     
    2337in the same data set. 
    2438 
    25 Need to write code to generate the polydispersity loops in python for 
    26 kernels that are only implemented in python.  Also, need to implement 
    27 an example kernel directly in python. 
     39Need to implement an example kernel directly in python.  Polydispersity 
     40loops should be generated automatically as they are for the OpenCL models. 
     41The kernels should be vectorized across Q.  These will need vectorized 
     42versions of numerical quadrature if we want to get reasonable performance. 
     43 
  • sasmodels/__init__.py

    r14de349 r19dcb933  
     1__version__ = "0.9" 
  • sasmodels/gen.py

    rf4cf580 r19dcb933  
    203203# Headers for the parameters tables in th sphinx documentation 
    204204PARTABLE_HEADERS = [ 
    205     "Parameter name", 
     205    "Parameter", 
     206    "Description", 
    206207    "Units", 
    207208    "Default value", 
     
    395396DOC_HEADER=""".. _%(name)s: 
    396397 
    397 %(name)s 
     398%(label)s 
    398399======================================================= 
    399400 
     
    542543    return kernel 
    543544 
    544 def make_partable(info): 
     545def make_partable(pars): 
    545546    """ 
    546547    Generate the parameter table to include in the sphinx documentation. 
    547548    """ 
    548     pars = info['parameters'] 
     549    pars = COMMON_PARAMETERS + pars 
    549550    column_widths = [ 
    550551        max(len(p[0]) for p in pars), 
     552        max(len(p[-1]) for p in pars), 
    551553        max(len(RST_UNITS[p[1]]) for p in pars), 
    552554        PARTABLE_VALUE_WIDTH, 
     
    564566        lines.append(" ".join([ 
    565567            "%-*s"%(column_widths[0],p[0]), 
    566             "%-*s"%(column_widths[1],RST_UNITS[p[1]]), 
    567             "%*g"%(column_widths[2],p[2]), 
     568            "%-*s"%(column_widths[1],p[-1]), 
     569            "%-*s"%(column_widths[2],RST_UNITS[p[1]]), 
     570            "%*g"%(column_widths[3],p[2]), 
    568571            ])) 
    569572    lines.append(sep) 
     
    678681    Return the documentation for the model. 
    679682    """ 
    680     subst = dict(name=kernel_module.name, 
     683    subst = dict(name=kernel_module.name.replace('_','-'), 
     684                 label=" ".join(kernel_module.name.split('_')).capitalize(), 
    681685                 title=kernel_module.title, 
    682686                 parameters=make_partable(kernel_module.parameters), 
    683                  doc=kernel_module.__doc__) 
     687                 docs=kernel_module.__doc__) 
    684688    return DOC_HEADER%subst 
    685689 
  • sasmodels/models/capped_cylinder.py

    rf4cf580 r19dcb933  
    1414The capped cylinder geometry is defined as 
    1515 
    16 .. image:: img/image112.JPG 
     16.. image:: img/capped_cylinder_geometry.jpg 
    1717 
    1818where $r$ is the radius of the cylinder. All other parameters are as defined 
     
    2424    h = - \sqrt{R^2 - r^2} 
    2525 
    26 The scattered intensity $I(q)$ is calculated as 
     26The scattered intensity $I(Q)$ is calculated as 
    2727 
    2828.. math:: 
    2929 
    30     I(q) = \frac{(\Delta \rho)^2}{V} left<A^2(q)\right> 
     30    I(Q) = \frac{(\Delta \rho)^2}{V} \left< A^2(Q)\right> 
    3131 
    32 where the amplitude $A(q)$ is given as 
     32where the amplitude $A(Q)$ is given as 
    3333 
    3434.. math:: 
    3535 
    36     A(Q) = \pi r^2L \frac{sin(Q(L/2) \cos \theta)}{Q(L/2) \cos \theta} \ 
    37         \frac{2 J_1(Q r \sin \theta)}{Q r \sin \theta} \ 
    38         + 4 \pi R^3 \int_{-h/R}^1{dt \cos [ Q cos\theta (Rt + h + L/2)] \ 
    39         x (1-t^2)\frac{J_1[Q R \sin \theta (1-t^2)^{1/2}]}{Q R \sin \theta (1-t^2)^{1/2} 
     36    A(Q) =&\ \pi r^2L 
     37        {\sin\left(\tfrac12 QL\cos\theta\right) 
     38            \over \tfrac12 QL\cos\theta} 
     39        {2 J_1(Qr\sin\theta) \over Qr\sin\theta} \\ 
     40        &\ + 4 \pi R^3 \int_{-h/R}^1 dt 
     41        \cos\left[ Q\cos\theta 
     42            \left(Rt + h + {\tfrac12} L\right)\right] 
     43        \times (1-t^2) 
     44        {J_1\left[QR\sin\theta \left(1-t^2\right)^{1/2}\right] 
     45             \over QR\sin\theta \left(1-t^2\right)^{1/2}} 
    4046 
    4147The $\left< \ldots \right>$ brackets denote an average of the structure over 
    42 all orientations. $\left< A^2(q)\right>$ is then the form factor, $P(q)$. 
     48all orientations. $\left< A^2(Q)\right>$ is then the form factor, $P(Q)$. 
    4349The scale factor is equivalent to the volume fraction of cylinders, each of 
    4450volume, $V$. Contrast is the difference of scattering length densities of 
     
    4955.. math:: 
    5056 
    51     V = \pi r_c^2 L + \frac{2\pi}{3}(R-h)^2(2R + h) 
     57    V = \pi r_c^2 L + \tfrac{2\pi}{3}(R-h)^2(2R + h) 
    5258 
    5359 
    5460and its radius-of-gyration is 
    5561 
    56     R_g^2 = \left[ \frac{12}{5}R^5 + R^4(6h+\frac{3}{2}L) \ 
    57         + R^2(4h^2 + L^2 + 4Lh) + R^2(3Lh^2 + [frac{3}{2}L^2h) \ 
    58         + \frac{2}{5}h^5 - \frac{1}{2}Lh^4 - \frac{1}{2}L^2h^3 \ 
    59         + \frac{1}{4}L^3r^2 + \frac{3}{2}Lr^4\right] \ 
    60         (4R^3 6R^2h - 2h^3 + 3r^2L)^{-1} 
     62.. math:: 
     63 
     64    R_g^2 =&\ \left[ \tfrac{12}{5}R^5 
     65        + R^4\left(6h+\tfrac32 L\right) 
     66        + R^2\left(4h^2 + L^2 + 4Lh\right) 
     67        + R^2\left(3Lh^2 + \tfrac32 L^2h\right) \right. \\ 
     68        &\ \left. + \tfrac25 h^5 - \tfrac12 Lh^4 - \tfrac12 L^2h^3 
     69        + \tfrac14 L^3r^2 + \tfrac32 Lr^4 \right] 
     70        \left( 4R^3 6R^2h - 2h^3 + 3r^2L \right)^{-1} 
    6171 
    6272 
    63 **The requirement that $R \ge r$ is not enforced in the model! It is up to 
    64 you to restrict this during analysis.** 
     73.. note:: 
    6574 
    66 Figure :num:`figure #capped-cylinder-1d` shows the output produced by 
     75    The requirement that $R \ge r$ is not enforced in the model! 
     76    It is up to you to restrict this during analysis. 
     77 
     78:num:`Figure #capped-cylinder-1d` shows the output produced by 
    6779a running the 1D capped cylinder model, using *qmin* = 0.001 |Ang^-1|, 
    6880*qmax* = 0.7 |Ang^-1| and  the default values of the parameters. 
     
    7082.. _capped-cylinder-1d: 
    7183 
    72 .. figure:: img/image117.jpg 
     84.. figure:: img/capped_cylinder_1d.jpg 
    7385 
    7486    1D plot using the default values (w/256 data point). 
    7587 
    7688The 2D scattering intensity is calculated similar to the 2D cylinder model. 
    77 Figure :num:`figure #capped-cylinder-2d` shows the output for $\theta=45^\circ$ 
     89:num:`Figure #capped-cylinder-2d` shows the output for $\theta=45^\circ$ 
    7890and $\phi=0^\circ$ with default values for the other parameters. 
    7991 
    8092.. _capped-cylinder-2d: 
    8193 
    82 .. figure:: img/image118.JPG 
     94.. figure:: img/capped_cylinder_2d.jpg 
    8395 
    8496    2D plot (w/(256X265) data points). 
    8597 
    86 .. figure:: img/image061.JPG 
     98.. figure:: img/orientation.jpg 
    8799 
    88100    Definition of the angles for oriented 2D cylinders. 
    89101 
    90 .. figure:: img/image062.jpg 
     102.. figure:: img/orientation2.jpg 
    91103 
    92104    Examples of the angles for oriented pp against the detector plane. 
  • sasmodels/models/core_shell_cylinder.py

    r5d4777d r19dcb933  
    1212.. math:: 
    1313 
    14     P(q,\alpha) = \frac{\text{scale}}{V_s} f^2(q) + \text{background} 
     14    P(Q,\alpha) = {\text{scale} \over V_s} F^2(Q) + \text{background} 
    1515 
    1616where 
     
    1818.. math:: 
    1919 
    20     f(q) = (\rho_c - \rho_s) V_c \ 
    21            \frac{\sin( Q L/2 \cos \alpha)}{Q L/2 \cos \alpha} \ 
    22            \frac{2 J_1 (Q R \sin \alpha)}{Q R \sin \alpha} 
    23            + (\rho_s - \rho_\text{solv}) V_s \ 
    24            \frac{\sin( Q (L/2+T) \cos \alpha)}{Q (L/2+T) \cos \alpha} 
    25            \frac{2 J_1 (Q (R+T) \sin \alpha)}{Q (R+T) \sin \alpha} 
     20    F(Q) = &\ (\rho_c - \rho_s) V_c 
     21           {\sin \left( Q \tfrac12 L\cos\alpha \right) 
     22               \over Q \tfrac12 L\cos\alpha } 
     23           {2 J_1 \left( QR\sin\alpha \right) 
     24               \over QR\sin\alpha } \\ 
     25         &\ + (\rho_s - \rho_\text{solv}) V_s 
     26           {\sin \left( Q \left(\tfrac12 L+T\right) \cos\alpha \right) 
     27               \over Q \left(\tfrac12 L +T \right) \cos\alpha } 
     28           { 2 J_1 \left( Q(R+T)\sin\alpha \right) 
     29               \over Q(R+T)\sin\alpha } 
    2630 
    2731and 
     
    2933.. math:: 
    3034 
    31     V_s = \pi (R + T)^2 \dot (L + 2T) 
    32  
     35    V_s = \pi (R + T)^2 (L + 2T) 
    3336 
    3437and $\alpha$ is the angle between the axis of the cylinder and $\vec q$, 
     
    4245shell is given by $L+2T$. $J1$ is the first order Bessel function. 
    4346 
    44 .. figure:: img/image069.JPG 
     47.. _core-shell-cylinder-geometry: 
     48 
     49.. figure:: img/core_shell_cylinder_geometry.jpg 
    4550 
    4651    Core shell cylinder schematic. 
     
    4954define the axis of the cylinder using two angles $\theta$ and $\phi$. As 
    5055for the case of the cylinder, those angles are defined in 
    51 Figure :num:`figure #cylinder-orientation`. 
     56:num:`figure #cylinder-orientation`. 
    5257 
    5358NB: The 2nd virial coefficient of the cylinder is calculated based on 
    5459the radius and 2 length values, and used as the effective radius for 
    55 $S(Q)$ when $P(Q) \dot S(Q)$ is applied. 
     60$S(Q)$ when $P(Q) \cdot S(Q)$ is applied. 
    5661 
    5762The $\theta$ and $\phi$ parameters are not used for the 1D output. Our 
     
    6469Validation of our code was done by comparing the output of the 1D model to 
    6570the output of the software provided by the NIST (Kline, 2006). 
    66 Figure :num:`figure #core-shell-cylinder-comparison-1d` shows a comparison 
     71:num:`Figure #core-shell-cylinder-1d` shows a comparison 
    6772of the 1D output of our model and the output of the NIST software. 
    6873 
    69 .. _core-shell-cylinder-comparison-1d: 
     74.. _core-shell-cylinder-1d: 
    7075 
    71 .. figure:: img/image070.JPG 
     76.. figure:: img/core_shell_cylinder_1d.jpg 
    7277 
    7378    Comparison of the SasView scattering intensity for a core-shell cylinder 
    7479    with the output of the NIST SANS analysis software. The parameters were 
    75     set to: *scale=1.0 |Ang|*, *radius=20 |Ang|*, *thickness=10 |Ang|*, 
    76     *length=400 |Ang|*, *core_sld=1e-6 |Ang^-2|*, *shell_sld=4e-6 |Ang^-2|*, 
    77     *solvent_sld=1e-6 |Ang^-2|*, and *background=0.01 |cm^-1|*. 
     80    set to: *scale* = 1.0 |Ang|, *radius* = 20 |Ang|, *thickness* = 10 |Ang|, 
     81    *length* =400 |Ang|, *core_sld* =1e-6 |Ang^-2|, *shell_sld* = 4e-6 |Ang^-2|, 
     82    *solvent_sld* = 1e-6 |Ang^-2|, and *background* = 0.01 |cm^-1|. 
    7883 
    7984Averaging over a distribution of orientation is done by evaluating the 
     
    8186implementation of the intensity for fully oriented cylinders, we can 
    8287compare the result of averaging our 2D output using a uniform 
    83 distribution $p(\theta,\phi)* = 1.0$. 
    84 Figure :num:`figure #core-shell-cylinder-comparison-2d` shows the result 
     88distribution $p(\theta,\phi) = 1.0$. 
     89:num:`Figure #core-shell-cylinder-2d` shows the result 
    8590of such a cross-check. 
    8691 
    87 .. _core-shell-cylinder-comparison-2d: 
     92.. _core-shell-cylinder-2d: 
    8893 
    89 .. figure:: img/image071.JPG 
     94.. figure:: img/core_shell_cylinder_2d.jpg 
    9095 
    9196    Comparison of the intensity for uniformly distributed core-shell 
    9297    cylinders calculated from our 2D model and the intensity from the 
    93     NIST SANS analysis software. The parameters used were: *scale*=1.0*, 
    94     *radius=20 |Ang|*, *thickness=10 |Ang|*, *length*=400 |Ang|*, 
    95     *core_sld=1e-6 |Ang^-2|*, *shell_sld=4e-6 |Ang^-2|*, 
    96     *solvent_sld=1e-6 |Ang^-2|*, and *background=0.0 |cm^-1|*. 
     98    NIST SANS analysis software. The parameters used were: *scale* = 1.0, 
     99    *radius* = 20 |Ang|, *thickness* = 10 |Ang|, *length* = 400 |Ang|, 
     100    *core_sld* = 1e-6 |Ang^-2|, *shell_sld* = 4e-6 |Ang^-2|, 
     101    *solvent_sld* = 1e-6 |Ang^-2|, and *background* = 0.0 |cm^-1|. 
    97102 
    981032013/11/26 - Description reviewed by Heenan, R. 
     
    101106from numpy import pi, inf 
    102107 
    103 name = "cylinder" 
     108name = "core_shell_cylinder" 
    104109title = "Right circular cylinder with a core-shell scattering length density profile." 
    105110description = """ 
  • sasmodels/models/cylinder.py

    r5d4777d r19dcb933  
    1414.. math:: 
    1515 
    16     P(q,\alpha) = \frac{\text{scale}}{V}f^2(q) + \text{bkg} 
     16    P(Q,\alpha) = {\text{scale} \over V} F^2(Q) + \text{background} 
    1717 
    1818where 
     
    2020.. math:: 
    2121 
    22     f(q) = 2 (\Delta \rho) V 
    23            \frac{\sin (q L/2 \cos \alpha)}{q L/2 \cos \alpha} 
    24            \frac{J_1 (q r \sin \alpha)}{q r \sin \alpha} 
     22    F(Q) = 2 (\Delta \rho) V 
     23           {\sin \left(Q\tfrac12 L\cos\alpha \right) 
     24               \over Q\tfrac12 L \cos \alpha} 
     25           {J_1 \left(Q R \sin \alpha\right) \over Q R \sin \alpha} 
    2526 
    2627and $\alpha$ is the angle between the axis of the cylinder and $\vec q$, $V$ 
    27 is the volume of the cylinder, $L$ is the length of the cylinder, $r$ is the 
    28 radius of the cylinder, and $d\rho$ (contrast) is the scattering length density 
    29 difference between the scatterer and the solvent. $J_1$ is the first order 
    30 Bessel function. 
     28is the volume of the cylinder, $L$ is the length of the cylinder, $R$ is the 
     29radius of the cylinder, and $\Delta\rho$ (contrast) is the scattering length 
     30density difference between the scatterer and the solvent. $J_1$ is the 
     31first order Bessel function. 
    3132 
    3233To provide easy access to the orientation of the cylinder, we define the 
    3334axis of the cylinder using two angles $\theta$ and $\phi$. Those angles 
    34 are defined in Figure :num:`figure #cylinder-orientation`. 
     35are defined in :num:`figure #cylinder-orientation`. 
    3536 
    3637.. _cylinder-orientation: 
    3738 
    38 .. figure:: img/image061.JPG   (should be img/cylinder-1.jpg, or img/cylinder-orientation.jpg) 
     39.. figure:: img/orientation.jpg 
    3940 
    4041    Definition of the angles for oriented cylinders. 
    4142 
    42 .. figure:: img/image062.JPG 
     43.. figure:: img/orientation2.jpg 
    4344 
    4445    Examples of the angles for oriented pp against the detector plane. 
     
    5354.. math:: 
    5455 
    55     P(q) = \frac{\text{scale}}{V} 
    56         \int_0^{\pi/2} f^2(q,\alpha) \sin \alpha d\alpha + \text{background} 
     56    P(Q) = {\text{scale} \over V} 
     57        \int_0^{\pi/2} F^2(Q,\alpha) \sin \alpha\ d\alpha + \text{background} 
    5758 
    5859The *theta* and *phi* parameters are not used for the 1D output. Our 
     
    6566Validation of our code was done by comparing the output of the 1D model 
    6667to the output of the software provided by the NIST (Kline, 2006). 
    67 Figure :num:`figure #cylinder-compare` shows a comparison of 
     68:num:`Figure #cylinder-compare` shows a comparison of 
    6869the 1D output of our model and the output of the NIST software. 
    6970 
    7071.. _cylinder-compare: 
    7172 
    72 .. figure:: img/image065.JPG 
     73.. figure:: img/cylinder_compare.jpg 
    7374 
    7475    Comparison of the SasView scattering intensity for a cylinder with the 
    7576    output of the NIST SANS analysis software. 
    76     The parameters were set to: *Scale* = 1.0, *Radius* = 20 |Ang|, 
    77     *Length* = 400 |Ang|, *Contrast* = 3e-6 |Ang^-2|, and 
    78     *Background* = 0.01 |cm^-1|. 
     77    The parameters were set to: *scale* = 1.0, *radius* = 20 |Ang|, 
     78    *length* = 400 |Ang|, *contrast* = 3e-6 |Ang^-2|, and 
     79    *background* = 0.01 |cm^-1|. 
    7980 
    8081In general, averaging over a distribution of orientations is done by 
     
    8384.. math:: 
    8485 
    85     P(q) = \int_0^{\pi/2} d\phi 
    86         \int_0^\pi p(\theta, \phi) P_0(q,\alpha) \sin \theta d\theta 
     86    P(Q) = \int_0^{\pi/2} d\phi 
     87        \int_0^\pi p(\theta, \phi) P_0(Q,\alpha) \sin \theta\ d\theta 
    8788 
    8889 
    8990where $p(\theta,\phi)$ is the probability distribution for the orientation 
    90 and $P_0(q,\alpha)$ is the scattering intensity for the fully oriented 
     91and $P_0(Q,\alpha)$ is the scattering intensity for the fully oriented 
    9192system. Since we have no other software to compare the implementation of 
    9293the intensity for fully oriented cylinders, we can compare the result of 
    9394averaging our 2D output using a uniform distribution $p(\theta, \phi) = 1.0$. 
    94 Figure :num:`figure #cylinder-crosscheck` shows the result of 
     95:num:`Figure #cylinder-crosscheck` shows the result of 
    9596such a cross-check. 
    9697 
    9798.. _cylinder-crosscheck: 
    9899 
    99 .. figure:: img/image066.JPG 
     100.. figure:: img/cylinder_crosscheck.jpg 
    100101 
    101102    Comparison of the intensity for uniformly distributed cylinders 
    102103    calculated from our 2D model and the intensity from the NIST SANS 
    103104    analysis software. 
    104     The parameters used were: *Scale* = 1.0, *Radius* = 20 |Ang|, 
    105     *Length* = 400 |Ang|, *Contrast* = 3e-6 |Ang^-2|, and 
    106     *Background* = 0.0 |cm^-1|. 
     105    The parameters used were: *scale* = 1.0, *radius* = 20 |Ang|, 
     106    *length* = 400 |Ang|, *contrast* = 3e-6 |Ang^-2|, and 
     107    *background* = 0.0 |cm^-1|. 
    107108""" 
    108109 
  • sasmodels/models/cylinder_clone.py

    r5d4777d r19dcb933  
    1 r""" 
    2 CylinderModel 
    3 ============= 
    4  
    5 This model provides the form factor for a right circular cylinder with uniform 
    6 scattering length density. The form factor is normalized by the particle volume. 
    7  
    8 For information about polarised and magnetic scattering, click here_. 
    9  
    10 Definition 
    11 ---------- 
    12  
    13 The output of the 2D scattering intensity function for oriented cylinders is 
    14 given by (Guinier, 1955) 
    15  
    16 .. math:: 
    17  
    18     P(q,\alpha) = \frac{\text{scale}}{V}f^2(q) + \text{bkg} 
    19  
    20 where 
    21  
    22 .. math:: 
    23  
    24     f(q) = 2 (\Delta \rho) V 
    25            \frac{\sin (q L/2 \cos \alpha)}{q L/2 \cos \alpha} 
    26            \frac{J_1 (q r \sin \alpha)}{q r \sin \alpha} 
    27  
    28 and $\alpha$ is the angle between the axis of the cylinder and $\vec q$, $V$ 
    29 is the volume of the cylinder, $L$ is the length of the cylinder, $r$ is the 
    30 radius of the cylinder, and $d\rho$ (contrast) is the scattering length density 
    31 difference between the scatterer and the solvent. $J_1$ is the first order 
    32 Bessel function. 
    33  
    34 To provide easy access to the orientation of the cylinder, we define the 
    35 axis of the cylinder using two angles $\theta$ and $\phi$. Those angles 
    36 are defined in Figure :num:`figure #CylinderModel-orientation`. 
    37  
    38 .. _CylinderModel-orientation: 
    39  
    40 .. figure:: img/image061.JPG 
    41  
    42     Definition of the angles for oriented cylinders. 
    43  
    44 .. figure:: img/image062.JPG 
    45  
    46     Examples of the angles for oriented pp against the detector plane. 
    47  
    48 NB: The 2nd virial coefficient of the cylinder is calculated based on the 
    49 radius and length values, and used as the effective radius for $S(Q)$ 
    50 when $P(Q) \cdot S(Q)$ is applied. 
    51  
    52 The returned value is scaled to units of |cm^-1| and the parameters of 
    53 the CylinderModel are the following: 
    54  
    55 %(parameters)s 
    56  
    57 The output of the 1D scattering intensity function for randomly oriented 
    58 cylinders is then given by 
    59  
    60 .. math:: 
    61  
    62     P(q) = \frac{\text{scale}}{V} 
    63         \int_0^{\pi/2} f^2(q,\alpha) \sin \alpha d\alpha + \text{background} 
    64  
    65 The *theta* and *phi* parameters are not used for the 1D output. Our 
    66 implementation of the scattering kernel and the 1D scattering intensity 
    67 use the c-library from NIST. 
    68  
    69 Validation of the CylinderModel 
    70 ------------------------------- 
    71  
    72 Validation of our code was done by comparing the output of the 1D model 
    73 to the output of the software provided by the NIST (Kline, 2006). 
    74 Figure :num:`figure #CylinderModel-compare` shows a comparison of 
    75 the 1D output of our model and the output of the NIST software. 
    76  
    77 .. _CylinderModel-compare: 
    78  
    79 .. figure:: img/image065.JPG 
    80  
    81     Comparison of the SasView scattering intensity for a cylinder with the 
    82     output of the NIST SANS analysis software. 
    83     The parameters were set to: *Scale* = 1.0, *Radius* = 20 |Ang|, 
    84     *Length* = 400 |Ang|, *Contrast* = 3e-6 |Ang^-2|, and 
    85     *Background* = 0.01 |cm^-1|. 
    86  
    87 In general, averaging over a distribution of orientations is done by 
    88 evaluating the following 
    89  
    90 .. math:: 
    91  
    92     P(q) = \int_0^{\pi/2} d\phi 
    93         \int_0^\pi p(\theta, \phi) P_0(q,\alpha) \sin \theta d\theta 
    94  
    95  
    96 where $p(\theta,\phi)$ is the probability distribution for the orientation 
    97 and $P_0(q,\alpha)$ is the scattering intensity for the fully oriented 
    98 system. Since we have no other software to compare the implementation of 
    99 the intensity for fully oriented cylinders, we can compare the result of 
    100 averaging our 2D output using a uniform distribution $p(\theta, \phi) = 1.0$. 
    101 Figure :num:`figure #CylinderModel-crosscheck` shows the result of 
    102 such a cross-check. 
    103  
    104 .. _CylinderModel-crosscheck: 
    105  
    106 .. figure:: img/image066.JPG 
    107  
    108     Comparison of the intensity for uniformly distributed cylinders 
    109     calculated from our 2D model and the intensity from the NIST SANS 
    110     analysis software. 
    111     The parameters used were: *Scale* = 1.0, *Radius* = 20 |Ang|, 
    112     *Length* = 400 |Ang|, *Contrast* = 3e-6 |Ang^-2|, and 
    113     *Background* = 0.0 |cm^-1|. 
    114 """ 
    1151 
    1162from numpy import pi, inf 
  • sasmodels/models/ellipsoid.py

    r5d4777d r19dcb933  
    1212.. math:: 
    1313 
    14     P(q,\alpha) = \frac{\text{scale}}{V} f^2(q) + \text{background} 
     14    P(Q,\alpha) = {\text{scale} \over V} F^2(Q) + \text{background} 
    1515 
    1616where 
     
    1818.. math:: 
    1919 
    20     f(q) = \frac{3 (\Delta rho)) V (\sin[qr(R_p,R_e,\alpha)] \ 
    21                  - \cos[qr(R_p,R_e,\alpha)])}{[qr(R_q,R_b,\alpha)]^3} 
     20    F(Q) = {3 (\Delta rho)) V (\sin[Qr(R_p,R_e,\alpha)] 
     21                - \cos[Qr(R_p,R_e,\alpha)]) 
     22            \over [Qr(R_p,R_e,\alpha)]^3 } 
    2223 
    2324and 
     
    2526.. math:: 
    2627 
    27     r(R_p,R_e,\alpha) = \left[ R_e^2 \sin^2 \alpha + R_p^2 \cos^2 \alpha \right]^{1/2} 
     28    r(R_p,R_e,\alpha) = \left[ R_e^2 \sin^2 \alpha 
     29        + R_p^2 \cos^2 \alpha \right]^{1/2} 
    2830 
    2931 
     
    3638To provide easy access to the orientation of the ellipsoid, we define 
    3739the rotation axis of the ellipsoid using two angles $\theta$ and $\phi$. 
    38 These angles are defined in Figure :num:`figure #cylinder-orientation`. 
     40These angles are defined in the 
     41:ref:`cylinder orientation figure <cylinder-orientation>`. 
    3942For the ellipsoid, $\theta$ is the angle between the rotational axis 
    4043and the $z$-axis. 
     
    4245NB: The 2nd virial coefficient of the solid ellipsoid is calculated based 
    4346on the $R_p$ and $R_e$ values, and used as the effective radius for 
    44 $S(Q)$ when $P(Q) \dot S(Q)$ is applied. 
     47$S(Q)$ when $P(Q) \cdot S(Q)$ is applied. 
    4548 
    46 .. figure:: img/image121.JPG 
     49.. _ellipsoid-1d: 
     50 
     51.. figure:: img/ellipsoid_1d.JPG 
    4752 
    4853    The output of the 1D scattering intensity function for randomly oriented 
     
    5459use the c-library from NIST. 
    5560 
    56 .. figure:: img/image122.JPG 
     61.. _ellipsoid-geometry: 
     62 
     63.. figure:: img/ellipsoid_geometry.JPG 
    5764 
    5865    The angles for oriented ellipsoid. 
     
    6370Validation of our code was done by comparing the output of the 1D model 
    6471to the output of the software provided by the NIST (Kline, 2006). 
    65 Figure :num:`figure ellipsoid-comparison-1d` below shows a comparison of 
     72:num:`Figure ellipsoid-comparison-1d` below shows a comparison of 
    6673the 1D output of our model and the output of the NIST software. 
    6774 
    6875.. _ellipsoid-comparison-1d: 
    6976 
    70 .. figure:: img/image123.JPG 
     77.. figure:: img/ellipsoid_comparison_1d.jpg 
    7178 
    7279    Comparison of the SasView scattering intensity for an ellipsoid 
    7380    with the output of the NIST SANS analysis software.  The parameters 
    74     were set to: *scale=1.0*, *a=20 |Ang|*, *b=400 |Ang|*, 
    75     *sld-solvent_sld=3e-6 |Ang^-2|*, and *background=0.01 |cm^-1|*. 
     81    were set to: *scale* = 1.0, *rpolar* = 20 |Ang|, 
     82    *requatorial* =400 |Ang|, *contrast* = 3e-6 |Ang^-2|, 
     83    and *background* = 0.01 |cm^-1|. 
    7684 
    7785Averaging over a distribution of orientation is done by evaluating the 
     
    7987implementation of the intensity for fully oriented ellipsoids, we can 
    8088compare the result of averaging our 2D output using a uniform distribution 
    81 $p(\theta,\phi) = 1.0$.  Figure :num:`figure #ellipsoid-comparison-2d` 
     89$p(\theta,\phi) = 1.0$.  :num:`Figure #ellipsoid-comparison-2d` 
    8290shows the result of such a cross-check. 
    8391 
    8492.. _ellipsoid-comparison-2d: 
    8593 
    86 .. figure:: img/image124.jpg 
     94.. figure:: img/ellipsoid_comparison_2d.jpg 
    8795 
    8896    Comparison of the intensity for uniformly distributed ellipsoids 
    8997    calculated from our 2D model and the intensity from the NIST SANS 
    90     analysis software. The parameters used were: *scale=1.0*, 
    91     *a=20 |Ang|*, *b=400 |Ang|*, *sld-solvent_sld=3e-6 |Ang^-2|*, 
    92     and *background=0.0 |cm^-1|*. 
     98    analysis software. The parameters used were: *scale* = 1.0, 
     99    *rpolar* = 20 |Ang|, *requatorial* = 400 |Ang|, 
     100    *contrast* = 3e-6 |Ang^-2|, and *background* = 0.0 |cm^-1|. 
    93101 
    94 The discrepancy above *q=0.3 |cm^-1|* is due to the way the form factors 
     102The discrepancy above *q* = 0.3 |cm^-1| is due to the way the form factors 
    95103are calculated in the c-library provided by NIST. A numerical integration 
    96 has to be performed to obtain *P(q)* for randomly oriented particles. 
     104has to be performed to obtain $P(Q)$ for randomly oriented particles. 
    97105The NIST software performs that integration with a 76-point Gaussian 
    98 quadrature rule, which will become imprecise at high q where the amplitude 
    99 varies quickly as a function of $q$. The SasView result shown has been 
     106quadrature rule, which will become imprecise at high $Q$ where the amplitude 
     107varies quickly as a function of $Q$. The SasView result shown has been 
    100108obtained by summing over 501 equidistant points. Our result was found 
    101 to be stable over the range of *q* shown for a number of points higher 
     109to be stable over the range of $Q$ shown for a number of points higher 
    102110than 500. 
    103111 
  • sasmodels/models/lamellar.py

    r5d4777d r19dcb933  
    55---------- 
    66 
    7 The scattering intensity *I(q)* is 
     7The scattering intensity *I(Q)* is 
    88 
    99.. math:: 
    1010 
    11     I(q) = 2\pi\frac{P(q){\delta q^2} 
     11    I(Q) = 2\pi{P(Q) \over \delta Q^2} 
    1212 
    1313 
     
    1616.. math:: 
    1717 
    18     P(q) = \frac{2\Delta\rho^2}{q^2}(1-cos(q\delta) 
     18    P(Q) = {2\Delta\rho^2 \over Q^2}(1-cos(Q\delta)) 
    1919 
    2020 
    2121where |delta| = bilayer thickness. 
    2222 
    23 The 2D scattering intensity is calculated in the same way as 1D, where the *q* vector is defined as 
     23The 2D scattering intensity is calculated in the same way as 1D, where the $Q$ vector is defined as 
    2424 
    2525.. math:: 
    2626 
    27     q = \sqrt{q_x^2 q_y^2} 
     27    Q = \sqrt{Q_x^2 + Q_y^2} 
    2828 
    2929 
     
    3232(Kline, 2006). 
    3333 
    34 .. figure:: img/image135.jpg 
     34.. figure:: img/lamellar_1d.jpg 
    3535 
    3636    1D plot using the default values (w/1000 data point). 
  • sasmodels/models/sphere.py

    rf4cf580 r19dcb933  
    11r""" 
     2For information about polarised and magnetic scattering, click here_. 
    23 
     4.. _here: polar_mag_help.html 
     5 
     6Definition 
     7---------- 
     8 
     9The 1D scattering intensity is calculated in the following way (Guinier, 1955) 
     10 
     11.. math:: 
     12 
     13    I(Q) = \frac{\text{scale}}{V} \cdot \left[ \ 
     14        3V(\Delta\rho) \cdot \frac{\sin(QR) - QR\cos(QR))}{(QR)^3} \ 
     15        \right]^2 + \text{background} 
     16 
     17where *scale* is a volume fraction, $V$ is the volume of the scatterer, 
     18$R$ is the radius of the sphere, *background* is the background level and 
     19*sld* and *solvent_sld* are the scattering length densities (SLDs) of the 
     20scatterer and the solvent respectively. 
     21 
     22Note that if your data is in absolute scale, the *scale* should represent 
     23the volume fraction (which is unitless) if you have a good fit. If not, 
     24it should represent the volume fraction times a factor (by which your data 
     25might need to be rescaled). 
     26 
     27The 2D scattering intensity is the same as above, regardless of the 
     28orientation of $\vec q$. 
     29 
     30Our model uses the form factor calculations as defined in the IGOR 
     31package provided by the NIST Center for Neutron Research (Kline, 2006). 
     32 
     33Validation 
     34---------- 
     35 
     36Validation of our code was done by comparing the output of the 1D model 
     37to the output of the software provided by the NIST (Kline, 2006). 
     38Figure :num:`figure #sphere-comparison` shows a comparison of the output 
     39of our model and the output of the NIST software. 
     40 
     41.. _sphere-comparison: 
     42 
     43.. figure:: img/sphere_comparison.jpg 
     44 
     45    Comparison of the DANSE scattering intensity for a sphere with the 
     46    output of the NIST SANS analysis software. The parameters were set to: 
     47    *scale* = 1.0, *radius* = 60 |Ang|, *contrast* = 1e-6 |Ang^-2|, and 
     48    *background* = 0.01 |cm^-1|. 
     49 
     50 
     51Reference 
     52--------- 
     53 
     54A Guinier and G. Fournet, *Small-Angle Scattering of X-Rays*, 
     55John Wiley and Sons, New York, (1955) 
     56 
     57*2013/09/09 and 2014/01/06 - Description reviewed by S King and P Parker.* 
    358""" 
    459 
     
    661 
    762name = "sphere" 
    8 title = "Spheres with uniform SLD" 
     63title = "Spheres with uniform scattering length density" 
    964description = """\ 
    10         [Sphere Form Factor] 
     65P(q)=(scale/V)*[3V(sld-solvent_sld)*(sin(qR)-qRcos(qR)) 
     66                /(qR)^3]^2 + background 
     67    R: radius of sphere 
     68    V: The volume of the scatter 
     69    sld: the SLD of the sphere 
     70    solvent_sld: the SLD of the solvent 
    1171""" 
    1272 
  • sasmodels/models/triaxial_ellipsoid.py

    r5d4777d r19dcb933  
    77.. math:: 
    88 
    9     P(q) = \text{scale} V \left< f^2(q) \right> + \text{background} 
     9    P(Q) = \text{scale} V \left< F^2(Q) \right> + \text{background} 
    1010 
    1111where the volume $V = 4/3 \pi R_a R_b R_c$, and the averaging 
    1212$\left< \cdots \right>$ is applied over all orientations for 1D. 
    1313 
    14 .. figure:: img/image128.JPG 
     14.. figure:: img/triaxial_ellipsoid_geometry.jpg 
    1515 
    1616    Ellipsoid schematic. 
     
    2525.. math:: 
    2626 
    27     P(q) = \frac{\text{scale}}{V}\int_0^1\int_0^1 \ 
    28         \Phi^2(qR_a^2\cos^2( \pi x/2) + qR_b^2\sin^2(\pi y/2)(1-y^2) + c^2y^2) \ 
     27    P(Q) = \frac{\text{scale}}{V}\int_0^1\int_0^1 
     28        \Phi^2(QR_a^2\cos^2( \pi x/2) + QR_b^2\sin^2(\pi y/2)(1-y^2) + c^2y^2) 
    2929        dx dy 
    3030 
     
    3838we define the axis of the cylinder using the angles $\theta$, $\phi$ 
    3939and $\psi$. These angles are defined on 
    40 Figure :num:`figure #triaxial-ellipsoid-angles`. 
     40:num:`figure #triaxial-ellipsoid-angles`. 
    4141The angle $\psi$ is the rotational angle around its own $c$ axis 
    42 against the $q$ plane. For example, $\psi = 0$ when the 
     42against the $Q$ plane. For example, $\psi = 0$ when the 
    4343$a$ axis is parallel to the $x$ axis of the detector. 
    4444 
    4545.. _triaxial-ellipsoid-angles: 
    4646 
    47 .. figure:: img/image132.JPG 
     47.. figure:: img/triaxial_ellipsoid_angles.jpg 
    4848 
    4949    The angles for oriented ellipsoid. 
    5050 
    51 The radius-of-gyration for this system is  $Rg^2 = (R_a R_b R_c)^2/5$. 
     51The radius-of-gyration for this system is  $R_g^2 = (R_a R_b R_c)^2/5$. 
    5252 
    5353The contrast is defined as SLD(ellipsoid) - SLD(solvent).  In the 
     
    5858calculated based on the polar radius $R_p = R_c$ and equatorial 
    5959radius $R_e = \sqrt{R_a R_b}$, and used as the effective radius for 
    60 $S(Q)$ when $P(Q) \dot S(Q)$ is applied. 
     60$S(Q)$ when $P(Q) \cdot S(Q)$ is applied. 
    6161 
    62 .. figure:: img/image130.JPG 
     62.. figure:: img/triaxial_ellipsoid_1d.jpg 
    6363 
    6464    1D plot using the default values (w/1000 data point). 
     
    70701D calculation to the angular average of the output of 2D calculation 
    7171over all possible angles. 
    72 Figure :num:`figure #triaxial-ellipsoid-compare` shows the comparison where 
     72:num:`Figure #triaxial-ellipsoid-comparison` shows the comparison where 
    7373the solid dot refers to averaged 2D while the line represents the 
    7474result of 1D calculation (for 2D averaging, 76, 180, and 76 points 
    7575are taken for the angles of $\theta$, $\phi$, and $\psi$ respectively). 
    7676 
    77 .. _triaxial-ellipsoid-compare: 
     77.. _triaxial-ellipsoid-comparison: 
    7878 
    79 .. figure:: img/image131.GIF 
     79.. figure:: img/triaxial_ellipsoid_comparison.png 
    8080 
    8181    Comparison between 1D and averaged 2D. 
Note: See TracChangeset for help on using the changeset viewer.