1 | # -*- coding: utf-8 -*- |
---|
2 | ########### SVN repository information ################### |
---|
3 | # $Date: 2012-02-13 11:33:35 -0600 (Mon, 13 Feb 2012) $ |
---|
4 | # $Author: vondreele & toby $ |
---|
5 | # $Revision: 482 $ |
---|
6 | # $URL: https://subversion.xor.aps.anl.gov/pyGSAS/trunk/G2importphase.py $ |
---|
7 | # $Id: G2importphase.py 482 2012-02-13 17:33:35Z vondreele $ |
---|
8 | ########### SVN repository information ################### |
---|
9 | # short routines to read in structure factors from simple file formats |
---|
10 | # |
---|
11 | import sys |
---|
12 | import numpy as np |
---|
13 | import GSASIIIO as G2IO |
---|
14 | |
---|
15 | class HKLF_ReaderClass(G2IO.ImportStructFactor): |
---|
16 | 'Routines to import F, sig(F) reflections from a HKLF file' |
---|
17 | def __init__(self): |
---|
18 | super(self.__class__,self).__init__( # fancy way to self-reference |
---|
19 | extensionlist=('.hkl','.HKL'), |
---|
20 | strictExtension=False, |
---|
21 | formatName = 'F HKL', |
---|
22 | longFormatName = 'Simple (hkl Fo sig(Fo)) Structure factor text file' |
---|
23 | ) |
---|
24 | # Validate the contents |
---|
25 | def ContentsValidator(self, filepointer): |
---|
26 | S = filepointer.readline() |
---|
27 | while '#' in S[0]: #get past comments, if any |
---|
28 | S = filepointer.readline() |
---|
29 | for i in range(3): # scan a few lines |
---|
30 | S = S.split() |
---|
31 | if len(S) != 5: return False |
---|
32 | for v in S: |
---|
33 | try: |
---|
34 | float(v) |
---|
35 | except ValueError: |
---|
36 | return False |
---|
37 | S = filepointer.readline() |
---|
38 | return True |
---|
39 | |
---|
40 | def Reader(self,filename,filepointer, ParentFrame=None, **unused): |
---|
41 | try: |
---|
42 | for S in filepointer: |
---|
43 | if S[0] == '#': continue #ignore comments, if any |
---|
44 | h,k,l,Fo,sigFo = S.split() |
---|
45 | h,k,l = [int(h),int(k),int(l)] |
---|
46 | if not any([h,k,l]): |
---|
47 | break |
---|
48 | Fo = float(Fo) |
---|
49 | sigFo = float(sigFo) |
---|
50 | # h,k,l,m,dsp,Fo2,sig,Fc2,Fot2,Fct2,phase,... |
---|
51 | self.RefList.append([h,k,l,0,0,Fo**2,2.*Fo*sigFo,0,Fo**2,0,0,[],[],0,{}]) |
---|
52 | self.UpdateControls(Type='Fosq',FcalcPresent=False) # set Fobs type & if Fcalc values are loaded |
---|
53 | self.UpdateParameters(Type='SXC',Wave=None) # histogram type |
---|
54 | return True |
---|
55 | except Exception as detail: |
---|
56 | print self.formatName+' read error:'+str(detail) # for testing |
---|
57 | import traceback |
---|
58 | traceback.print_exc(file=sys.stdout) |
---|
59 | return False |
---|
60 | |
---|
61 | class HKLF2_ReaderClass(G2IO.ImportStructFactor): |
---|
62 | 'Routines to import F**2, sig(F**2) reflections from a HKLF file' |
---|
63 | def __init__(self): |
---|
64 | super(self.__class__,self).__init__( # fancy way to self-reference |
---|
65 | extensionlist=('.hkl','.HKL'), |
---|
66 | strictExtension=False, |
---|
67 | formatName = 'F**2 HKL', |
---|
68 | longFormatName = 'Simple (hkl Fo**2 sig(Fo**2)) Structure factor text file' |
---|
69 | ) |
---|
70 | # Validate the contents |
---|
71 | def ContentsValidator(self, filepointer): |
---|
72 | S = filepointer.readline() |
---|
73 | while '#' in S[0]: #get past comments, if any |
---|
74 | S = filepointer.readline() |
---|
75 | for i in range(3): # scan a few lines |
---|
76 | S = S.split() |
---|
77 | if len(S) != 5: return False |
---|
78 | for v in S: |
---|
79 | try: |
---|
80 | float(v) |
---|
81 | except ValueError: |
---|
82 | return False |
---|
83 | S = filepointer.readline() |
---|
84 | return True |
---|
85 | |
---|
86 | def Reader(self,filename,filepointer, ParentFrame=None, **unused): |
---|
87 | try: |
---|
88 | for S in filepointer: |
---|
89 | if S[0] == '#': continue #ignore comments, if any |
---|
90 | h,k,l,Fo,sigFo = S.split() |
---|
91 | h,k,l = [int(h),int(k),int(l)] |
---|
92 | if not any([h,k,l]): |
---|
93 | break |
---|
94 | Fo = float(Fo) |
---|
95 | sigFo = float(sigFo) |
---|
96 | # h,k,l,m,dsp,Fo2,sig,Fc2,Fot2,Fct2,phase,... |
---|
97 | self.RefList.append([h,k,l,0,0,Fo,sigFo,0,Fo,0,0,[],[],0,{}]) |
---|
98 | self.UpdateControls(Type='Fosq',FcalcPresent=False) # set Fobs type & if Fcalc values are loaded |
---|
99 | self.UpdateParameters(Type='SXC',Wave=None) # histogram type |
---|
100 | return True |
---|
101 | except Exception as detail: |
---|
102 | print self.formatName+' read error:'+str(detail) # for testing |
---|
103 | import traceback |
---|
104 | traceback.print_exc(file=sys.stdout) |
---|
105 | return False |
---|