Changeset 40a87fa in sasmodels for sasmodels/models
- Timestamp:
- Aug 8, 2016 11:24:11 AM (8 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:
- 2472141
- Parents:
- 2d65d51
- Location:
- sasmodels/models
- Files:
-
- 1 deleted
- 45 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/models/adsorbed_layer.py
r2c74c11 r40a87fa 93 93 inten = 6.0e-02 * pi * volfraction * aa**2 * exp(-bb**2) / radius 94 94 return inten 95 Iq.vectorized = 95 Iq.vectorized = True # Iq accepts an array of q values 96 96 97 97 # unit test values taken from SasView 3.1.2 98 tests = 98 tests = [ 99 99 [{'scale': 1.0, 'second_moment': 23.0, 'adsorbed_amount': 1.9, 100 100 'density_shell': 0.7, 'radius': 500.0, 'volfraction': 0.14, -
sasmodels/models/broad_peak.py
r2c74c11 r40a87fa 15 15 The scattering intensity $I(q)$ is calculated as 16 16 17 .. math:: 18 19 I(q) = \frac{A}{q^n} + \frac{C}{1 + (|q - q_0|\xi)^m} + B 17 .. math:: I(q) = \frac{A}{q^n} + \frac{C}{1 + (|q - q_0|\xi)^m} + B 20 18 21 19 Here the peak position is related to the d-spacing as $q_o = 2\pi / d_o$. 22 20 23 $A$ is the Porod law scale factor, $n$ the Porod exponent, $C$ is the Lorentzian 24 scale factor, $m$ the exponent of q, \ |xi|\ the screening length, and $B$ the flat background. 21 $A$ is the Porod law scale factor, $n$ the Porod exponent, $C$ is the 22 Lorentzian scale factor, $m$ the exponent of $q$, $\xi$ the screening length, 23 and $B$ the flat background. 25 24 26 25 For 2D data the scattering intensity is calculated in the same way as 1D, 27 26 where the $q$ vector is defined as 28 27 29 .. math:: 30 31 q = \sqrt{q_x^2 + q_y^2} 32 28 .. math:: q = \sqrt{q_x^2 + q_y^2} 33 29 34 30 References … … 38 34 39 35 *2013/09/09 - Description reviewed by King, S and Parker, P.* 40 41 36 """ 42 37 -
sasmodels/models/core_multi_shell.py
re187b25 r40a87fa 4 4 5 5 This model is a trivial extension of the CoreShell function to a larger number 6 of shells. The scattering length density profile for the default sld values 6 of shells. The scattering length density profile for the default sld values 7 7 (w/ 4 shells). 8 8 … … 25 25 effective radius for $S(Q)$ when $P(Q)*S(Q)$ is applied. 26 26 27 For information about polarised and magnetic scattering, see 27 For information about polarised and magnetic scattering, see 28 28 the :doc:`magnetic help <../sasgui/perspectives/fitting/mag_help>` documentation. 29 29 … … 33 33 References 34 34 ---------- 35 See the :ref:`core _shell_sphere <core_shell_sphere>` model documentation.35 See the :ref:`core-shell-sphere` model documentation. 36 36 37 37 L A Feigin and D I Svergun, … … 51 51 52 52 import numpy as np 53 from numpy import inf, nan 54 from math import fabs, exp, expm1 53 from numpy import inf 55 54 56 55 name = "core_multi_shell" … … 99 98 ["thickness[n]", "Ang", 40., [0, inf], "volume", 100 99 "Thickness of shell k"], 101 100 ] 102 101 103 102 source = ["lib/sph_j1c.c", "core_multi_shell.c"] … … 107 106 Returns the SLD profile *r* (Ang), and *rho* (1e-6/Ang^2). 108 107 """ 109 r= []108 z = [] 110 109 rho = [] 111 110 112 111 # add in the core 113 r.append(0)112 z.append(0) 114 113 rho.append(sld_core) 115 r.append(radius)114 z.append(radius) 116 115 rho.append(sld_core) 117 116 … … 119 118 for k in range(n): 120 119 # Left side of each shells 121 r.append(r[-1])120 z.append(z[-1]) 122 121 rho.append(sld[k]) 123 r.append(r[-1] + thickness[k])122 z.append(z[-1] + thickness[k]) 124 123 rho.append(sld[k]) 125 124 # add in the solvent 126 r.append(r[-1])125 z.append(z[-1]) 127 126 rho.append(sld_solvent) 128 r.append(r[-1]*1.25)127 z.append(z[-1]*1.25) 129 128 rho.append(sld_solvent) 130 129 131 return np.asarray( r), np.asarray(rho)130 return np.asarray(z), np.asarray(rho) 132 131 133 132 def ER(radius, n, thickness): 133 """Effective radius""" 134 134 n = n[0] # n cannot be polydisperse 135 135 return np.sum(thickness[:n], axis=0) + radius 136 136 137 def VR(radius, n, thickness): 138 return 1.0, 1.0 139 140 demo = dict(sld_core = 6.4, 141 radius = 60, 142 sld_solvent = 6.4, 143 n = 2, 144 sld = [2.0, 3.0], 145 thickness = 20, 146 thickness1_pd = 0.3, 147 thickness2_pd = 0.3, 148 thickness1_pd_n = 10, 149 thickness2_pd_n = 10, 137 demo = dict(sld_core=6.4, 138 radius=60, 139 sld_solvent=6.4, 140 n=2, 141 sld=[2.0, 3.0], 142 thickness=20, 143 thickness1_pd=0.3, 144 thickness2_pd=0.3, 145 thickness1_pd_n=10, 146 thickness2_pd_n=10, 150 147 ) -
sasmodels/models/core_shell_bicelle.py
r42356c8 r40a87fa 3 3 Definition 4 4 ---------- 5 This model provides the form factor for a circular cylinder with a core-shell 6 scattering length density profile. Thus this is a variation of a core-shell cylinder 7 or disc where the shell on the walls and ends may be of different thicknesses and scattering 8 length densities. The form factor is normalized by the particle volume. 5 This model provides the form factor for a circular cylinder with a 6 core-shell scattering length density profile. Thus this is a variation 7 of a core-shell cylinder or disc where the shell on the walls and ends 8 may be of different thicknesses and scattering length densities. The form 9 factor is normalized by the particle volume. 9 10 10 11 .. _core-shell-bicelle-geometry: … … 12 13 .. figure:: img/core_shell_bicelle_geometry.png 13 14 14 (Graphic from DOI: 10.1039/C0NP00002G, note however that the model here calculates for rectangular, not curved, rims.)15 15 (Graphic from DOI: 10.1039/C0NP00002G, note however that the model here 16 calculates for rectangular, not curved, rims.) 16 17 17 18 The output of the 1D scattering intensity function for randomly oriented … … 88 89 # pylint: enable=bad-whitespace, line-too-long 89 90 90 source = ["lib/Si.c","lib/polevl.c", "lib/sas_J1.c", "lib/gauss76.c", "core_shell_bicelle.c"] 91 source = ["lib/Si.c", "lib/polevl.c", "lib/sas_J1.c", "lib/gauss76.c", 92 "core_shell_bicelle.c"] 91 93 92 94 demo = dict(scale=1, background=0, -
sasmodels/models/core_shell_cylinder.py
r42356c8 r40a87fa 52 52 53 53 To provide easy access to the orientation of the core-shell cylinder, we 54 define the axis of the cylinder using two angles $\theta$ and $\phi$. 54 define the axis of the cylinder using two angles $\theta$ and $\phi$. 55 55 (see :ref:`cylinder model <cylinder-angle-definition>`) 56 56 … … 130 130 ] 131 131 132 source = ["lib/polevl.c", "lib/sas_J1.c", "lib/gauss76.c", "core_shell_cylinder.c"]132 source = ["lib/polevl.c", "lib/sas_J1.c", "lib/gauss76.c", "core_shell_cylinder.c"] 133 133 134 134 def ER(radius, thickness, length): 135 135 """ 136 136 Returns the effective radius used in the S*P calculation 137 137 """ 138 138 radius = radius + thickness … … 143 143 def VR(radius, thickness, length): 144 144 """ 145 145 Returns volume ratio 146 146 """ 147 147 whole = pi * (radius + thickness) ** 2 * (length + 2 * thickness) -
sasmodels/models/core_shell_ellipsoid.py
r7f1ee79 r40a87fa 5 5 .. math:: 6 6 7 P(q) = scale * \left<f^2\right>/V + background7 P(q) = \text{scale} * \left<f^2\right>/V + \text{background} 8 8 9 where the volume $V = (4/3)\pi( R_{major\_outer}R_{minor\_outer}^2)$ and the averaging $< >$ is10 a pplied over all orientations for 1D.9 where the volume $V = (4/3)\pi(r_\text{major outer} r_\text{minor outer}^2)$ 10 and the averaging $< >$ is applied over all orientations for 1D. 11 11 12 12 .. figure:: img/core_shell_ellipsoid_geometry.png 13 13 14 The returned value is in units of $cm^{-1}$, on absolute scale.14 The returned value is in units of |cm^-1|, on absolute scale. 15 15 16 16 Definition … … 21 21 .. math:: 22 22 23 P(q) = \frac{scale}{V}\int_0^1 24 \left|F(q,r_{minor\_core},r_{major\_core},\alpha) + F(q,r_{major\_outer},r_{major\_outer},\alpha)\right|^2d\alpha + background 23 P(q) &= \frac{\text{scale}}{V}\int_0^1 24 \left|F(q,r_\text{minor core},r_\text{major core},\alpha) 25 + F(q,r_\text{minor outer},r_\text{major outer},\alpha)\right|^2 26 d\alpha 27 + \text{background} 25 28 26 \left|F(q,r_{minor},r_{major},\alpha)\right|=(4\pi/3)r_{major}r_{minor}^2 \Delta \rho \cdot (3j_1(u)/u) 29 \left|F(q,r_\text{minor},r_\text{major},\alpha)\right| 30 &=(4\pi/3)r_\text{major}r_\text{minor}^2 \Delta \rho \cdot (3j_1(u)/u) 27 31 28 u = q\left[ r_{major}^2\alpha ^2 + r_{minor}^2(1-\alpha ^2)\right]^{1/2} 32 u &= q\left[ r_\text{major}^2\alpha ^2 33 + r_\text{minor}^2(1-\alpha ^2)\right]^{1/2} 29 34 30 35 where … … 40 45 The contrast is defined as SLD(core) - SLD(shell) and SLD(shell) - SLD(solvent). 41 46 42 In the parameters, *equat_core* = equatorial core radius, *polar_core* = 43 polar core radius, *equat_shell* = $r_{min}$ (or equatorial outer radius), 44 and *polar_shell* = $r_{maj}$ (or polar outer radius). 45 46 Note:It is the users' responsibility to ensure that shell radii are larger than 47 Note: It is the users' responsibility to ensure that shell radii are larger than 47 48 the core radii, especially if both are polydisperse, in which case the 48 49 core_shell_ellipsoid_xt model may be much better. … … 67 68 68 69 S J Berr, *Phys. Chem.*, 91 (1987) 4760 69 70 70 """ 71 71 … … 100 100 101 101 # pylint: disable=bad-whitespace, line-too-long 102 # 102 # ["name", "units", default, [lower, upper], "type", "description"], 103 103 parameters = [ 104 ["equat_core", "Ang", 200, [0, inf], "volume", "Equatorial radius of core, Rminor_core"],105 ["polar_core", "Ang", 10, [0, inf], "volume", "Polar radius of core, Rmajor_core"],106 ["equat_shell", "Ang", 250, [0, inf], "volume", "Equatorial radius of shell, Rminor_outer"],107 ["polar_shell", "Ang", 30, [0, inf], "volume", "Polar radius of shell, Rmajor_outer"],108 ["sld_core", "1e-6/Ang^2", 2, [-inf, inf], "sld", 109 ["sld_shell", "1e-6/Ang^2", 1, [-inf, inf], "sld", 110 ["sld_solvent", "1e-6/Ang^2", 6.3, [-inf, inf], "sld", 104 ["equat_core", "Ang", 200, [0, inf], "volume", "Equatorial radius of core, r minor core"], 105 ["polar_core", "Ang", 10, [0, inf], "volume", "Polar radius of core, r major core"], 106 ["equat_shell", "Ang", 250, [0, inf], "volume", "Equatorial radius of shell, r minor outer"], 107 ["polar_shell", "Ang", 30, [0, inf], "volume", "Polar radius of shell, r major outer"], 108 ["sld_core", "1e-6/Ang^2", 2, [-inf, inf], "sld", "Core scattering length density"], 109 ["sld_shell", "1e-6/Ang^2", 1, [-inf, inf], "sld", "Shell scattering length density"], 110 ["sld_solvent", "1e-6/Ang^2", 6.3, [-inf, inf], "sld", "Solvent scattering length density"], 111 111 ["theta", "degrees", 0, [-inf, inf], "orientation", "Oblate orientation wrt incoming beam"], 112 112 ["phi", "degrees", 0, [-inf, inf], "orientation", "Oblate orientation in the plane of the detector"], … … 120 120 Returns the effective radius used in the S*P calculation 121 121 """ 122 import numpy as np123 122 from .ellipsoid import ER as ellipsoid_ER 124 123 return ellipsoid_ER(polar_shell, equat_shell) -
sasmodels/models/core_shell_ellipsoid_xt.py
r42356c8 r40a87fa 1 1 r""" 2 2 An alternative version of $P(q)$ for the core_shell_ellipsoid 3 having as parameters the core axial ratio X and a shell thickness, 3 having as parameters the core axial ratio X and a shell thickness, 4 4 which are more often what we would like to determine. 5 5 -
sasmodels/models/core_shell_sphere.py
r42356c8 r40a87fa 2 2 .. _core_shell_sphere: 3 3 4 This model provides the form factor, $P(q)$, for a spherical particle with a core-shell structure.5 The form factor is normalized by the particle volume.4 This model provides the form factor, $P(q)$, for a spherical particle with 5 a core-shell structure. The form factor is normalized by the particle volume. 6 6 7 7 Definition … … 18 18 .. math:: 19 19 20 F^2(q)=\frac{3}{V_s}\left[V_c(\rho_c-\rho_s)\frac{\sin(qr_c)-qr_c\cos(qr_c)}{(qr_c)^3}+ 21 V_s(\rho_s-\rho_{solv})\frac{\sin(qr_s)-qr_s\cos(qr_s)}{(qr_s)^3}\right] 20 F^2(q) = \frac{3}{V_s}\left[ 21 V_c(\rho_c-\rho_s)\frac{\sin(qr_c)-qr_c\cos(qr_c)}{(qr_c)^3} + 22 V_s(\rho_s-\rho_\text{solv})\frac{\sin(qr_s)-qr_s\cos(qr_s)}{(qr_s)^3} 23 \right] 22 24 23 where $V_s$ is the volume of the whole particle, $V_c$ is 24 the volume of the core, $r_s$ = $radius$ + $thickness$ is the radius of the particle, $r_c$ is the radius of the 25 core, $\rho_c$ is the scattering length density of the core, $\rho_s$ is the scattering length 26 density of the shell, $\rho_{solv}$ is the scattering length density of the solvent. 25 where $V_s$ is the volume of the whole particle, $V_c$ is the volume of the 26 core, $r_s$ = $radius$ + $thickness$ is the radius of the particle, $r_c$ 27 is the radius of the core, $\rho_c$ is the scattering length density of the 28 core, $\rho_s$ is the scattering length density of the shell, 29 $\rho_\text{solv}$, is the scattering length density of the solvent. 27 30 28 31 The 2D scattering intensity is the same as $P(q)$ above, regardless of the … … 35 38 ---------- 36 39 37 A Guinier and G Fournet, *Small-Angle Scattering of X-Rays*, John Wiley and Sons, New York, (1955) 40 A Guinier and G Fournet, *Small-Angle Scattering of X-Rays*, 41 John Wiley and Sons, New York, (1955) 38 42 39 43 Validation 40 44 ---------- 41 45 42 Validation of our code was done by comparing the output of the 1D model to the output of 43 the software provided by NIST (Kline, 2006). Figure 1 shows a comparison of the output of 44 our model and the output of the NIST software. 45 46 Validation of our code was done by comparing the output of the 1D model to 47 the output of the software provided by NIST (Kline, 2006). Figure 1 shows a 48 comparison of the output of our model and the output of the NIST software. 46 49 """ 47 50 … … 88 91 @param thickness: shell thickness 89 92 """ 90 return (1, 1)93 return (1, 1) 91 94 whole = 4.0 * pi / 3.0 * pow((radius + thickness), 3) 92 95 core = 4.0 * pi / 3.0 * radius * radius * radius 93 96 return whole, whole - core 94 97 95 tests = [[{'radius': 20.0, 'thickness': 10.0}, 'ER', 30.0], 96 # TODO: VR test suppressed until we sort out new product model 97 # and determine what to do with volume ratio. 98 #[{'radius': 20.0, 'thickness': 10.0}, 'VR', 0.703703704], 98 tests = [ 99 [{'radius': 20.0, 'thickness': 10.0}, 'ER', 30.0], 100 # TODO: VR test suppressed until we sort out new product model 101 # and determine what to do with volume ratio. 102 #[{'radius': 20.0, 'thickness': 10.0}, 'VR', 0.703703704], 99 103 100 # The SasView test result was 0.00169, with a background of 0.001 101 [{'radius': 60.0, 102 'thickness': 10.0, 103 'sld_core': 1.0, 104 'sld_shell':2.0, 105 'sld_solvent':3.0, 106 'background':0.0 107 }, 0.4, 0.000698838]] 104 # The SasView test result was 0.00169, with a background of 0.001 105 [{'radius': 60.0, 'thickness': 10.0, 'sld_core': 1.0, 'sld_shell':2.0, 106 'sld_solvent':3.0, 'background':0.0}, 107 0.4, 0.000698838], 108 ] -
sasmodels/models/correlation_length.py
r2c74c11 r40a87fa 8 8 9 9 .. math:: 10 I(Q) = \frac{A}{Q^n} + \frac{C}{1 + (Q\xi)^m} + B10 I(Q) = \frac{A}{Q^n} + \frac{C}{1 + (Q\xi)^m} + \text{background} 11 11 12 The first term describes Porod scattering from clusters (exponent = n) and the 13 second term is a Lorentzian function describing scattering from polymer chains 14 (exponent = m). This second term characterizes the polymer/solvent interactions 15 and therefore the thermodynamics. The two multiplicative factors A and C, the 16 incoherent background B and the two exponents n and m are used as fitting 17 parameters. (Respectively $porod\_scale$, $lorentz\_scale$, $background$, $exponent\_p$ and 18 $exponent\_l$ in the parameter list.) The remaining parameter \ |xi|\ is a correlation 19 length for the polymer chains. Note that when m=2 this functional form becomes the 20 familiar Lorentzian function. Some interpretation of the values of A and C may be 21 possible depending on the values of m and n. 12 The first term describes Porod scattering from clusters (exponent = $n$) and 13 the second term is a Lorentzian function describing scattering from 14 polymer chains (exponent = $m$). This second term characterizes the 15 polymer/solvent interactions and therefore the thermodynamics. The two 16 multiplicative factors $A$ and $C$, and the two exponents $n$ and $m$ are 17 used as fitting parameters. (Respectively *porod_scale*, *lorentz_scale*, 18 *exponent_p* and *exponent_l* in the parameter list.) The remaining 19 parameter $\xi$ (*cor_length* in the parameter list) is a correlation 20 length for the polymer chains. Note that when $m=2$ this functional form 21 becomes the familiar Lorentzian function. Some interpretation of the 22 values of $A$ and $C$ may be possible depending on the values of $m$ and $n$. 22 23 23 24 For 2D data: The 2D scattering intensity is calculated in the same way as 1D, 24 25 where the q vector is defined as 25 26 26 .. math:: 27 q = \sqrt{q_x^2 + q_y^2} 27 .. math:: q = \sqrt{q_x^2 + q_y^2} 28 28 29 29 References -
sasmodels/models/cylinder.py
r42356c8 r40a87fa 119 119 ] 120 120 121 source = ["lib/polevl.c", "lib/sas_J1.c", "lib/gauss76.c", "cylinder.c"]121 source = ["lib/polevl.c", "lib/sas_J1.c", "lib/gauss76.c", "cylinder.c"] 122 122 123 123 def ER(radius, length): -
sasmodels/models/elliptical_cylinder.c
rabdd01c r40a87fa 19 19 20 20 arg = q*r_minor*sqrt((1.0+r_ratio*r_ratio)/2+(1.0-r_ratio*r_ratio)*cos(theta)/2); 21 if (arg == 0.0){ 22 retval = 1.0; 23 }else{ 24 //retval = 2.0*NR_BessJ1(arg)/arg; 25 retval = sas_J1c(arg); 26 } 21 //retval = 2.0*J1(arg)/arg; 22 retval = sas_J1c(arg); 27 23 return retval*retval ; 28 24 } … … 68 64 //now calculate the value of the inner integral 69 65 answer = (vbj-vaj)/2.0*summj; 70 //divide integral by Pi71 answer /= M_PI;72 66 73 67 //now calculate outer integral 74 68 arg = q*length*zi/2.0; 75 if (arg == 0.0){ 76 si = 1.0; 77 }else{ 78 si = sin(arg) * sin(arg) / arg / arg; 79 } 69 si = square(sinc(arg)); 80 70 yyy = Gauss76Wt[i] * answer * si; 81 71 summ += yyy; 82 72 } 83 73 84 answer = (vb-va)/2.0*summ; 74 //divide integral by Pi 75 answer = (vb-va)/2.0*summ/M_PI; 85 76 // Multiply by contrast^2 86 77 answer *= delrho*delrho; -
sasmodels/models/elliptical_cylinder.py
r42356c8 r40a87fa 1 1 # pylint: disable=line-too-long 2 2 r""" 3 This function calculates the scattering from an elliptical cylinder.4 5 3 Definition for 2D (orientated system) 6 4 ------------------------------------- 7 5 8 The angles |theta| and |phi| define the orientation of the axis of the cylinder. The angle |bigpsi| is defined as the 9 orientation of the major axis of the ellipse with respect to the vector *Q*\ . A gaussian polydispersity can be added 10 to any of the orientation angles, and also for the minor radius and the ratio of the ellipse radii. 6 The angles $\theta$ and $\phi$ define the orientation of the axis of the 7 cylinder. The angle $\Psi$ is defined as the orientation of the major 8 axis of the ellipse with respect to the vector $Q$. A gaussian polydispersity 9 can be added to any of the orientation angles, and also for the minor 10 radius and the ratio of the ellipse radii. 11 11 12 12 .. figure:: img/elliptical_cylinder_geometry.png 13 13 14 Elliptical cylinder geometry $a$ = $r_{minor}$ and \ |nu|\ = $axis\_ratio$ = $r_{major} / r_{minor}$ 14 Elliptical cylinder geometry $a = r_\text{minor}$ 15 and $\nu = r_\text{major} / r_\text{minor}$ is the *axis_ratio*. 15 16 16 17 The function calculated is … … 18 19 .. math:: 19 20 20 I(\mathbf{q})=\frac{1}{V_{cyl}}\int{d\psi}\int{d\phi}\int{p(\theta,\phi,\psi)F^2(\mathbf{q},\alpha,\psi)\sin(\theta)d\theta} 21 I(\vec q)=\frac{1}{V_\text{cyl}}\int{d\psi}\int{d\phi}\int{ 22 p(\theta,\phi,\psi)F^2(\vec q,\alpha,\psi)\sin(\theta)d\theta} 21 23 22 24 with the functions … … 24 26 .. math:: 25 27 26 F(\mathbf{q},\alpha,\psi)=2\frac{J_1(a)\sin(b)}{ab} 27 \\ 28 where a = \mathbf{q}\sin(\alpha)\left[ r^2_{major}\sin^2(\psi)+r^2_{minor}\cos(\psi) \right]^{1/2} 29 \\ 30 b=\mathbf{q}\frac{L}{2}\cos(\alpha) 28 F(\vec q,\alpha,\psi) = 2\frac{J_1(a)\sin(b)}{ab} 31 29 32 and the angle |bigpsi| is defined as the orientation of the major axis of the ellipse with respect to the vector $\vec q$ . 33 The angle $\alpha$ is the angle between the axis of the cylinder and $\vec q$. 30 where 31 32 .. math:: 33 34 a &= \vec q\sin(\alpha)\left[ 35 r^2_\text{major}\sin^2(\psi)+r^2_\text{minor}\cos(\psi) \right]^{1/2} 36 37 b &= \vec q\frac{L}{2}\cos(\alpha) 38 39 and the angle $\Psi$ is defined as the orientation of the major axis of the 40 ellipse with respect to the vector $\vec q$. The angle $\alpha$ is the angle 41 between the axis of the cylinder and $\vec q$. 34 42 35 43 … … 37 45 -------------------------------------------- 38 46 39 The form factor is averaged over all possible orientation before normalized by the particle volume 47 The form factor is averaged over all possible orientation before normalized 48 by the particle volume 40 49 41 50 .. math:: 42 P(q) = scale <F^2> / V43 51 44 To provide easy access to the orientation of the elliptical cylinder, we define the axis of the cylinder using two 45 angles |theta|, |phi| and |bigpsi| (see :ref:`cylinder orientation <cylinder-angle-definition>`). 46 The angle |bigpsi| is the rotational angle around its own long_c axis against the *q* plane. 47 For example, |bigpsi| = 0 when the *r_minor* axis is parallel to the *x*\ -axis of the detector. 52 P(q) = \text{scale} <F^2> / V 48 53 49 All angle parameters are valid and given only for 2D calculation; ie, an oriented system. 54 To provide easy access to the orientation of the elliptical cylinder, we 55 define the axis of the cylinder using two angles $\theta$, $\phi$ and $\Psi$ 56 (see :ref:`cylinder orientation <cylinder-angle-definition>`). The angle 57 $\Psi$ is the rotational angle around its own long_c axis against the $q$ plane. 58 For example, $\Psi = 0$ when the $r_\text{minor}$ axis is parallel to the 59 $x$ axis of the detector. 60 61 All angle parameters are valid and given only for 2D calculation; ie, an 62 oriented system. 50 63 51 64 .. figure:: img/elliptical_cylinder_angle_definition.jpg … … 55 68 .. figure:: img/cylinder_angle_projection.jpg 56 69 57 Examples of the angles for oriented elliptical cylinders against the detector plane. 70 Examples of the angles for oriented elliptical cylinders against the 71 detector plane. 58 72 59 NB: The 2nd virial coefficient of the cylinder is calculated based on the averaged radius (= sqrt(*r_minor*\ :sup:`2` \* *axis_ratio*)) 60 and length values, and used as the effective radius for *S(Q)* when *P(Q)* \* *S(Q)* is applied. 73 NB: The 2nd virial coefficient of the cylinder is calculated based on the 74 averaged radius $(=\sqrt{r_\text{minor}^2 * \text{axis ratio}})$ and length 75 values, and used as the effective radius for $S(Q)$ when $P(Q)*S(Q)$ is applied. 61 76 62 77 … … 64 79 ---------- 65 80 66 Validation of our code was done by comparing the output of the 1D calculation to the 67 angular average of the output of the 2D calculation over all possible angles. 81 Validation of our code was done by comparing the output of the 1D calculation 82 to the angular average of the output of the 2D calculation over all possible 83 angles. 68 84 69 In the 2D average, more binning in the angle |phi| is necessary to get the proper result. 70 The following figure shows the results of the averaging by varying the number of angular bins. 85 In the 2D average, more binning in the angle $\phi$ is necessary to get the 86 proper result. The following figure shows the results of the averaging by 87 varying the number of angular bins. 71 88 72 89 .. figure:: img/elliptical_cylinder_averaging.png … … 77 94 ---------- 78 95 79 L A Feigin and D I Svergun, *Structure Analysis by Small-Angle X-Ray and Neutron Scattering*, Plenum,80 Ne w York, (1987)96 L A Feigin and D I Svergun, *Structure Analysis by Small-Angle X-Ray and 97 Neutron Scattering*, Plenum, New York, (1987) 81 98 """ 82 99 … … 104 121 # pylint: enable=bad-whitespace, line-too-long 105 122 106 source = ["lib/polevl.c","lib/sas_J1.c", "lib/gauss76.c", "lib/gauss20.c", "elliptical_cylinder.c"] 123 source = ["lib/polevl.c", "lib/sas_J1.c", "lib/gauss76.c", "lib/gauss20.c", 124 "elliptical_cylinder.c"] 107 125 108 126 demo = dict(scale=1, background=0, r_minor=100, axis_ratio=1.5, length=400.0, 109 sld=4.0, sld_solvent=1.0, theta=10.0, phi=20, psi=30, theta_pd=10, phi_pd=2, psi_pd=3) 127 sld=4.0, sld_solvent=1.0, theta=10.0, phi=20, psi=30, 128 theta_pd=10, phi_pd=2, psi_pd=3) 110 129 111 130 def ER(r_minor, axis_ratio, length): … … 117 136 """ 118 137 radius = sqrt(r_minor * r_minor * axis_ratio) 119 ddd = 0.75 * radius * (2 * radius * length + (length + radius) * (length + pi * radius)) 138 ddd = 0.75 * radius * (2 * radius * length 139 + (length + radius) * (length + pi * radius)) 120 140 return 0.5 * (ddd) ** (1. / 3.) 121 141 122 tests = [[{'r_minor': 20.0, 'axis_ratio': 1.5, 'length':400.0}, 'ER', 79.89245454155024], 123 [{'r_minor': 20.0, 'axis_ratio': 1.2, 'length':300.0}, 'VR', 1], 142 tests = [ 143 [{'r_minor': 20.0, 'axis_ratio': 1.5, 'length':400.0}, 'ER', 79.89245454155024], 144 [{'r_minor': 20.0, 'axis_ratio': 1.2, 'length':300.0}, 'VR', 1], 124 145 125 # The SasView test result was 0.00169, with a background of 0.001 126 [{'r_minor': 20.0, 127 'axis_ratio': 1.5, 128 'sld': 4.0, 129 'length':400.0, 130 'sld_solvent':1.0, 131 'background':0.0 132 }, 0.001, 675.504402]] 146 # The SasView test result was 0.00169, with a background of 0.001 147 [{'r_minor': 20.0, 'axis_ratio': 1.5, 'sld': 4.0, 'length':400.0, 148 'sld_solvent':1.0, 'background':0.0}, 149 0.001, 675.504402], 150 ] -
sasmodels/models/flexible_cylinder_elliptical.py
r42356c8 r40a87fa 109 109 # pylint: enable=bad-whitespace, line-too-long 110 110 111 source = ["lib/polevl.c","lib/sas_J1.c", "lib/gauss76.c", "lib/wrc_cyl.c", "flexible_cylinder_elliptical.c"] 111 source = ["lib/polevl.c", "lib/sas_J1.c", "lib/gauss76.c", "lib/wrc_cyl.c", 112 "flexible_cylinder_elliptical.c"] 112 113 113 114 demo = dict(scale=1.0, background=0.0001, -
sasmodels/models/fuzzy_sphere.py
r2c74c11 r40a87fa 1 1 r""" 2 For information about polarised and magnetic scattering, see 3 the :doc:`magnetic help <../sasgui/perspectives/fitting/mag_help>` documentation. 2 For information about polarised and magnetic scattering, see 3 the :doc:`magnetic help <../sasgui/perspectives/fitting/mag_help>` 4 documentation. 4 5 5 6 Definition 6 7 ---------- 7 8 8 The scattering intensity *I(q)*is calculated as:9 The scattering intensity $I(q)$ is calculated as: 9 10 10 11 .. math:: 11 I(q) = \frac{scale}{V}(\Delta \rho)^2 A^2(q) S(q) +\text{background} 12 13 I(q) = \frac{\text{scale}}{V}(\Delta \rho)^2 A^2(q) S(q) 14 + \text{background} 12 15 13 16 14 where the amplitude *A(q)*is given as the typical sphere scattering convoluted17 where the amplitude $A(q)$ is given as the typical sphere scattering convoluted 15 18 with a Gaussian to get a gradual drop-off in the scattering length density: 16 19 … … 18 21 19 22 A(q) = \frac{3\left[\sin(qR) - qR \cos(qR)\right]}{(qR)^3} 20 \exp\left(\frac{-(\sigma_ {fuzzy}q)^2}{2}\right)23 \exp\left(\frac{-(\sigma_\text{fuzzy}q)^2}{2}\right) 21 24 22 Here *|A(q)|*:sup:`2`\ is the form factor, *P(q)*. The scale is equivalent to the23 volume fraction of spheres, each of volume, *V*\. Contrast (|drho|) is the24 difference of scattering length densities of the sphere and the surrounding 25 s olvent.25 Here $A(q)^2$ is the form factor, $P(q)$. The scale is equivalent to the 26 volume fraction of spheres, each of volume, $V$. Contrast $(\Delta \rho)$ 27 is the difference of scattering length densities of the sphere and the 28 surrounding solvent. 26 29 27 Poly-dispersion in radius and in fuzziness is provided for, though the fuzziness 28 must be kept much smaller than the sphere radius for meaningful results. 29 30 30 Poly-dispersion in radius and in fuzziness is provided for, though the 31 fuzziness must be kept much smaller than the sphere radius for meaningful 32 results. 31 33 32 34 From the reference: 33 35 34 36 The "fuzziness" of the interface is defined by the parameter 35 |sigma| :sub:`fuzzy`\ . The particle radius *R*represents the radius of the37 $\sigma_\text{fuzzy}$. The particle radius $R$ represents the radius of the 36 38 particle where the scattering length density profile decreased to 1/2 of the 37 core density. The |sigma| :sub:`fuzzy`\is the width of the smeared particle39 core density. $\sigma_\text{fuzzy}$ is the width of the smeared particle 38 40 surface; i.e., the standard deviation from the average height of the fuzzy 39 41 interface. The inner regions of the microgel that display a higher density 40 42 are described by the radial box profile extending to a radius of 41 approximately *Rbox* ~ *R* - 2\ |sigma|\ . The profile approaches zero as42 *Rsans* ~ *R* + 2\ |sigma|\.43 approximately $R_\text{box} \sim R - 2 \sigma$. The profile approaches 44 zero as $R_\text{sans} \sim R + 2\sigma$. 43 45 44 46 For 2D data: The 2D scattering intensity is calculated in the same way as 1D, 45 where the *q*vector is defined as47 where the $q$ vector is defined as 46 48 47 .. math:: 48 49 q = \sqrt{{q_x}^2 + {q_y}^2} 50 49 .. math:: q = \sqrt{{q_x}^2 + {q_y}^2} 51 50 52 51 References -
sasmodels/models/gauss_lorentz_gel.py
r2c74c11 r40a87fa 9 9 ---------- 10 10 11 The scattering intensity I(q)is calculated as (Eqn. 5 from the reference)11 The scattering intensity $I(q)$ is calculated as (Eqn. 5 from the reference) 12 12 13 .. math:: 13 .. math:: I(q) = I_G(0) \exp(-q^2\Xi ^2/2) + I_L(0)/(1+q^2\xi^2) 14 14 15 I(q) = I_G(0)exp(-q^2\Xi ^2/2) + I_L(0)/(1+q^2\xi^2) 16 17 $\Xi$ is the length scale of the static correlations in the gel, 18 which can be attributed to the "frozen-in" crosslinks. 19 \ |xi|\ is the dynamic correlation length, which can be attributed to the 20 fluctuating polymer chains between crosslinks. 21 $I_G(0)$ and $I_L(0)$ are the scaling factors for each of these structures. 22 Think carefully about how these map to your particular system! 15 $\Xi$ is the length scale of the static correlations in the gel, which can 16 be attributed to the "frozen-in" crosslinks. $\xi$ is the dynamic correlation 17 length, which can be attributed to the fluctuating polymer chains between 18 crosslinks. $I_G(0)$ and $I_L(0)$ are the scaling factors for each of these 19 structures. Think carefully about how these map to your particular system! 23 20 24 21 .. note:: 25 22 The peaked structure at higher $q$ values (Figure 2 from the reference) 26 23 is not reproduced by the model. Peaks can be introduced into the model 27 by summing this model with the PeakGaussModel function.24 by summing this model with the :ref:`gaussian-peak` model. 28 25 29 26 For 2D data the scattering intensity is calculated in the same way as 1D, 30 27 where the $q$ vector is defined as 31 28 32 .. math:: 33 34 q = \sqrt{q_x^2 + q_y^2} 35 29 .. math:: q = \sqrt{q_x^2 + q_y^2} 36 30 37 31 References -
sasmodels/models/gel_fit.py
rec45c4f r40a87fa 8 8 and a longer distance (denoted here as $a2$ ) needed to account for the static 9 9 accumulations of polymer pinned down by junction points or clusters of such 10 points. The latter is derived from a simple Guinier function. Compare also the 10 points. The latter is derived from a simple Guinier function. Compare also the 11 11 gauss_lorentz_gel model. 12 12 -
sasmodels/models/guinier.py
r2c74c11 r40a87fa 5 5 This model fits the Guinier function 6 6 7 .. math:: I(q) = scale \exp{\left[ \frac{-Q^2R_g^2}{3} \right]}7 .. math:: 8 8 9 to the data directly without any need for linearisation 10 (*cf*. the usual plot of $\ln I(q)$ vs $q^2$\ ). Note that you may have to 11 restrict the data range to include small q only, where the Guinier approximation 12 actually applies. See also the guinier_porod model. 9 I(q) = \text{scale} \cdot \exp{\left[ \frac{-Q^2R_g^2}{3} \right]} 10 + \text{background} 11 12 to the data directly without any need for linearisation (*cf*. the usual 13 plot of $\ln I(q)$ vs $q^2$\ ). Note that you may have to restrict the data 14 range to include small q only, where the Guinier approximation actually 15 applies. See also the guinier_porod model. 13 16 14 17 For 2D data the scattering intensity is calculated in the same way as 1D, 15 18 where the $q$ vector is defined as 16 19 17 .. math:: q =\sqrt{q_x^2 + q_y^2}20 .. math:: q = \sqrt{q_x^2 + q_y^2} 18 21 19 22 References -
sasmodels/models/guinier_porod.py
r2c74c11 r40a87fa 1 # pylint: disable=line-too-long2 1 r""" 3 2 Calculates the scattering for a generalized Guinier/power law object. … … 13 12 14 13 .. math:: 15 I(q) = \frac{G}{Q^s} \ \exp{\left[ \frac{-Q^2R_g^2}{3-s} \right]} \textrm{ for } Q \leq Q_1 16 \\ 17 I(q) = D / Q^m \textrm{ for } Q \geq Q_1 14 15 I(q) = \begin{cases} 16 \frac{G}{Q^s}\ \exp{\left[\frac{-Q^2R_g^2}{3-s} \right]} & Q \leq Q_1 \\ 17 D / Q^m & Q \geq Q_1 18 \end{cases} 18 19 19 20 This is based on the generalized Guinier law for such elongated objects 20 (see the Glatter reference below). For 3D globular objects (such as spheres), $s = 0$ 21 and one recovers the standard Guinier formula. 22 For 2D symmetry (such as for rods) $s = 1$, 23 and for 1D symmetry (such as for lamellae or platelets) $s = 2$. 24 A dimensionality parameter ($3-s$) is thus defined, and is 3 for spherical objects, 25 2 for rods, and 1 for plates. 21 (see the Glatter reference below). For 3D globular objects (such as spheres), 22 $s = 0$ and one recovers the standard Guinier formula. For 2D symmetry 23 (such as for rods) $s = 1$, and for 1D symmetry (such as for lamellae or 24 platelets) $s = 2$. A dimensionality parameter ($3-s$) is thus defined, 25 and is 3 for spherical objects, 2 for rods, and 1 for plates. 26 26 27 Enforcing the continuity of the Guinier and Porod functions and their derivatives yields 27 Enforcing the continuity of the Guinier and Porod functions and their 28 derivatives yields 28 29 29 30 .. math:: 31 30 32 Q_1 = \frac{1}{R_g} \sqrt{(m-s)(3-s)/2} 31 33 … … 33 35 34 36 .. math:: 35 D = G \ \exp{ \left[ \frac{-Q_1^2 R_g^2}{3-s} \right]} \ Q_1^{m-s} 36 = \frac{G}{R_g^{m-s}} \ \exp{\left[ -\frac{m-s}{2} \right]} \left( \frac{(m-s)(3-s)}{2} \right)^{\frac{m-s}{2}} 37 38 D &= G \ \exp{ \left[ \frac{-Q_1^2 R_g^2}{3-s} \right]} \ Q_1^{m-s} 39 40 &= \frac{G}{R_g^{m-s}} \ \exp \left[ -\frac{m-s}{2} \right] 41 \left( \frac{(m-s)(3-s)}{2} \right)^{\frac{m-s}{2}} 37 42 38 43 39 Note that the radius-of-gyration for a sphere of radius R is given by $R_g = R \sqrt(3/5)$. 40 41 For a cylinder of radius $R$ and length $L$, $R_g^2 = \frac{L^2}{12} + \frac{R^2}{2}$ 42 43 from which the cross-sectional radius-of-gyration for a randomly oriented thin 44 cylinder is $R_g = R / \sqrt(2)$. 45 46 and the cross-sectional radius-of-gyration of a randomly oriented lamella 47 of thickness $T$ is given by $R_g = T / \sqrt(12)$. 44 Note that the radius of gyration for a sphere of radius $R$ is given 45 by $R_g = R \sqrt{3/5}$. For a cylinder of radius $R$ and length $L$, 46 $R_g^2 = \frac{L^2}{12} + \frac{R^2}{2}$ from which the cross-sectional 47 radius of gyration for a randomly oriented thin cylinder is $R_g = R/\sqrt{2}$ 48 and the cross-sectional radius of gyration of a randomly oriented lamella 49 of thickness $T$ is given by $R_g = T / \sqrt{12}$. 48 50 49 51 For 2D data: The 2D scattering intensity is calculated in the same way as 1D, … … 57 59 --------- 58 60 59 A Guinier, G Fournet, Small-Angle Scattering of X-Rays, John Wiley and Sons, New York, (1955) 61 A Guinier, G Fournet, *Small-Angle Scattering of X-Rays*, 62 John Wiley and Sons, New York, (1955) 60 63 61 O Glatter, O Kratky, Small-Angle X-Ray Scattering, Academic Press (1982)64 O Glatter, O Kratky, *Small-Angle X-Ray Scattering*, Academic Press (1982) 62 65 Check out Chapter 4 on Data Treatment, pages 155-156. 63 66 """ -
sasmodels/models/hardsphere.py
r7f1ee79 r40a87fa 3 3 spherical particles interacting through hard sphere (excluded volume) 4 4 interactions. 5 May be a reasonable approximation for other shapes of particles that 6 freely rotate, and for moderately polydisperse systems. Though strictly 5 May be a reasonable approximation for other shapes of particles that 6 freely rotate, and for moderately polydisperse systems. Though strictly 7 7 the maths needs to be modified (no \Beta(Q) correction yet in sasview). 8 8 … … 13 13 used in the form factor $P(q)$ that this $S(q)$ is combined with. 14 14 15 For numerical stability the computation uses a Taylor series expansion 15 For numerical stability the computation uses a Taylor series expansion 16 16 at very small $qR$, there may be a very minor glitch at the transition point 17 17 in some circumstances. … … 156 156 # VR defaults to 1.0 157 157 158 demo = dict(radius_effective=200, volfraction=0.2, radius_effective_pd=0.1, radius_effective_pd_n=40) 158 demo = dict(radius_effective=200, volfraction=0.2, 159 radius_effective_pd=0.1, radius_effective_pd_n=40) 159 160 # Q=0.001 is in the Taylor series, low Q part, so add Q=0.1, assuming double precision sasview is correct 160 161 tests = [ 161 [ {'scale': 1.0, 'background' : 0.0, 'radius_effective' : 50.0, 'volfraction' : 0.2, 162 'radius_effective_pd' : 0}, [0.001,0.1], [0.209128,0.930587]] 162 [ {'scale': 1.0, 'background' : 0.0, 'radius_effective' : 50.0, 163 'volfraction' : 0.2, 'radius_effective_pd' : 0}, 164 [0.001,0.1], [0.209128,0.930587]], 163 165 ] 164 # ADDED by: RKH ON: 16Mar2016 using equations from FISH as better than orig sasview, see notes above. Added Taylor expansions at small Q, 166 # ADDED by: RKH ON: 16Mar2016 using equations from FISH as better than orig sasview, see notes above. Added Taylor expansions at small Q, -
sasmodels/models/hayter_msa.py
rd2bb604 r40a87fa 16 16 there is no provision for entering the ionic strength directly nor for use 17 17 of any multivalent salts, though it should be possible to simulate the effect 18 of this by increasing the salt concentration. The counterions are also assumed to19 be monovalent.18 of this by increasing the salt concentration. The counterions are also 19 assumed to be monovalent. 20 20 21 21 In sasview the effective radius may be calculated from the parameters 22 22 used in the form factor $P(q)$ that this $S(q)$ is combined with. 23 23 24 The computation uses a Taylor series expansion at very small rescaled $qR$, to 25 avoid some serious rounding error issues, this may result in a minor artefact 24 The computation uses a Taylor series expansion at very small rescaled $qR$, to 25 avoid some serious rounding error issues, this may result in a minor artefact 26 26 in the transition region under some circumstances. 27 27 … … 103 103 radius_effective_pd_n=40) 104 104 # 105 # attempt to use same values as old sasview unit test at Q=.001 was 0.0712928, 106 # then add lots new ones assuming values from new model are OK, need some low Q values to test the small Q Taylor expansion 105 # attempt to use same values as old sasview unit test at Q=.001 was 0.0712928, 106 # then add lots new ones assuming values from new model are OK, need some 107 # low Q values to test the small Q Taylor expansion 107 108 tests = [ 108 109 [{'scale': 1.0, … … 115 116 'dielectconst': 78.0, 116 117 'radius_effective_pd': 0}, 117 [0.00001, 0.0010,0.01,0.075], [0.0711646,0.0712928,0.0847006,1.07150]],118 [0.00001, 0.0010, 0.01, 0.075], [0.0711646, 0.0712928, 0.0847006, 1.07150]], 118 119 [{'scale': 1.0, 119 120 'background': 0.0, … … 126 127 'radius_effective_pd': 0.1, 127 128 'radius_effective_pd_n': 40}, 128 [0.00001, 0.0010,0.01,0.075], [0.450272,0.450420,0.465116,1.039625]]129 [0.00001, 0.0010, 0.01, 0.075], [0.450272, 0.450420, 0.465116, 1.039625]] 129 130 ] 130 131 # ADDED by: RKH ON: 16Mar2016 converted from sasview, new Taylor expansion at smallest rescaled Q -
sasmodels/models/hollow_rectangular_prism.py
r42356c8 r40a87fa 115 115 ] 116 116 117 source = [ 117 source = ["lib/gauss76.c", "hollow_rectangular_prism.c"] 118 118 119 119 def ER(a_side, b2a_ratio, c2a_ratio, thickness): 120 120 """ 121 122 121 Return equivalent radius (ER) 122 thickness parameter not used 123 123 """ 124 124 b_side = a_side * b2a_ratio … … 133 133 def VR(a_side, b2a_ratio, c2a_ratio, thickness): 134 134 """ 135 135 Return shell volume and total volume 136 136 """ 137 137 b_side = a_side * b2a_ratio -
sasmodels/models/lamellar.py
r42356c8 r40a87fa 5 5 ---------- 6 6 7 The scattering intensity $I(q)$ for dilute, randomly oriented, "infinitely large" sheets or lamellae is 7 The scattering intensity $I(q)$ for dilute, randomly oriented, 8 "infinitely large" sheets or lamellae is 8 9 9 10 .. math:: … … 19 20 = \frac{4\Delta\rho^2}{q^2}\sin^2\left(\frac{q\delta}{2}\right) 20 21 21 where $\delta$ is the total layer thickness and $\Delta\rho$ is the scattering length density difference. 22 where $\delta$ is the total layer thickness and $\Delta\rho$ is the 23 scattering length density difference. 22 24 23 This is the limiting form for a spherical shell of infinitely large radius. Note that the division by $\delta$ 24 means that $scale$ in sasview is the volume fraction of sheet, $\phi = S\delta$ where $S$ is the area of 25 sheet per unit volume. $S$ is half the Porod surface area per unit volume of a thicker layer (as that would 26 include both faces of the sheet). 25 This is the limiting form for a spherical shell of infinitely large radius. 26 Note that the division by $\delta$ means that $scale$ in sasview is the 27 volume fraction of sheet, $\phi = S\delta$ where $S$ is the area of sheet 28 per unit volume. $S$ is half the Porod surface area per unit volume of a 29 thicker layer (as that would include both faces of the sheet). 27 30 28 31 The 2D scattering intensity is calculated in the same way as 1D, where … … 60 63 category = "shape:lamellae" 61 64 62 # ["name", "units", default, [lower, upper], "type","description"], 63 parameters = [ ["thickness", "Ang", 50, [0, inf], "volume","total layer thickness" ], 64 ["sld", "1e-6/Ang^2", 1, [-inf, inf], "sld","Layer scattering length density" ], 65 ["sld_solvent", "1e-6/Ang^2", 6, [-inf, inf], "sld","Solvent scattering length density" ], 66 ] 65 # pylint: disable=bad-whitespace, line-too-long 66 # ["name", "units", default, [lower, upper], "type","description"], 67 parameters = [ 68 ["thickness", "Ang", 50, [0, inf], "volume", "total layer thickness" ], 69 ["sld", "1e-6/Ang^2", 1, [-inf, inf], "sld", "Layer scattering length density" ], 70 ["sld_solvent", "1e-6/Ang^2", 6, [-inf, inf], "sld", "Solvent scattering length density" ], 71 ] 72 # pylint: enable=bad-whitespace, line-too-long 67 73 68 74 # No volume normalization despite having a volume parameter … … 91 97 thickness_pd=0.2, thickness_pd_n=40) 92 98 tests = [ 93 [ {'scale': 1.0, 'background' : 0.0, 'thickness' : 50.0, 'sld' : 1.0,'sld_solvent' : 6.3, 'thickness_pd' : 0.0, 94 }, [0.001], [882289.54309]] 99 [ {'scale': 1.0, 'background': 0.0, 'thickness': 50.0, 100 'sld': 1.0, 'sld_solvent': 6.3, 'thickness_pd': 0.0}, 101 [0.001], [882289.54309]] 95 102 ] 96 103 # ADDED by: converted by PAK? (or RKH?) ON: 16Mar2016 - RKH adding unit tests from sasview to early 2015 conversion -
sasmodels/models/lamellar_hg.py
r42356c8 r40a87fa 29 29 and $\Delta\rho_T$ is tail contrast (*sld* $-$ *sld_solvent*). 30 30 31 The total thickness of the lamellar sheet is $\delta_H $ + $\delta_T$ + $\delta_T$ + $\delta_H$.32 Note that in a non aqueous solvent the chemical "head" group may be the 31 The total thickness of the lamellar sheet is $\delta_H + \delta_T + \delta_T + \delta_H$. 32 Note that in a non aqueous solvent the chemical "head" group may be the 33 33 "Tail region" and vice-versa. 34 34 … … 36 36 the $q$ vector is defined as 37 37 38 .. math:: 39 40 q = \sqrt{q_x^2 + q_y^2} 41 38 .. math:: q = \sqrt{q_x^2 + q_y^2} 42 39 43 40 References … … 111 108 112 109 # 113 tests = [[{'scale': 1.0, 'background': 0.0, 'tail_length': 15.0, 'head_length': 10.0, 114 'sld': 0.4, 'sld_head': 3.0, 'sld_solvent': 6.0}, [0.001], [653143.9209]]] 110 tests = [ 111 [{'scale': 1.0, 'background': 0.0, 'tail_length': 15.0, 'head_length': 10.0, 112 'sld': 0.4, 'sld_head': 3.0, 'sld_solvent': 6.0}, 113 [0.001], [653143.9209]], 114 ] 115 115 # ADDED by: RKH ON: 18Mar2016 converted from sasview previously, now renaming everything & sorting the docs -
sasmodels/models/lamellar_stack_paracrystal.py
r42356c8 r40a87fa 142 142 # 143 143 tests = [ 144 [ {'scale': 1.0, 'background' : 0.0, 'thickness' : 33.,'Nlayers' : 20.0, 'spacing' : 250., 'spacing_polydisp' : 0.2, 145 'sld' : 1.0, 'sld_solvent' : 6.34, 146 'thickness_pd' : 0.0, 'thickness_pd_n' : 40 }, [0.001, 0.215268], [21829.3, 0.00487686]] 147 ] 144 [{'scale': 1.0, 'background': 0.0, 'thickness': 33.,'Nlayers': 20.0, 145 'spacing': 250., 'spacing_polydisp': 0.2, 'sld': 1.0, 146 'sld_solvent': 6.34, 'thickness_pd': 0.0, 'thickness_pd_n': 40 }, 147 [0.001, 0.215268], [21829.3, 0.00487686]], 148 ] 148 149 # ADDED by: RKH ON: 18Mar2016 converted from sasview previously, now renaming everything & sorting the docs -
sasmodels/models/linear_pearls.py
rd2d6100 r40a87fa 61 61 ] 62 62 # pylint: enable=bad-whitespace, line-too-long 63 single =False63 single = False 64 64 65 65 source = ["linear_pearls.c"] -
sasmodels/models/mono_gauss_coil.py
r2c74c11 r40a87fa 2 2 #conversion of DebyeModel.py 3 3 #converted by Steve King, Mar 2016 4 r""" 5 This Debye Gaussian coil model strictly describes the scattering from 6 *monodisperse* polymer chains in theta solvents or polymer melts, conditions 7 under which the distances between segments follow a Gaussian distribution. 8 Provided the number of segments is large (ie, high molecular weight polymers) 9 the single-chain form factor P(Q) is that described by Debye (1947). 4 10 5 6 7 r""" 8 This Debye Gaussian coil model strictly describes the scattering from *monodisperse* polymer chains in theta solvents or polymer melts, conditions under which the distances between segments follow a Gaussian distribution. Provided the number of segments is large (ie, high molecular weight polymers) the single-chain form factor P(Q) is that described by Debye (1947). 9 10 To describe the scattering from *polydisperse* polymer chains see the :ref:`poly_gauss_coil <poly-gauss-coil>` model. 11 To describe the scattering from *polydisperse* polymer chains see the 12 :ref:`poly-gauss-coil` model. 11 13 12 14 Definition 13 15 ---------- 14 16 15 *I(q)* = *scale* |cdot| *I* \ :sub:`0` |cdot| *P(q)* + *background* 17 .. math:: 18 19 I(q) = \text{scale} \cdot I_0 \cdot P(q) + \text{background} 16 20 17 21 where 18 22 19 *I*\ :sub:`0` = |phi|\ :sub:`poly` |cdot| *V* |cdot| (|rho|\ :sub:`poly` - |rho|\ :sub:`solv`)\ :sup:`2` 23 .. math:: 20 24 21 *P(q)* = 2 [exp(-Z) + Z - 1] / Z \ :sup:`2` 25 I_0 &= \phi_\text{poly} \cdot V 26 \cdot (\rho_\text{poly} - \rho_\text{solv})^2 22 27 23 *Z* = (*q R* \ :sub:`g`)\ :sup:`2`28 P(q) &= 2 [\exp(-Z) + Z - 1] / Z^2 24 29 25 and 30 Z &= (q R_g)^2 26 31 27 *V* = *M* / (*N*\ :sub:`A` |delta|)32 V &= M / (N_A \delta) 28 33 29 Here, |phi|\ :sub:`poly` is the volume fraction of polymer, *V* is the volume of a polymer coil, *M* is the molecular weight of the polymer, *N*\ :sub:`A` is Avogadro's Number, |delta| is the bulk density of the polymer, |rho|\ :sub:`poly` is the sld of the polymer, |rho|\ :sub:`solv` is the sld of the solvent, and *R*\ :sub:`g` is the radius of gyration of the polymer coil. 34 Here, $\phi_\text{poly}$ is the volume fraction of polymer, $V$ is the 35 volume of a polymer coil, *M* is the molecular weight of the polymer, 36 $N_A$ is Avogadro's Number, $\delta$ is the bulk density of the polymer, 37 $\rho_\text{poly}$ is the sld of the polymer, $\rho\text{solv}$ is the 38 sld of the solvent, and $R_g$ is the radius of gyration of the polymer coil. 30 39 31 The 2D scattering intensity is calculated in the same way as the 1D, but where the *q* vector is redefined as 40 The 2D scattering intensity is calculated in the same way as the 1D, 41 but where the *q* vector is redefined as 32 42 33 43 .. math:: … … 40 50 P Debye, *J. Phys. Colloid. Chem.*, 51 (1947) 18. 41 51 42 R J Roe, *Methods of X-Ray and Neutron Scattering in Polymer Science*, Oxford University Press, New York (2000). 52 R J Roe, *Methods of X-Ray and Neutron Scattering in Polymer Science*, 53 Oxford University Press, New York (2000). 43 54 44 55 http://www.ncnr.nist.gov/staff/hammouda/distance_learning/chapter_28.pdf … … 47 58 from numpy import inf, exp, errstate 48 59 49 name = 50 title = 60 name = "mono_gauss_coil" 61 title = "Scattering from monodisperse polymer coils" 51 62 52 description = 63 description = """ 53 64 Evaluates the scattering from 54 65 monodisperse polymer chains. 55 66 """ 56 category = 67 category = "shape-independent" 57 68 58 # ["name", "units", default, [lower, upper], "type", "description"], 59 parameters = [["i_zero", "1/cm", 70.0, [0.0, inf], "", "Intensity at q=0"], 60 ["radius_gyration", "Ang", 75.0, [0.0, inf], "", "Radius of gyration"]] 69 # pylint: disable=bad-whitespace, line-too-long 70 # ["name", "units", default, [lower, upper], "type", "description"], 71 parameters = [ 72 ["i_zero", "1/cm", 70.0, [0.0, inf], "", "Intensity at q=0"], 73 ["radius_gyration", "Ang", 75.0, [0.0, inf], "", "Radius of gyration"], 74 ] 75 # pylint: enable=bad-whitespace, line-too-long 61 76 62 77 # NB: Scale and Background are implicit parameters on every model … … 71 86 Iq.vectorized = True # Iq accepts an array of q values 72 87 73 demo = dict(scale = 1.0, 74 i_zero = 70.0, 75 radius_gyration = 75.0, 76 background = 0.0) 88 demo = dict(scale=1.0, i_zero=70.0, radius_gyration=75.0, background=0.0) 77 89 78 90 # these unit test values taken from SasView 3.1.2 79 tests = 91 tests = [ 80 92 [{'scale': 1.0, 'i_zero': 70.0, 'radius_gyration': 75.0, 'background': 0.0}, 81 93 [0.0106939, 0.469418], [57.1241, 0.112859]], -
sasmodels/models/multilayer_vesicle.py
rf67f26c r40a87fa 13 13 Geometry of the multilayer_vesicle model. 14 14 15 See the core_shell_ function for more documentation. 16 17 .. _core_shell: core_shell_sphere.html 15 See the :ref:`core-shell` model for more documentation. 18 16 19 17 The 2D scattering intensity is the same as 1D, regardless of the orientation … … 29 27 is used as the effective radius for *S(Q)* when $P(Q) * S(Q)$ is applied. 30 28 31 For information about polarised and magnetic scattering, see 29 For information about polarised and magnetic scattering, see 32 30 the :doc:`magnetic help <../sasgui/perspectives/fitting/mag_help>` documentation. 33 31 -
sasmodels/models/onion.py
r785cbec r40a87fa 300 300 # TODO: n is a volume parameter that is not polydisperse 301 301 302 # ["name", "units", default, [lower, upper], "type","description"], 303 parameters = [["sld_core", "1e-6/Ang^2", 1.0, [-inf, inf], "sld", 304 "Core scattering length density"], 305 ["radius_core", "Ang", 200., [0, inf], "volume", 306 "Radius of the core"], 307 ["sld_solvent", "1e-6/Ang^2", 6.4, [-inf, inf], "sld", 308 "Solvent scattering length density"], 309 ["n_shells", "", 1, [0, 10], "volume", 310 "number of shells"], 311 ["sld_in[n_shells]", "1e-6/Ang^2", 1.7, [-inf, inf], "sld", 312 "scattering length density at the inner radius of shell k"], 313 ["sld_out[n_shells]", "1e-6/Ang^2", 2.0, [-inf, inf], "sld", 314 "scattering length density at the outer radius of shell k"], 315 ["thickness[n_shells]", "Ang", 40., [0, inf], "volume", 316 "Thickness of shell k"], 317 ["A[n_shells]", "", 1.0, [-inf, inf], "", 318 "Decay rate of shell k"], 319 ] 302 # pylint: disable=bad-whitespace, line-too-long 303 # ["name", "units", default, [lower, upper], "type","description"], 304 parameters = [ 305 ["sld_core", "1e-6/Ang^2", 1.0, [-inf, inf], "sld", "Core scattering length density"], 306 ["radius_core", "Ang", 200., [0, inf], "volume", "Radius of the core"], 307 ["sld_solvent", "1e-6/Ang^2", 6.4, [-inf, inf], "sld", "Solvent scattering length density"], 308 ["n_shells", "", 1, [0, 10], "volume", "number of shells"], 309 ["sld_in[n_shells]", "1e-6/Ang^2", 1.7, [-inf, inf], "sld", "scattering length density at the inner radius of shell k"], 310 ["sld_out[n_shells]", "1e-6/Ang^2", 2.0, [-inf, inf], "sld", "scattering length density at the outer radius of shell k"], 311 ["thickness[n_shells]", "Ang", 40., [0, inf], "volume", "Thickness of shell k"], 312 ["A[n_shells]", "", 1.0, [-inf, inf], "", "Decay rate of shell k"], 313 ] 314 # pylint: enable=bad-whitespace, line-too-long 320 315 321 316 source = ["lib/sph_j1c.c", "onion.c"] … … 330 325 331 326 total_radius = 1.25*(sum(thickness[:n_shells]) + radius_core + 1) 332 d r= total_radius/400 # 400 points for a smooth plot333 334 r= []327 dz = total_radius/400 # 400 points for a smooth plot 328 329 z = [] 335 330 rho = [] 336 331 337 332 # add in the core 338 r.append(0)333 z.append(0) 339 334 rho.append(sld_core) 340 r.append(radius_core)335 z.append(radius_core) 341 336 rho.append(sld_core) 342 337 … … 344 339 for k in range(n_shells): 345 340 # Left side of each shells 346 r0 = r[-1]347 r.append(r0)341 z_current = z[-1] 342 z.append(z_current) 348 343 rho.append(sld_in[k]) 349 344 350 345 if fabs(A[k]) < 1.0e-16: 351 346 # flat shell 352 r.append(r0+ thickness[k])347 z.append(z_current + thickness[k]) 353 348 rho.append(sld_out[k]) 354 349 else: … … 356 351 # num_steps must be at least 1, so use floor()+1 rather than ceil 357 352 # to protect against a thickness0. 358 num_steps = np.floor(thickness[k]/d r) + 1353 num_steps = np.floor(thickness[k]/dz) + 1 359 354 slope = (sld_out[k] - sld_in[k]) / expm1(A[k]) 360 355 const = (sld_in[k] - slope) 361 for rkin np.linspace(0, thickness[k], num_steps+1):362 r.append(r0+rk)363 rho.append(slope*exp(A[k]* rk/thickness[k]) + const)356 for z_shell in np.linspace(0, thickness[k], num_steps+1): 357 z.append(z_current+z_shell) 358 rho.append(slope*exp(A[k]*z_shell/thickness[k]) + const) 364 359 365 360 # add in the solvent 366 r.append(r[-1])361 z.append(z[-1]) 367 362 rho.append(sld_solvent) 368 r.append(total_radius)363 z.append(total_radius) 369 364 rho.append(sld_solvent) 370 365 371 return np.asarray( r), np.asarray(rho)366 return np.asarray(z), np.asarray(rho) 372 367 373 368 def ER(core_radius, n, thickness): 369 """Effective radius""" 374 370 return np.sum(thickness[:n[0]], axis=0) + core_radius 375 376 def VR(core_radius, n, thickness):377 return 1.0, 1.0378 371 379 372 demo = { -
sasmodels/models/parallelepiped.py
r42356c8 r40a87fa 7 7 ---------- 8 8 9 | This model calculates the scattering from a rectangular parallelepiped (:numref:`parallelepiped-image`). 9 | This model calculates the scattering from a rectangular parallelepiped 10 | (:numref:`parallelepiped-image`). 10 11 | If you need to apply polydispersity, see also :ref:`rectangular-prism`. 11 12 … … 34 35 .. math:: 35 36 36 I(q) = \frac{\text{scale}}{V} (\Delta\rho \cdot V)^2 \left< P(q, \alpha) \right>37 + \text{background}37 I(q) = \frac{\text{scale}}{V} (\Delta\rho \cdot V)^2 38 \left< P(q, \alpha) \right> + \text{background} 38 39 39 40 where the volume $V = A B C$, the contrast is defined as 40 :math:`\Delta\rho = \rho_{\textstyle p} - \rho_{\textstyle solvent}`,41 $\Delta\rho = \rho_\text{p} - \rho_\text{solvent}$, 41 42 $P(q, \alpha)$ is the form factor corresponding to a parallelepiped oriented 42 at an angle $\alpha$ (angle between the long axis C and :math:`\vec q`),43 at an angle $\alpha$ (angle between the long axis C and $\vec q$), 43 44 and the averaging $\left<\ldots\right>$ is applied over all orientations. 44 45 … … 55 56 .. math:: 56 57 57 \phi_Q(\mu,a) = \int_0^158 \phi_Q(\mu,a) &= \int_0^1 58 59 \left\{S\left[\frac{\mu}{2}\cos\left(\frac{\pi}{2}u\right)\right] 59 60 S\left[\frac{\mu a}{2}\sin\left(\frac{\pi}{2}u\right)\right] 60 61 \right\}^2 du 61 62 62 S(x) = \frac{\sin x}{x}63 64 \mu = qB63 S(x) &= \frac{\sin x}{x} 64 65 \mu &= qB 65 66 66 67 … … 105 106 .. figure:: img/parallelepiped_angle_projection.jpg 106 107 107 Examples of the angles for oriented parallelepipeds against the detector plane. 108 109 For a given orientation of the parallelepiped, the 2D form factor is calculated as 110 111 .. math:: 112 113 P(q_x, q_y) = \left[\frac{sin(qA\cos\alpha/2)}{(qA\cos\alpha/2)}\right]^2 114 \left[\frac{sin(qB\cos\beta/2)}{(qB\cos\beta/2)}\right]^2 115 \left[\frac{sin(qC\cos\gamma/2)}{(qC\cos\gamma/2)}\right]^2 108 Examples of the angles for oriented parallelepipeds against the 109 detector plane. 110 111 For a given orientation of the parallelepiped, the 2D form factor is 112 calculated as 113 114 .. math:: 115 116 P(q_x, q_y) = \left[\frac{\sin(qA\cos\alpha/2)}{(qA\cos\alpha/2)}\right]^2 117 \left[\frac{\sin(qB\cos\beta/2)}{(qB\cos\beta/2)}\right]^2 118 \left[\frac{\sin(qC\cos\gamma/2)}{(qC\cos\gamma/2)}\right]^2 116 119 117 120 with … … 119 122 .. math:: 120 123 121 \cos\alpha = \hat A \cdot \hat q, \; 122 \cos\beta = \hat B \cdot \hat q, \; 123 \cos\gamma = \hat C \cdot \hat q 124 \cos\alpha &= \hat A \cdot \hat q, 125 126 \cos\beta &= \hat B \cdot \hat q, 127 128 \cos\gamma &= \hat C \cdot \hat q 124 129 125 130 and the scattering intensity as: … … 127 132 .. math:: 128 133 129 I(q_x, q_y) = \frac{\text{scale}}{V} V^2 \Delta\rho^2 P(q_x, q_y) + \text{background} 134 I(q_x, q_y) = \frac{\text{scale}}{V} V^2 \Delta\rho^2 P(q_x, q_y) 135 + \text{background} 130 136 131 137 .. Comment by Miguel Gonzalez: 132 138 This reflects the logic of the code, as in parallelepiped.c the call 133 to _pkernel returns P(q_x, q_y) and then this is multiplied by V^2 * (delta rho)^2. 134 And finally outside parallelepiped.c it will be multiplied by scale, normalized by 135 V and the background added. But mathematically it makes more sense to write 136 I(q_x, q_y) = \text{scale} V \Delta\rho^2 P(q_x, q_y) + \text{background}, 139 to _pkernel returns $P(q_x, q_y)$ and then this is multiplied by 140 $V^2 * (\Delta \rho)^2$. And finally outside parallelepiped.c it will be 141 multiplied by scale, normalized by $V$ and the background added. But 142 mathematically it makes more sense to write 143 $I(q_x, q_y) = \text{scale} V \Delta\rho^2 P(q_x, q_y) + \text{background}$, 137 144 with scale being the volume fraction. 138 145 … … 143 150 Validation of the code was done by comparing the output of the 1D calculation 144 151 to the angular average of the output of a 2D calculation over all possible 145 angles. 152 angles. 146 153 147 154 This model is based on form factor calculations implemented in a c-library -
sasmodels/models/poly_gauss_coil.py
r2c74c11 r40a87fa 2 2 #conversion of Poly_GaussCoil.py 3 3 #converted by Steve King, Mar 2016 4 r""" 5 This empirical model describes the scattering from *polydisperse* polymer 6 chains in theta solvents or polymer melts, assuming a Schulz-Zimm type 7 molecular weight distribution. 4 8 5 6 7 r""" 8 This empirical model describes the scattering from *polydisperse* polymer chains in theta solvents or polymer melts, assuming a Schulz-Zimm type molecular weight distribution. 9 10 To describe the scattering from *monodisperse* polymer chains, see the :ref:`mono_gauss_coil <mono-gauss-coil>` model. 9 To describe the scattering from *monodisperse* polymer chains, see the 10 :ref:`mono-gauss-coil` model. 11 11 12 12 Definition 13 13 ---------- 14 14 15 *I(q)* = *scale* |cdot| *I* \ :sub:`0` |cdot| *P(q)* + *background* 15 .. math:: 16 17 I(q) = \text{scale} \cdot I_0 \cdot P(q) + \text{background} 16 18 17 19 where 18 20 19 *I*\ :sub:`0` = |phi|\ :sub:`poly` |cdot| *V* |cdot| (|rho|\ :sub:`poly` - |rho|\ :sub:`solv`)\ :sup:`2` 21 .. math:: 20 22 21 *P(q)* = 2 [(1 + UZ)\ :sup:`-1/U` + Z - 1] / [(1 + U) Z\ :sup:`2`]23 I_0 &= \phi_\text{poly} \cdot V \cdot (\rho_\text{poly}-\rho_\text{solv})^2 22 24 23 *Z* = [(*q R*\ :sub:`g`)\ :sup:`2`] / (1 + 2U)25 P(q) &= 2 [(1 + UZ)^{-1/U} + Z - 1] / [(1 + U) Z^2] 24 26 25 *U* = (Mw / Mn) - 1 = (*polydispersity ratio*) - 127 Z &= [(q R_g)^2] / (1 + 2U) 26 28 27 and 29 U &= (Mw / Mn) - 1 = \text{polydispersity ratio} - 1 28 30 29 *V* = *M* / (*N*\ :sub:`A` |delta|)31 V &= M / (N_A \delta) 30 32 31 Here, |phi|\ :sub:`poly`, is the volume fraction of polymer, *V* is the volume of a polymer coil, *M* is the molecular weight of the polymer, *N*\ :sub:`A` is Avogadro's Number, |delta| is the bulk density of the polymer, |rho|\ :sub:`poly` is the sld of the polymer, |rho|\ :sub:`solv` is the sld of the solvent, and *R*\ :sub:`g` is the radius of gyration of the polymer coil. 33 Here, $\phi_\text{poly}$, is the volume fraction of polymer, $V$ is the 34 volume of a polymer coil, $M$ is the molecular weight of the polymer, 35 $N_A$ is Avogadro's Number, $\delta$ is the bulk density of the polymer, 36 $\rho_\text{poly}$ is the sld of the polymer, $\rho_\text{solv}$ is the 37 sld of the solvent, and $R_g$ is the radius of gyration of the polymer coil. 32 38 33 The 2D scattering intensity is calculated in the same way as the 1D, but where the *q* vector is redefined as 39 The 2D scattering intensity is calculated in the same way as the 1D, 40 but where the $q$ vector is redefined as 34 41 35 42 .. math:: … … 40 47 ---------- 41 48 42 O Glatter and O Kratky (editors), *Small Angle X-ray Scattering*, Academic Press, (1982)43 Page 404.49 O Glatter and O Kratky (editors), *Small Angle X-ray Scattering*, 50 Academic Press, (1982) Page 404. 44 51 45 J S Higgins, H C Benoit, *Polymers and Neutron Scattering*, Oxford Science Publications, (1996). 52 J S Higgins, H C Benoit, *Polymers and Neutron Scattering*, 53 Oxford Science Publications, (1996). 46 54 47 S M King, *Small Angle Neutron Scattering* in *Modern Techniques for Polymer Characterisation*, Wiley, (1999). 55 S M King, *Small Angle Neutron Scattering* in *Modern Techniques for 56 Polymer Characterisation*, Wiley, (1999). 48 57 49 58 http://www.ncnr.nist.gov/staff/hammouda/distance_learning/chapter_28.pdf … … 52 61 from numpy import inf, exp, power 53 62 54 name = 55 title = 63 name = "poly_gauss_coil" 64 title = "Scattering from polydisperse polymer coils" 56 65 57 description = 66 description = """ 58 67 Evaluates the scattering from 59 68 polydisperse polymer chains. 60 69 """ 61 category = 70 category = "shape-independent" 62 71 63 # ["name", "units", default, [lower, upper], "type", "description"], 64 parameters = [["i_zero", "1/cm", 70.0, [0.0, inf], "", "Intensity at q=0"], 65 ["radius_gyration", "Ang", 75.0, [0.0, inf], "", "Radius of gyration"], 66 ["polydispersity", "None", 2.0, [1.0, inf], "", "Polymer Mw/Mn"]] 72 # pylint: disable=bad-whitespace, line-too-long 73 # ["name", "units", default, [lower, upper], "type", "description"], 74 parameters = [ 75 ["i_zero", "1/cm", 70.0, [0.0, inf], "", "Intensity at q=0"], 76 ["radius_gyration", "Ang", 75.0, [0.0, inf], "", "Radius of gyration"], 77 ["polydispersity", "None", 2.0, [1.0, inf], "", "Polymer Mw/Mn"], 78 ] 79 # pylint: enable=bad-whitespace, line-too-long 67 80 68 81 # NB: Scale and Background are implicit parameters on every model … … 71 84 u = polydispersity - 1.0 72 85 z = (q*radius_gyration)**2 / (1.0 + 2.0*u) 73 # need to trap the case of the polydispersity being 1 (ie, monodispers ity!)86 # need to trap the case of the polydispersity being 1 (ie, monodisperse!) 74 87 if polydispersity == 1.0: 75 88 inten = i_zero * 2.0 * (exp(-z) + z - 1.0) … … 80 93 inten[index] /= z[index]**2 81 94 return inten 82 Iq.vectorized = 95 Iq.vectorized = True # Iq accepts an array of q values 83 96 84 demo = dict(scale =1.0,85 i_zero =70.0,86 radius_gyration =75.0,87 polydispersity =2.0,88 background =0.0)97 demo = dict(scale=1.0, 98 i_zero=70.0, 99 radius_gyration=75.0, 100 polydispersity=2.0, 101 background=0.0) 89 102 90 103 # these unit test values taken from SasView 3.1.2 91 tests = [ 92 [{'scale': 1.0, 'i_zero': 70.0, 'radius_gyration': 75.0, 'polydispersity': 2.0, 'background': 0.0}, 104 tests = [ 105 [{'scale': 1.0, 'i_zero': 70.0, 'radius_gyration': 75.0, 106 'polydispersity': 2.0, 'background': 0.0}, 93 107 [0.0106939, 0.469418], [57.6405, 0.169016]], 94 108 ] -
sasmodels/models/polymer_excl_volume.py
r2c74c11 r40a87fa 106 106 107 107 # pylint: disable=bad-whitespace, line-too-long 108 # ["name", "units", default, [lower, upper], "type", "description"], 109 parameters = [["rg", "Ang", 60.0, [0, inf], "", "Radius of Gyration"], 110 ["porod_exp", "", 3.0, [-inf, inf], "", "Porod exponent"], 111 ] 108 # ["name", "units", default, [lower, upper], "type", "description"], 109 parameters = [ 110 ["rg", "Ang", 60.0, [0, inf], "", "Radius of Gyration"], 111 ["porod_exp", "", 3.0, [-inf, inf], "", "Porod exponent"], 112 ] 112 113 # pylint: enable=bad-whitespace, line-too-long 113 114 … … 120 121 :return: Calculated intensity 121 122 """ 122 u = (q*rg)**2 * (2.0/porod_exp + 1.0) * (2.0/porod_exp + 2.0)/6.0123 usub = (q*rg)**2 * (2.0/porod_exp + 1.0) * (2.0/porod_exp + 2.0)/6.0 123 124 with errstate(divide='ignore', invalid='ignore'): 124 upow = power(u , -0.5*porod_exp)125 iq= (porod_exp*upow *126 (gamma(0.5*porod_exp)*gammainc(0.5*porod_exp, u) -127 upow*gamma(porod_exp)*gammainc(porod_exp, u)))128 iq[q <= 0] = 1.0125 upow = power(usub, -0.5*porod_exp) 126 result= (porod_exp*upow * 127 (gamma(0.5*porod_exp)*gammainc(0.5*porod_exp, usub) - 128 upow*gamma(porod_exp)*gammainc(porod_exp, usub))) 129 result[q <= 0] = 1.0 129 130 130 return iq131 return result 131 132 132 133 Iq.vectorized = True # Iq accepts an array of q values 133 134 134 135 135 tests = [ -
sasmodels/models/polymer_micelle.py
rd2d6100 r40a87fa 3 3 This model provides the form factor, $P(q)$, for a micelle with a spherical 4 4 core and Gaussian polymer chains attached to the surface, thus may be applied 5 to block copolymer micelles. To work well the Gaussian chains must be much smaller 6 than the core, which is often not the case. Please study the reference carefully. 5 to block copolymer micelles. To work well the Gaussian chains must be much 6 smaller than the core, which is often not the case. Please study the 7 reference carefully. 7 8 8 9 Definition … … 71 72 [{}, 0.01, 15.3532], 72 73 ] 73 # RKH 20Mar2016 - need to check whether the core & corona volumes are per monomer ??? and how aggregation number works! 74 # renamed from micelle_spherical_core to polymer_micelle, moved from shape-independent to spheres section. 74 # RKH 20Mar2016 - need to check whether the core & corona volumes are per 75 # monomer ??? and how aggregation number works! 76 # renamed from micelle_spherical_core to polymer_micelle, 77 # moved from shape-independent to spheres section. 75 78 # Ought to be able to add polydisp to core? And add ability to x by S(Q) ? -
sasmodels/models/porod.py
r2c74c11 r40a87fa 2 2 This model fits the Porod function 3 3 4 .. math:: 5 6 I(q) = C/q^4 7 \\ 8 C = 2\pi (\Delta\rho)^2 S_v 4 .. math:: I(q) = C/q^4 9 5 10 6 to the data directly without any need for linearisation (cf. Log I(q) vs Log q). 11 7 12 Here $C$ is the scale factor and $S_v$ is the specific surface area (ie, surface area / volume) 13 of the sample, and $\Delta\rho$ is the contrast factor. 8 Here $C = 2\pi (\Delta\rho)^2 S_v$ is the scale factor where $S_v$ is 9 the specific surface area (ie, surface area / volume) of the sample, and 10 $\Delta\rho$ is the contrast factor. 14 11 15 12 For 2D data: The 2D scattering intensity is calculated in the same way as 1D, 16 13 where the q vector is defined as 17 14 18 .. math:: 19 q = \sqrt{q_x^2+q_y^2} 15 .. math:: q = \sqrt{q_x^2+q_y^2} 20 16 21 17 References … … 23 19 24 20 G Porod. *Kolloid Zeit*. 124 (1951) 83. 25 L A Feigin, D I Svergun, G W Taylor. *Structure Analysis by Small-Angle X-ray and Neutron Scattering*. Springer. (1987) 21 22 L A Feigin, D I Svergun, G W Taylor. *Structure Analysis by Small-Angle 23 X-ray and Neutron Scattering*. Springer. (1987) 26 24 """ 27 25 -
sasmodels/models/power_law.py
r2c74c11 r40a87fa 46 46 # pylint: disable=missing-docstring 47 47 with errstate(divide='ignore'): 48 iq= q**-power49 return iq48 result = q**-power 49 return result 50 50 Iq.vectorized = True # Iq accepts an array of q values 51 51 52 demo = dict(scale=1.0, 53 power=4.0, 54 background=0.0) 52 demo = dict(scale=1.0, power=4.0, background=0.0) 55 53 56 54 tests = [ -
sasmodels/models/pringle.py
rc047acf r40a87fa 31 31 $d$ and $R$ are the "pringle" thickness and radius respectively, $\alpha$ and 32 32 $\beta$ are the two curvature parameters, and $J_n$ is the n\ :sup:`th` order 33 Bessel function of the first kind. 33 Bessel function of the first kind. 34 34 35 35 .. figure:: img/pringles_fig1.png … … 79 79 def ER(radius, thickness, alpha, beta): 80 80 """ 81 81 Return equivalent radius (ER) 82 82 """ 83 83 ddd = 0.75 * radius * (2 * radius * thickness + (thickness + radius) \ -
sasmodels/models/raspberry.py
r42356c8 r40a87fa 22 22 .. math:: 23 23 24 S(q) = \frac{ sin(qR_1)}{qR_1}\frac{sin(qR_2)}{qR_2}\frac{sin(qr)}{qr}24 S(q) = \frac{\sin(qR_1)}{qR_1}\frac{\sin(qR_2)}{qR_2}\frac{\sin(qr)}{qr} 25 25 26 26 In this case, the large droplet and small particles are solid spheres rather … … 31 31 .. math:: 32 32 33 \Psi_L = \int_0^{R_L}(4\pi R^2_L)\frac{ sin(qR_L)}{qR_L}dR_L =34 \frac{3[ sin(qR_L)-qR_Lcos(qR_L)]}{(qR_L)^2}33 \Psi_L = \int_0^{R_L}(4\pi R^2_L)\frac{\sin(qR_L)}{qR_L}dR_L = 34 \frac{3[\sin(qR_L)-qR_L\cos(qR_L)]}{(qR_L)^2} 35 35 36 36 .. math:: 37 37 38 \Psi_S = \int_0^{R_S}(4\pi R^2_S)\frac{ sin(qR_S)}{qR_S}dR_S =39 \frac{3[ sin(qR_S)-qR_Lcos(qR_S)]}{(qR_S)^2}38 \Psi_S = \int_0^{R_S}(4\pi R^2_S)\frac{\sin(qR_S)}{qR_S}dR_S = 39 \frac{3[\sin(qR_S)-qR_L\cos(qR_S)]}{(qR_S)^2} 40 40 41 41 The cross term between the large droplet and small particles is given by: 42 42 43 43 .. math:: 44 S_{LS} = \Psi_L\Psi_S\frac{ sin(q(R_L+\delta R_S))}{q(R_L+\delta\ R_S)}44 S_{LS} = \Psi_L\Psi_S\frac{\sin(q(R_L+\delta R_S))}{q(R_L+\delta\ R_S)} 45 45 46 46 and the self term between small particles is given by: 47 47 48 48 .. math:: 49 S_{SS} = \Psi_S^2\biggl[\frac{ sin(q(R_L+\delta R_S))}{q(R_L+\delta\ R_S)}49 S_{SS} = \Psi_S^2\biggl[\frac{\sin(q(R_L+\delta R_S))}{q(R_L+\delta\ R_S)} 50 50 \biggr]^2 51 51 … … 54 54 .. math:: 55 55 56 N_p = \frac{\phi_S\phi_ {surface}V_L}{\phi_L V_S}56 N_p = \frac{\phi_S\phi_\text{surface}V_L}{\phi_L V_S} 57 57 58 58 where $\phi_S$ is the volume fraction of small particles in the sample, 59 $\phi_ {surface}$ is the fraction of the small particles that are adsorbed to60 t he large droplets, $\phi_L$ is the volume fraction of large droplets in the59 $\phi_\text{surface}$ is the fraction of the small particles that are adsorbed 60 to the large droplets, $\phi_L$ is the volume fraction of large droplets in the 61 61 sample, and $V_S$ and $V_L$ are the volumes of individual small particles and 62 62 large droplets respectively. … … 64 64 The form factor of the entire complex can now be calculated including the excess 65 65 scattering length densities of the components $\Delta\rho_L$ and $\Delta\rho_S$, 66 where $\Delta\rho_x = |\rho_x-\rho_{solvent}|$ :66 where $\Delta\rho_x = \left|\rho_x-\rho_\text{solvent}\right|$ : 67 67 68 68 .. math:: … … 83 83 84 84 .. math:: 85 I(Q) = I_{LS}(Q) + I_S(Q) = (\phi_L(\Delta\rho_L)^2V_L + 86 \phi_S\phi_ {surface}N_p(\Delta\rho_S)^2V_S)P_{LS}87 + \phi_S(1-\phi_ {surface})(\Delta\rho_S)^2V_S\Psi_S^285 I(Q) = I_{LS}(Q) + I_S(Q) = (\phi_L(\Delta\rho_L)^2V_L + 86 \phi_S\phi_\text{surface}N_p(\Delta\rho_S)^2V_S)P_{LS} 87 + \phi_S(1-\phi_\text{surface})(\Delta\rho_S)^2V_S\Psi_S^2 88 88 89 89 A useful parameter to extract is the fraction of the surface area of the large … … 92 92 93 93 .. math:: 94 \chi = \frac{4\phi_L\phi_ {surface}(R_L+\delta R_S)}{\phi_LR_S}94 \chi = \frac{4\phi_L\phi_\text{surface}(R_L+\delta R_S)}{\phi_LR_S} 95 95 96 96 … … 109 109 """ 110 110 111 from numpy import pi,inf111 from numpy import inf 112 112 113 113 name = "raspberry" -
sasmodels/models/rpa.py
r51ec7e8 r40a87fa 111 111 HIDE_AB = set("N2 Phi2 v2 L2 b2 K23 K24".split()).union(HIDE_A) 112 112 def hidden(case_num): 113 """ 114 Return a list of parameters to hide depending on the multiplicity parameter. 115 """ 113 116 if case_num < 2: 114 117 return HIDE_AB -
sasmodels/models/sphere.py
r2c74c11 r40a87fa 1 1 r""" 2 For information about polarised and magnetic scattering, see 3 the :doc:`magnetic help <../sasgui/perspectives/fitting/mag_help>` documentation. 2 For information about polarised and magnetic scattering, see 3 the :doc:`magnetic help <../sasgui/perspectives/fitting/mag_help>` 4 documentation. 4 5 5 6 Definition -
sasmodels/models/squarewell.py
r56b2687 r40a87fa 1 1 # Note: model title and parameter table are inserted automatically 2 2 r""" 3 This calculates the interparticle structure factor for a square well fluid spherical particles. The mean spherical 4 approximation (MSA) closure was used for this calculation, and is not the most appropriate closure for an attractive 5 interparticle potential. This solution has been compared to Monte Carlo simulations for a square well fluid, showing 6 this calculation to be limited in applicability to well depths |epsilon| < 1.5 kT and volume fractions |phi| < 0.08. 3 This calculates the interparticle structure factor for a square well fluid 4 spherical particles. The mean spherical approximation (MSA) closure was 5 used for this calculation, and is not the most appropriate closure for 6 an attractive interparticle potential. This solution has been compared 7 to Monte Carlo simulations for a square well fluid, showing this calculation 8 to be limited in applicability to well depths $\epsilon < 1.5$ kT and 9 volume fractions $\phi < 0.08$. 7 10 8 Positive well depths correspond to an attractive potential well. Negative well depths correspond to a potential 9 "shoulder", which may or may not be physically reasonable. The stickyhardsphere model may be a better choice in 11 Positive well depths correspond to an attractive potential well. Negative 12 well depths correspond to a potential "shoulder", which may or may not be 13 physically reasonable. The stickyhardsphere model may be a better choice in 10 14 some circumstances. Computed values may behave badly at extremely small $qR$. 11 15 12 The well width (|lambda| ) is defined as multiples of the particle diameter (2\*\ *R*\ ) 16 The well width $(\lambda)$ is defined as multiples of the particle diameter 17 $(2 R)$. 13 18 14 19 The interaction potential is: … … 29 34 used in the form factor $P(q)$ that this $S(q)$ is combined with. 30 35 31 For 2D data: The 2D scattering intensity is calculated in the same way as 1D, where the *q* vector is defined as 36 For 2D data: The 2D scattering intensity is calculated in the same way as 1D, 37 where the $q$ vector is defined as 32 38 33 39 .. math:: … … 130 136 # 131 137 tests = [ 132 [ {'scale': 1.0, 'background' : 0.0, 'radius_effective' : 50.0, 'volfraction' : 0.04,'welldepth' : 1.5, 'wellwidth' : 1.2, 133 'radius_effective_pd' : 0}, [0.001], [0.97665742]] 134 ] 138 [{'scale': 1.0, 'background' : 0.0, 'radius_effective' : 50.0, 139 'volfraction' : 0.04,'welldepth' : 1.5, 'wellwidth' : 1.2, 140 'radius_effective_pd' : 0}, 141 [0.001], [0.97665742]], 142 ] 135 143 # ADDED by: converting from sasview RKH ON: 16Mar2016 136 144 -
sasmodels/models/stacked_disks.py
r42356c8 r40a87fa 14 14 of the q vector which is defined as 15 15 16 .. math:: 17 18 q = \sqrt{q_x^2 + q_y^2} 16 .. math:: q = \sqrt{q_x^2 + q_y^2} 19 17 20 18 Definition … … 28 26 29 27 I(q) = N\int_{0}^{\pi /2}\left[ \Delta \rho_t 30 \left( V_t f_t(q) - V_cf_c(q)\right) + \Delta \rho_cV_cf_c(q)31 \right]^2 S(q)\sin{\alpha d\alpha} + background28 \left( V_t f_t(q) - V_c f_c(q)\right) + \Delta \rho_c V_c f_c(q) 29 \right]^2 S(q)\sin{\alpha}\ d\alpha + \text{background} 32 30 33 31 where the contrast … … 35 33 .. math:: 36 34 37 \Delta \rho_i = \rho_i - \rho_ {solvent}38 39 and *N*is the number of discs per unit volume,40 $\alpha$ is the angle between the axis of the disc and *q*,35 \Delta \rho_i = \rho_i - \rho_\text{solvent} 36 37 and $N$ is the number of discs per unit volume, 38 $\alpha$ is the angle between the axis of the disc and $q$, 41 39 and $V_t$ and $V_c$ are the total volume and the core volume of 42 40 a single disc, respectively. … … 46 44 \left\langle f_{t}^2(q)\right\rangle_{\alpha} = 47 45 \int_{0}^{\pi/2}\left[ 48 \left(\frac{ sin(q(d+h)\cos{\alpha})}{q(d+h)\cos{\alpha}}\right)46 \left(\frac{\sin(q(d+h)\cos{\alpha})}{q(d+h)\cos{\alpha}}\right) 49 47 \left(\frac{2J_1(qR\sin{\alpha})}{qR\sin{\alpha}} \right) 50 \right]^2 \sin{\alpha d\alpha}48 \right]^2 \sin{\alpha}\ d\alpha 51 49 52 50 \left\langle f_{c}^2(q)\right\rangle_{\alpha} = 53 51 \int_{0}^{\pi/2}\left[ 54 \left(\frac{ sin(qh)\cos{\alpha})}{qh\cos{\alpha}}\right)55 \left(\frac{2J_1(qR\sin{\alpha})}{qR\sin{\alpha}} 56 \right]^2 \sin{\alpha d\alpha}57 58 where *d* = thickness of the layer (layer_thick),59 *2h* = core thickness (core_thick), and *R* = radius of the disc (radius).52 \left(\frac{\sin(qh)\cos{\alpha})}{qh\cos{\alpha}}\right) 53 \left(\frac{2J_1(qR\sin{\alpha})}{qR\sin{\alpha}}\right) 54 \right]^2 \sin{\alpha}\ d\alpha 55 56 where $d$ = thickness of the layer (*layer_thick*), 57 $2h$ = core thickness (*core_thick*), and $R$ = radius of the disc (*radius*). 60 58 61 59 .. math:: 62 60 63 61 S(q) = 1 + \frac{1}{2}\sum_{k=1}^n(n-k)\cos{(kDq\cos{\alpha})} 64 exp\left[ -k(q\cos{\alpha})^2\sigma_D/2\right]65 66 where *n* = the total number of the disc stacked (n_stacking),67 *D* = 2*(*d*+*h*)the next neighbor center-to-center distance (d-spacing),68 and $\sigma_D$ = the Gaussian standard deviation of the d-spacing ( sigma_d).62 \exp\left[ -k(q\cos{\alpha})^2\sigma_D/2\right] 63 64 where $n$ is the total number of the disc stacked (*n_stacking*), 65 $D = 2(d+h)$ is the next neighbor center-to-center distance (d-spacing), 66 and $\sigma_D$ = the Gaussian standard deviation of the d-spacing (*sigma_d*). 69 67 70 68 .. note:: 71 Each assmebly in the stack is layer/core/layer, so the spacing of the cores72 is core plus two layers. The 2nd virial coefficient of the cylinder is73 calculated based on the74 *radius* and *length*= *n_stacking* * (*core_thick* + 2 * *layer_thick*)69 Each assmebly in the stack is layer/core/layer, so the spacing of the 70 cores is core plus two layers. The 2nd virial coefficient of the cylinder 71 is calculated based on the *radius* and *length* 72 = *n_stacking* * (*core_thick* + 2 * *layer_thick*) 75 73 values, and used as the effective radius for $S(Q)$ when $P(Q) * S(Q)$ 76 74 is applied. … … 94 92 ---------- 95 93 96 A Guinier and G Fournet, *Small-Angle Scattering of X-Rays*, John Wiley and Sons, New York, 1955 94 A Guinier and G Fournet, *Small-Angle Scattering of X-Rays*, 95 John Wiley and Sons, New York, 1955 97 96 98 97 O Kratky and G Porod, *J. Colloid Science*, 4, (1949) 35 99 98 100 J S Higgins and H C Benoit, *Polymers and Neutron Scattering*, Clarendon, Oxford, 1994 99 J S Higgins and H C Benoit, *Polymers and Neutron Scattering*, 100 Clarendon, Oxford, 1994 101 101 102 102 **Author:** NIST IGOR/DANSE **on:** pre 2010 -
sasmodels/models/star_polymer.py
rec45c4f r40a87fa 1 1 r""" 2 The Benoit model for a simple star polymer, with Gaussian coils arms from 2 The Benoit model for a simple star polymer, with Gaussian coils arms from 3 3 a common point. 4 4 … … 10 10 .. math:: 11 11 12 I(q) = \frac{2}{fv^2}\left[ v-1+ exp(-v)+\frac{f-1}{2}13 \left[ 1- exp(-v)\right]^2\right]12 I(q) = \frac{2}{fv^2}\left[ v-1+\exp(-v)+\frac{f-1}{2} 13 \left[ 1-\exp(-v)\right]^2\right] 14 14 15 15 where 16 16 17 .. math:: 18 19 v=\frac{u^2f}{(3f-2)} 17 .. math:: v=\frac{u^2f}{(3f-2)} 20 18 21 19 and 22 20 23 .. math:: 21 .. math:: u = \left\langle R_{g}^2\right\rangle q^2 24 22 25 u = \left\langle R_{g}^2\right\rangle q^2 26 27 contains the square of the ensemble average radius-of-gyration of an arm. Note that 28 when there is only one arm, $f$ = 1, the Debye Gaussian coil equation is recovered. 29 Star polymers in solutions tend to have strong interparticle and osmotic effects, so 30 the Benoit equation may not work well. At small q the Guinier term and hence I(q=0) 31 is the same as for $f$ arms of radius of gyration $R_g$, as described for the :ref:`mono_gauss_coil <mono-gauss-coil>`. 32 23 contains the square of the ensemble average radius-of-gyration of an arm. 24 Note that when there is only one arm, $f = 1$, the Debye Gaussian coil 25 equation is recovered. Star polymers in solutions tend to have strong 26 interparticle and osmotic effects, so the Benoit equation may not work well. 27 At small $q$ the Guinier term and hence $I(q=0)$ is the same as for $f$ arms 28 of radius of gyration $R_g$, as described for the :ref:`mono-gauss-coil` model. 33 29 34 30 References … … 36 32 37 33 H Benoit *J. Polymer Science*, 11, 596-599 (1953) 38 39 40 34 """ 41 35 -
sasmodels/models/stickyhardsphere.py
rd2bb604 r40a87fa 178 178 # 179 179 tests = [ 180 [ {'scale': 1.0, 'background' : 0.0, 'radius_effective' : 50.0, 'perturb' : 0.05, 'stickiness' : 0.2, 'volfraction' : 0.1,181 'radius_effective_pd' : 0}, [0.001, 0.003], [1.09718, 1.087830]]182 ]183 184 180 [{'scale': 1.0, 'background': 0.0, 'radius_effective': 50.0, 181 'perturb': 0.05, 'stickiness': 0.2, 'volfraction': 0.1, 182 'radius_effective_pd': 0}, 183 [0.001, 0.003], [1.09718, 1.087830]], 184 ] -
sasmodels/models/teubner_strey.py
r2c74c11 r40a87fa 47 47 48 48 import numpy as np 49 from numpy import inf , sqrt49 from numpy import inf 50 50 51 51 name = "teubner_strey" … … 58 58 category = "shape-independent" 59 59 60 # ["name", "units", default, [lower, upper], "type","description"], 61 parameters = [["a2", "", 0.1, [0, inf], "", 62 "a2"], 63 ["c1", "1e-6/Ang^2", -30., [-inf, 0], "", 64 "c1"], 65 ["c2", "Ang", 5000., [0, inf], "volume", 66 "c2"], 67 ] 68 60 # ["name", "units", default, [lower, upper], "type","description"], 61 parameters = [ 62 ["a2", "", 0.1, [0, inf], "", "a2"], 63 ["c1", "1e-6/Ang^2", -30., [-inf, 0], "", "c1"], 64 ["c2", "Ang", 5000., [0, inf], "volume", "c2"], 65 ] 69 66 70 67 def Iq(q, a2, c1, c2): 68 """SAS form""" 71 69 return 1. / np.polyval([c2, c1, a2], q**2) 72 70 Iq.vectorized = True # Iq accepts an array of q values -
sasmodels/models/two_power_law.py
r2c74c11 r40a87fa 14 14 where $q_c$ = the location of the crossover from one slope to the other, 15 15 $A$ = the scaling coefficent that sets the overall intensity of the lower Q 16 power law region, $m1$ = power law exponent at low Q, and $m2$ = power law 16 power law region, $m1$ = power law exponent at low Q, and $m2$ = power law 17 17 exponent at high Q. The scaling of the second power law region (coefficent C) 18 18 is then automatically scaled to match the first by following formula: … … 62 62 category = "shape-independent" 63 63 64 # ["name", "units", default, [lower, upper], "type", "description"], 65 parameters = [["coefficent_1", "", 1.0, [-inf, inf], "", 66 "coefficent A in low Q region"], 67 ["crossover", "1/Ang", 0.04,[0, inf], "", 68 "crossover location"], 69 ["power_1", "", 1.0, [0, inf], "", 70 "power law exponent at low Q"], 71 ["power_2", "", 4.0, [0, inf], "", 72 "power law exponent at high Q"], 73 ] 64 # pylint: disable=bad-whitespace, line-too-long 65 # ["name", "units", default, [lower, upper], "type", "description"], 66 parameters = [ 67 ["coefficent_1", "", 1.0, [-inf, inf], "", "coefficent A in low Q region"], 68 ["crossover", "1/Ang", 0.04,[0, inf], "", "crossover location"], 69 ["power_1", "", 1.0, [0, inf], "", "power law exponent at low Q"], 70 ["power_2", "", 4.0, [0, inf], "", "power law exponent at high Q"], 71 ] 72 # pylint: enable=bad-whitespace, line-too-long 74 73 75 74 … … 89 88 :return: Calculated intensity 90 89 """ 91 iq= empty(q.shape, 'd')92 i dx = (q <= crossover)90 result= empty(q.shape, 'd') 91 index = (q <= crossover) 93 92 with errstate(divide='ignore'): 94 93 coefficent_2 = coefficent_1 * power(crossover, power_2 - power_1) 95 iq[idx] = coefficent_1 * power(q[idx], -power_1)96 iq[~idx] = coefficent_2 * power(q[~idx], -power_2)97 return iq94 result[index] = coefficent_1 * power(q[index], -power_1) 95 result[~index] = coefficent_2 * power(q[~index], -power_2) 96 return result 98 97 99 98 Iq.vectorized = True # Iq accepts an array of q values -
sasmodels/models/unified_power_Rg.py
r785cbec r40a87fa 37 37 $q_i^*$ which is ignored here. 38 38 39 For example, to approximate the scattering from random coils (Debye _equation),39 For example, to approximate the scattering from random coils (Debye equation), 40 40 set $R_{gi}$ as the Guinier radius, $P_i = 2$, and $B_i = 2 G_i / R_{gi}$ 41 41 … … 65 65 from scipy.special import erf 66 66 67 category = "shape-independent" 68 69 # pylint: disable=bad-whitespace, line-too-long 67 70 parameters = [ 68 71 ["level", "", 1, [0, 6], "", "Level number"], … … 72 75 ["G[level]", "1/cm", 400, [0, inf], "", ""], 73 76 ] 74 category = "shape-independent" 77 # pylint: enable=bad-whitespace, line-too-long 75 78 76 79 def Iq(q, level, rg, power, B, G): … … 87 90 exp_next = exp(-(q*rg[i+1])**2/3.) if i < ilevel-1 else 1. 88 91 result += G[i]*exp_now + B[i]*exp_next*pow_now 89 result[q ==0] = np.sum(G[:ilevel])92 result[q == 0] = np.sum(G[:ilevel]) 90 93 return result 91 94
Note: See TracChangeset
for help on using the changeset viewer.