Changeset 8632a35 in sasmodels
- Timestamp:
- Feb 19, 2015 10:53:28 AM (10 years ago)
- Branches:
- master, core_shell_microgels, costrafo411, magnetic_model, release_v0.94, release_v0.95, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
- Children:
- 16bc3fc, 33d38d5
- Parents:
- 9c117a2 (diff), c9801b8 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent. - Files:
-
- 26 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
.gitignore
r8fff00e r946cdc8e 1 1 /build/ 2 2 /dist/ 3 /*.csv 3 4 *.pyc 4 5 *.cl -
sasmodels/bumps_model.py
r9c117a2 r8632a35 17 17 try: 18 18 from .kernelcl import load_model as _loader 19 except ImportError,exc:19 except RuntimeError,exc: 20 20 import warnings 21 21 warnings.warn(str(exc)) -
sasmodels/generate.py
r3271e20 rae7b97b 731 731 info['limits'] = dict((p[0],p[3]) for p in info['parameters']) 732 732 info['partype'] = categorize_parameters(info['parameters']) 733 info['defaults'] = dict((p[0],p[2]) for p in info['parameters']) 733 734 734 735 source = make_model(info) … … 757 758 print "time:",toc() 758 759 759 def demo(): 760 from .models import cylinder 761 source, info = make(cylinder) 762 #print doc(cylinder) 763 print source 760 def main(): 761 if len(sys.argv) <= 1: 762 print "usage: python -m sasmodels.generate modelname" 763 else: 764 name = sys.argv[1] 765 import sasmodels.models 766 __import__('sasmodels.models.'+name) 767 model = getattr(sasmodels.models, name) 768 source, info = make(model); print source 769 #print doc(model) 764 770 765 771 if __name__ == "__main__": 766 demo()772 main() -
sasmodels/kernelcl.py
r87fce00 r676351f 30 30 try: 31 31 import pyopencl as cl 32 except RuntimeError,exc:32 except ImportError,exc: 33 33 warnings.warn(str(exc)) 34 34 raise RuntimeError("OpenCL not available") 35 36 try: 37 context = cl.create_some_context(interactive=False) 38 del context 39 except cl.RuntimeError, exc: 40 warnings.warn(str(exc)) 41 raise RuntimeError("OpenCl not available") 35 42 36 43 from pyopencl import mem_flags as mf -
sasmodels/kerneldll.py
r87fce00 rafb2c78 24 24 #COMPILE = "cl /nologo /Ox /MD /W3 /GS- /DNDEBUG /Tp%(source)s /link /DLL /INCREMENTAL:NO /MANIFEST /OUT:%(output)s" 25 25 #COMPILE = "cl /nologo /Ox /MD /W3 /GS- /DNDEBUG /Tp%(source)s /openmp /link /DLL /INCREMENTAL:NO /MANIFEST /OUT:%(output)s" 26 COMPILE = "gcc -shared -fPIC -std=c99 -fopenmp -O2 -Wall %(source)s -o %(output)s -lm" 26 #COMPILE = "gcc -shared -fPIC -std=c99 -fopenmp -O2 -Wall %(source)s -o %(output)s -lm" 27 COMPILE = "gcc -shared -fPIC -std=c99 -O2 -Wall %(source)s -o %(output)s -lm" 27 28 else: 28 29 COMPILE = "cc -shared -fPIC -std=c99 -fopenmp -O2 -Wall %(source)s -o %(output)s -lm" -
sasmodels/models/bcc.py
rc95dc908 re166cb9 80 80 from numpy import pi, inf 81 81 82 name = " BCCparacrystal"82 name = "bcc_paracrystal" 83 83 title = "Body-centred cubic lattic with paracrystalline distortion" 84 84 description = """ -
sasmodels/models/fcc.c
r3271e20 re7b3d7b 5 5 double theta, double phi, double psi); 6 6 7 double _ BCC_Integrand(double q, double dnn, double d_factor, double theta, double phi);8 double _ BCCeval(double Theta, double Phi, double temp1, double temp3);7 double _FCC_Integrand(double q, double dnn, double d_factor, double theta, double phi); 8 double _FCCeval(double Theta, double Phi, double temp1, double temp3); 9 9 double _sphereform(double q, double radius, double sld, double solvent_sld); 10 10 11 11 12 double _ BCC_Integrand(double q, double dnn, double d_factor, double theta, double phi) {12 double _FCC_Integrand(double q, double dnn, double d_factor, double theta, double phi) { 13 13 14 14 const double Da = d_factor*dnn; … … 16 16 const double temp3 = q*dnn; 17 17 18 double retVal = _ BCCeval(theta,phi,temp1,temp3)/(4.0*M_PI);18 double retVal = _FCCeval(theta,phi,temp1,temp3)/(4.0*M_PI); 19 19 return(retVal); 20 20 } 21 21 22 double _ BCCeval(double Theta, double Phi, double temp1, double temp3) {22 double _FCCeval(double Theta, double Phi, double temp1, double temp3) { 23 23 24 24 double temp6,temp7,temp8,temp9,temp10; … … 26 26 27 27 temp6 = sin(Theta); 28 temp7 = sin(Theta)* cos(Phi)+sin(Theta)*sin(Phi)+cos(Theta);29 temp8 = -1.0*sin(Theta)*cos(Phi) -sin(Theta)*sin(Phi)+cos(Theta);30 temp9 = -1.0*sin(Theta)*cos(Phi)+sin(Theta)*sin(Phi) -cos(Theta);28 temp7 = sin(Theta)*sin(Phi)+cos(Theta); 29 temp8 = -1.0*sin(Theta)*cos(Phi)+cos(Theta); 30 temp9 = -1.0*sin(Theta)*cos(Phi)+sin(Theta)*sin(Phi); 31 31 temp10 = exp((-1.0/8.0)*temp1*((temp7*temp7)+(temp8*temp8)+(temp9*temp9))); 32 result = pow( 1.0-(temp10*temp10),3)*temp6/((1.0-2.0*temp10*cos(0.5*temp3*(temp7))+(temp10*temp10))*(1.0-2.0*temp10*cos(0.5*temp3*(temp8))+(temp10*temp10))*(1.0-2.0*temp10*cos(0.5*temp3*(temp9))+(temp10*temp10)));32 result = pow((1.0-(temp10*temp10)),3)*temp6/((1.0-2.0*temp10*cos(0.5*temp3*(temp7))+(temp10*temp10))*(1.0-2.0*temp10*cos(0.5*temp3*(temp8))+(temp10*temp10))*(1.0-2.0*temp10*cos(0.5*temp3*(temp9))+(temp10*temp10))); 33 33 34 34 return (result); … … 54 54 55 55 //Volume fraction calculated from lattice symmetry and sphere radius 56 const double s1 = dnn /sqrt(0.75);57 const double latticescale = 2.0*(4.0/3.0)*M_PI*(radius*radius*radius)/(s1*s1*s1);56 const double s1 = dnn*sqrt(2.0); 57 const double latticescale = 4.0*(4.0/3.0)*M_PI*(radius*radius*radius)/(s1*s1*s1); 58 58 59 59 const double va = 0.0; … … 71 71 //20 gauss points for the inner integral 72 72 double ztheta = ( Gauss150Z[j]*(vbj-vaj) + vaj + vbj )/2.0; //the inner dummy is theta 73 double yyy = Gauss150Wt[j] * _ BCC_Integrand(q,dnn,d_factor,ztheta,zphi);73 double yyy = Gauss150Wt[j] * _FCC_Integrand(q,dnn,d_factor,ztheta,zphi); 74 74 summj += yyy; 75 75 } … … 140 140 // The following test should always pass 141 141 if (fabs(cos_val_b3)>1.0) { 142 //printf(" bcc_ana_2D: Unexpected error: cos()>1\n");142 //printf("FCC_ana_2D: Unexpected error: cos()>1\n"); 143 143 cos_val_b3 = 1.0; 144 144 } 145 145 if (fabs(cos_val_b2)>1.0) { 146 //printf(" bcc_ana_2D: Unexpected error: cos()>1\n");146 //printf("FCC_ana_2D: Unexpected error: cos()>1\n"); 147 147 cos_val_b2 = 1.0; 148 148 } 149 149 if (fabs(cos_val_b1)>1.0) { 150 //printf(" bcc_ana_2D: Unexpected error: cos()>1\n");150 //printf("FCC_ana_2D: Unexpected error: cos()>1\n"); 151 151 cos_val_b1 = 1.0; 152 152 } -
sasmodels/models/fcc.py
r3271e20 re7b3d7b 1 # bcc paracrystal model1 #fcc paracrystal model 2 2 #note model title and parameter table are automatically inserted 3 3 #note - calculation requires double precision 4 """5 Calculates the scattering from a ** body-centered cubic lattice** with paracrystalline distortion. Thermal vibrations4 r""" 5 Calculates the scattering from a **face-centered cubic lattice** with paracrystalline distortion. Thermal vibrations 6 6 are considered to be negligible, and the size of the paracrystal is infinitely large. Paracrystalline distortion is 7 7 assumed to be isotropic and characterized by a Gaussian distribution. … … 14 14 The scattering intensity *I(q)* is calculated as 15 15 16 .. image:: img/image1 67.jpg16 .. image:: img/image158.jpg 17 17 18 18 where *scale* is the volume fraction of spheres, *Vp* is the volume of the primary particle, *V(lattice)* is a volume 19 19 correction for the crystal structure, *P(q)* is the form factor of the sphere (normalized), and *Z(q)* is the 20 paracrystalline structure factor for a body-centered cubic structure.20 paracrystalline structure factor for a face-centered cubic structure. 21 21 22 Equation (1) of the 1990 reference is used to calculate *Z(q)*, using equations (2 9)-(31) from the 1987 paper for22 Equation (1) of the 1990 reference is used to calculate *Z(q)*, using equations (23)-(25) from the 1987 paper for 23 23 *Z1*\ , *Z2*\ , and *Z3*\ . 24 24 25 The lattice correction (the occupied volume of the lattice) for a body-centered cubic structure of particles of radius25 The lattice correction (the occupied volume of the lattice) for a face-centered cubic structure of particles of radius 26 26 *R* and nearest neighbor separation *D* is 27 27 … … 34 34 where *g* is a fractional distortion based on the nearest neighbor distance. 35 35 36 The body-centered cubic lattice is36 The face-centered cubic lattice is 37 37 38 .. image:: img/image16 8.jpg38 .. image:: img/image161.jpg 39 39 40 40 For a crystal, diffraction peaks appear at reduced q-values given by … … 42 42 .. image:: img/image162.jpg 43 43 44 where for a body-centered cubic lattice, only reflections where (\ *h* + *k* + *l*\ ) = even are allowed and45 reflections where (\ *h* + *k* + *l*\ ) = oddare forbidden. Thus the peak positions correspond to (just the first 5)44 where for a face-centered cubic lattice *h*\ , *k*\ , *l* all odd or all even are allowed and reflections where 45 *h*\ , *k*\ , *l* are mixed odd/even are forbidden. Thus the peak positions correspond to (just the first 5) 46 46 47 .. image:: img/image16 9.jpg47 .. image:: img/image163.jpg 48 48 49 49 **NB: The calculation of** *Z(q)* **is a double numerical integral that must be carried out with a high density of** … … 52 52 makes a triple integral. Very, very slow. Go get lunch! 53 53 54 This example dataset is produced using 200 data points, *qmin* = 0.0 01 |Ang^-1|, *qmax* = 0.1 |Ang^-1| and the above54 This example dataset is produced using 200 data points, *qmin* = 0.01 |Ang^-1|, *qmax* = 0.1 |Ang^-1| and the above 55 55 default values. 56 56 57 .. image:: img/image1 70.jpg57 .. image:: img/image164.jpg 58 58 59 59 *Figure. 1D plot in the linear scale using the default values (w/200 data point).* … … 65 65 .. image:: img/image165.gif 66 66 67 .. image:: img/image1 71.jpg67 .. image:: img/image166.jpg 68 68 69 69 *Figure. 2D plot using the default values (w/200X200 pixels).* … … 80 80 from numpy import pi, inf 81 81 82 name = " BCCparacrystal"83 title = " Body-centred cubic lattic with paracrystalline distortion"82 name = "fcc_paracrystal" 83 title = "Face-centred cubic lattic with paracrystalline distortion" 84 84 description = """ 85 Calculates the scattering from a ** body-centered cubic lattice** with paracrystalline distortion. Thermal vibrations85 Calculates the scattering from a **face-centered cubic lattice** with paracrystalline distortion. Thermal vibrations 86 86 are considered to be negligible, and the size of the paracrystal is infinitely large. Paracrystalline distortion is 87 87 assumed to be isotropic and characterized by a Gaussian distribution. … … 100 100 ] 101 101 102 source = [ "lib/J1.c", "lib/gauss150.c", " bcc.c" ]102 source = [ "lib/J1.c", "lib/gauss150.c", "fcc.c" ] 103 103 104 104 def ER(radius, length): … … 119 119 # For testing against the old sasview models, include the converted parameter 120 120 # names and the target sasview model name. 121 oldname=' BCCrystalModel'121 oldname='FCCrystalModel' 122 122 oldpars=dict(sld='sldSph', 123 123 solvent_sld='sldSolv') -
example/sesansfit.py
r0ac3db5 r9c117a2 4 4 from sasmodels import bumps_model as sas 5 5 kernel = sas.load_model('sphere', dtype='single') 6 #kernel = sas.load_model('triaxial_ellipsoid', dtype='single') 6 7 7 8 … … 11 12 loader=Loader() 12 13 data=loader.load('testsasview1.ses') 14 data.x /=10 13 15 14 16 # data = load_sesans('mydatfile.pz') … … 20 22 err_data = np.ones_like(SElength)*0.03 21 23 24 class Sample: 25 zacceptance = 0.1 # [A^-1] 26 thickness = 0.2 # [cm] 27 22 28 class SESANSData1D: 23 29 #q_zmax = 0.23 # [A^-1] 24 zacceptance = 0.1 # [A^-1] 25 lam = 2e-10 # [m] 26 thickness = 0.2 # [cm] 30 lam = 0.2 # [nm] 27 31 x = SElength 28 32 y = data 29 33 dy = err_data 30 data = SesansData()31 print dir(data)34 sample = Sample() 35 data = SESANSData1D() 32 36 33 37 radius = 1000 34 38 data.Rmax = 3*radius # [A] 35 39 40 ## Sphere parameters 41 36 42 phi = Parameter(0.1, name="phi") 37 43 model = sas.BumpsModel(data, kernel, 38 44 scale=phi*(1-phi), sld=7.0, solvent_sld=1.0, radius=radius) 39 phi.pmp(10) 40 model.radius.pmp(40) 41 model.sld.pm(2) 42 model.background.range(0,5) 43 45 phi.range(0.001,0.90) 46 #model.radius.pmp(40) 47 model.radius.range(100,10000) 48 #model.sld.pmp(5) 49 #model.background 50 #model.radius_pd=0 51 #model.radius_pd_n=0 44 52 45 53 if False: # have sans data … … 49 57 problem = FitProblem(model) 50 58 59 60 ### Tri-Axial Ellipsoid 61 # 62 #phi = Parameter(0.1, name='phi') 63 #model = sas.BumpsModel(data, kernel, 64 # scale=phi*(1-phi), sld=7.0, solvent_sld=1.0, radius=radius) 65 #phi.range(0.001,0.90) 66 ##model.radius.pmp(40) 67 #model.radius.range(100,10000) 68 ##model.sld.pmp(5) 69 ##model.background 70 ##model.radius_pd=0 71 ##model.radius_pd_n=0 72 # 73 #if False: # have sans data 74 # sansmodel = sas.BumpsModel(sans_data, kernel, **model.parameters()) 75 # problem = FitProblem([model, sansmodel]) 76 #else: 77 # problem = FitProblem(model)
Note: See TracChangeset
for help on using the changeset viewer.