1 | # -*- coding: utf-8 -*- |
---|
2 | ########### SVN repository information ################### |
---|
3 | # $Date: 2021-03-24 23:16:47 +0000 (Wed, 24 Mar 2021) $ |
---|
4 | # $Author: vondreele $ |
---|
5 | # $Revision: 4866 $ |
---|
6 | # $URL: trunk/imports/G2sfact.py $ |
---|
7 | # $Id: G2sfact.py 4866 2021-03-24 23:16:47Z vondreele $ |
---|
8 | ########### SVN repository information ################### |
---|
9 | ''' |
---|
10 | *Module G2sfact: simple HKL import* |
---|
11 | ----------------------------------- |
---|
12 | Read structure factors from a simple hkl file. Two routines are |
---|
13 | provided to read from files containing F or F\ :sup:`2` values. |
---|
14 | |
---|
15 | ''' |
---|
16 | from __future__ import division, print_function |
---|
17 | import sys |
---|
18 | import numpy as np |
---|
19 | import GSASIIobj as G2obj |
---|
20 | import GSASIIpath |
---|
21 | GSASIIpath.SetVersionNumber("$Revision: 4866 $") |
---|
22 | |
---|
23 | def ColumnValidator(parent, filepointer,nCol=5): |
---|
24 | 'Validate a file to check that it contains columns of numbers' |
---|
25 | l = filepointer.readline() |
---|
26 | line = 1 |
---|
27 | while l[0] in ['#','(']: #get past comments & fortran formats, if any |
---|
28 | l = filepointer.readline() |
---|
29 | line += 1 |
---|
30 | for i in range(10): # scan a few lines |
---|
31 | S = l.split() |
---|
32 | if len(S) < nCol: |
---|
33 | parent.errors = 'line '+str(line)+': invalid input\n'+l |
---|
34 | return False |
---|
35 | for v in S[:nCol]: |
---|
36 | try: |
---|
37 | float(v) |
---|
38 | except ValueError: |
---|
39 | parent.errors = 'line '+str(line)+': string found where a number is expected\n'+l |
---|
40 | return False |
---|
41 | l = filepointer.readline() |
---|
42 | line += 1 |
---|
43 | return True |
---|
44 | |
---|
45 | |
---|
46 | class HKLF_ReaderClass(G2obj.ImportStructFactor): |
---|
47 | 'Routines to import F, sig(F) reflections from a HKLF file' |
---|
48 | def __init__(self): |
---|
49 | super(self.__class__,self).__init__( # fancy way to self-reference |
---|
50 | extensionlist=('.hkl','.HKL'), |
---|
51 | strictExtension=False, |
---|
52 | formatName = 'HKL F', |
---|
53 | longFormatName = 'Simple [hkl, Fo, sig(Fo)] Structure factor text file' |
---|
54 | ) |
---|
55 | |
---|
56 | def ContentsValidator(self, filename): |
---|
57 | 'Make sure file contains the expected columns on numbers' |
---|
58 | fp = open(filename,'r') |
---|
59 | valid = ColumnValidator(self, fp) |
---|
60 | fp.close() |
---|
61 | return valid |
---|
62 | |
---|
63 | def Reader(self,filename, ParentFrame=None, **unused): |
---|
64 | 'Read the file' |
---|
65 | fp = open(filename,'r') |
---|
66 | for line,S in enumerate(fp): |
---|
67 | self.errors = ' Error reading line '+str(line+1) |
---|
68 | if S[0] == '#': continue #ignore comments, if any |
---|
69 | h,k,l,Fo,sigFo = S.split() |
---|
70 | h,k,l = [int(h),int(k),int(l)] |
---|
71 | if not any([h,k,l]): |
---|
72 | break |
---|
73 | Fo = float(Fo) |
---|
74 | sigFo = float(sigFo) |
---|
75 | # h,k,l,m,dsp,Fo2,sig,Fc2,Fot2,Fct2,phase,... |
---|
76 | self.RefDict['RefList'].append([h,k,l,1,0,Fo**2,2.*Fo*sigFo,0,Fo**2,0,0,0]) |
---|
77 | fp.close() |
---|
78 | self.errors = 'Error after reading reflections (unexpected!)' |
---|
79 | self.RefDict['RefList'] = np.array(self.RefDict['RefList']) |
---|
80 | self.RefDict['Type'] = 'SXC' |
---|
81 | self.RefDict['Super'] = 0 |
---|
82 | self.UpdateParameters(Type='SXC',Wave=None) # histogram type |
---|
83 | return True |
---|
84 | |
---|
85 | class HKLMF_ReaderClass(G2obj.ImportStructFactor): |
---|
86 | 'Routines to import F, reflections from a REMOS HKLMF file' |
---|
87 | def __init__(self): |
---|
88 | super(self.__class__,self).__init__( # fancy way to self-reference |
---|
89 | extensionlist=('.fo','.FO'), |
---|
90 | strictExtension=False, |
---|
91 | formatName = 'HKLM F', |
---|
92 | longFormatName = 'REMOS [hklm, Fo] Structure factor text file' |
---|
93 | ) |
---|
94 | |
---|
95 | def ContentsValidator(self, filename): |
---|
96 | 'Make sure file contains the expected columns on numbers' |
---|
97 | fp = open(filename,'r') |
---|
98 | valid = ColumnValidator(self, fp) |
---|
99 | fp.close() |
---|
100 | return valid |
---|
101 | |
---|
102 | def Reader(self,filename, ParentFrame=None, **unused): |
---|
103 | 'Read the file' |
---|
104 | fp = open(filename,'r') |
---|
105 | for line,S in enumerate(fp): |
---|
106 | self.errors = ' Error reading line '+str(line+1) |
---|
107 | if S[0] == '#': continue #ignore comments, if any |
---|
108 | h,k,l,m,Fo= S.split() |
---|
109 | h,k,l,m = [int(h),int(k),int(l),int(m)] |
---|
110 | if h == 999 or not any([h,k,l]): |
---|
111 | break |
---|
112 | Fo = float(Fo) |
---|
113 | sigFo2 = Fo |
---|
114 | if Fo < 1.0: |
---|
115 | sigFo2 = 1.0 |
---|
116 | # h,k,l,m,tw,dsp,Fo2,sig,Fc2,Fot2,Fct2,phase,... |
---|
117 | self.RefDict['RefList'].append([h,k,l,m,1,0,Fo**2,sigFo2,0,Fo**2,0,0,0]) |
---|
118 | fp.close() |
---|
119 | self.errors = 'Error after reading reflections (unexpected!)' |
---|
120 | self.RefDict['RefList'] = np.array(self.RefDict['RefList']) |
---|
121 | self.RefDict['Type'] = 'SXC' |
---|
122 | self.RefDict['Super'] = 1 |
---|
123 | self.UpdateParameters(Type='SXC',Wave=None) # histogram type |
---|
124 | return True |
---|
125 | |
---|
126 | class SHELX4_ReaderClass(G2obj.ImportStructFactor): |
---|
127 | 'Routines to import F**2, sig(F**2) reflections from a Shelx HKLF 4 file' |
---|
128 | def __init__(self): |
---|
129 | if 'linux' in sys.platform: # wx 3.0.0.0 on gtk does not like Unicode in menus |
---|
130 | formatName = 'HKLF 4' |
---|
131 | longFormatName = 'Shelx HKLF 4 [hkl, Fo2, sig(Fo2)] Structure factor text file' |
---|
132 | else: |
---|
133 | formatName = u'Shelx HKLF 4 F\u00b2' |
---|
134 | longFormatName = u'Shelx HKLF 4 [hkl, Fo\u00b2, sig(Fo\u00b2)] Structure factor text file' |
---|
135 | super(self.__class__,self).__init__( # fancy way to self-reference |
---|
136 | extensionlist=('.hkl','.HKL'), |
---|
137 | strictExtension=False, |
---|
138 | formatName=formatName, |
---|
139 | longFormatName=longFormatName) |
---|
140 | |
---|
141 | def ContentsValidator(self, filename): |
---|
142 | 'Make sure file contains the expected columns on numbers' |
---|
143 | return True |
---|
144 | # return ColumnValidator(self, filepointer) |
---|
145 | |
---|
146 | def Reader(self,filename, ParentFrame=None, **unused): |
---|
147 | 'Read the file' |
---|
148 | fp = open(filename,'r') |
---|
149 | for line,S in enumerate(fp): |
---|
150 | self.errors = ' Error reading line '+str(line+1) |
---|
151 | if S[0] == '#': continue #ignore comments, if any |
---|
152 | # h,k,l,Fo,sigFo = S[:4],S[4:8],S[8:12],S[12:20],S[20:28] |
---|
153 | h,k,l,Fo,sigFo = S.split() |
---|
154 | h,k,l = [int(h),int(k),int(l)] |
---|
155 | if not any([h,k,l]): |
---|
156 | break |
---|
157 | Fo = float(Fo) |
---|
158 | sigFo = float(sigFo) |
---|
159 | # h,k,l,m,dsp,Fo2,sig,Fc2,Fot2,Fct2,phase,... |
---|
160 | self.RefDict['RefList'].append([h,k,l,1,0,Fo,sigFo,0,Fo,0,0,0]) |
---|
161 | #self.RefDict['FF'].append({}) # now done in OnImportSfact |
---|
162 | fp.close() |
---|
163 | self.errors = 'Error after reading reflections (unexpected!)' |
---|
164 | self.RefDict['RefList'] = np.array(self.RefDict['RefList']) |
---|
165 | self.RefDict['Type'] = 'SXC' |
---|
166 | self.RefDict['Super'] = 0 |
---|
167 | self.UpdateParameters(Type='SXC',Wave=None) # histogram type |
---|
168 | return True |
---|
169 | |
---|
170 | class SHELX5_ReaderClass(G2obj.ImportStructFactor): |
---|
171 | 'Routines to import F**2, sig(F**2) twin/incommensurate reflections from a fixed format SHELX HKLF5 file' |
---|
172 | def __init__(self): |
---|
173 | if 'linux' in sys.platform: # wx 3.0.0.0 on gtk does not like Unicode in menus |
---|
174 | formatName = 'Shelx HKLF 5 F2 Tw/Incom' |
---|
175 | longFormatName = 'Shelx HKLF 5 [hklm, Fo2, sig(Fo2), Tind] Twin/incommensurate structure factor text file' |
---|
176 | else: |
---|
177 | formatName = u'Shelx HKLF 5 F\u00b2 Tw/Incom' |
---|
178 | longFormatName = u'Shelx HKLF 5 [hklm, Fo\u00b2, sig(Fo\u00b2), Tind] Twin/incommensurate structure factor text file' |
---|
179 | super(self.__class__,self).__init__( # fancy way to self-reference |
---|
180 | extensionlist=('.hkl','.HKL'), |
---|
181 | strictExtension=False, |
---|
182 | formatName=formatName, |
---|
183 | longFormatName=longFormatName) |
---|
184 | self.Super = 0 |
---|
185 | |
---|
186 | def ContentsValidator(self, filename): |
---|
187 | '''Discover how many columns before F^2 are in the SHELX HKL5 file |
---|
188 | - could be 3-6 depending on satellites''' |
---|
189 | numCols = 0 |
---|
190 | fp = open(filename,'r') |
---|
191 | for i,line in enumerate(fp): |
---|
192 | for j,item in enumerate(line.split()): #find 1st col with '.'; has F^2 |
---|
193 | if '.' in item: |
---|
194 | numCols = max(numCols,j) |
---|
195 | break |
---|
196 | if i > 20: |
---|
197 | break |
---|
198 | fp.close() |
---|
199 | self.Super = numCols-3 #= 0,1,2,or 3 |
---|
200 | if self.Super > 1: |
---|
201 | raise self.ImportException("Supersymmetry too high; GSAS-II limited to (3+1) supersymmetry") |
---|
202 | return True |
---|
203 | |
---|
204 | def Reader(self,filename, ParentFrame=None, **unused): |
---|
205 | 'Read the file' |
---|
206 | TwDict = {} |
---|
207 | TwSet = {} |
---|
208 | TwMax = [-1,[]] |
---|
209 | first = True |
---|
210 | fp = open(filename,'r') |
---|
211 | m1 = 0 |
---|
212 | for line,S in enumerate(fp): |
---|
213 | self.errors = ' Error reading line '+str(line+1) |
---|
214 | if self.Super == 0: |
---|
215 | h,k,l,Fo,sigFo,Tw = S.split() |
---|
216 | # h,k,l,Fo,sigFo,Tw = S[:4],S[4:8],S[8:12],S[12:20],S[20:28],S[28:32] |
---|
217 | h,k,l = [int(h),int(k),int(l)] |
---|
218 | elif self.Super == 1: |
---|
219 | h,k,l,m1,Fo,sigFo,Tw = SF.split() |
---|
220 | # h,k,l,m1,Fo,sigFo,Tw = S[:4],S[4:8],S[8:12],S[12:16],S[16:24],S[24:32],S[32:36] |
---|
221 | h,k,l,m1 = [int(h),int(k),int(l),int(m1)] |
---|
222 | Tw = Tw.strip() |
---|
223 | if Tw in ['','0']: |
---|
224 | Tw = '1' |
---|
225 | if not any([h,k,l,m1]): |
---|
226 | break |
---|
227 | if '-' in Tw: |
---|
228 | if Tw == '-1': #fix reversed twin ids |
---|
229 | Tw = '-2' |
---|
230 | if first: |
---|
231 | self.warnings += '\nPrimary twin id changed to 1' |
---|
232 | first = False |
---|
233 | TwId = -int(Tw)-1 |
---|
234 | TwSet[TwId] = np.array([h,k,l]) |
---|
235 | if TwId not in TwMax[1]: |
---|
236 | TwMax[1].append(TwId) |
---|
237 | else: |
---|
238 | if Tw != '1': #fix reversed twin ids |
---|
239 | if first: |
---|
240 | self.warnings += '\nPrimary twin id changed to 1\nNB: multiple primary twins not working' |
---|
241 | first = False |
---|
242 | Tw = '1' |
---|
243 | TwId = int(Tw)-1 |
---|
244 | if TwSet: |
---|
245 | TwDict[len(self.RefDict['RefList'])] = TwSet |
---|
246 | TwSet = {} |
---|
247 | Fo = float(Fo) |
---|
248 | sigFo = float(sigFo) |
---|
249 | # h,k,l,m,dsp,Fo2,sig,Fc2,Fot2,Fct2,phase,... |
---|
250 | if self.Super == 0: |
---|
251 | self.RefDict['RefList'].append([h,k,l,int(Tw),0,Fo,sigFo,0,Fo,0,0,0]) |
---|
252 | elif self.Super == 1: |
---|
253 | self.RefDict['RefList'].append([h,k,l,m1,int(Tw),0,Fo,sigFo,0,Fo,0,0,0]) |
---|
254 | TwMax[0] = max(TwMax[0],TwId) |
---|
255 | fp.close() |
---|
256 | self.errors = 'Error after reading reflections (unexpected!)' |
---|
257 | self.RefDict['RefList'] = np.array(self.RefDict['RefList']) |
---|
258 | self.RefDict['Type'] = 'SXC' |
---|
259 | self.RefDict['Super'] = self.Super |
---|
260 | self.RefDict['TwDict'] = TwDict |
---|
261 | self.RefDict['TwMax'] = TwMax |
---|
262 | self.UpdateParameters(Type='SXC',Wave=None) # histogram type |
---|
263 | return True |
---|
264 | |
---|
265 | class SHELX6_ReaderClass(G2obj.ImportStructFactor): |
---|
266 | 'Routines to import F**2, sig(F**2) twin/incommensurate reflections from a fixed format SHELX HKLF6 file' |
---|
267 | def __init__(self): |
---|
268 | if 'linux' in sys.platform: # wx 3.0.0.0 on gtk does not like Unicode in menus |
---|
269 | formatName = 'Shelx HKLF 6 F2 Tw/Incom' |
---|
270 | longFormatName = 'Shelx HKLF 6 [hklm, Fo2, sig(Fo2), Tind] Twin/incommensurate structure factor text file' |
---|
271 | else: |
---|
272 | formatName = u'Shelx HKLF 6 F\u00b2 Tw/Incom' |
---|
273 | longFormatName = u'Shelx HKLF 6 [hklm, Fo\u00b2, sig(Fo\u00b2), Tind] Twin/incommensurate structure factor text file' |
---|
274 | super(self.__class__,self).__init__( # fancy way to self-reference |
---|
275 | extensionlist=('.hk6','.HK6'), |
---|
276 | strictExtension=False, |
---|
277 | formatName=formatName, |
---|
278 | longFormatName=longFormatName) |
---|
279 | self.Super = 0 |
---|
280 | |
---|
281 | def ContentsValidator(self, filename): |
---|
282 | '''Discover how many columns before F^2 are in the SHELX HKL6 file |
---|
283 | - could be 3-6 depending on satellites''' |
---|
284 | numCols = 0 |
---|
285 | fp = open(filename,'r') |
---|
286 | for i,line in enumerate(fp): |
---|
287 | for j,item in enumerate(line.split()): #find 1st col with '.'; has F^2 |
---|
288 | if '.' in item: |
---|
289 | numCols = max(numCols,j) |
---|
290 | break |
---|
291 | if i > 20: |
---|
292 | break |
---|
293 | fp.close() |
---|
294 | if numCols != 6: |
---|
295 | self.warnings += '\nInvalid hk6 file; wrong number of columns' |
---|
296 | raise self.ImportException('Invalid hk6 file; wrong number of columns') |
---|
297 | self.Super = 1 |
---|
298 | return True |
---|
299 | |
---|
300 | def Reader(self,filename, ParentFrame=None, **unused): |
---|
301 | 'Read the file' |
---|
302 | TwDict = {} |
---|
303 | TwSet = {} |
---|
304 | TwMax = [-1,[]] |
---|
305 | first = True |
---|
306 | fp = open(filename,'r') |
---|
307 | for line,S in enumerate(fp): |
---|
308 | self.errors = ' Error reading line '+str(line+1) |
---|
309 | h,k,l,m1,m2,m3,Fo,sigFo,Tw = S[:4],S[4:8],S[8:12],S[12:16],S[16:20],S[20:24],S[24:32],S[32:40],S[40:44] |
---|
310 | h,k,l,m1,m2,m3 = [int(h),int(k),int(l),int(m1),int(m2),int(m3)] |
---|
311 | if m2 or m3: |
---|
312 | self.warnings += '\n(3+2) & (3+3) Supersymmetry not allowed in GSAS-II. Reformulate as twinned (3+1) supersymmetry' |
---|
313 | raise self.ImportException("Supersymmetry too high; GSAS-II limited to (3+1) supersymmetry") |
---|
314 | Tw = Tw.strip() |
---|
315 | if Tw in ['','0']: |
---|
316 | Tw = '1' |
---|
317 | if not any([h,k,l]): #look for 0 0 0 or blank line |
---|
318 | break |
---|
319 | if '-' in Tw: |
---|
320 | if Tw == '-1': #fix reversed twin ids |
---|
321 | Tw = '-2' |
---|
322 | if first: |
---|
323 | self.warnings += '\nPrimary twin id changed to 1' |
---|
324 | first = False |
---|
325 | TwId = -int(Tw)-1 |
---|
326 | TwSet[TwId] = np.array([h,k,l]) |
---|
327 | if TwId not in TwMax[1]: |
---|
328 | TwMax[1].append(TwId) |
---|
329 | else: |
---|
330 | if Tw != '1': #fix reversed twin ids |
---|
331 | if first: |
---|
332 | self.warnings += '\nPrimary twin id changed to 1\nNB: multiple primary twins not working' |
---|
333 | first = False |
---|
334 | Tw = '1' |
---|
335 | TwId = int(Tw)-1 |
---|
336 | if TwSet: |
---|
337 | TwDict[len(self.RefDict['RefList'])] = TwSet |
---|
338 | TwSet = {} |
---|
339 | Fo = float(Fo) |
---|
340 | sigFo = float(sigFo) |
---|
341 | # h,k,l,m,dsp,Fo2,sig,Fc2,Fot2,Fct2,phase,... |
---|
342 | self.RefDict['RefList'].append([h,k,l,m1,int(Tw),0,Fo,sigFo,0,Fo,0,0,0]) |
---|
343 | TwMax[0] = max(TwMax[0],TwId) |
---|
344 | fp.close() |
---|
345 | self.errors = 'Error after reading reflections (unexpected!)' |
---|
346 | self.RefDict['RefList'] = np.array(self.RefDict['RefList']) |
---|
347 | self.RefDict['Type'] = 'SXC' |
---|
348 | self.RefDict['Super'] = self.Super |
---|
349 | self.RefDict['TwDict'] = TwDict |
---|
350 | self.RefDict['TwMax'] = TwMax |
---|
351 | self.UpdateParameters(Type='SXC',Wave=None) # histogram type |
---|
352 | return True |
---|
353 | |
---|
354 | class M90_ReaderClass(G2obj.ImportStructFactor): |
---|
355 | 'Routines to import F**2, sig(F**2) reflections from a JANA M90 file' |
---|
356 | def __init__(self): |
---|
357 | if 'linux' in sys.platform: # wx 3.0.0.0 on gtk does not like Unicode in menus |
---|
358 | longFormatName = 'JANA [hkl, Fo2, sig(Fo2)] Structure factor text file' |
---|
359 | else: |
---|
360 | longFormatName = u'JANA [hkl, Fo\u00b2, sig(Fo\u00b2)] Structure factor text file' |
---|
361 | super(self.__class__,self).__init__( # fancy way to self-reference |
---|
362 | extensionlist=('.m90','.M90'), |
---|
363 | strictExtension=False, |
---|
364 | formatName = u'JANA M90', |
---|
365 | longFormatName = longFormatName |
---|
366 | ) |
---|
367 | self.Super = 0 |
---|
368 | |
---|
369 | def ContentsValidator(self, filename): |
---|
370 | 'Discover how many columns are in the m90 file - could be 9-12 depending on satellites' |
---|
371 | numCols = 0 |
---|
372 | fp = open(filename,'r') |
---|
373 | for i,line in enumerate(fp): |
---|
374 | if 'Data' in line: |
---|
375 | startData = i |
---|
376 | break |
---|
377 | for i,line in enumerate(fp): |
---|
378 | if i > startData: |
---|
379 | numCols = max(numCols,len(line.split())) |
---|
380 | if i > startData+20: |
---|
381 | break |
---|
382 | fp.close() |
---|
383 | self.Super = numCols-9 #= 0,1,2,or 3 |
---|
384 | if self.Super > 1: |
---|
385 | raise self.ImportException("Supersymmetry too high; GSAS-II limited to (3+1) supersymmetry") |
---|
386 | return True #ColumnValidator(self, filepointer) |
---|
387 | |
---|
388 | def Reader(self,filename,filepointer, ParentFrame=None, **unused): |
---|
389 | 'Read the file' |
---|
390 | fp = open(filename,'r') |
---|
391 | for line,S in enumerate(fp): |
---|
392 | self.errors = ' Error reading line '+str(line+1) |
---|
393 | if S[0] == '#': continue #ignore comments, if any |
---|
394 | try: |
---|
395 | if self.Super == 0: |
---|
396 | h,k,l,Fo,sigFo = S.split()[:5] |
---|
397 | h,k,l = [int(h),int(k),int(l)] |
---|
398 | elif self.Super == 1: |
---|
399 | h,k,l,m1,Fo,sigFo = S.split()[:6] |
---|
400 | h,k,l,m1 = [int(h),int(k),int(l),int(m1)] |
---|
401 | except ValueError: #skipping text at front |
---|
402 | if not S: |
---|
403 | break |
---|
404 | text = S.split() |
---|
405 | if text[0] == 'lambda': |
---|
406 | wave = float(text[1]) |
---|
407 | continue |
---|
408 | Fo = float(Fo) |
---|
409 | sigFo = float(sigFo) |
---|
410 | # h,k,l,m,dsp,Fo2,sig,Fc2,Fot2,Fct2,phase,... |
---|
411 | if self.Super == 0: |
---|
412 | self.RefDict['RefList'].append([h,k,l,1,0,Fo,sigFo,0,Fo,0,0,0]) |
---|
413 | elif self.Super == 1: |
---|
414 | self.RefDict['RefList'].append([h,k,l,m1,1,0,Fo,sigFo,0,Fo,0,0,0]) |
---|
415 | fp.close() |
---|
416 | self.errors = 'Error after reading reflections (unexpected!)' |
---|
417 | self.RefDict['RefList'] = np.array(self.RefDict['RefList']) |
---|
418 | self.RefDict['Type'] = 'SXC' |
---|
419 | self.RefDict['Super'] = self.Super |
---|
420 | self.UpdateParameters(Type='SXC',Wave=wave) # histogram type |
---|
421 | return True |
---|
422 | |
---|
423 | class NT_HKLF2_ReaderClass(G2obj.ImportStructFactor): |
---|
424 | 'Routines to import neutron TOF F**2, sig(F**2) reflections from a HKLF file' |
---|
425 | def __init__(self): |
---|
426 | if 'linux' in sys.platform: # wx 3.0.0.0 on gtk does not like Unicode in menus |
---|
427 | formatName = 'Neutron SNS TOF HKL F2' |
---|
428 | longFormatName = 'Neutron SNS TOF [hkl, Fo2, sig(Fo2),...] Structure factor text file' |
---|
429 | else: |
---|
430 | formatName = u'Neutron SNS TOF HKL F\u00b2' |
---|
431 | longFormatName = u'Neutron SNS TOF [hkl, Fo\u00b2, sig(Fo\u00b2),...] Structure factor text file' |
---|
432 | super(self.__class__,self).__init__( # fancy way to self-reference |
---|
433 | extensionlist=('.hkl','.HKL'), |
---|
434 | strictExtension=False, |
---|
435 | formatName=formatName, |
---|
436 | longFormatName=longFormatName) |
---|
437 | |
---|
438 | def ContentsValidator(self, filename): |
---|
439 | 'Make sure file contains the expected columns on numbers & count number of data blocks - "Banks"' |
---|
440 | oldNo = -1 |
---|
441 | fp = open(filename,'r') |
---|
442 | for line,S in enumerate(fp): |
---|
443 | if not S: #empty line terminates read |
---|
444 | break |
---|
445 | if S[0] == '#': continue #ignore comments, if any |
---|
446 | if S.split()[:3] == ['0','0','0']: |
---|
447 | break |
---|
448 | bankNo = S.split()[5] |
---|
449 | if bankNo != oldNo: |
---|
450 | self.Banks.append({'RefDict':{'RefList':[],}}) |
---|
451 | oldNo = bankNo |
---|
452 | fp.seek(0) |
---|
453 | valid = ColumnValidator(self, fp,nCol=8) |
---|
454 | fp.close() |
---|
455 | return valid |
---|
456 | |
---|
457 | def Reader(self,filename, ParentFrame=None, **unused): |
---|
458 | 'Read the file' |
---|
459 | fp = open(filename,'r') |
---|
460 | for line,S in enumerate(fp): |
---|
461 | if not S: |
---|
462 | break |
---|
463 | self.errors = ' Error reading line '+str(line+1) |
---|
464 | if S[0] == '#': continue #ignore comments, if any |
---|
465 | data = S.split() |
---|
466 | h,k,l,Fo,sigFo,bN,wave,tbar = data[:8] #bN = 1..., 6 dir cos next |
---|
467 | h,k,l = [int(h),int(k),int(l)] |
---|
468 | if not any([h,k,l]): |
---|
469 | break |
---|
470 | Fo = float(Fo) |
---|
471 | sigFo = float(sigFo) |
---|
472 | wave = float(wave) |
---|
473 | tbar = float(tbar) |
---|
474 | if len(self.Banks): |
---|
475 | self.Banks[int(bN)-1]['RefDict']['RefList'].append([h,k,l,1,0,Fo,sigFo,0,Fo,0,0,0,wave,tbar]) |
---|
476 | else: |
---|
477 | # h,k,l,m,dsp,Fo2,sig,Fc2,Fot2,Fct2,phase,... |
---|
478 | self.RefDict['RefList'].append([h,k,l,1,0,Fo,sigFo,0,Fo,0,0,0,wave,tbar]) |
---|
479 | fp.close() |
---|
480 | if len(self.Banks): |
---|
481 | self.UpdateParameters(Type='SNT',Wave=None) # histogram type |
---|
482 | for Bank in self.Banks: |
---|
483 | Bank['RefDict']['RefList'] = np.array(Bank['RefDict']['RefList']) |
---|
484 | Bank['RefDict']['Type'] = 'SNT' |
---|
485 | Bank['RefDict']['Super'] = 0 |
---|
486 | else: |
---|
487 | self.RefDict['RefList'] = np.array(self.RefDict['RefList']) |
---|
488 | self.RefDict['Type'] = 'SNT' |
---|
489 | self.RefDict['Super'] = 0 |
---|
490 | self.errors = 'Error after reading reflections (unexpected!)' |
---|
491 | self.UpdateParameters(Type='SNT',Wave=None) # histogram type |
---|
492 | return True |
---|
493 | |
---|
494 | class NT_JANA2K_ReaderClass(G2obj.ImportStructFactor): |
---|
495 | 'Routines to import neutron TOF F**2, sig(F**2) reflections from a JANA2000 file' |
---|
496 | def __init__(self): |
---|
497 | if 'linux' in sys.platform: # wx 3.0.0.0 on gtk does not like Unicode in menus |
---|
498 | formatName = 'Neutron TOF JANA2000 F2' |
---|
499 | longFormatName = 'Neutron TOF [hkl, Fo2, sig(Fo2),...] Structure factor text file' |
---|
500 | else: |
---|
501 | formatName = u'Neutron TOF JANA2000 F\u00b2' |
---|
502 | longFormatName = u'Neutron TOF [hkl, Fo\u00b2, sig(Fo\u00b2),...] Structure factor text file' |
---|
503 | super(self.__class__,self).__init__( # fancy way to self-reference |
---|
504 | extensionlist=('.int','.INT'), |
---|
505 | strictExtension=False, |
---|
506 | formatName=formatName, |
---|
507 | longFormatName=longFormatName) |
---|
508 | |
---|
509 | def ContentsValidator(self, filename): |
---|
510 | 'Make sure file contains the expected columns on numbers & count number of data blocks - "Banks"' |
---|
511 | oldNo = -1 |
---|
512 | fp = open(filename,'r') |
---|
513 | for line,S in enumerate(fp): |
---|
514 | if not S: #empty line terminates read |
---|
515 | break |
---|
516 | if S[0] in ['#','(']: continue #ignore comments & fortran format line |
---|
517 | bankNo = S.split()[5] |
---|
518 | if bankNo != oldNo: |
---|
519 | self.Banks.append({'RefDict':{'RefList':[],}}) |
---|
520 | oldNo = bankNo |
---|
521 | fp.seek(0) |
---|
522 | valid = ColumnValidator(self, fp,nCol=10) |
---|
523 | fp.close() |
---|
524 | return valid |
---|
525 | |
---|
526 | def Reader(self,filename,filepointer, ParentFrame=None, **unused): |
---|
527 | 'Read the file' |
---|
528 | fp = open(filename,'r') |
---|
529 | for line,S in enumerate(fp): |
---|
530 | self.errors = ' Error reading line '+str(line+1) |
---|
531 | if S[0] in ['#','(']: continue #ignore comments & fortran format line |
---|
532 | data = S.split() |
---|
533 | h,k,l,Fo,sigFo,bN,wave,x,x,tbar = data[:10] #bN = 1..., 6 dir cos next |
---|
534 | h,k,l = [int(h),int(k),int(l)] |
---|
535 | if not any([h,k,l]): |
---|
536 | break |
---|
537 | Fo = float(Fo) |
---|
538 | sigFo = float(sigFo) |
---|
539 | wave = float(wave) |
---|
540 | tbar = float(tbar) |
---|
541 | if len(self.Banks): |
---|
542 | self.Banks[int(bN)-1]['RefDict']['RefList'].append([h,k,l,1,0,Fo,sigFo,0,Fo,0,0,0,wave,tbar]) |
---|
543 | else: |
---|
544 | # h,k,l,m,dsp,Fo2,sig,Fc2,Fot2,Fct2,phase,... |
---|
545 | self.RefDict['RefList'].append([h,k,l,1,0,Fo,sigFo,0,Fo,0,0,0,wave,tbar]) |
---|
546 | fp.close() |
---|
547 | if len(self.Banks): |
---|
548 | self.UpdateParameters(Type='SNT',Wave=None) # histogram type |
---|
549 | for Bank in self.Banks: |
---|
550 | Bank['RefDict']['RefList'] = np.array(Bank['RefDict']['RefList']) |
---|
551 | Bank['RefDict']['Type'] = 'SNT' |
---|
552 | Bank['RefDict']['Super'] = 0 #for now |
---|
553 | else: |
---|
554 | self.RefDict['RefList'] = np.array(self.RefDict['RefList']) |
---|
555 | self.RefDict['Type'] = 'SNT' |
---|
556 | self.RefDict['Super'] = 0 #for now |
---|
557 | self.errors = 'Error after reading reflections (unexpected!)' |
---|
558 | self.UpdateParameters(Type='SNT',Wave=None) # histogram type |
---|
559 | return True |
---|
560 | |
---|
561 | class NIST_hb3a_INT_ReaderClass(G2obj.ImportStructFactor): |
---|
562 | 'Routines to import neutron CW F**2, sig(F**2) reflections from a NIST hb3a int file' |
---|
563 | def __init__(self): |
---|
564 | if 'linux' in sys.platform: # wx 3.0.0.0 on gtk does not like Unicode in menus |
---|
565 | formatName = u'Neutron NIST hb3a CW HKL F2' |
---|
566 | longFormatName = u'Neutron NIST hb3a CW HKL [hkl, Fo2, sig(Fo2),...] 5 column Structure factor text file' |
---|
567 | else: |
---|
568 | formatName = u'Neutron NIST hb3a CW HKL F\u00b2' |
---|
569 | longFormatName = u'Neutron NIST hb3a CW HKL [hkl, Fo\u00b2, sig(Fo\u00b2),...] 5 column Structure factor text file' |
---|
570 | super(self.__class__,self).__init__( # fancy way to self-reference |
---|
571 | extensionlist=('.int','.INT'), |
---|
572 | strictExtension=False, |
---|
573 | formatName=formatName, |
---|
574 | longFormatName=longFormatName) |
---|
575 | |
---|
576 | def ContentsValidator(self, filename): |
---|
577 | 'Make sure file contains the expected columns on numbers & count number of data blocks - "Banks"' |
---|
578 | fp = open(filename,'r') |
---|
579 | for line,S in enumerate(fp): |
---|
580 | if not S: #empty line terminates read |
---|
581 | break |
---|
582 | if S[0] == '#': continue #ignore comments, if any |
---|
583 | fp.seek(0) |
---|
584 | valid = ColumnValidator(self, fp,nCol=5) |
---|
585 | fp.close() |
---|
586 | return valid |
---|
587 | |
---|
588 | def Reader(self,filename,filepointer, ParentFrame=None, **unused): |
---|
589 | 'Read the file' |
---|
590 | fp = open(filename,'r') |
---|
591 | for line,S in enumerate(fp): |
---|
592 | self.errors = ' Error reading line '+str(line+1) |
---|
593 | if S[0] == '#': continue #ignore comments, if any |
---|
594 | data = S.split() |
---|
595 | h,k,l,Fo,sigFo = data |
---|
596 | h,k,l = [int(h),int(k),int(l)] |
---|
597 | if not any([h,k,l]): |
---|
598 | break |
---|
599 | Fo = float(Fo) |
---|
600 | sigFo = float(sigFo) |
---|
601 | # h,k,l,m,dsp,Fo2,sig,Fc2,Fot2,Fct2,phase,... |
---|
602 | self.RefDict['RefList'].append([h,k,l,1,0,Fo,sigFo,0,Fo,0,0,0]) |
---|
603 | fp.close() |
---|
604 | self.RefDict['RefList'] = np.array(self.RefDict['RefList']) |
---|
605 | self.RefDict['Type'] = 'SNC' |
---|
606 | self.RefDict['Super'] = 0 |
---|
607 | self.errors = 'Error after reading reflections (unexpected!)' |
---|
608 | self.UpdateParameters(Type='SNC',Wave=None) # histogram type |
---|
609 | return True |
---|