-
Notifications
You must be signed in to change notification settings - Fork 0
/
PESplotter.py
179 lines (130 loc) · 4.52 KB
/
PESplotter.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
import matplotlib.pyplot as plt
from os import listdir, environ
from sys import argv, exit
import plotext.plot as plx
from termcolor import colored
import numpy as np
import pandas as pd
def input_file():
"""
DESCRIPTION
Function for setting the file_name. It can be the default (PES.plt) or an input file. It is checked if the file is in the directory and the program is quitted if it isn't.
"""
print(argv)
if len(argv) == 1:
if 'PES.plt' in listdir():
file_name = 'PES.plt'
else :
print('No PES.plt file in the directory. Please, specify the filename as an argument')
exit()
elif len(argv) == 2:
if argv[1] in listdir():
file_name = argv[1]
else :
print(file_name, 'does not exist in the directory.')
exit()
return file_name
def parse_file(file_name):
df = pd.DataFrame(pd.read_csv(file_name))
x_key = []
y_key = []
for key in df.keys():
if key.find('rc') != -1:
x_key.append(key)
elif key.find('deltaE') != -1:
y_key.append(key)
else :
pass
if len(x_key) > 1:
print('Detected possible coordinates:')
for key in range(len(x_key)):
print(key + 1, '. ', x_key[key])
while True:
try :
quest = int(input('Which coordinate do you want? '))
if quest in range(1, len(x_key) + 1):
x_key = x_key[quest-1]
break
else :
print('The selected coordinate does not exist.')
continue
except ValueError:
print('Type a number')
continue
elif len(x_key) == 1:
x_key = x_key[0]
elif len(x_key) == 0:
print('No reaction coordinate has been detected. Please, select one of the following: ')
for k in range(len(df.keys())):
print(k+1, ': ', df.keys()[k])
while True:
try :
quest = int(input('Select the number of the column containing the reaction coordinate: '))
if quest in range(1, len(df.keys()) + 1):
x_key = x_key[quest-1]
break
else :
print('The selected column does not exist.')
continue
except ValueError:
print('Type a number')
continue
x = list(df[x_key])
if len(y_key) > 1:
print('Detected possible relative energy:')
for key in range(len(x_key)):
print(key + 1, '. ', y_key[key])
while True:
try :
quest = int(input('Which energy do you want? '))
if quest in range(1, len(y_key) + 1):
y_key = y_key[quest-1]
break
else :
print('The selected coordinate does not exist.')
continue
except ValueError:
print('Type a number')
continue
elif len(y_key) == 1:
y_key = y_key[0]
elif len(y_key) == 0:
print('No relative energy has been detected. Please, select one of the following: ')
for k in range(len(df.keys())):
print(k+1, ': ', df.keys()[k])
while True:
try :
quest = int(input('Select the number of the column containing the relative energy: '))
if quest in range(1, len(y_key) + 1):
y_key = y_key[quest-1]
break
else :
print('The selected column does not exist.')
continue
except ValueError:
print('Type a number')
continue
y = list(df[y_key])
return x, y, x_key, y_key
def plot_energy_plx(x,y):
plx.plot(x,y)
plx.show()
print(colored(str(len(x)) + ' points of the scan have been calculated so far.', 'red'))
def plot_energy_mtl(x, y, x_key, y_key):
plt.plot(x, y, marker='.')
plt.xlabel(x_key)
plt.ylabel(y_key)
plt.grid()
plt.show()
print(colored(str(len(x)) + ' points of the scan have been calculated so far.', 'red'))
def main():
file_name = input_file()
x, y, x_key, y_key = parse_file(file_name)
try :
environ['DISPLAY']
#print('MATPLOTLIB')
plot_energy_mtl(x, y, x_key, y_key)
except KeyError:
plot_energy_plx(x,y)
if __name__ == '__main__':
main()