-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmovie_poscartoxyz.py
40 lines (31 loc) · 1.07 KB
/
movie_poscartoxyz.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
# input working path and number of frames
import os
import sys
from ase.io import read,write
def main():
if len(sys.argv) < 3:
print("Usage: python movie.py base_directory frames_numbers")
sys.exit()
base_dir = sys.argv[1] # working path
frames_number=int(sys.argv[2]) #number of frames
movie_file = open('movie.xyz', 'w')
#print(base_dir)
trajs=[]
for i in range(frames_number):
dir_name = os.path.join(base_dir, str(i))
#print('this is the work path', dir_name)
if not os.path.isdir(dir_name):
print(f"this is not a dir {os.path.isdir(dir_name)}")
continue
os.chdir(dir_name)
poscars = [f for f in os.listdir() if f.endswith('POSCAR')]
for f in os.listdir():
if f.endswith('POSCAR'):
trajs1 = read(f, ':', 'vasp')
#print(trajs1)
trajs=trajs+trajs1
os.chdir(base_dir)
os.system(f" cd .")
write(movie_file, trajs, 'extxyz')
if __name__ == '__main__':
main()