Print

MD Backbone dihedral angles

Written by Super User. Posted in Uncategorised

In need of a simple and quick-and-dirty solution to extract backbone dihedral angles from pdb files or simulation data?  Try this python snippet using the python package MDAnalysis (https://code.google.com/p/mdanalysis/).

 

import MDAnalysis
import sys
import numpy

u = MDAnalysis.Universe(sys.argv[1])
# protein = u.selectAtoms("bynum 1:371") # select atoms if neccesary - here by atom index 
numresidues = protein.numberOfResidues()
print numresidues
PHI=[]
PSI=[]
RES=[]
startwith=1
for res in range(startwith, numresidues-1):
    print "Processing residue %d" % res
    RES.append(res)
    phi_sel = protein.residues[res].phi_selection()
    phi=phi_sel.dihedral()
    PHI.append(phi)
    #  selection of the atoms involved for the psi for resid '%d' %res
    psi_sel = protein.residues[res].psi_selection()
    psi=psi_sel.dihedral()
    PSI.append(psi)
	
file=open("DIHEDRALS.dat","a")
file.write("FILE ="+str(sys.argv[1])+"\n PHI[deg]\tPSI[deg]\tRESNR\n")
for res in range(startwith, numresidues-1):
	WRITESTR="{>.2f}\t\t{>.2f}\t\t{>.2f}\t\t{>d}\t\t!\n".format(PHI[res-2],PSI[res-2],res)
	file.write(WRITESTR)
file.close()