-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathneb2movie.py
executable file
·72 lines (62 loc) · 2.47 KB
/
neb2movie.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
#!/usr/bin/env python3
#
# Script to convert VASP NEB calculation to ASE-extxyz trajectory
# by Patrick Melix
#
# You can import the module and then call .main() or use it as a script
from ase import io
import os, glob
def main(outFile='movie.xyz', workdir='.', wrap='False', use=None):
"""
use: None -> Auto use CONTCAR if available, otherwise POSCAR
CONTCAR or POSCAR
"""
#if output exists mv to .bak
if os.path.isfile(outFile):
print('ATTENTION: {:} exists, moving to *.bak'.format(outFile))
os.rename(outFile, outFile+'.bak')
if use:
filename = use
else:
if os.path.isfile(os.path.join(workdir,'01','CONTCAR')):
filename = 'CONTCAR'
elif os.path.isfile(os.path.join(workdir,'01','POSCAR')):
filename = 'POSCAR'
else:
raise RuntimeError("Could neither find CONTCAR nor POSCAR in {:}".format(os.path.join(workdir,'01')))
print("Using {:} files.".format(filename))
mol = []
dirs = glob.glob(os.path.join(workdir,'[0-9][0-9]'))
dirs.sort()
print("Found {:} NEB subdirs.".format(len(dirs)))
print("Loading images ", end='')
for i,image in enumerate(dirs):
if (i == 0) or (i == len(dirs)-1):
imagePath = os.path.join(image, 'POSCAR')
else:
imagePath = os.path.join(image,filename)
if not os.path.isfile(imagePath):
raise RuntimeError('File {:} does not exist'.format(str(imagePath)))
print(" {:}".format(os.path.split(image)[-1]), end='')
mol.append(io.read(imagePath, format='vasp'))
print("")
for frame in mol:
if wrap:
frame.wrap(center=(0.0,0.0,0.0))
frame.write(outFile,append=True)
return
if __name__ == "__main__":
import argparse
parser = argparse.ArgumentParser(description='Convert VASP NEB to ASE-extxyz trajectory')
parser.add_argument('-o', type=str, help='Output xyz file', default='movie.xyz')
parser.add_argument('-i', type=str, help='Workdir', default='.')
parser.add_argument('-w', help='Wrap structure with origin as center', action='store_const', default=False, const=True)
parser.add_argument('use', type=str, help='Use 1: CONTCAR or 0: POSCAR, default: Auto choose CONTCAR over POSCAR.', nargs='?')
args = parser.parse_args()
if args.use == "1":
use = 'CONTCAR'
elif args.use == "0":
use = 'POSCAR'
else:
use = None
main(args.o, args.i, args.w, use)