-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcp2krestart2xyz.py
More file actions
executable file
·58 lines (45 loc) · 1.64 KB
/
cp2krestart2xyz.py
File metadata and controls
executable file
·58 lines (45 loc) · 1.64 KB
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
#!/usr/bin/env python3
# creates an ASE xyz file from a cp2k restart file
import os
from ase import io
def main(inFile,outFile):
if not os.path.isfile(inFile):
raise ValueError('File {:} does not exist'.format(str(inFile)))
#if output exists mv to .bak
if os.path.isfile(outFile):
print('ATTENTION: {:} exists, moving to *.bak'.format(outFile))
os.rename(outFile, outFile+'.bak')
cell = []
atoms = []
with open(inFile, 'r') as f:
for line in f:
if '&CELL' in line:
while True:
l = f.readline().strip()
if l.startswith(('A', 'B', 'C')):
cell.append([ s for s in l.split()[1:] ])
if '&END' in l:
break
if '&COORD' in line:
while True:
l = f.readline().strip()
if '&END' in l:
break
atoms.append(l)
with open(outFile,'w') as f:
f.write("{:}\n".format(len(atoms)))
f.write("\n")
for atom in atoms:
f.write("{}\n".format(atom))
for i, vec in enumerate(cell):
f.write("VEC{} {} {} {}\n".format(i+1, *vec))
#test
mol = io.read(outFile)
mol.write(outFile)
if __name__ == "__main__":
import argparse
parser = argparse.ArgumentParser(description='Convert Gaussian output to ASE-extxyz trajectory')
parser.add_argument('input', type=str, help='input restart file')
parser.add_argument('output', type=str, help='output file')
args = parser.parse_args()
main(args.input,args.output)