-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqe_parse.py
100 lines (88 loc) · 3.62 KB
/
qe_parse.py
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/usr/bin/python
#===========================================================================#
# #
# File: qe_parse.py #
# Dependence: util.py #
# Usage: parse files generated by Quantum ESPRESSO #
# Author: Shunhong Zhang <[email protected]> #
# Date: Apr 22, 2017 #
# #
#===========================================================================#
import numpy as np
from math import *
import os
def parse_qe_eigenval(filename,nspin=1):
print "Parsing {0} ...".format(filename)
f=open(filename,'r')
line = f.readline().split()
nband = int(line[2].split(",")[0])
nkpt = int(line[4])
print "number of bands = ",nband,"\nnumber of q points = ",nkpt
kpt = np.zeros((nkpt,3),float)
eigenval = np.zeros((nkpt,nband,nspin),float)
for ikpt in range(nkpt):
line = f.readline().split()
kpt[ikpt] = [float(line[i]) for i in range(3)]
data = np.fromfile(f,sep=' ',count=nband*nspin).reshape((nspin,nband))
for ispin in range(nspin):
eigenval[ikpt,:,ispin]=[float(data[ispin,iband]) for iband in range(nband)]
eigenval[ikpt,:,ispin].sort()
f.close()
print "Done"
return kpt,eigenval
# Extract the final lattice and atom coordinates of a relaxation calculation by qe
def parse_qe_rx(filename):
ibrav=int(os.popen('grep "bravais-lattice index" '+filename).readline().split('=')[1])
get_cell=os.popen('grep -A 6 "Begin final " '+filename).readlines()
alat=float(get_cell[3].split('=')[1].split(')')[0])
cell = np.zeros((3,3),float)
for i in range(3):
for j in range(3):
cell[i,j]=float(get_cell[i+4].split()[j])
cell=cell*alat
celldm = find_celldm(ibrav,cell)
for i in range(1,7):
if celldm[i]!=0:
print "celldm("+str(i)+") =",celldm[i]
natom = int(os.popen('grep "number of atoms" '+filename).readline().split('=')[1])
pos = os.popen('grep -B '+str(natom)+' "End final coordinates" '+filename).readlines()[:-1]
for i in range(len(pos)):
print pos[i],
def get_rec_vec_qe():
try:
line=os.popen("grep 'lattice parameter (alat)' nscf.out").readline()
alat=float(line.split()[4])*0.529
print "alat=",alat,"angstrom"
except:
print "unable to extract the lattice parameter"
exit()
rec_vec=np.zeros((3,3),float)
try:
lines=os.popen("grep -A 3 'reciprocal axes' nscf.out").readlines()
for i in range(3):
for j in range(3):
rec_vec[i,j] = float(lines[i+1].split()[j+3])/2/np.pi*alat
except:
print "unable to extract the reciprocal axes"
exit()
return rec_vec
def parse_abinit_eigenval(filename,nspin=1):
print "Parsing {0} ...".format(filename)
f=open(filename,'r')
line = f.readline().split()
nkpt = int(line[6])
print "number of k points = ",nkpt
kpt = np.zeros((nkpt,3),float)
kweight=np.zeros(nkpt,float)
eigenval=[]
for ikpt in range(nkpt):
line = f.readline().split()
nband=int(line[3].rstrip(','))
kweight[ikpt]=float(line[5].rstrip(','))
kpt[ikpt] = [float(line[i]) for i in range(7,10)]
data = np.fromfile(f,sep=' ',count=nband)
eigenval.append(data)
f.close()
eigenval=np.array(eigenval)
print "Done"
return kpt,kweight,eigenval