-
Notifications
You must be signed in to change notification settings - Fork 0
/
delete_traj_files.py
executable file
·56 lines (47 loc) · 1.61 KB
/
delete_traj_files.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
import glob
import multiprocessing
import os
import sys
import argparse
# Build commandline parser
parser = argparse.ArgumentParser(description="Remove the traj files created by the Rosetta ddg_monomer app.")
# Arguments
parser.add_argument(
"-db_split_dir",
"--db_split_dir",
type=str,
dest="db_split_dir",
metavar="PATH",
help="Absolute path to the split directory containing all the two character folders, pdb style.",
required=True)
# Set default arguments
parser.set_defaults()
# Put arguments into args object:
args = parser.parse_args()
def delete_traj(split):
'''Find all protein directories in the split directory. Walk thorugh them and delete all _traj files.'''
# Find the protein folders:
prot_glob = split + '*/'
prots = glob.glob(prot_glob)
for prot in prots:
# Find all the chain folders:
chain_glob = prot + '*/'
chains = glob.glob(chain_glob)
for chain in chains:
# Then find the all _traj files
traj_glob = chain + '*_traj*'
trajs = glob.glob(traj_glob)
for traj in trajs:
# Delete the _traj files one by one.
# Use try to avoid termination if moving/removing while the script is running.
try:
os.remove(traj)
except:
pass
if __name__ == "__main__":
# Find all the sub directories under split:
splits_glob = args.db_split_dir + '/' + '*/'
splits = glob.glob(splits_glob)
# Paralellise the process:
pool = multiprocessing.Pool(32)
output = pool.map(delete_traj, splits)