Changeset 513efc5 in sasmodels
- Timestamp:
- Jan 20, 2016 4:50:50 AM (9 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:
- 7ed702f
- Parents:
- 30b4ddf
- Location:
- sasmodels/models
- Files:
-
- 1 added
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/models/ellipsoid.c
r3f832f9 r513efc5 7 7 double _ellipsoid_kernel(double q, double rpolar, double requatorial, double sin_alpha) 8 8 { 9 double sn, cn;10 9 double ratio = rpolar/requatorial; 11 10 const double u = q*requatorial*sqrt(1.0 12 11 + sin_alpha*sin_alpha*(ratio*ratio - 1.0)); 13 SINCOS(u, sn, cn); 14 //const double f = ( u==0.0 ? 1.0 : 3.0*(sn-u*cn)/(u*u*u) ); 15 const double usq = u*u; 16 const double f = (u < 1.e-1) 17 ? 1.0 + usq*(-3./30. + usq*(3./840. + usq*(-3./45360.)))// + qrsq*(3./3991680.)))) 18 : 3.0*(sn/u - cn)/usq; 12 const double f = J1c(u); 13 19 14 return f*f; 20 15 } -
sasmodels/models/ellipsoid.py
rcade620 r513efc5 152 152 ] 153 153 154 source = ["lib/J1.c", "lib/ gauss76.c", "ellipsoid.c"]154 source = ["lib/J1.c", "lib/J1c.c", "lib/gauss76.c", "ellipsoid.c"] 155 155 156 156 def ER(rpolar, requatorial): -
sasmodels/models/gel_fit.py
r30b4ddf r513efc5 18 18 .. math:: 19 19 20 I(Q) = I(0)_L \frac{1}{\left( 1+\left[ ((D+1/3)Q^2a_{1}^2 \right]\right)^{D/2}} + I(0)_G exp\left( -Q^2a_{2}^2\right) + B 20 I(Q) = I(0)_L \frac{1}{\left( 1+\left[ ((D+1/3)Q^2a_{1}^2 21 \right]\right)^{D/2}} + I(0)_G exp\left( -Q^2a_{2}^2\right) + B 21 22 22 23 where … … 26 27 a_{2}^2 \approx \frac{R_{g}^2}{3} 27 28 28 Note that the first term reduces to the Ornstein-Zernicke equation when $D = 2$; 29 ie, when the Flory exponent is 0.5 (theta conditions). 30 In gels with significant hydrogen bonding $D$ has been reported to be ~2.6 to 2.8. 29 Note that the first term reduces to the Ornstein-Zernicke equation 30 when $D = 2$; ie, when the Flory exponent is 0.5 (theta conditions). 31 In gels with significant hydrogen bonding $D$ has been reported to be 32 ~2.6 to 2.8. 31 33 32 34 … … 38 40 --------- 39 41 40 Mitsuhiro Shibayama, Toyoichi Tanaka, Charles C Han, J. Chem. Phys. 1992, 97 (9), 6829-6841 42 Mitsuhiro Shibayama, Toyoichi Tanaka, Charles C Han, J. Chem. Phys. 1992, 97 (9), 43 6829-6841 41 44 42 Simon Mallam, Ferenc Horkay, Anne-Marie Hecht, Adrian R Rennie, Erik Geissler, Macromolecules 1991, 24, 543-548 45 Simon Mallam, Ferenc Horkay, Anne-Marie Hecht, Adrian R Rennie, Erik Geissler, 46 Macromolecules 1991, 24, 543-548 43 47 44 48 """ -
sasmodels/models/polymer_excl_volume.py
r23d3b41 r513efc5 1 1 r""" 2 This model describes the scattering from polymer chains subject to excluded volume effects3 and has been used as a template for describing mass fractals.2 This model describes the scattering from polymer chains subject to excluded 3 volume effects and has been used as a template for describing mass fractals. 4 4 5 5 Definition 6 6 ---------- 7 7 8 The form factor was originally presented in the following integral form (Benoit, 1957) 8 The form factor was originally presented in the following integral form 9 (Benoit, 1957) 9 10 10 11 .. math:: … … 16 17 $a$ is the statistical segment length of the polymer chain, 17 18 and $n$ is the degree of polymerization. 18 This integral was later put into an almost analytical form as follows (Hammouda, 1993) 19 This integral was later put into an almost analytical form as follows 20 (Hammouda, 1993) 19 21 20 22 .. math:: … … 43 45 Note that this model applies only in the mass fractal range (ie, $5/3<=m<=3$ ) 44 46 and **does not apply** to surface fractals ( $3<m<=4$ ). 45 It also does not reproduce the rigid rod limit (m=1) because it assumes chain flexibility 46 from the outset. It may cover a portion of the semi-flexible chain range ( $1<m<5/3$ ). 47 It also does not reproduce the rigid rod limit (m=1) because it assumes chain 48 flexibility from the outset. It may cover a portion of the semi-flexible chain 49 range ( $1<m<5/3$ ). 47 50 48 A low-Q expansion yields the Guinier form and a high-Q expansion yields the Porod form49 which is given by51 A low-Q expansion yields the Guinier form and a high-Q expansion yields the 52 Porod form which is given by 50 53 51 54 .. math:: 52 55 53 P(Q\rightarrow \infty) = \frac{1}{\nu U^{1/2\nu}}\Gamma\left(\frac{1}{2\nu}\right) - 54 \frac{1}{\nu U^{1/\nu}}\Gamma\left(\frac{1}{\nu}\right) 56 P(Q\rightarrow \infty) = \frac{1}{\nu U^{1/2\nu}}\Gamma\left( 57 \frac{1}{2\nu}\right) - \frac{1}{\nu U^{1/\nu}}\Gamma\left( 58 \frac{1}{\nu}\right) 55 59 56 60 Here $\Gamma(x) = \gamma(x,\infty)$ is the gamma function. … … 102 106 name = "polymer_excl_volume" 103 107 title = "Polymer Excluded Volume model" 104 description = """Compute the scattering intensity from polymers with excluded volume effects. 108 description = """Compute the scattering intensity from polymers with excluded 109 volume effects. 105 110 rg: radius of gyration 106 111 porod_exp: Porod exponent … … 127 132 128 133 intensity = ((1.0/(nu*power(u, o2nu))) * (gamma(o2nu)*gammainc(o2nu, u) - 129 1.0/power(u, o2nu) * gamma(porod_exp)*gammainc(porod_exp, u)))*(q > 0) + \130 1.0*(q <= 0)134 1.0/power(u, o2nu) * gamma(porod_exp) * 135 gammainc(porod_exp, u))) * (q > 0) + 1.0*(q <= 0) 131 136 132 137 return intensity … … 156 161 [{'rg': 2.2, 'porod_exp': 22.0, 'background': 100.0}, 5.0, 100.0], 157 162 158 [{'rg': 1.1, 'porod_exp': 1, 'background': 10.0, 'scale': 1.25}, 20000., 10.0000712097] 163 [{'rg': 1.1, 'porod_exp': 1, 'background': 10.0, 'scale': 1.25}, 164 20000., 10.0000712097] 159 165 ] -
sasmodels/models/sphere.py
rd53d3cd r513efc5 78 78 ] 79 79 80 source = ["lib/J1c.c"] 80 81 81 82 # No volume normalization despite having a volume parameter … … 87 88 Iq = """ 88 89 const double qr = q*radius; 89 const double qrsq = qr*qr; 90 double sn, cn; 91 SINCOS(qr, sn, cn); 92 // Use taylor series for low q to avoid cancellation error. Tested against 93 // the following expression in quad precision: 94 // 3.0*(sn-qr*cn)/(qr*qr*qr); 95 // Note that the values differ from sasview ~ 5e-12 rather than 5e-14, but 96 // in this case it is likely cancellation errors in the original expression 97 // using double precision that are the source. Single precision only 98 // requires the first 3 terms. Double precision requires the 4th term. 99 // The fifth term is not needed, and is commented out below. 100 const double bes = (qr < 1.e-1) 101 ? 1.0 + qrsq*(-3./30. + qrsq*(3./840. + qrsq*(-3./45360.)))// + qrsq*(3./3991680.)))) 102 : 3.0*(sn/qr - cn)/qrsq; 90 const double bes = J1c(qr); 103 91 const double fq = bes * (sld - solvent_sld) * form_volume(radius); 104 92 return 1.0e-4*fq*fq; -
sasmodels/models/surface_fractal.c
rda84551 r513efc5 1 1 double form_volume(double radius); 2 2 3 double Iq(double q, double radius, double surface_dim, double cutoff_length); 4 double Iqxy(double qx, double qy, double radius, double surface_dim, double cutoff_length); 3 double Iq(double q, 4 double radius, 5 double surface_dim, 6 double cutoff_length); 7 8 double Iqxy(double qx, double qy, 9 double radius, 10 double surface_dim, 11 double cutoff_length); 5 12 6 13 static double _gamln(double q) … … 26 33 } 27 34 28 static double surface_fractal_kernel(double q,35 static double _surface_fractal_kernel(double q, 29 36 double radius, 30 37 double surface_dim, … … 33 40 double pq, sq, mmo, result; 34 41 35 //calculate P(q) for the spherical subunits; not normalized 36 pq = pow((3.0*(sin(q*radius) - q*radius*cos(q*radius))/pow((q*radius),3)),2); 42 //Replaced the original formula with Taylor expansion near zero. 43 //pq = pow((3.0*(sin(q*radius) - q*radius*cos(q*radius))/pow((q*radius),3)),2); 44 45 pq = J1c(q*radius); 46 pq = pq*pq; 37 47 38 48 //calculate S(q) … … 59 69 ) 60 70 { 61 return surface_fractal_kernel(q, radius, surface_dim, cutoff_length);71 return _surface_fractal_kernel(q, radius, surface_dim, cutoff_length); 62 72 } 63 73 … … 69 79 { 70 80 double q = sqrt(qx*qx + qy*qy); 71 return surface_fractal_kernel(q, radius, surface_dim, cutoff_length);81 return _surface_fractal_kernel(q, radius, surface_dim, cutoff_length); 72 82 } 73 83 -
sasmodels/models/surface_fractal.py
r30b4ddf r513efc5 22 22 .. math:: 23 23 24 S(q) = \frac{\Gamma(5-D_S)\zeta^{5-D_S}}{\left[1+(q\zeta)^2\right]^{(5-D_S)/2}} 24 S(q) = \frac{\Gamma(5-D_S)\zeta^{5-D_S}}{\left[1+(q\zeta)^2 25 \right]^{(5-D_S)/2}} 25 26 \frac{sin\left[(D_S - 5) tan^{-1}(q\zeta) \right]}{q} 26 27 … … 33 34 V = \frac{4}{3}\pi R^3 34 35 35 where $R$ is the radius of the building block, $D_S$ is the **surface** fractal dimension, 36 $\zeta$ is the cut-off length, $\rho_{solvent}$ is the scattering length density of the solvent, 36 where $R$ is the radius of the building block, $D_S$ is the **surface** fractal 37 dimension,$\zeta$ is the cut-off length, $\rho_{solvent}$ is the scattering 38 length density of the solvent, 37 39 and $\rho_{particle}$ is the scattering length density of particles. 38 40 39 41 .. note:: 40 42 The surface fractal dimension $D_s$ is only valid if $1<surface\_dim<3$. 41 It is also only valid over a limited $q$ range (see the reference for details) 43 It is also only valid over a limited $q$ range (see the reference for 44 details) 42 45 43 46 … … 78 81 79 82 # ["name", "units", default, [lower, upper], "type","description"], 80 parameters = [["radius", "Ang", 10.0, [0, inf], "", "Particle radius"], 81 ["surface_dim", "", 2.0, [0, inf], "", "Surface fractal dimension"], 82 ["cutoff_length", "Ang", 500., [0.0, inf], "", "Cut-off Length"], 83 parameters = [["radius", "Ang", 10.0, [0, inf], "", 84 "Particle radius"], 85 ["surface_dim", "", 2.0, [0, inf], "", 86 "Surface fractal dimension"], 87 ["cutoff_length", "Ang", 500., [0.0, inf], "", 88 "Cut-off Length"], 83 89 ] 84 90 85 91 86 source = [" surface_fractal.c"]92 source = ["lib/J1c.c", "surface_fractal.c"] 87 93 88 94 demo = dict(scale=1, background=0, -
sasmodels/models/triaxial_ellipsoid.c
rd53d3cd r513efc5 36 36 const double y = 0.5*(Gauss76Z[j] + 1.0); 37 37 const double t = q*sqrt(acosx2 + bsinx2*(1.0-y*y) + c2*y*y); 38 SINCOS(t, st, ct); 39 //const double fq = ( t==0.0 ? 1.0 : 3.0*(st-t*ct)/(t*t*t) ); 40 const double tsq = t*t; 41 const double fq = (t < 1.e-1) 42 ? 1.0 + tsq*(-3./30. + tsq*(3./840. + tsq*(-3./45360.)))// + tsq*(3./3991680.)))) 43 : 3.0*(st/t - ct)/tsq; 38 const double fq = J1c(t); 44 39 inner += Gauss76Wt[j] * fq * fq ; 45 40 } -
sasmodels/models/triaxial_ellipsoid.py
reb69cce r513efc5 117 117 ] 118 118 119 source = ["lib/J1.c", "lib/ gauss76.c", "triaxial_ellipsoid.c"]119 source = ["lib/J1.c", "lib/J1c.c", "lib/gauss76.c", "triaxial_ellipsoid.c"] 120 120 121 121 def ER(req_minor, req_major, rpolar): -
sasmodels/models/two_lorentzian.py
r421e55c r513efc5 1 1 r""" 2 This model calculates an empirical functional form for SAS data characterized by two Lorentzian-type functions. 2 This model calculates an empirical functional form for SAS data characterized 3 by two Lorentzian-type functions. 3 4 4 5 Definition … … 12 13 13 14 where $A$ = Lorentzian scale factor #1, $C$ = Lorentzian scale #2, 14 $\xi_1$ and $\xi_2$ are the corresponding correlation lengths, and $n$ and $m$ are the respective 15 power law exponents (set $n = m = 2$ for Ornstein-Zernicke behaviour). 15 $\xi_1$ and $\xi_2$ are the corresponding correlation lengths, and $n$ and 16 $m$ are the respective power law exponents (set $n = m = 2$ for 17 Ornstein-Zernicke behaviour). 16 18 17 19 For 2D data the scattering intensity is calculated in the same way as 1D, … … 52 54 category = "shape-independent" 53 55 54 # ["name", "units", default, [lower, upper], "type", "description"], 55 parameters = [["lorentz_scale_1", "", 10.0, [-inf, inf], "", "First power law scale factor"], 56 ["lorentz_length_1", "Ang", 100.0, [-inf, inf], "", "First Lorentzian screening length"], 57 ["lorentz_exp_1", "", 3.0, [-inf, inf], "", "First exponent of power law"], 58 ["lorentz_scale_2", "", 1.0, [-inf, inf], "", "Second scale factor for broad Lorentzian peak"], 59 ["lorentz_length_2", "Ang", 10.0, [-inf, inf], "", "Second Lorentzian screening length"], 60 ["lorentz_exp_2", "", 2.0, [-inf, inf], "", "Second exponent of power law"], 56 # ["name", "units", default, [lower, upper], "type", "description"], 57 parameters = [["lorentz_scale_1", "", 10.0, [-inf, inf], "", 58 "First power law scale factor"], 59 ["lorentz_length_1", "Ang", 100.0, [-inf, inf], "", 60 "First Lorentzian screening length"], 61 ["lorentz_exp_1", "", 3.0, [-inf, inf], "", 62 "First exponent of power law"], 63 ["lorentz_scale_2", "", 1.0, [-inf, inf], "", 64 "Second scale factor for broad Lorentzian peak"], 65 ["lorentz_length_2", "Ang", 10.0, [-inf, inf], "", 66 "Second Lorentzian screening length"], 67 ["lorentz_exp_2", "", 2.0, [-inf, inf], "", 68 "Second exponent of power law"], 61 69 ] 62 70 63 71 64 def Iq(q, lorentz_scale_1, lorentz_length_1, lorentz_exp_1, lorentz_scale_2, lorentz_length_2, lorentz_exp_2): 72 def Iq(q, 73 lorentz_scale_1, 74 lorentz_length_1, 75 lorentz_exp_1, 76 lorentz_scale_2, 77 lorentz_length_2, 78 lorentz_exp_2): 65 79 66 80 """ … … 75 89 """ 76 90 77 intensity = lorentz_scale_1/(1.0 + power(q*lorentz_length_1, lorentz_exp_1)) 78 intensity += lorentz_scale_2/(1.0 + power(q*lorentz_length_2, lorentz_exp_2)) 91 intensity = lorentz_scale_1/(1.0 + 92 power(q*lorentz_length_1, lorentz_exp_1)) 93 intensity += lorentz_scale_2/(1.0 + 94 power(q*lorentz_length_2, lorentz_exp_2)) 79 95 80 96 return intensity … … 101 117 lorentz_exp_1='exponent_1', lorentz_exp_2='exponent_2') 102 118 103 tests = [[{'lorentz_scale_1': 10, 'lorentz_length_1': 100.0, 'lorentz_exp_1' : 3.0, 104 'lorentz_scale_2': 1, 'lorentz_length_2': 10.0, 'lorentz_exp_2' : 2.0, 119 tests = [[{'lorentz_scale_1': 10.0, 120 'lorentz_length_1': 100.0, 121 'lorentz_exp_1': 3.0, 122 'lorentz_scale_2': 1.0, 123 'lorentz_length_2': 10.0, 124 'lorentz_exp_2': 2.0, 105 125 }, 0.000332070182643, 10.9996228107], 106 126 107 [{'lorentz_scale_1': 0, 'lorentz_length_1': 0.0, 'lorentz_exp_1' : 0.0, 108 'lorentz_scale_2': 0, 'lorentz_length_2': 0.0, 'lorentz_exp_2' : 0.0, 109 'background':100. 127 [{'lorentz_scale_1': 0.0, 128 'lorentz_length_1': 0.0, 129 'lorentz_exp_1': 0.0, 130 'lorentz_scale_2': 0.0, 131 'lorentz_length_2': 0.0, 132 'lorentz_exp_2': 0.0, 133 'background': 100.0 110 134 }, 5.0, 100.0], 111 135 112 [{'lorentz_scale_1': 200, 'lorentz_length_1': 10.0, 'lorentz_exp_1' : 0.1, 113 'lorentz_scale_2': 0.1, 'lorentz_length_2': 5.0, 'lorentz_exp_2' : 2.0 136 [{'lorentz_scale_1': 200.0, 137 'lorentz_length_1': 10.0, 138 'lorentz_exp_1': 0.1, 139 'lorentz_scale_2': 0.1, 140 'lorentz_length_2': 5.0, 141 'lorentz_exp_2': 2.0 114 142 }, 20000., 45.5659201896], 115 143 ]
Note: See TracChangeset
for help on using the changeset viewer.