Réimplémentation du programme DSSP en Python

geom.py 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import math
  2. import numpy as np
  3. # A couple of obvious functions for vector manipulation.
  4. # Lack of time caused this not to be OOP-implemented, or furthermore
  5. # documented.
  6. def vector_from_pos(a, b):
  7. xAB = b[0]-a[0]
  8. yAB = b[1]-a[1]
  9. zAB = b[2]-a[2]
  10. coord_AB = [xAB,yAB,zAB]
  11. return coord_AB
  12. def vector_norm(v):
  13. norm = math.sqrt(v[0]**2 + v[1]**2 + v[2]**2)
  14. return norm
  15. def dot_product(v1,v2):
  16. dot_product = v1[0]*v2[0] + v1[1]*v2[1] + v1[2]*v2[2]
  17. return(dot_product)
  18. def position_vector(c):
  19. vector = vector_from_pos([0,0,0],c)
  20. return vector
  21. def vectors_substr(v1, v2):
  22. return ([v1[0]-v2[0],
  23. v1[1]-v2[1],
  24. v1[2]-v2[2]])
  25. def vector_angles(v1,v2):
  26. dot_prod = dot_product(v1,v2)
  27. norm_v1 = vector_norm(v1)
  28. norm_v2 = vector_norm(v2)
  29. term = dot_prod/(abs(norm_v1)*abs(norm_v2))
  30. rad_angle = math.acos(term)
  31. return rad_angle
  32. def calc_dihedral(u1, u2, u3, u4):
  33. """ Calculate dihedral angle method. From bioPython.PDB
  34. (adapted to np.array)
  35. Calculate the dihedral angle between 4 vectors
  36. representing 4 connected points. The angle is in
  37. [-pi, pi].
  38. Adapted function of dihedral_angle_from_coordinates.py
  39. by Eric Alcaide.
  40. Source : https://gist.github.com/EricAlcaide
  41. URL : https://gist.github.com/EricAlcaide/30d6bfdb8358d3a57d010c9a501fda56
  42. """
  43. #convert coords to numpy arrays
  44. u1 = np.array(u1)
  45. u2 = np.array(u2)
  46. u3 = np.array(u3)
  47. u4 = np.array(u4)
  48. a1 = u2 - u1
  49. a2 = u3 - u2
  50. a3 = u4 - u3
  51. v1 = np.cross(a1, a2)
  52. v1 = v1 / (v1 * v1).sum(-1)**0.5
  53. v2 = np.cross(a2, a3)
  54. v2 = v2 / (v2 * v2).sum(-1)**0.5
  55. porm = np.sign((v1 * a3).sum(-1))
  56. rad = np.arccos((v1*v2).sum(-1) / ((v1**2).sum(-1) * (v2**2).sum(-1))**0.5)
  57. if not porm == 0:
  58. rad = rad * porm
  59. deg_angle = rad*(180/math.pi)
  60. return deg_angle