Changeset 19dcb933 in sasmodels
- Timestamp:
- Sep 3, 2014 3:16:10 AM (10 years ago)
- 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
- Files:
-
- 20 added
- 10 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
README.rst
r5d4777d r19dcb933 1 Sasmodels 2 ========= 3 4 Theory models for small angle scattering. 5 6 The models provided are usable directly in the bumps fitting package and 7 in the sasview analysis package. If OpenCL is available, the models will 8 run much faster. If not, then precompiled versions will be included with 9 the distributed package. New models can be added if OpenCL or a C compiler 10 is available. 11 1 12 cylinder.c + cylinder.py is the cylinder model with renamed variables and 2 13 sld scaled by 1e6 so the numbers are nicer. The model name is "cylinder" … … 10 21 11 22 Note: 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.23 calc_Iq/calc_Iqxy in model interface. Similarly ER/VR go to calc_ER/calc_VR. 13 24 14 25 Note: It is possible to translate python code automatically to opencl, using 15 26 something like numba, clyther, shedskin or pypy, so maybe the kernel functions 16 27 could be implemented without any C syntax. 28 29 Note: angular dispersion in theta is probably not calculated correctly, but 30 is left this way for compatibility with sasview. 17 31 18 32 Magnetism hasn't been implemented yet. We may want a separate Imagnetic … … 23 37 in the same data set. 24 38 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. 39 Need to implement an example kernel directly in python. Polydispersity 40 loops should be generated automatically as they are for the OpenCL models. 41 The kernels should be vectorized across Q. These will need vectorized 42 versions 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 203 203 # Headers for the parameters tables in th sphinx documentation 204 204 PARTABLE_HEADERS = [ 205 "Parameter name", 205 "Parameter", 206 "Description", 206 207 "Units", 207 208 "Default value", … … 395 396 DOC_HEADER=""".. _%(name)s: 396 397 397 %( name)s398 %(label)s 398 399 ======================================================= 399 400 … … 542 543 return kernel 543 544 544 def make_partable( info):545 def make_partable(pars): 545 546 """ 546 547 Generate the parameter table to include in the sphinx documentation. 547 548 """ 548 pars = info['parameters']549 pars = COMMON_PARAMETERS + pars 549 550 column_widths = [ 550 551 max(len(p[0]) for p in pars), 552 max(len(p[-1]) for p in pars), 551 553 max(len(RST_UNITS[p[1]]) for p in pars), 552 554 PARTABLE_VALUE_WIDTH, … … 564 566 lines.append(" ".join([ 565 567 "%-*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]), 568 571 ])) 569 572 lines.append(sep) … … 678 681 Return the documentation for the model. 679 682 """ 680 subst = dict(name=kernel_module.name, 683 subst = dict(name=kernel_module.name.replace('_','-'), 684 label=" ".join(kernel_module.name.split('_')).capitalize(), 681 685 title=kernel_module.title, 682 686 parameters=make_partable(kernel_module.parameters), 683 doc =kernel_module.__doc__)687 docs=kernel_module.__doc__) 684 688 return DOC_HEADER%subst 685 689 -
sasmodels/models/capped_cylinder.py
rf4cf580 r19dcb933 14 14 The capped cylinder geometry is defined as 15 15 16 .. image:: img/ image112.JPG16 .. image:: img/capped_cylinder_geometry.jpg 17 17 18 18 where $r$ is the radius of the cylinder. All other parameters are as defined … … 24 24 h = - \sqrt{R^2 - r^2} 25 25 26 The scattered intensity $I( q)$ is calculated as26 The scattered intensity $I(Q)$ is calculated as 27 27 28 28 .. math:: 29 29 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> 31 31 32 where the amplitude $A( q)$ is given as32 where the amplitude $A(Q)$ is given as 33 33 34 34 .. math:: 35 35 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}} 40 46 41 47 The $\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)$.48 all orientations. $\left< A^2(Q)\right>$ is then the form factor, $P(Q)$. 43 49 The scale factor is equivalent to the volume fraction of cylinders, each of 44 50 volume, $V$. Contrast is the difference of scattering length densities of … … 49 55 .. math:: 50 56 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) 52 58 53 59 54 60 and its radius-of-gyration is 55 61 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} 61 71 62 72 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:: 65 74 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 67 79 a running the 1D capped cylinder model, using *qmin* = 0.001 |Ang^-1|, 68 80 *qmax* = 0.7 |Ang^-1| and the default values of the parameters. … … 70 82 .. _capped-cylinder-1d: 71 83 72 .. figure:: img/ image117.jpg84 .. figure:: img/capped_cylinder_1d.jpg 73 85 74 86 1D plot using the default values (w/256 data point). 75 87 76 88 The 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$ 78 90 and $\phi=0^\circ$ with default values for the other parameters. 79 91 80 92 .. _capped-cylinder-2d: 81 93 82 .. figure:: img/ image118.JPG94 .. figure:: img/capped_cylinder_2d.jpg 83 95 84 96 2D plot (w/(256X265) data points). 85 97 86 .. figure:: img/ image061.JPG98 .. figure:: img/orientation.jpg 87 99 88 100 Definition of the angles for oriented 2D cylinders. 89 101 90 .. figure:: img/ image062.jpg102 .. figure:: img/orientation2.jpg 91 103 92 104 Examples of the angles for oriented pp against the detector plane. -
sasmodels/models/core_shell_cylinder.py
r5d4777d r19dcb933 12 12 .. math:: 13 13 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} 15 15 16 16 where … … 18 18 .. math:: 19 19 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 } 26 30 27 31 and … … 29 33 .. math:: 30 34 31 V_s = \pi (R + T)^2 \dot (L + 2T) 32 35 V_s = \pi (R + T)^2 (L + 2T) 33 36 34 37 and $\alpha$ is the angle between the axis of the cylinder and $\vec q$, … … 42 45 shell is given by $L+2T$. $J1$ is the first order Bessel function. 43 46 44 .. figure:: img/image069.JPG 47 .. _core-shell-cylinder-geometry: 48 49 .. figure:: img/core_shell_cylinder_geometry.jpg 45 50 46 51 Core shell cylinder schematic. … … 49 54 define the axis of the cylinder using two angles $\theta$ and $\phi$. As 50 55 for the case of the cylinder, those angles are defined in 51 Figure:num:`figure #cylinder-orientation`.56 :num:`figure #cylinder-orientation`. 52 57 53 58 NB: The 2nd virial coefficient of the cylinder is calculated based on 54 59 the 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. 56 61 57 62 The $\theta$ and $\phi$ parameters are not used for the 1D output. Our … … 64 69 Validation of our code was done by comparing the output of the 1D model to 65 70 the output of the software provided by the NIST (Kline, 2006). 66 Figure :num:`figure #core-shell-cylinder-comparison-1d` shows a comparison71 :num:`Figure #core-shell-cylinder-1d` shows a comparison 67 72 of the 1D output of our model and the output of the NIST software. 68 73 69 .. _core-shell-cylinder- comparison-1d:74 .. _core-shell-cylinder-1d: 70 75 71 .. figure:: img/ image070.JPG76 .. figure:: img/core_shell_cylinder_1d.jpg 72 77 73 78 Comparison of the SasView scattering intensity for a core-shell cylinder 74 79 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|. 78 83 79 84 Averaging over a distribution of orientation is done by evaluating the … … 81 86 implementation of the intensity for fully oriented cylinders, we can 82 87 compare 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 result88 distribution $p(\theta,\phi) = 1.0$. 89 :num:`Figure #core-shell-cylinder-2d` shows the result 85 90 of such a cross-check. 86 91 87 .. _core-shell-cylinder- comparison-2d:92 .. _core-shell-cylinder-2d: 88 93 89 .. figure:: img/ image071.JPG94 .. figure:: img/core_shell_cylinder_2d.jpg 90 95 91 96 Comparison of the intensity for uniformly distributed core-shell 92 97 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|. 97 102 98 103 2013/11/26 - Description reviewed by Heenan, R. … … 101 106 from numpy import pi, inf 102 107 103 name = "c ylinder"108 name = "core_shell_cylinder" 104 109 title = "Right circular cylinder with a core-shell scattering length density profile." 105 110 description = """ -
sasmodels/models/cylinder.py
r5d4777d r19dcb933 14 14 .. math:: 15 15 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} 17 17 18 18 where … … 20 20 .. math:: 21 21 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} 25 26 26 27 and $\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 the28 radius of the cylinder, and $ d\rho$ (contrast) is the scattering length density29 d ifference between the scatterer and the solvent. $J_1$ is the first order30 Bessel function.28 is the volume of the cylinder, $L$ is the length of the cylinder, $R$ is the 29 radius of the cylinder, and $\Delta\rho$ (contrast) is the scattering length 30 density difference between the scatterer and the solvent. $J_1$ is the 31 first order Bessel function. 31 32 32 33 To provide easy access to the orientation of the cylinder, we define the 33 34 axis of the cylinder using two angles $\theta$ and $\phi$. Those angles 34 are defined in Figure:num:`figure #cylinder-orientation`.35 are defined in :num:`figure #cylinder-orientation`. 35 36 36 37 .. _cylinder-orientation: 37 38 38 .. figure:: img/ image061.JPG (should be img/cylinder-1.jpg, or img/cylinder-orientation.jpg)39 .. figure:: img/orientation.jpg 39 40 40 41 Definition of the angles for oriented cylinders. 41 42 42 .. figure:: img/ image062.JPG43 .. figure:: img/orientation2.jpg 43 44 44 45 Examples of the angles for oriented pp against the detector plane. … … 53 54 .. math:: 54 55 55 P( q) = \frac{\text{scale}}{V}56 \int_0^{\pi/2} f^2(q,\alpha) \sin \alphad\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} 57 58 58 59 The *theta* and *phi* parameters are not used for the 1D output. Our … … 65 66 Validation of our code was done by comparing the output of the 1D model 66 67 to the output of the software provided by the NIST (Kline, 2006). 67 Figure :num:`figure #cylinder-compare` shows a comparison of68 :num:`Figure #cylinder-compare` shows a comparison of 68 69 the 1D output of our model and the output of the NIST software. 69 70 70 71 .. _cylinder-compare: 71 72 72 .. figure:: img/ image065.JPG73 .. figure:: img/cylinder_compare.jpg 73 74 74 75 Comparison of the SasView scattering intensity for a cylinder with the 75 76 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|, and78 * 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|. 79 80 80 81 In general, averaging over a distribution of orientations is done by … … 83 84 .. math:: 84 85 85 P( q) = \int_0^{\pi/2} d\phi86 \int_0^\pi p(\theta, \phi) P_0( q,\alpha) \sin \thetad\theta86 P(Q) = \int_0^{\pi/2} d\phi 87 \int_0^\pi p(\theta, \phi) P_0(Q,\alpha) \sin \theta\ d\theta 87 88 88 89 89 90 where $p(\theta,\phi)$ is the probability distribution for the orientation 90 and $P_0( q,\alpha)$ is the scattering intensity for the fully oriented91 and $P_0(Q,\alpha)$ is the scattering intensity for the fully oriented 91 92 system. Since we have no other software to compare the implementation of 92 93 the intensity for fully oriented cylinders, we can compare the result of 93 94 averaging our 2D output using a uniform distribution $p(\theta, \phi) = 1.0$. 94 Figure :num:`figure #cylinder-crosscheck` shows the result of95 :num:`Figure #cylinder-crosscheck` shows the result of 95 96 such a cross-check. 96 97 97 98 .. _cylinder-crosscheck: 98 99 99 .. figure:: img/ image066.JPG100 .. figure:: img/cylinder_crosscheck.jpg 100 101 101 102 Comparison of the intensity for uniformly distributed cylinders 102 103 calculated from our 2D model and the intensity from the NIST SANS 103 104 analysis software. 104 The parameters used were: * Scale* = 1.0, *Radius* = 20 |Ang|,105 * Length* = 400 |Ang|, *Contrast* = 3e-6 |Ang^-2|, and106 * 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|. 107 108 """ 108 109 -
sasmodels/models/cylinder_clone.py
r5d4777d r19dcb933 1 r"""2 CylinderModel3 =============4 5 This model provides the form factor for a right circular cylinder with uniform6 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 Definition11 ----------12 13 The output of the 2D scattering intensity function for oriented cylinders is14 given by (Guinier, 1955)15 16 .. math::17 18 P(q,\alpha) = \frac{\text{scale}}{V}f^2(q) + \text{bkg}19 20 where21 22 .. math::23 24 f(q) = 2 (\Delta \rho) V25 \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 the30 radius of the cylinder, and $d\rho$ (contrast) is the scattering length density31 difference between the scatterer and the solvent. $J_1$ is the first order32 Bessel function.33 34 To provide easy access to the orientation of the cylinder, we define the35 axis of the cylinder using two angles $\theta$ and $\phi$. Those angles36 are defined in Figure :num:`figure #CylinderModel-orientation`.37 38 .. _CylinderModel-orientation:39 40 .. figure:: img/image061.JPG41 42 Definition of the angles for oriented cylinders.43 44 .. figure:: img/image062.JPG45 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 the49 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 of53 the CylinderModel are the following:54 55 %(parameters)s56 57 The output of the 1D scattering intensity function for randomly oriented58 cylinders is then given by59 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. Our66 implementation of the scattering kernel and the 1D scattering intensity67 use the c-library from NIST.68 69 Validation of the CylinderModel70 -------------------------------71 72 Validation of our code was done by comparing the output of the 1D model73 to the output of the software provided by the NIST (Kline, 2006).74 Figure :num:`figure #CylinderModel-compare` shows a comparison of75 the 1D output of our model and the output of the NIST software.76 77 .. _CylinderModel-compare:78 79 .. figure:: img/image065.JPG80 81 Comparison of the SasView scattering intensity for a cylinder with the82 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|, and85 *Background* = 0.01 |cm^-1|.86 87 In general, averaging over a distribution of orientations is done by88 evaluating the following89 90 .. math::91 92 P(q) = \int_0^{\pi/2} d\phi93 \int_0^\pi p(\theta, \phi) P_0(q,\alpha) \sin \theta d\theta94 95 96 where $p(\theta,\phi)$ is the probability distribution for the orientation97 and $P_0(q,\alpha)$ is the scattering intensity for the fully oriented98 system. Since we have no other software to compare the implementation of99 the intensity for fully oriented cylinders, we can compare the result of100 averaging our 2D output using a uniform distribution $p(\theta, \phi) = 1.0$.101 Figure :num:`figure #CylinderModel-crosscheck` shows the result of102 such a cross-check.103 104 .. _CylinderModel-crosscheck:105 106 .. figure:: img/image066.JPG107 108 Comparison of the intensity for uniformly distributed cylinders109 calculated from our 2D model and the intensity from the NIST SANS110 analysis software.111 The parameters used were: *Scale* = 1.0, *Radius* = 20 |Ang|,112 *Length* = 400 |Ang|, *Contrast* = 3e-6 |Ang^-2|, and113 *Background* = 0.0 |cm^-1|.114 """115 1 116 2 from numpy import pi, inf -
sasmodels/models/ellipsoid.py
r5d4777d r19dcb933 12 12 .. math:: 13 13 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} 15 15 16 16 where … … 18 18 .. math:: 19 19 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 } 22 23 23 24 and … … 25 26 .. math:: 26 27 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} 28 30 29 31 … … 36 38 To provide easy access to the orientation of the ellipsoid, we define 37 39 the rotation axis of the ellipsoid using two angles $\theta$ and $\phi$. 38 These angles are defined in Figure :num:`figure #cylinder-orientation`. 40 These angles are defined in the 41 :ref:`cylinder orientation figure <cylinder-orientation>`. 39 42 For the ellipsoid, $\theta$ is the angle between the rotational axis 40 43 and the $z$-axis. … … 42 45 NB: The 2nd virial coefficient of the solid ellipsoid is calculated based 43 46 on 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. 45 48 46 .. figure:: img/image121.JPG 49 .. _ellipsoid-1d: 50 51 .. figure:: img/ellipsoid_1d.JPG 47 52 48 53 The output of the 1D scattering intensity function for randomly oriented … … 54 59 use the c-library from NIST. 55 60 56 .. figure:: img/image122.JPG 61 .. _ellipsoid-geometry: 62 63 .. figure:: img/ellipsoid_geometry.JPG 57 64 58 65 The angles for oriented ellipsoid. … … 63 70 Validation of our code was done by comparing the output of the 1D model 64 71 to the output of the software provided by the NIST (Kline, 2006). 65 Figure :num:`figure ellipsoid-comparison-1d` below shows a comparison of72 :num:`Figure ellipsoid-comparison-1d` below shows a comparison of 66 73 the 1D output of our model and the output of the NIST software. 67 74 68 75 .. _ellipsoid-comparison-1d: 69 76 70 .. figure:: img/ image123.JPG77 .. figure:: img/ellipsoid_comparison_1d.jpg 71 78 72 79 Comparison of the SasView scattering intensity for an ellipsoid 73 80 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|. 76 84 77 85 Averaging over a distribution of orientation is done by evaluating the … … 79 87 implementation of the intensity for fully oriented ellipsoids, we can 80 88 compare 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` 82 90 shows the result of such a cross-check. 83 91 84 92 .. _ellipsoid-comparison-2d: 85 93 86 .. figure:: img/ image124.jpg94 .. figure:: img/ellipsoid_comparison_2d.jpg 87 95 88 96 Comparison of the intensity for uniformly distributed ellipsoids 89 97 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|. 93 101 94 The discrepancy above *q =0.3 |cm^-1|*is due to the way the form factors102 The discrepancy above *q* = 0.3 |cm^-1| is due to the way the form factors 95 103 are calculated in the c-library provided by NIST. A numerical integration 96 has to be performed to obtain *P(q)*for randomly oriented particles.104 has to be performed to obtain $P(Q)$ for randomly oriented particles. 97 105 The NIST software performs that integration with a 76-point Gaussian 98 quadrature rule, which will become imprecise at high qwhere the amplitude99 varies quickly as a function of $ q$. The SasView result shown has been106 quadrature rule, which will become imprecise at high $Q$ where the amplitude 107 varies quickly as a function of $Q$. The SasView result shown has been 100 108 obtained 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 higher109 to be stable over the range of $Q$ shown for a number of points higher 102 110 than 500. 103 111 -
sasmodels/models/lamellar.py
r5d4777d r19dcb933 5 5 ---------- 6 6 7 The scattering intensity *I( q)* is7 The scattering intensity *I(Q)* is 8 8 9 9 .. math:: 10 10 11 I( q) = 2\pi\frac{P(q){\delta q^2}11 I(Q) = 2\pi{P(Q) \over \delta Q^2} 12 12 13 13 … … 16 16 .. math:: 17 17 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)) 19 19 20 20 21 21 where |delta| = bilayer thickness. 22 22 23 The 2D scattering intensity is calculated in the same way as 1D, where the *q*vector is defined as23 The 2D scattering intensity is calculated in the same way as 1D, where the $Q$ vector is defined as 24 24 25 25 .. math:: 26 26 27 q = \sqrt{q_x^2 q_y^2}27 Q = \sqrt{Q_x^2 + Q_y^2} 28 28 29 29 … … 32 32 (Kline, 2006). 33 33 34 .. figure:: img/ image135.jpg34 .. figure:: img/lamellar_1d.jpg 35 35 36 36 1D plot using the default values (w/1000 data point). -
sasmodels/models/sphere.py
rf4cf580 r19dcb933 1 1 r""" 2 For information about polarised and magnetic scattering, click here_. 2 3 4 .. _here: polar_mag_help.html 5 6 Definition 7 ---------- 8 9 The 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 17 where *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 20 scatterer and the solvent respectively. 21 22 Note that if your data is in absolute scale, the *scale* should represent 23 the volume fraction (which is unitless) if you have a good fit. If not, 24 it should represent the volume fraction times a factor (by which your data 25 might need to be rescaled). 26 27 The 2D scattering intensity is the same as above, regardless of the 28 orientation of $\vec q$. 29 30 Our model uses the form factor calculations as defined in the IGOR 31 package provided by the NIST Center for Neutron Research (Kline, 2006). 32 33 Validation 34 ---------- 35 36 Validation of our code was done by comparing the output of the 1D model 37 to the output of the software provided by the NIST (Kline, 2006). 38 Figure :num:`figure #sphere-comparison` shows a comparison of the output 39 of 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 51 Reference 52 --------- 53 54 A Guinier and G. Fournet, *Small-Angle Scattering of X-Rays*, 55 John Wiley and Sons, New York, (1955) 56 57 *2013/09/09 and 2014/01/06 - Description reviewed by S King and P Parker.* 3 58 """ 4 59 … … 6 61 7 62 name = "sphere" 8 title = "Spheres with uniform SLD"63 title = "Spheres with uniform scattering length density" 9 64 description = """\ 10 [Sphere Form Factor] 65 P(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 11 71 """ 12 72 -
sasmodels/models/triaxial_ellipsoid.py
r5d4777d r19dcb933 7 7 .. math:: 8 8 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} 10 10 11 11 where the volume $V = 4/3 \pi R_a R_b R_c$, and the averaging 12 12 $\left< \cdots \right>$ is applied over all orientations for 1D. 13 13 14 .. figure:: img/ image128.JPG14 .. figure:: img/triaxial_ellipsoid_geometry.jpg 15 15 16 16 Ellipsoid schematic. … … 25 25 .. math:: 26 26 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) 29 29 dx dy 30 30 … … 38 38 we define the axis of the cylinder using the angles $\theta$, $\phi$ 39 39 and $\psi$. These angles are defined on 40 Figure:num:`figure #triaxial-ellipsoid-angles`.40 :num:`figure #triaxial-ellipsoid-angles`. 41 41 The angle $\psi$ is the rotational angle around its own $c$ axis 42 against the $ q$ plane. For example, $\psi = 0$ when the42 against the $Q$ plane. For example, $\psi = 0$ when the 43 43 $a$ axis is parallel to the $x$ axis of the detector. 44 44 45 45 .. _triaxial-ellipsoid-angles: 46 46 47 .. figure:: img/ image132.JPG47 .. figure:: img/triaxial_ellipsoid_angles.jpg 48 48 49 49 The angles for oriented ellipsoid. 50 50 51 The radius-of-gyration for this system is $R g^2 = (R_a R_b R_c)^2/5$.51 The radius-of-gyration for this system is $R_g^2 = (R_a R_b R_c)^2/5$. 52 52 53 53 The contrast is defined as SLD(ellipsoid) - SLD(solvent). In the … … 58 58 calculated based on the polar radius $R_p = R_c$ and equatorial 59 59 radius $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. 61 61 62 .. figure:: img/ image130.JPG62 .. figure:: img/triaxial_ellipsoid_1d.jpg 63 63 64 64 1D plot using the default values (w/1000 data point). … … 70 70 1D calculation to the angular average of the output of 2D calculation 71 71 over all possible angles. 72 Figure :num:`figure #triaxial-ellipsoid-compare` shows the comparison where72 :num:`Figure #triaxial-ellipsoid-comparison` shows the comparison where 73 73 the solid dot refers to averaged 2D while the line represents the 74 74 result of 1D calculation (for 2D averaging, 76, 180, and 76 points 75 75 are taken for the angles of $\theta$, $\phi$, and $\psi$ respectively). 76 76 77 .. _triaxial-ellipsoid-compar e:77 .. _triaxial-ellipsoid-comparison: 78 78 79 .. figure:: img/ image131.GIF79 .. figure:: img/triaxial_ellipsoid_comparison.png 80 80 81 81 Comparison between 1D and averaged 2D.
Note: See TracChangeset
for help on using the changeset viewer.