Advertisement
ProzacR

rmsdvkpdb.py

Nov 27th, 2014
712
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.04 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3.  
  4. import sys
  5. sys.path.append("/home/visvaldas/software/openbabel/lib")
  6. import math
  7. import pybel
  8.  
  9. def squared_distance(coordsA, coordsB):
  10.     """Find the squared distance between two 3-tuples"""
  11.     sqrdist = sum( (a-b)**2 for a, b in zip(coordsA, coordsB) )
  12.     return sqrdist
  13.    
  14. def rmsd(allcoordsA, allcoordsB):
  15.     """Find the RMSD between two lists of 3-tuples"""
  16.     deviation = sum(squared_distance(atomA, atomB) for
  17.                     (atomA, atomB) in zip(allcoordsA, allcoordsB))
  18.     return math.sqrt(deviation / float(len(allcoordsA)))
  19.  
  20. # Make sure we have a filename
  21. try:
  22.     filename1 = sys.argv[1]
  23. except:
  24.     print "Usage: python energy.py filename1 filename2"
  25.     sys.exit(1)
  26. try:
  27.     filename2 = sys.argv[2]
  28. except:
  29.     print "Usage: python energy.py filename1 filename2"
  30.     sys.exit(1)
  31.  
  32.    
  33. if __name__ == "__main__":
  34.     # Read crystal pose
  35.     crystal = next(pybel.readfile("pdb", filename1))
  36.  
  37.     # Find automorphisms involving only non-H atoms
  38.     mappings = pybel.ob.vvpairUIntUInt()
  39.     bitvec = pybel.ob.OBBitVec()
  40.     lookup = []
  41.     for i, atom in enumerate(crystal):
  42.         if not atom.OBAtom.IsHydrogen():
  43.             bitvec.SetBitOn(i+1)
  44.             lookup.append(i)
  45.     success = pybel.ob.FindAutomorphisms(crystal.OBMol, mappings, bitvec)
  46.  
  47.     # Find the RMSD between the crystal pose and each docked pose
  48.     xtalcoords = [atom.coords for atom in crystal if not atom.OBAtom.IsHydrogen()]
  49.     for i, dockedpose in enumerate(pybel.readfile("pdb", filename2)):
  50.         posecoords = [atom.coords for atom in dockedpose if not atom.OBAtom.IsHydrogen()]
  51.         minrmsd = 999999999999
  52.         for mapping in mappings:
  53.             automorph_coords = [None] * len(xtalcoords)
  54.             for x, y in mapping:
  55.                 automorph_coords[lookup.index(x)] = xtalcoords[lookup.index(y)]
  56.             mapping_rmsd = rmsd(posecoords, automorph_coords)
  57.             if mapping_rmsd < minrmsd:
  58.                 minrmsd = mapping_rmsd
  59.         print("The RMSD is %.3f for pose %d" % (minrmsd, (i+1)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement