-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmol2_split.py
executable file
·51 lines (33 loc) · 1.15 KB
/
mol2_split.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 python
# Sebastian Raschka 2014
# Python PyProt script that splits a multi-MOL2 file into individual mol2 files.
#
# run
# ./mol2_split.py -h
# for help
#
import sys
import os
import argparse
from pyprot.mol2io import split_multimol2
parser = argparse.ArgumentParser(
description='Splits a multi-MOL2 file into individual mol2 files',
formatter_class=argparse.RawTextHelpFormatter
)
parser.add_argument('-i', '--input', type=str, help='MOL2 input file.')
parser.add_argument('-o', '--output', type=str, help='Output directory for the individual mol2 files.')
args = parser.parse_args()
if not args.input:
print('Please provide an input file via the -i flag. Use --help for more information.\n')
quit()
if not args.output:
print('Please provide an output file via the -o flag. Use --help for more information.\n')
quit()
if not os.path.exists(args.output):
os.mkdir(args.output)
single_mol2s = split_multimol2(args.input)
for mol2 in single_mol2s:
out_mol2 = os.path.join(args.output, mol2[0]) + '.mol2'
with open(out_mol2, 'w') as out_file:
for line in mol2[1]:
out_file.write(line)