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