-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQE-extract-xyz.py
executable file
·49 lines (42 loc) · 1.35 KB
/
QE-extract-xyz.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
#!/usr/bin/env python
# extract all coordinates from Quantum Espresso output file
# and write in a file as a catresian trajectory
#
# python QE-extract-xyz.py outfilename
# Written by Rahul Verma ([email protected])
import sys,os
start = []
end = []
#Reading QE oufilename as an argument from the same line
file = sys.argv[1]
# Open a file as outfile-traj.xyz to write xyz
nwfile = os.path.splitext(file)[0] + "-traj.xyz"
oldfile = open(file,"r")
newfile = open(nwfile,"w")
#Read the complete outfile
rline = oldfile.readlines()
# Find the given arguments from the file, if finds :
# Stores that line number in i as start array
# Similar for the end string in m and append it to end array
for i in range (len(rline)):
if "ATOMIC_POSITIONS (angstrom)" in rline[i]:
start.append(i+1)
for m in range (start[-1],len(rline)):
if "Writing " in rline[m]:
end.append(m-3)
break
#print(start)
#print(end)
j = len(start)-1
end[j] = end[j]-1
# Writing the extracted coordinates in a formatted xyz format
for i,iStart in enumerate(start):
nAtoms = end[i] - (start[i])
newfile.write(str(nAtoms))
newfile.write('\n\n')
for line in rline[start[i] : end[i]]:
words = line.split()
newfile.write("{:10} {:}\n".format(words[0],line[7:-1]))
oldfile.close()
newfile.close()
#end of the program