-
Notifications
You must be signed in to change notification settings - Fork 0
/
slow-growth.py
54 lines (43 loc) · 1.6 KB
/
slow-growth.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
## Settings ##
PLOT = True # Whether to visualize data automatically
input_file = "REPORT" # The name of the input file. Only the VASP format "REPORT" file is supported.
output_file = "slow-growth.csv" # The name of the output file
output_img ="slow-growth.png" # The name of the output image. This option only works when "PLOT = True"
## END Settings ##
x = []
y = []
def intergral(x,y):
# Only the Eular Method is implemented here
free_energy = [0]
for i in range(len(x)-1):
dx=x[i+1]-x[i]
free_energy.append(free_energy[-1]+dx*y[i])
return free_energy
with open(input_file,"r") as f:
raw_data = f.readlines()
for i in range(len(raw_data)):
temp = raw_data[i].split()
if len(temp) == 0:
continue
if temp[0] == 'b_m>':
y.append(float(temp[1]))
if temp[0] == "cc>":
x.append(float(temp[2]))
free_energy=intergral(x,y)
energy_barrier = max(free_energy)-free_energy[0]
with open(output_file,"w") as f:
f.write(f"Energy_Barrier,{energy_barrier} eV.\n")
f.write(f"CV,lambad,Free_Energy\n")
for i in range(len(free_energy)):
f.write(f"{x[i]},{y[i]},{free_energy[i]}\n")
print(f"{len(free_energy)} frames are found.")
print(f"Energy Barrier: {energy_barrier} eV.\nThe data has been written to the {output_file}.")
if PLOT == True:
import matplotlib.pyplot as plt
plt.plot(x,y)
plt.plot(x,free_energy)
plt.legend(["Lambda","Free Energy"])
plt.xlabel("CV")
plt.ylabel("Lambda / Free Energy (eV)")
plt.savefig(output_img,dpi=300)
plt.show()