Guest User

example.py

a guest
Mar 9th, 2022
587
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. from Bio.PDB import *
  2.  
  3.  
  4. def extract_torsion_angles(structure):
  5. ic_chain = internal_coords.IC_Chain(structure)
  6. ic_chain.atom_to_internal_coordinates()
  7.  
  8. d = ic_chain.dihedra
  9.  
  10. """
  11. Update the keys of a dihedra dictionary to make searching easier.
  12.  
  13. The keys of the dihedra dictionary (as obtained from
  14. extract_torsion_angles()) are 4-tuples where each element is
  15. an AtomKey containing 5 fields (respos, icode, resname, atm,
  16. altloc, occ). We use the residue position, residue name and
  17. atom name in order to create a new representation for each
  18. AtomKey. The final dihedra dictionary will have 4-tuple keys
  19. where each element of the tuple is one such string.
  20. """
  21.  
  22. new_d = {}
  23. for key, value in sorted(d.items(), key=lambda x: x[0]):
  24. new_key = []
  25. for atom_key in key:
  26. # Keep: residue position + resiude name + atom name.
  27. atom_key_str = (atom_key.akl[0] + '_' +
  28. atom_key.akl[2] + '_' + atom_key.akl[3])
  29.  
  30. new_key.append(atom_key_str)
  31.  
  32. new_d[tuple(new_key)] = value
  33.  
  34. return new_d
  35.  
  36.  
  37. f1 = 'protein1.pdb'
  38. f2 = 'protein2.pdb'
  39.  
  40. parser = PDBParser(PERMISSIVE=1, QUIET=0)
  41. s1 = parser.get_structure('', f1)
  42. s2 = parser.get_structure('', f2)
  43.  
  44. c1 = list(s1.get_chains())
  45. c2 = list(s2.get_chains())
  46.  
  47. print('Chains: ', len(c1), ' ', len(c2))
  48.  
  49. r1 = list(c1[0].get_residues())
  50. r2 = list(c2[0].get_residues())
  51.  
  52. print('Residues: ', len(r1), ' ', len(r2))
  53.  
  54. for i in range(len(r1)):
  55. resname1 = r1[i].get_resname()
  56. resname2 = r2[i].get_resname()
  57.  
  58. if resname1 != resname2:
  59. print('Residues not matching')
  60. break
  61.  
  62. atoms1 = list(r1[i].get_atoms())
  63. atoms2 = list(r2[i].get_atoms())
  64.  
  65. atom_names1 = sorted([atom.get_id() for atom in atoms1])
  66. atom_names2 = sorted([atom.get_id() for atom in atoms2])
  67.  
  68. if atom_names1 != atom_names2:
  69. print('Different atoms!')
  70.  
  71. d1 = extract_torsion_angles(s1)
  72. d2 = extract_torsion_angles(s2)
  73.  
  74. print('Torsion angles: ', len(d1), ' ', len(d2))
  75.  
  76. diff_keys = set(d2.keys()) - set(d1.keys())
  77. print(diff_keys)
Advertisement
Add Comment
Please, Sign In to add comment