Changeset 1364


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

read TOPAZ structure factor files

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASII.py

    r1359 r1364  
    722722            HistName = 'HKLF '+HistName
    723723            # make new histogram names unique
    724             HistName = G2obj.MakeUniqueLabel(HistName,HKLFlist)
    725             print 'Read structure factor table '+str(HistName)+' from file '+str(self.lastimport)
    726             if not rd.RefDict.get('FF'):
    727                 rd.RefDict['FF'] = [{} for i in range(len(rd.RefDict['RefList']))]
    728             Id = self.PatternTree.AppendItem(parent=self.root,text=HistName)
    729724            valuesdict = {
    730725                'wtFactor':1.0,
     
    732727                'ranId':ran.randint(0,sys.maxint),
    733728                }
    734             self.PatternTree.SetItemPyData(Id,[valuesdict,rd.RefDict])
    735             Sub = self.PatternTree.AppendItem(Id,text='Instrument Parameters')
    736             self.PatternTree.SetItemPyData(Sub,rd.Parameters)
    737             self.PatternTree.SetItemPyData(
    738                 self.PatternTree.AppendItem(Id,text='HKL Plot Controls'),
    739                 rd.Controls)
    740             self.PatternTree.SetItemPyData(
    741                 self.PatternTree.AppendItem(Id,text='Reflection List'),[])  #dummy entry for GUI use
     729            if len(rd.Banks):
     730                for Bank in rd.Banks:
     731                    HistName = G2obj.MakeUniqueLabel(HistName,HKLFlist)
     732                    print 'Read structure factor table '+str(HistName)+' from file '+str(self.lastimport)
     733                    Id = self.PatternTree.AppendItem(parent=self.root,text=HistName)
     734                    if not Bank['RefDict'].get('FF'):
     735                        Bank['RefDict']['FF'] = [{} for i in range(len(Bank['RefDict']['RefList']))]
     736                    self.PatternTree.SetItemPyData(Id,[valuesdict,Bank['RefDict']])
     737                    Sub = self.PatternTree.AppendItem(Id,text='Instrument Parameters')
     738                    self.PatternTree.SetItemPyData(Sub,copy.copy(rd.Parameters))
     739                    self.PatternTree.SetItemPyData(
     740                        self.PatternTree.AppendItem(Id,text='Reflection List'),[])  #dummy entry for GUI use
     741            else:
     742                HistName = G2obj.MakeUniqueLabel(HistName,HKLFlist)
     743                print 'Read structure factor table '+str(HistName)+' from file '+str(self.lastimport)
     744                if not rd.RefDict.get('FF'):
     745                    rd.RefDict['FF'] = [{} for i in range(len(rd.RefDict['RefList']))]
     746                Id = self.PatternTree.AppendItem(parent=self.root,text=HistName)
     747                print rd.RefDict
     748                self.PatternTree.SetItemPyData(Id,[valuesdict,rd.RefDict])
     749                Sub = self.PatternTree.AppendItem(Id,text='Instrument Parameters')
     750                self.PatternTree.SetItemPyData(Sub,rd.Parameters)
     751                self.PatternTree.SetItemPyData(
     752                    self.PatternTree.AppendItem(Id,text='Reflection List'),[])  #dummy entry for GUI use
     753               
    742754            self.PatternTree.SelectItem(Id)
    743755            self.PatternTree.Expand(Id)
     
    16411653        filelist = []
    16421654        for path in pathlist:
    1643             for filename in glob.iglob(os.path.join(
    1644                 path,
    1645                 "G2export*.py")):
     1655            for filename in glob.iglob(os.path.join(path,"G2export*.py")):
    16461656                filelist.append(filename)   
    16471657        filelist = sorted(list(set(filelist))) # remove duplicates
  • trunk/GSASIIElem.py

    r1362 r1364  
    338338#    for BL in BLdata:
    339339#        if len(BL) >= 6:
    340 #            Emev = 81.80703/wave**2
    341340#            G2 = BL[5]**2
    342341#            T = [Emev-BL[4],0,0]
  • trunk/GSASIIIO.py

    r1359 r1364  
    16061606    and set :attr:`Parameters` with the instrument parameters
    16071607    (initialized with :meth:`InitParameters` and set with :meth:`UpdateParameters`).
    1608     Also, set :attr:`Controls`,
    1609     which specifies how the histogram is plotted
    1610     (initialized with :meth:`InitControls` and set with :meth:`UpdateControls`).
    16111608    '''
    16121609    def __init__(self,formatName,longFormatName=None,extensionlist=[],
     
    16191616        'self.Parameters is a list with two dicts for data parameter settings'
    16201617        self.InitParameters()
    1621         self.Controls = {}
    1622         'self.Controls is a dict with plotting controls'
    1623         self.InitControls() # initialize the above
    16241618        self.RefDict = {'RefList':[],'FF':[]}
     1619        self.Banks = []             #for multi bank data (usually TOF)
    16251620        '''self.RefDict is a dict containing the reflection information, as read from the file.
    16261621        Item 'RefList' contains the reflection information. See the
     
    16341629        ImportBaseclass.ReInitialize(self)
    16351630        self.InitParameters()
    1636         self.InitControls()
    16371631        self.RefDict = {'RefList':[],'FF':[]}
    1638 
    16391632       
    1640     def InitControls(self):
    1641         'initialize the controls structure'
    1642         self.Controls = { # dictionary with plotting controls
    1643             'Type' : 'Fosq',
    1644             'ifFc' : False,    #
    1645             'HKLmax' : [None,None,None],
    1646             'HKLmin' : [None,None,None],
    1647             'FoMax' : None,   # maximum observed structure factor as Fo
    1648             'Zone' : '001',
    1649             'Layer' : 0,
    1650             'Scale' : 1.0,
    1651             }
    1652 
    16531633    def InitParameters(self):
    16541634        'initialize the instrument parameters structure'
     
    16661646        if Wave is not None:
    16671647            self.Parameters[0]['Lam'] = [Wave,Wave]
    1668            
    1669     def UpdateControls(self,Type='Fosq',FcalcPresent=False):
    1670         '''Scan through the reflections to update the Controls dictionary
    1671         '''
    1672         self.Controls['Type'] = Type
    1673         self.Controls['ifFc'] = FcalcPresent
    1674         HKLmax = [None,None,None]
    1675         HKLmin = [None,None,None]
    1676         Fo2max = None
    1677         for refl in self.RefDict['RefList']:
    1678             HKL = refl[:3]
    1679             if Fo2max is None:
    1680                 Fo2max = refl[8]
    1681             else:
    1682                 Fo2max = max(Fo2max,refl[8])
    1683             for i,hkl in enumerate(HKL):
    1684                 if HKLmax[i] is None:
    1685                     HKLmax[i] = hkl
    1686                     HKLmin[i] = hkl
    1687                 else:
    1688                     HKLmax[i] = max(HKLmax[i],hkl)
    1689                     HKLmin[i] = min(HKLmin[i],hkl)
    1690         self.Controls['HKLmax'] = HKLmax
    1691         self.Controls['HKLmin'] = HKLmin
    1692         if Type ==  'Fosq':
    1693             self.Controls['FoMax'] = np.sqrt(Fo2max)
    1694         elif Type ==  'Fo':
    1695             self.Controls['FoMax'] = Fo2max
    1696         else:
    1697             print "Unsupported Struct Fact type in ImportStructFactor.UpdateControls"
    1698             raise Exception,"Unsupported Struct Fact type in ImportStructFactor.UpdateControls"
    1699 
     1648                       
    17001649######################################################################
    17011650class ImportPowderData(ImportBaseclass):
  • 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.