-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathpdb_grab_atom_radius.py
executable file
·76 lines (51 loc) · 1.8 KB
/
pdb_grab_atom_radius.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env python
# Sebastian Raschka 2014
#
# Python PyProt script to extracts atoms within a radius from a PDB file.
#
# run
# ./pdb_grab_atom_radius.py -h
# for help
#
import pyprot
import argparse
parser = argparse.ArgumentParser(
description='Extracts atoms within a radius from a PDB file.\n'\
'By default, all atoms in the PDB file are included in the calculation.',
formatter_class=argparse.RawTextHelpFormatter
)
# positional arguments
parser.add_argument('-i', '--input', help='Input PDB file')
parser.add_argument('-r', '--radius',
type=float,
metavar='int/float',
default='10.0',
help='radius in Angstrom for atoms to extract (default 10.0)')
parser.add_argument('-c', '--coordinates',
type=str,
metavar='X,Y,Z',
default='0,0,0',
help='center for extracting atoms (default "0,0,0")')
# optional arguments
parser.add_argument('-n', '--include', type=str,
default='ATOM,HETATM',
metavar='coordinate-ID',
help='Coordinate lines to include (default: "ATOM,HETATM")')
parser.add_argument('-o', '--out', metavar='out.fasta', type=str,
help='writes atoms to an output file instead of printing it to the screen')
args = parser.parse_args()
if not args.input:
print('{0}\nPlease provide an input file.\n{0}'.format(50* '-'))
parser.print_help()
quit()
pdb = pyprot.Pdb(args.input)
coords = args.coordinates.split(',')
coords = [float(i) for i in coords]
residues = pdb.grab_radius(args.radius, coords)
if args.out:
with open(args.out, 'w') as out:
for line in residues:
out.write(line + '\n')
else:
for line in residues:
print(line)