-
Notifications
You must be signed in to change notification settings - Fork 5
/
separate_configs_box.py
executable file
·48 lines (37 loc) · 1.35 KB
/
separate_configs_box.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
#!/usr/bin/env python3
"""
Given the filename a xyz trajectory and the interval between each save,
print a box configuration.
Author: Henrique Musseli Cezar
Date: JUN/2018
"""
import argparse
import os
def print_configs(fname, svint, nconfs, init):
with open(fname,'r') as f:
natoms = int(f.readline())
boxsize = natoms + 2
f.seek(0)
confnum = 1
#skip to the initial configuration
for _ in range(init*boxsize):
f.readline()
confnum += init
# loop to print nconfs configurations
for i in range(nconfs):
# skip svint-1 configurations
for j in range(svint-1):
for lnum in range(boxsize):
f.readline()
for lnum in range(boxsize):
line = f.readline()
print(line, end="")
confnum += 1
if __name__ == '__main__':
parser = argparse.ArgumentParser(description="Separates configurations from a xyz trajectory")
parser.add_argument("filename", help="the xyz file containing the trajectory")
parser.add_argument("svint", help="save interval (configuration will be saved each this number of steps)")
parser.add_argument("nconfs", help="number of configuration to be saved")
parser.add_argument("--init", help="initial configutation (default=0)", default=0)
args = parser.parse_args()
print_configs(args.filename, int(args.svint), int(args.nconfs), int(args.init))