-
Notifications
You must be signed in to change notification settings - Fork 21
/
convert_to_XYZ.py
95 lines (67 loc) · 1.93 KB
/
convert_to_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
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
#!/usr/bin/python
# Anna Tomberg
#
# Last updated : 04-12-2015
import re
import sys
import os
msg="""
------------------------------------------------------
This script convert GAMESS-US log file into xyz format.
Options:
-h print help
-i inverse tranjectory
[ ] default
------------------------------------------------------
"""
inverse_trajectory = False
if sys.argv[1] == '-h':
sys.exit(msg)
elif sys.argv[1] == '-i':
inverse_trajectory = True
file_name = sys.argv[2]
else:
file_name = sys.argv[1]
fo = open(file_name , "r")
lines = fo.readlines()
fo.close()
gamess_output = False
if lines[0].startswith("----- GAMESS execution script 'rungms' -----"):
gamess_output = True
print(">>> Reading a GAMESS output.")
if gamess_output:
line_counter = -1
total_atoms = 0
IRC_step = []
IRC_energy = 0
xyz_name = file_name.replace('.log', '.')
for line in lines:
line_counter += 1
if line.startswith(" TOTAL NUMBER OF ATOMS"):
total_atoms = int(line.split()[-1])
print("TOTAL NUMBER OF ATOMS:"),total_atoms
elif re.search("ON THE REACTION PATH",line):
IRC_step.append(line.split()[2])
IRC_energy = (lines[line_counter+3].split()[3])
ft = open(xyz_name+IRC_step[-1], "w")
ft.write(str(total_atoms)+'\n')
ft.write('Coordinates from GAMESS job ' +file_name+ ' E ' + IRC_energy+'\n')
for n in range(total_atoms):
temp = lines[line_counter + 9 + n].split()
ft.write('\t'+temp[0]+'\t'+temp[2]+'\t'+temp[3]+'\t'+temp[4]+'\n')
ft.close()
if inverse_trajectory:
fo = open(xyz_name+'xyz', "w")
for x in reversed(range(len(IRC_step))):
ft = open(xyz_name+IRC_step[x], "r")
fo.writelines(ft.readlines())
ft.close()
os.remove(xyz_name+IRC_step[x])
else:
fo = open(xyz_name+'xyz', "w")
for x in reversed(range(len(IRC_step))):
ft = open(xyz_name+IRC_step[x], "r")
fo.writelines(ft.readlines())
ft.close()
os.remove(xyz_name+IRC_step[x])
fo.close()