Changeset 6530963 in sasmodels
- Timestamp:
- Sep 9, 2018 6:46:10 AM (6 years ago)
- Branches:
- ticket_1156
- Children:
- 78f8308
- Parents:
- 2c12061
- Location:
- sasmodels/models
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/models/bcc_paracrystal.c
r108e70e r6530963 1 1 static double 2 bcc_Zq(double qa, double qb, double qc, double dnn, double d_factor)2 bcc_Zq(double qa, double qb, double qc, double lattice_spacing, double lattice_distortion) 3 3 { 4 4 // Equations from Matsuoka 26-27-28, multiplied by |q| … … 17 17 // => exp(a)^2 - 2 cos(d ak) exp(a) + 1) 18 18 // => (exp(a) - 2 cos(d ak)) * exp(a) + 1 19 const double arg = -0.5*square( dnn*d_factor)*(a1*a1 + a2*a2 + a3*a3);19 const double arg = -0.5*square(lattice_spacing*lattice_distortion)*(a1*a1 + a2*a2 + a3*a3); 20 20 const double exp_arg = exp(arg); 21 21 const double Zq = -cube(expm1(2.0*arg)) 22 / ( ((exp_arg - 2.0*cos( dnn*a1))*exp_arg + 1.0)23 * ((exp_arg - 2.0*cos( dnn*a2))*exp_arg + 1.0)24 * ((exp_arg - 2.0*cos( dnn*a3))*exp_arg + 1.0));22 / ( ((exp_arg - 2.0*cos(lattice_spacing*a1))*exp_arg + 1.0) 23 * ((exp_arg - 2.0*cos(lattice_spacing*a2))*exp_arg + 1.0) 24 * ((exp_arg - 2.0*cos(lattice_spacing*a3))*exp_arg + 1.0)); 25 25 26 26 #elif 0 … … 36 36 // = tanh(-a) / [1 - cos(d a_k)/cosh(-a)] 37 37 // 38 const double arg = 0.5*square( dnn*d_factor)*(a1*a1 + a2*a2 + a3*a3);38 const double arg = 0.5*square(lattice_spacing*lattice_distortion)*(a1*a1 + a2*a2 + a3*a3); 39 39 const double sinh_qd = sinh(arg); 40 40 const double cosh_qd = cosh(arg); 41 const double Zq = sinh_qd/(cosh_qd - cos( dnn*a1))42 * sinh_qd/(cosh_qd - cos( dnn*a2))43 * sinh_qd/(cosh_qd - cos( dnn*a3));41 const double Zq = sinh_qd/(cosh_qd - cos(lattice_spacing*a1)) 42 * sinh_qd/(cosh_qd - cos(lattice_spacing*a2)) 43 * sinh_qd/(cosh_qd - cos(lattice_spacing*a3)); 44 44 #else 45 const double arg = 0.5*square( dnn*d_factor)*(a1*a1 + a2*a2 + a3*a3);45 const double arg = 0.5*square(lattice_spacing*lattice_distortion)*(a1*a1 + a2*a2 + a3*a3); 46 46 const double tanh_qd = tanh(arg); 47 47 const double cosh_qd = cosh(arg); 48 const double Zq = tanh_qd/(1.0 - cos( dnn*a1)/cosh_qd)49 * tanh_qd/(1.0 - cos( dnn*a2)/cosh_qd)50 * tanh_qd/(1.0 - cos( dnn*a3)/cosh_qd);48 const double Zq = tanh_qd/(1.0 - cos(lattice_spacing*a1)/cosh_qd) 49 * tanh_qd/(1.0 - cos(lattice_spacing*a2)/cosh_qd) 50 * tanh_qd/(1.0 - cos(lattice_spacing*a3)/cosh_qd); 51 51 #endif 52 52 … … 57 57 // occupied volume fraction calculated from lattice symmetry and sphere radius 58 58 static double 59 bcc_volume_fraction(double radius, double dnn)59 bcc_volume_fraction(double radius, double lattice_spacing) 60 60 { 61 return 2.0*sphere_volume(sqrt(0.75)*radius/ dnn);61 return 2.0*sphere_volume(sqrt(0.75)*radius/lattice_spacing); 62 62 } 63 63 … … 69 69 70 70 71 static double Iq(double q, double dnn,72 double d_factor, double radius,71 static double Iq(double q, double lattice_spacing, 72 double lattice_distortion, double radius, 73 73 double sld, double solvent_sld) 74 74 { … … 94 94 const double qa = qab*cos_phi; 95 95 const double qb = qab*sin_phi; 96 const double form = bcc_Zq(qa, qb, qc, dnn, d_factor);96 const double form = bcc_Zq(qa, qb, qc, lattice_spacing, lattice_distortion); 97 97 inner_sum += GAUSS_W[j] * form; 98 98 } … … 103 103 const double Zq = outer_sum/(4.0*M_PI); 104 104 const double Pq = sphere_form(q, radius, sld, solvent_sld); 105 return bcc_volume_fraction(radius, dnn) * Pq * Zq;105 return bcc_volume_fraction(radius, lattice_spacing) * Pq * Zq; 106 106 } 107 107 108 108 109 109 static double Iqabc(double qa, double qb, double qc, 110 double dnn, double d_factor, double radius,110 double lattice_spacing, double lattice_distortion, double radius, 111 111 double sld, double solvent_sld) 112 112 { 113 113 const double q = sqrt(qa*qa + qb*qb + qc*qc); 114 const double Zq = bcc_Zq(qa, qb, qc, dnn, d_factor);114 const double Zq = bcc_Zq(qa, qb, qc, lattice_spacing, lattice_distortion); 115 115 const double Pq = sphere_form(q, radius, sld, solvent_sld); 116 return bcc_volume_fraction(radius, dnn) * Pq * Zq;116 return bcc_volume_fraction(radius, lattice_spacing) * Pq * Zq; 117 117 } -
sasmodels/models/bcc_paracrystal.py
r2d81cfe r6530963 123 123 # pylint: disable=bad-whitespace, line-too-long 124 124 # ["name", "units", default, [lower, upper], "type","description" ], 125 parameters = [[" dnn", "Ang", 220, [-inf, inf], "", "Nearest neighbour distance"],126 [" d_factor", "", 0.06, [-inf, inf], "", "Paracrystal distortion factor"],125 parameters = [["lattice_spacing", "Ang", 220, [-inf, inf], "", "Lattice spacing"], 126 ["lattice_distortion", "", 0.06, [-inf, inf], "", "Paracrystal distortion factor"], 127 127 ["radius", "Ang", 40, [0, inf], "volume", "Particle radius"], 128 128 ["sld", "1e-6/Ang^2", 4, [-inf, inf], "sld", "Particle scattering length density"], … … 145 145 # in this range 'cuz its easy. 146 146 radius = 10**np.random.uniform(1.3, 4) 147 d_factor= 10**np.random.uniform(-2, -0.7) # sigma_d in 0.01-0.7148 dnn_fraction = np.random.beta(a=10, b=1)149 dnn = radius*4/np.sqrt(3)/dnn_fraction147 lattice_distortion = 10**np.random.uniform(-2, -0.7) # sigma_d in 0.01-0.7 148 lattice_spacing_fraction = np.random.beta(a=10, b=1) 149 lattice_spacing = radius*4/np.sqrt(3)/lattice_spacing_fraction 150 150 pars = dict( 151 151 #sld=1, sld_solvent=0, scale=1, background=1e-32, 152 dnn=dnn,153 d_factor=d_factor,152 lattice_spacing=lattice_spacing, 153 lattice_distortion=lattice_distortion, 154 154 radius=radius, 155 155 ) -
sasmodels/models/fcc_paracrystal.c
r108e70e r6530963 1 1 static double 2 fcc_Zq(double qa, double qb, double qc, double dnn, double d_factor)2 fcc_Zq(double qa, double qb, double qc, double lattice_spacing, double lattice_distortion) 3 3 { 4 4 // Equations from Matsuoka 17-18-19, multiplied by |q| … … 16 16 // => exp(a)^2 - 2 cos(d ak) exp(a) + 1) 17 17 // => (exp(a) - 2 cos(d ak)) * exp(a) + 1 18 const double arg = -0.5*square( dnn*d_factor)*(a1*a1 + a2*a2 + a3*a3);18 const double arg = -0.5*square(lattice_spacing*lattice_distortion)*(a1*a1 + a2*a2 + a3*a3); 19 19 const double exp_arg = exp(arg); 20 20 const double Zq = -cube(expm1(2.0*arg)) 21 / ( ((exp_arg - 2.0*cos( dnn*a1))*exp_arg + 1.0)22 * ((exp_arg - 2.0*cos( dnn*a2))*exp_arg + 1.0)23 * ((exp_arg - 2.0*cos( dnn*a3))*exp_arg + 1.0));21 / ( ((exp_arg - 2.0*cos(lattice_spacing*a1))*exp_arg + 1.0) 22 * ((exp_arg - 2.0*cos(lattice_spacing*a2))*exp_arg + 1.0) 23 * ((exp_arg - 2.0*cos(lattice_spacing*a3))*exp_arg + 1.0)); 24 24 25 25 return Zq; … … 29 29 // occupied volume fraction calculated from lattice symmetry and sphere radius 30 30 static double 31 fcc_volume_fraction(double radius, double dnn)31 fcc_volume_fraction(double radius, double lattice_spacing) 32 32 { 33 return 4.0*sphere_volume(M_SQRT1_2*radius/ dnn);33 return 4.0*sphere_volume(M_SQRT1_2*radius/lattice_spacing); 34 34 } 35 35 … … 41 41 42 42 43 static double Iq(double q, double dnn,44 double d_factor, double radius,43 static double Iq(double q, double lattice_spacing, 44 double lattice_distortion, double radius, 45 45 double sld, double solvent_sld) 46 46 { … … 66 66 const double qa = qab*cos_phi; 67 67 const double qb = qab*sin_phi; 68 const double form = fcc_Zq(qa, qb, qc, dnn, d_factor);68 const double form = fcc_Zq(qa, qb, qc, lattice_spacing, lattice_distortion); 69 69 inner_sum += GAUSS_W[j] * form; 70 70 } … … 76 76 const double Pq = sphere_form(q, radius, sld, solvent_sld); 77 77 78 return fcc_volume_fraction(radius, dnn) * Pq * Zq;78 return fcc_volume_fraction(radius, lattice_spacing) * Pq * Zq; 79 79 } 80 80 81 81 82 82 static double Iqabc(double qa, double qb, double qc, 83 double dnn, double d_factor, double radius,83 double lattice_spacing, double lattice_distortion, double radius, 84 84 double sld, double solvent_sld) 85 85 { 86 86 const double q = sqrt(qa*qa + qb*qb + qc*qc); 87 87 const double Pq = sphere_form(q, radius, sld, solvent_sld); 88 const double Zq = fcc_Zq(qa, qb, qc, dnn, d_factor);89 return fcc_volume_fraction(radius, dnn) * Pq * Zq;88 const double Zq = fcc_Zq(qa, qb, qc, lattice_spacing, lattice_distortion); 89 return fcc_volume_fraction(radius, lattice_spacing) * Pq * Zq; 90 90 } -
sasmodels/models/fcc_paracrystal.py
r2d81cfe r6530963 111 111 # pylint: disable=bad-whitespace, line-too-long 112 112 # ["name", "units", default, [lower, upper], "type","description"], 113 parameters = [[" dnn", "Ang", 220, [-inf, inf], "", "Nearest neighbour distance"],114 [" d_factor", "", 0.06, [-inf, inf], "", "Paracrystal distortion factor"],113 parameters = [["lattice_spacing", "Ang", 220, [-inf, inf], "", "Lattice spacing"], 114 ["lattice_distortion", "", 0.06, [-inf, inf], "", "Paracrystal distortion factor"], 115 115 ["radius", "Ang", 40, [0, inf], "volume", "Particle radius"], 116 116 ["sld", "1e-6/Ang^2", 4, [-inf, inf], "sld", "Particle scattering length density"], … … 127 127 # copied from bcc_paracrystal 128 128 radius = 10**np.random.uniform(1.3, 4) 129 d_factor= 10**np.random.uniform(-2, -0.7) # sigma_d in 0.01-0.7130 dnn_fraction = np.random.beta(a=10, b=1)131 dnn = radius*4/np.sqrt(2)/dnn_fraction129 lattice_distortion = 10**np.random.uniform(-2, -0.7) # sigma_d in 0.01-0.7 130 lattice_spacing_fraction = np.random.beta(a=10, b=1) 131 lattice_spacing = radius*4/np.sqrt(2)/lattice_spacing_fraction 132 132 pars = dict( 133 133 #sld=1, sld_solvent=0, scale=1, background=1e-32, 134 dnn=dnn,135 d_factor=d_factor,134 latice_spacing=lattice_spacing, 135 lattice_distortion=d_factor, 136 136 radius=radius, 137 137 ) -
sasmodels/models/sc_paracrystal.c
r108e70e r6530963 1 1 static double 2 sc_Zq(double qa, double qb, double qc, double dnn, double d_factor)2 sc_Zq(double qa, double qb, double qc, double lattice_spacing, double lattice_distortion) 3 3 { 4 4 // Equations from Matsuoka 9-10-11, multiplied by |q| … … 16 16 // => exp(a)^2 - 2 cos(d ak) exp(a) + 1) 17 17 // => (exp(a) - 2 cos(d ak)) * exp(a) + 1 18 const double arg = -0.5*square( dnn*d_factor)*(a1*a1 + a2*a2 + a3*a3);18 const double arg = -0.5*square(lattice_spacing*lattice_distortion)*(a1*a1 + a2*a2 + a3*a3); 19 19 const double exp_arg = exp(arg); 20 20 const double Zq = -cube(expm1(2.0*arg)) 21 / ( ((exp_arg - 2.0*cos( dnn*a1))*exp_arg + 1.0)22 * ((exp_arg - 2.0*cos( dnn*a2))*exp_arg + 1.0)23 * ((exp_arg - 2.0*cos( dnn*a3))*exp_arg + 1.0));21 / ( ((exp_arg - 2.0*cos(lattice_spacing*a1))*exp_arg + 1.0) 22 * ((exp_arg - 2.0*cos(lattice_spacing*a2))*exp_arg + 1.0) 23 * ((exp_arg - 2.0*cos(lattice_spacing*a3))*exp_arg + 1.0)); 24 24 25 25 return Zq; … … 28 28 // occupied volume fraction calculated from lattice symmetry and sphere radius 29 29 static double 30 sc_volume_fraction(double radius, double dnn)30 sc_volume_fraction(double radius, double lattice_spacing) 31 31 { 32 return sphere_volume(radius/ dnn);32 return sphere_volume(radius/lattice_spacing); 33 33 } 34 34 … … 41 41 42 42 static double 43 Iq(double q, double dnn,44 double d_factor, double radius,43 Iq(double q, double lattice_spacing, 44 double lattice_distortion, double radius, 45 45 double sld, double solvent_sld) 46 46 { … … 67 67 const double qa = qab*cos_phi; 68 68 const double qb = qab*sin_phi; 69 const double form = sc_Zq(qa, qb, qc, dnn, d_factor);69 const double form = sc_Zq(qa, qb, qc, lattice_spacing, lattice_distortion); 70 70 inner_sum += GAUSS_W[j] * form; 71 71 } … … 77 77 const double Pq = sphere_form(q, radius, sld, solvent_sld); 78 78 79 return sc_volume_fraction(radius, dnn) * Pq * Zq;79 return sc_volume_fraction(radius, lattice_spacing) * Pq * Zq; 80 80 } 81 81 … … 83 83 static double 84 84 Iqabc(double qa, double qb, double qc, 85 double dnn, double d_factor, double radius,85 double lattice_spacing, double lattice_distortion, double radius, 86 86 double sld, double solvent_sld) 87 87 { 88 88 const double q = sqrt(qa*qa + qb*qb + qc*qc); 89 89 const double Pq = sphere_form(q, radius, sld, solvent_sld); 90 const double Zq = sc_Zq(qa, qb, qc, dnn, d_factor);91 return sc_volume_fraction(radius, dnn) * Pq * Zq;90 const double Zq = sc_Zq(qa, qb, qc, lattice_spacing, lattice_distortion); 91 return sc_volume_fraction(radius, lattice_spacing) * Pq * Zq; 92 92 } -
sasmodels/models/sc_paracrystal.py
r2d81cfe r6530963 116 116 scale: volume fraction of spheres 117 117 bkg:background, R: radius of sphere 118 dnn: Nearest neighbor distance119 d_factor: Paracrystal distortion factor118 lattice_spacing: Nearest neighbor distance 119 lattice_distortion: Paracrystal distortion factor 120 120 radius: radius of the spheres 121 121 sldSph: SLD of the sphere … … 126 126 # pylint: disable=bad-whitespace, line-too-long 127 127 # ["name", "units", default, [lower, upper], "type","description"], 128 parameters = [[" dnn", "Ang", 220.0, [0.0, inf], "", "Nearest neighbor distance"],129 [" d_factor", "", 0.06, [-inf, inf], "","Paracrystal distortion factor"],128 parameters = [["lattice_spacing", "Ang", 220.0, [0.0, inf], "", "Lattice spacing"], 129 ["lattice_distortion", "", 0.06, [-inf, inf], "", "Paracrystal distortion factor"], 130 130 ["radius", "Ang", 40.0, [0.0, inf], "volume", "Radius of sphere"], 131 131 ["sld", "1e-6/Ang^2", 3.0, [0.0, inf], "sld", "Sphere scattering length density"], … … 142 142 # copied from bcc_paracrystal 143 143 radius = 10**np.random.uniform(1.3, 4) 144 d_factor= 10**np.random.uniform(-2, -0.7) # sigma_d in 0.01-0.7145 dnn_fraction = np.random.beta(a=10, b=1)146 dnn = radius*4/np.sqrt(4)/dnn_fraction144 lattice_distortion = 10**np.random.uniform(-2, -0.7) # sigma_d in 0.01-0.7 145 lattice_spacing_fraction = np.random.beta(a=10, b=1) 146 lattice_spacing = radius*4/np.sqrt(4)/lattice_spacing_fraction 147 147 pars = dict( 148 148 #sld=1, sld_solvent=0, scale=1, background=1e-32, 149 dnn=dnn,150 d_factor=d_factor,149 lattice_spacing=lattice_spacing, 150 lattice_distortion=lattice_distortion, 151 151 radius=radius, 152 152 )
Note: See TracChangeset
for help on using the changeset viewer.