-
Notifications
You must be signed in to change notification settings - Fork 0
/
pdb_torsion.py
executable file
·93 lines (68 loc) · 2.6 KB
/
pdb_torsion.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/env python
# Copyright 2007, Michael J. Harms
# This program is distributed under General Public License v. 3. See the file
# COPYING for a copy of the license.
__description__ = \
"""
Determines the dihedral angles (phi,psi) for each residue in a protein.
"""
__author__ = "Michael J. Harms"
__date__ = "070601"
import os, sys
from helper import cmdline, geometry
def pdbTorsion(pdb):
"""
Calculate the backbone torsion angles for a pdb file.
"""
# Filter pdb file taking only N, CA, and C atoms
atoms = [line for line in pdb if line[0:4] == 'ATOM' and
line[13:16] in ['N ','CA ','C ']]
# Define arrays that will contain CA, CO, and N coordinates
num_resid = len(atoms)/3
N = [[0.,0.,0.] for i in range(num_resid)]
CA = [[0.,0.,0.] for i in range(num_resid)]
CO = [[0.,0.,0.] for i in range(num_resid)]
# Read the list of atoms into the coordinate arrays
for i in range(num_resid):
for j in range(3):
N[i][j] = float(atoms[i*3][30+8*j:39+8*j])
CA[i][j] = float(atoms[1+i*3][30+8*j:39+8*j])
CO[i][j] = float(atoms[2+i*3][30+8*j:39+8*j])
# Calculate phi and psi for each residue
labels = []
dihedrals = []
label_atoms = [l for l in atoms if l[0:4] == "ATOM" and l[13:16] == "CA "]
for i in range(1,num_resid-1):
try:
labels.append((label_atoms[i][17:20],label_atoms[i][21:26]))
dihedrals.append(geometry.calcDihedrals(CO[i-1],N[i],CA[i],CO[i],
N[i+1]))
except ValueError:
pass
return dihedrals, labels
def main():
"""
Call if this is called from the command line.
"""
cmdline.initializeParser(__description__,__date__)
file_list, options = cmdline.parseCommandLine()
out = []
for pdb_file in file_list:
# Read in input file
f = open(pdb_file,'r')
pdb = f.readlines()
f.close()
# Calculate torsion angles and secondary structure
dihedrals, labels = pdbTorsion(pdb)
# Print out results in pretty fashion
short_pdb = os.path.split(pdb_file)[-1][:-4]
for i in range(len(dihedrals)):
out.append("%30s%4s \"%5s\"%10.2F%10.2F\n" %\
(short_pdb,labels[i][0],labels[i][1],
dihedrals[i][0],dihedrals[i][1]))
out = ["%10i%s" % (i,x) for i, x in enumerate(out)]
header = "%10s%30s%4s%8s%10s%10s\n" % (" ","pdb","aa","res","phi","psi")
out.insert(0,header)
print "".join(out)
if __name__ == "__main__":
main()