forked from Angel-Jia/VASP-script
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nebforce.py
161 lines (135 loc) · 5.95 KB
/
nebforce.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
#!/usr/bin/env python
################################################################################
# The tangential force analyzer for NEB calculation by VASP #
################################################################################
#This script generates the tangential force profile for the NEB calculation by VASP
#This script is based on the work from the Computational Heterogeneous Catalysis group at the Nankai University
#writen by sky from Energy & Environmental Catalysis Research Group of Nankai University
#ver 1.0
#this is for the original VASP code
#this script can noly be used in python2.
#if you want to use it in python3, you only need to change grammar of "print" in the end of the script
import os
import sys
import subprocess
def die_out(a):
print "Error occurred in "+a
print "This may possibly due to the fact that the information had not been output by VASP yet."
print "Please try later"
sys.exit(1)
def readlist(tmp_file,list_name,field):
try:
in_buf = tmp_file.readline()
except:
die_out("reading and parsing the computational result.")
if (len(in_buf)==0):
die_out("reading and parsing the computational result.")
tmp_file.seek(0)
try:
for in_buf in tmp_file.readlines():
in_buf = in_buf.split()
list_name.append(in_buf[field])
except:
die_out("reading and parsing the computational result.")
#welcome
print "********************************************************************************"
print "* The tangential force analyzer for NEB calculation by VASP *"
print "********************************************************************************"
print "by the Energy & Environmental Catalysis Research Group of Nankai University"
print "based on Energetic profile generator"
print "which comes from Computational Heterogeneous Catalysis group at the Nankai University"
print "Version 1.0"
print
print
#get the number of image points
while True:
in_buf=raw_input( "Please type in the number of image points in your simulation:")
try:
images=int(eval(in_buf))
break
except:
print "Invalid value, type again!"
continue
while True:
in_filename=raw_input( "you need to creat a file to save information, please type in a file name:")
try:
f=open(in_filename,'w')
break
except:
print "failed to creat file, try again!"
continue
#information acquisition
line_number = ['0']
energy_list = ['0']
tangential_list = ['0']
for i in xrange(1,(images+1),1):
folder_name = "./%2.2d" % i
try:
os.chdir(folder_name)
if os.path.isfile('OUTCAR'):
print "OUTCAR successfully spotted in folder %2.2d." % i
outcar_zipped = False
elif os.path.isfile('OUTCAR.gz'):
print "OUTCAR.gz successfully spotted. It would be unzipped temporarily in folder %2.2d." % i
gunzip_outcar = subprocess.Popen(['gunzip','OUTCAR.gz'])
gunzip_outcar.wait()
outcar_zipped = True
else:
die_out('opening the file OUTCAR.')
#creat energy list
os.system("grep -n 'energy without' OUTCAR > prof_tmp_ene_all")
prof_tmp_ene_all = open("prof_tmp_ene_all",mode='r')
energy_tmp_list = []
readlist(prof_tmp_ene_all,energy_tmp_list,4)
energy_list.append(energy_tmp_list)
line_tmp_list = []
prof_tmp_ene_all.seek(0)
readlist(prof_tmp_ene_all,line_tmp_list,0)
line_number.append(line_tmp_list)
prof_tmp_ene_all.close()
#reading the projections onto the tangent
os.system("grep 'tangential force (eV/A)' OUTCAR >prof_tmp_tan_all")
prof_tmp_tan_all = open('prof_tmp_tan_all',mode='r')
tangential_tmp_list = []
readlist(prof_tmp_tan_all,tangential_tmp_list,3)
tangential_list.append(tangential_tmp_list)
prof_tmp_tan_all.close()
os.system("rm -f prof_tmp_*")
if outcar_zipped:
os.system("gzip OUTCAR")
print "The file OUTCAR had been successfully gzipped back in folder %2.2d!" % i
os.chdir("..")
except:
die_out("reading and parsing the result in folder %2.2d." % i)
#information output
min=10.0
min_index=0
min_distance=10
min_distance_index=0
n=len(line_number[1])
print >>f, " %.10s %.10s" % ("energy","tangential")
print " %.10s %.10s" % ("energy","tangential")
for i in xrange(0,n,1):
print >>f, "steps:%d" % (i+1)
print "steps:%d" % (i+1)
for j in xrange(1,(images+1),1):
print >>f, "folder%2.2d %10s %12.10f %12.10s" % (j,line_number[j][i],eval(energy_list[j][i]),eval(tangential_list[j][i]))
print "folder%2.2d %10s %12.10f %12.10s" % (j,line_number[j][i],eval(energy_list[j][i]),eval(tangential_list[j][i]))
if abs(float(tangential_list[j][i])-0) < min:
min=abs(float(tangential_list[j][i]))
min_index=i
if float(tangential_list[1][i]) < 0 and float(tangential_list[images][i]) > 0:
for j in xrange(1,(images+1),1):
if float(tangential_list[j][i]) < 0 and float(tangential_list[j+1][i]) > 0 and (float(tangential_list[j+1][i]) - float(tangential_list[j][i])) < min_distance:
min_distance=float(tangential_list[j+1][i]) - float(tangential_list[j][i])
min_distance_index=i
print >>f, ""
print ""
print >>f, "The minimum tangential force is in steps:%d The value is:%f" % (min_index+1,min)
print >>f, "Transition state may be in steps:%d The value is:%f" % (min_distance_index+1,min_distance)
print "The minimum tangential force is in steps:%d The value is:%f" % (min_index+1,min)
print "Transition state may be in steps:%d The value is:%f" % (min_distance_index+1,min_distance)
f.close()
print ""
print "Result has been saved in", in_filename
print ""