Skip to content

Instantly share code, notes, and snippets.

@latticetower
Created May 5, 2017 09:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save latticetower/29b37cfe2050a890265727f8eaf21b0c to your computer and use it in GitHub Desktop.
Save latticetower/29b37cfe2050a890265727f8eaf21b0c to your computer and use it in GitHub Desktop.
Example code with iteration over pdb file chains with sliding window
from prody import *
pdb = parsePDB("1QS3")
def sliding_window(aminoacids, width=3):
"""
iterates over residues in given chain, returns iterator
with arrays containing each width elements (as a sliding window)
"""
index = 1 # prody starts iteration from 1, or at least it seems
aa_list = [ aminoacids[index + offset] for offset in xrange(width) ]
yield aa_list
offset = 0
while width+offset < len(aminoacids):
aa_list.pop(0)
aa_list.append(aminoacids[width + offset])
yield aa_list
offset += 1
def get_angles(fragment):
"""
gets list of Aminoacid elements as an input
returns list of torsion angles (phi, psi) for all atoms except first and last in list
"""
return [
(prody.measure.measure.calcPhi(x), prody.measure.measure.calcPsi(x))
for x in fragment[1:len(fragment) - 1]
]
def get_aminoacid_sequence(fragment):
"""
gets list of Aminoacid elements as an input
returns aminoacid sequence as a string containing 1-letter IUPAC codes
"""
get = prody.atomic.chain.AAMAP.get
return ''.join([get(res.getResname(), 'X') for res in fragment])
print(pdb)
for chain in pdb.getHierView():
for fragment in sliding_window(chain):
print(fragment)
print(get_aminoacid_sequence(fragment)) # this should be converted to smiles string
print(get_angles(fragment))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment