-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathextractor.py
More file actions
executable file
·76 lines (69 loc) · 1.88 KB
/
extractor.py
File metadata and controls
executable file
·76 lines (69 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env python
import sys
import glob
import QE
from bandgapoccu import bg as BG
import os
import json
import re
def separate_aimd(fname='scf.out',tempfile='OUT.out',jfile='data.json'):
"""This takes a AIMD run from QE and separates the data into jfile
run as separate_aimd(fname=QE out file, tempfile = Temporary file used for parsing, jfile = json file for output
"""
temp = [zz.split()[2] for zz in open(fname).read().split('\n') if 'temperature' in zz]
temp = [float(zz) for zz in temp if re.match('\d+.\d+$',zz)]
scf = open(fname,'r')
header = ''
for i in scf:
if 'PseudoPot' in i: break
header += i
data = []
rest = header + '\n\n'
tmp = ''
tmp += rest
cnt = 1
base = QE.Struct()
try:
for i in scf:
while '! total energy' not in i:
i = next(scf)
tmp += i
#data[cnt] = {}
t_ = {}
OUT = tempfile
output = open(OUT,'w')
output.write(tmp)
output.close()
x = QE.Struct()
x.File_Process(OUT)
atoms,cell = x.return_params()
if cnt == 1: base.File_Process(OUT)
displ = {}
for zz in base.atoms:
displ[zz] = list(base.atoms[zz]-x.atoms[zz])
t_['str'] = x.print()
t_['atoms'] = atoms
t_['cell'] = cell
t_['displ'] = displ
t_['energy'] = x.energy
del x
Gap = BG(OUT)
t_['gap'] = Gap.bg
try:
t_['temp'] = temp[cnt - 1] #[zz for zz in open(str(cnt) + '.out').read().split('\n') if 'temperature' in zz][-1].split()[2]
except:
t_['temp'] = 'NA'
cnt += 1
tmp = rest
data.append(t_)
with open(jfile, 'w') as outfile:
json.dump(data, outfile)
i = next(scf)
continue
scf.close()
except StopIteration:
scf.close()
with open(jfile, 'w') as outfile:
json.dump(data, outfile)
if __name__ == '__main__':
separate_aimd(fname=sys.argv[1])