-
Notifications
You must be signed in to change notification settings - Fork 1
/
pad-trajectory.py
executable file
·56 lines (40 loc) · 1.55 KB
/
pad-trajectory.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
#!/usr/bin/env python3
#
# Script to generate an ext-xyz trajectory from individual ext-xyz files with varying atom numbers using ASE.
# Appens 'X' atoms at origin to obtain frames with equal lengths
# by Patrick Melix
# 2020/06/08
#
from ase import io, Atom
import os
def main(inList, outFile='traj.xyz', outFormat='extxyz'):
#if output exists mv to .bak
if os.path.isfile(outFile):
print('ATTENTION: {:} exists, moving to *.bak'.format(outFile))
os.rename(outFile, outFile+'.bak')
traj = []
for inFile in inList:
if not os.path.isfile(inFile):
raise ValueError('File {:} does not exist'.format(inFile))
print(inFile)
traj.append(io.read(inFile))
maxLen = max([len(frame) for frame in traj])
for i in range(len(traj)):
if len(traj[i]) < maxLen:
for j in range(maxLen-len(traj[i])):
traj[i].append(Atom('X'))
with open(outFile,'w') as f:
for frame in traj:
frame.write(f, format=outFormat)
return
#########################
# Functions
########################
if __name__ == "__main__":
import argparse
parser = argparse.ArgumentParser(description='Combine different lengths of XYZ')
parser.add_argument('--outformat', help='Output ASE Format', default='extxyz')
parser.add_argument('--outfile', help='Output File', default='traj.xyz')
parser.add_argument('-files', type=str, nargs='+', default=[], help='All the XYZ Files')
args = parser.parse_args()
main(args.files, args.outfile, args.outformat)