1
2
3
4
5
6
7
8
9
10
11
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
24 """ Convert input structure file to a dictionary """
25
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
38 """ put cif content to dictionary """
39 import re
40
41
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
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