Ignore:
Timestamp:
May 27, 2014 12:14:59 PM (8 years ago)
Author:
vondreele
Message:

read TOPAZ structure factor files

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/imports/G2sfact.py

    r1359 r1364  
    1616import sys
    1717import numpy as np
     18import copy
    1819import GSASIIIO as G2IO
    1920import GSASIIpath
    2021GSASIIpath.SetVersionNumber("$Revision$")
    2122
    22 def ColumnValidator(parent, filepointer):
     23def ColumnValidator(parent, filepointer,nCol=5):
    2324    'Validate a file to check that it contains columns of numbers'
    24     l = S = filepointer.readline()
     25    l = filepointer.readline()
    2526    line = 1
    26     while '#' in S[0]:        #get past comments, if any
     27    while '#' in l[0]:        #get past comments, if any
    2728        l = filepointer.readline()       
    2829        line += 1
    2930    for i in range(10): # scan a few lines
    3031        S = l.split()
    31         if len(S) != 5:
     32        if len(S) < nCol:
    3233            parent.errors = 'line '+str(line)+': invalid input\n'+l
    3334            return False
     
    4950            extensionlist=('.hkl','.HKL'),
    5051            strictExtension=False,
    51             formatName = 'HKL containing F',
     52            formatName = 'HKL F',
    5253            longFormatName = 'Simple [hkl, Fo, sig(Fo)] Structure factor text file'
    5354            )
     
    7475            self.errors = 'Error after reading reflections (unexpected!)'
    7576            self.RefDict['RefList'] = np.array(self.RefDict['RefList'])
    76             self.UpdateControls(Type='Fosq',FcalcPresent=False) # set Fobs type & if Fcalc values are loaded
    7777            self.UpdateParameters(Type='SXC',Wave=None) # histogram type
    7878            return True
     
    9090            extensionlist=('.hkl','.HKL'),
    9191            strictExtension=False,
    92             formatName = u'HKL containing F\u00b2',
     92            formatName = u'HKL F\u00b2',
    9393            longFormatName = u'Simple [hkl, Fo\u00b2, sig(Fo\u00b2)] Structure factor text file'
    9494            )
     
    115115            self.errors = 'Error after reading reflections (unexpected!)'
    116116            self.RefDict['RefList'] = np.array(self.RefDict['RefList'])
    117             self.UpdateControls(Type='Fosq',FcalcPresent=False) # set Fobs type & if Fcalc values are loaded
    118117            self.UpdateParameters(Type='SXC',Wave=None) # histogram type
    119118            return True
     
    131130            extensionlist=('.hkl','.HKL'),
    132131            strictExtension=False,
    133             formatName = u'Neutron TOF HKL containing F\u00b2',
     132            formatName = u'Neutron TOF HKL F\u00b2',
    134133            longFormatName = u'Neutron TOF [hkl, Fo\u00b2, sig(Fo\u00b2),...] Structure factor text file'
    135134            )
    136135
    137136    def ContentsValidator(self, filepointer):
    138         'Make sure file contains the expected columns on numbers'
    139         return ColumnValidator(self, filepointer)
     137        'Make sure file contains the expected columns on numbers & count number of data blocks - "Banks"'
     138        oldNo = -1
     139        for line,S in enumerate(filepointer):
     140            if not S:   #empty line terminates read
     141                break
     142            if S[0] == '#': continue       #ignore comments, if any
     143            if S.split()[:3] == ['0','0','0']:
     144                break
     145            bankNo = S.split()[5]
     146            if bankNo != oldNo:
     147                self.Banks.append({'RefDict':{'RefList':[],}})
     148                oldNo = bankNo
     149        filepointer.seek(0)
     150        return ColumnValidator(self, filepointer,nCol=8)
    140151
    141152    def Reader(self,filename,filepointer, ParentFrame=None, **unused):
    142153        'Read the file'
     154        filepointer.seek(0)
    143155        try:
    144             oldNo = -1
    145             Banks = []
    146             for line,S in enumerate(filepointer):
    147                 if S[0] == '#': continue       #ignore comments, if any
    148                 bankNo = S.split()[5]
    149                 if bankNo != oldNo:
    150                     Banks.append([])
    151                    
    152156            for line,S in enumerate(filepointer):
    153157                self.errors = '  Error reading line '+str(line+1)
    154158                if S[0] == '#': continue       #ignore comments, if any
    155                 h,k,l,Fo,sigFo = S.split()
     159                data = S.split()
     160                h,k,l,Fo,sigFo,bN,wave,tbar = data[:8]  #bN = 1..., 6 dir cos next                   
    156161                h,k,l = [int(h),int(k),int(l)]
    157162                if not any([h,k,l]):
     
    159164                Fo = float(Fo)
    160165                sigFo = float(sigFo)
     166                wave = float(wave)
     167                tbar = float(tbar)
     168                if len(self.Banks):
     169                    self.Banks[int(bN)-1]['RefDict']['RefList'].append([h,k,l,0,0,Fo,sigFo,0,Fo,0,0,0,wave,tbar])
     170                else:
    161171                # h,k,l,m,dsp,Fo2,sig,Fc2,Fot2,Fct2,phase,...
    162                 self.RefDict['RefList'].append([h,k,l,0,0,Fo,sigFo,0,Fo,0,0,0])
    163             self.errors = 'Error after reading reflections (unexpected!)'
    164             self.RefDict['RefList'] = np.array(self.RefDict['RefList'])
    165             self.UpdateControls(Type='Fosq',FcalcPresent=False) # set Fobs type & if Fcalc values are loaded
    166             self.UpdateParameters(Type='SNT',Wave=None) # histogram type
     172                    self.RefDict['RefList'].append([h,k,l,0,0,Fo,sigFo,0,Fo,0,0,0])
     173            if len(self.Banks):
     174                self.UpdateParameters(Type='SNT',Wave=None) # histogram type
     175                for Bank in self.Banks:
     176                    Bank['RefDict']['RefList'] = np.array(Bank['RefDict']['RefList'])                   
     177            else:
     178                self.RefDict['RefList'] = np.array(self.RefDict['RefList'])
     179                self.errors = 'Error after reading reflections (unexpected!)'
     180                self.UpdateParameters(Type='SNT',Wave=None) # histogram type
    167181            return True
    168182        except Exception as detail:
Note: See TracChangeset for help on using the changeset viewer.