Package diffpy :: Package srrietveld :: Package addon :: Module structurefile
[frames] | no frames]

Source Code for Module diffpy.srrietveld.addon.structurefile

 1  ############################################################################## 
 2  # 
 3  # diffpy.srrietveld by DANSE Diffraction group 
 4  #                   Simon J. L. Billinge 
 5  #                   (c) 2009 Trustees of the Columbia University 
 6  #                   in the City of New York.  All rights reserved. 
 7  # 
 8  # File coded by:    Peng Tian 
 9  # 
10  # See AUTHORS.txt for a list of people who contributed. 
11  # See LICENSE.txt for license information. 
12  # 
13  ############################################################################## 
14   
15  """ structurefile.py is to convert different format structure files to a dictionary. 
16      currently only cif file can be converted. Assume one cif for one structure. 
17  """ 
18   
19  __id__ = "$Id: structurefile.py 5657 2010-07-09 19:43:17Z juhas $" 
20   
21  from diffpy.Structure import Structure 
22   
23 -class StructureFileConverter:
24 """ Convert input structure file to a dictionary """ 25
26 - def __init__(self, structurefile):
27 """ Initialization """ 28 import os 29 self.strufile = structurefile 30 filename = os.path.basename(structurefile) 31 self.name = os.path.splitext(filename)[0] 32 self.structure = Structure() 33 self.atominfo = self.structure.read(structurefile) 34 self.strudict = {'PHASE':[]} 35 return
36
37 - def cifToDict(self):
38 """ put cif content to dictionary """ 39 import re 40 41 # set single Phase section 42 phase = {} 43 phase['Name'] = self.name 44 phase['a'] = self.structure.lattice.a 45 phase['b'] = self.structure.lattice.b 46 phase['c'] = self.structure.lattice.c 47 phase['alpha'] = self.structure.lattice.alpha 48 phase['beta'] = self.structure.lattice.beta 49 phase['gamma'] = self.structure.lattice.gamma 50 phase['Spacegroup'] = self.atominfo.cif_sgname 51 atomlist = self.atominfo.asymmetric_unit 52 for atom in atomlist: 53 atomkey = 'ATOM' + str(atomlist.index(atom)+1) 54 phase[atomkey] = [] 55 tempdict = {} 56 # find the atom name 57 res = re.search(r'([^0-9]*)', atom.name) 58 if res and res.groups(): 59 atomname = res.groups()[0] 60 else: 61 atomname = atom.name 62 tempdict['Name'] = atomname 63 tempdict['Symbol'] = atomname 64 tempdict['Typ'] = atomname 65 if atom.Bisoequiv <= 0.0: 66 tempdict['Biso'] = 1.0 67 else: 68 tempdict['Biso'] = atom.Bisoequiv 69 xyz = map(None, atom.xyz) 70 tempdict['X'] = xyz[0] 71 tempdict['Y'] = xyz[1] 72 tempdict['Z'] = xyz[2] 73 phase[atomkey].append(tempdict) 74 self.strudict['PHASE'].append(phase) 75 return self.strudict
76