Changeset 3162 for trunk


Ignore:
Timestamp:
Nov 27, 2017 1:03:30 PM (8 years ago)
Author:
vondreele
Message:

add importer for ICDD .str files

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified trunk/imports/G2phase.py ΒΆ

    r3136 r3162  
    572572        Phase['Atoms'] = Atoms
    573573        return Phase
     574   
     575class PDF_ReaderClass(G2obj.ImportPhase):
     576    'Routine to import Phase information from ICDD PDF Card files'
     577    def __init__(self):
     578        super(self.__class__,self).__init__( # fancy way to say ImportPhase.__init__
     579            extensionlist=('.str',),
     580            strictExtension=True,
     581            formatName = 'ICDD .str',
     582            longFormatName = 'ICDD PDF Card (.str file) import'
     583            )
     584       
     585    def ContentsValidator(self, filename):
     586        'Look for a str tag in 1st line'
     587        fp = open(filename,'r')
     588        if fp.read(3) == 'str':
     589            fp.close()
     590            return True
     591        self.errors = 'File does not begin with str tag'
     592        fp.close()
     593        return False
     594
     595    def Reader(self,filename, ParentFrame=None, **unused):
     596        'Read phase from a ICDD .str file using :meth:`ReadPDFPhase`'
     597        fp = open(filename,'r')
     598        self.Phase = self.ReadPDFPhase(ParentFrame, fp)
     599        fp.close()
     600        return True
     601
     602    def ReadPDFPhase(self, G2frame,fp):
     603        '''Read a phase from a ICDD .str file.
     604        '''
     605        EightPiSq = 8.*math.pi**2
     606        self.errors = 'Error opening file'
     607        Phase = {}
     608        Atoms = []
     609        S = fp.readline()
     610        line = 1
     611        SGData = None
     612        cell = []
     613        cellkey = []
     614        while S:
     615            if 'space_group' in S:
     616                break
     617            S = fp.readline()                   
     618        while S:
     619            self.errors = 'Error reading at line '+str(line)
     620            if 'phase_name' in S:
     621                Title = S.split('"')[1]
     622            elif 'Space group (HMS)' in S:
     623                SpGrp = S.split()[-1]
     624                SpGrpNorm = G2spc.StandardizeSpcName(SpGrp)
     625                E,SGData = G2spc.SpcGroup(SpGrpNorm)
     626                # space group processing failed, try to look up name in table
     627                while E:
     628                    print (G2spc.SGErrors(E))
     629                    dlg = wx.TextEntryDialog(G2frame,
     630                        SpGrp[:-1]+' is invalid \nN.B.: make sure spaces separate axial fields in symbol',
     631                        'ERROR in space group symbol','',style=wx.OK)
     632                    if dlg.ShowModal() == wx.ID_OK:
     633                        SpGrp = dlg.GetValue()
     634                        E,SGData = G2spc.SpcGroup(SpGrp)
     635                    else:
     636                        SGData = G2obj.P1SGData # P 1
     637                        self.warnings += '\nThe space group was not interpreted and has been set to "P 1".'
     638                        self.warnings += "Change this in phase's General tab."           
     639                    dlg.Destroy()
     640                G2spc.SGPrint(SGData) #silent check of space group symbol
     641            elif 'a a_' in S[:7]:
     642                data = S.split()
     643                cell.append(float(data[2]))
     644                cellkey.append(data[1])
     645            elif 'b b_' in S[:7]:
     646                data = S.split()
     647                cell.append(float(data[2]))
     648                cellkey.append(data[1])
     649            elif 'b =' in S[:6]:
     650                data = S.split('=')
     651                indx = cellkey.index(data[1].split(';')[0])
     652                cell.append(cell[indx])
     653            elif 'c c_' in S[:7]:
     654                data = S.split()
     655                cell.append(float(data[2]))
     656            elif 'c =' in S[:6]:
     657                data = S.split('=')
     658                indx = cellkey.index(data[1].split(';')[0])
     659                cell.append(cell[indx])
     660            elif 'al' in S[:5]:
     661                cell.append(float(S.split()[1]))
     662            elif 'be' in S[:5]:
     663                cell.append(float(S.split()[1]))
     664            elif 'ga' in S[:5]:
     665                cell.append(float(S.split()[1]))
     666                Volume = G2lat.calc_V(G2lat.cell2A(cell))
     667                break
     668            S = fp.readline()
     669        S = fp.readline()
     670        while S:
     671            if '/*' in S[:5]:
     672                break
     673            if 'site' in S[:7]:
     674                atom = []
     675                data = S.split()
     676                atom.append(data[1])    #name
     677                pos = data.index('occ')+1
     678                atom.append(data[pos])  #type
     679                atom.append('')         #refine
     680                for xid in ['x =','y =','z =']:
     681                    if xid in S:
     682                        xpos = S.index(xid)+3
     683                        xend = xpos+S[xpos:].index(';')
     684                        atom.append(eval(S[xpos:xend]+'.'))
     685                    else:
     686                        xpos = data.index(xid[0])+2
     687                        atom.append(float(data[xpos]))
     688                atom.append(float(data[pos+2]))
     689                SytSym,Mult = G2spc.SytSym(np.array(atom[3:6]),SGData)[:2]
     690                atom.append(SytSym)
     691                atom.append(Mult)
     692                if 'beq' in S:
     693                    atom.append('I')
     694                    upos = data.index('beq')
     695                    atom.append(float(data[upos+2])/EightPiSq)
     696                    atom += [0.,0.,0.,0.,0.,0.,]
     697                elif 'ADPs' in S:
     698                    upos = data.index('ADPs')
     699                    atom.append('A')
     700                    atom.append(0.0)
     701                    for uid in ['Bani11','Bani22','Bani33','Bani12','Bani13','Bani23']:
     702                        upos = data.index(uid)+1
     703                        atom.append(float(data[upos])/EightPiSq)
     704                else:
     705                    atom.append('I')
     706                    atom += [0.02,0.,0.,0.,0.,0.,0.,]                   
     707                atom.append(ran.randint(0,sys.maxsize))
     708                Atoms.append(atom)
     709            S = fp.readline()               
     710        fp.close()
     711        self.errors = 'Error after read complete'
     712        if not SGData:
     713            raise self.ImportException("No space group (spcgroup entry) found")
     714        if not cell:
     715            raise self.ImportException("No cell found")
     716        Phase = G2obj.SetNewPhase(Name=Title,SGData=SGData,cell=cell+[Volume,])
     717        Phase['General']['Type'] = 'nuclear'
     718        Phase['General']['AtomPtrs'] = [3,1,7,9]
     719        Phase['Atoms'] = Atoms
     720        return Phase
Note: See TracChangeset for help on using the changeset viewer.