-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinterp.py
executable file
·89 lines (74 loc) · 2.73 KB
/
interp.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
#!/usr/bin/python3
"""Read .interp files from ORCA NEB calculations and create graphs."""
import argparse
import matplotlib.pyplot as plt
import numpy as np
from scipy.constants import calorie
from scipy.constants import kilo
from scipy.constants import N_A
from scipy.constants import physical_constants
hartree, _, _ = physical_constants["Hartree energy"]
def main():
"""Run main procedure."""
parser = argparse.ArgumentParser()
parser.add_argument(
"interp_file", type=argparse.FileType("r"), default="-"
)
parser.add_argument("-a", "--all", action="store_true")
args = parser.parse_args()
images = []
interps = []
for line in args.interp_file:
line = line.strip()
if line:
fields = line.split()
if fields[0] == "Iteration:":
try:
images.append(np.array(image))
interps.append(np.array(interp))
except UnboundLocalError:
pass
image = []
interp = []
elif fields[0] == "Images:":
mode = "images"
elif fields[0] == "Interp.:":
mode = "interps"
else:
if mode == "images":
image.append(np.array([float(entry) for entry in fields]))
if mode == "interps":
interp.append(np.array([float(entry) for entry in fields]))
# Add the last set of data
images.append(np.array(image))
interps.append(np.array(interp))
images = np.array(images)
interps = np.array(interps)
i_max = images[-1, :, 2].argmax()
forward_barrier = images[-1, i_max, 2] - images[-1, 0, 2]
backward_barrier = images[-1, i_max, 2] - images[-1, -1, 2]
print(
f"barrier is at the {i_max + 1}th (out of {len(images[-1, :, 2])}) position"
)
print(
f"forward barrier = {forward_barrier:6.4f} Eh "
f"= {forward_barrier * hartree * N_A / kilo:5.1f} kJ/mol "
f"= {forward_barrier * hartree * N_A / (kilo * calorie):5.1f} kcal/mol"
)
print(
f"backward barrier = {backward_barrier:6.4f} Eh "
f"= {backward_barrier * hartree * N_A / kilo:5.1f} kJ/mol "
f"= {backward_barrier * hartree * N_A / (kilo * calorie):5.1f} kcal/mol"
)
if args.all:
for i in range(len(images) - 1):
plt.plot(images[i, :, 1], images[i, :, 2], "ok")
plt.plot(interps[i, :, 1], interps[i, :, 2], "--", label=i)
plt.plot(images[-1, :, 1], images[-1, :, 2], "ok")
plt.plot(interps[-1, :, 1], interps[-1, :, 2], "--", label=-1)
plt.xlabel("Distance (Bohr)")
plt.ylabel("Energy (Eh)")
plt.legend()
plt.show()
if __name__ == "__main__":
main()