-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathpdb_split_atom_hetatm.py
More file actions
executable file
·60 lines (41 loc) · 1.45 KB
/
pdb_split_atom_hetatm.py
File metadata and controls
executable file
·60 lines (41 loc) · 1.45 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
57
58
59
60
#!/usr/bin/env python
# Sebastian Raschka 2014
#
# Python PyProt script to autmatically create separate PDB files
# from ATOM and HETATM lines in a PDB file.
#
# run
# ./pdb_split_atom_hetatm.py -h
# for help
#
import argparse
import pyprot
import os
parser = argparse.ArgumentParser(
description='Autmatically creates separate PDB files from ATOM and HETATM lines in a PDB file.',
formatter_class=argparse.RawTextHelpFormatter
)
parser.add_argument('-i', '--input', type=str, help='Path to directory that contains PDB files.')
args = parser.parse_args()
if not args.input:
print('{0}\nPlease provide an input directory.\n{0}'.format(50* '-'))
parser.print_help()
quit()
atom_out = os.path.join(args.input, 'pdb_atom')
hetatm_out = os.path.join(args.input, 'pdb_hetatm')
for d in (atom_out, hetatm_out):
if not os.path.exists(d):
os.mkdir(d)
pdb_list = [os.path.join(args.input, pdb) for pdb in os.listdir(args.input)
if pdb.endswith('.pdb')]
n = len(pdb_list)
if not n:
print('{0}\nPDB list is empty. Please check the input directory for PDB files.\n{0}'.format(50* '-'))
parser.print_help()
quit()
for pdb in pdb_list:
pdb_obj = pyprot.Pdb(pdb)
pdb_atom = pyprot.Pdb(pdb_obj.atom_ter)
pdb_hetatm = pyprot.Pdb(pdb_obj.hetatm)
pdb_atom.save_pdb(os.path.join(atom_out, os.path.basename(pdb)))
pdb_hetatm.save_pdb(os.path.join(hetatm_out, os.path.basename(pdb)))