Réimplémentation du programme DSSP en Python

pdb.py 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import sys
  2. #import collections
  3. # custom imports
  4. from atom import *
  5. class PDBFile:
  6. def getContent(self, filename):
  7. with open(filename) as f:
  8. return(f.readlines())
  9. def getHeader(self):
  10. #Metadata = collections.namedtuple("Metadata", ["header", "compound", "source", "author"])
  11. Metadata = {}
  12. for line in self.rawLines:
  13. # no need to continue if meta are complete
  14. if(len(Metadata) <4):
  15. if(line[0:10] == "HEADER "):
  16. Metadata['header']=line
  17. elif(line[0:10] == "COMPND 2"):
  18. Metadata['compound']=line
  19. elif(line[0:10] == "SOURCE 2"):
  20. Metadata['source']=line
  21. elif(line[0:10] == "AUTHOR "):
  22. Metadata['author']=line
  23. else:
  24. # if meta are complete, stop parsing
  25. break
  26. return(Metadata)
  27. def getAtoms(self):
  28. self.ATOMS = []
  29. for line in self.rawLines:
  30. if line.startswith("ATOM" or "HETATM"):
  31. atom = Atom(ATOM_ID = int(line[6:11].strip()),
  32. ATOM_NAME = line[12:16].strip(),
  33. ALT_LOCAT = line[16:17].strip(),
  34. RES_NAME = line[17:20].strip(),
  35. CHAIN_ID = line[21:22].strip(),
  36. RES_SEQ_NB = int(line[22:26].strip()),
  37. RES_INSER_CODE = line[26:27].strip(),
  38. COORD_X = float(line[30:38].strip()),
  39. COORD_Y = float(line[38:46].strip()),
  40. COORD_Z = float(line[46:54].strip()),
  41. OCCUPANCY = float(line[54:60].strip()),
  42. TEMP_FACT = float(line[60:66].strip()),
  43. ELEM_SYMBOL = line[76:78].strip(),
  44. ATOM_CHARGE = line[78:80].strip())
  45. self.ATOMS.append(atom)
  46. def __init__(self, filename):
  47. self.rawLines = self.getContent(filename)
  48. self.Metadata = self.getHeader()
  49. self.getAtoms()
  50. for elem in self.Metadata :
  51. print(self.Metadata[elem], end="")
  52. if __name__ == "__main__":
  53. if(len(sys.argv)<2):
  54. print("Not enough arguments! Run with --help to learn more about proper"
  55. "call structure and parameters.")
  56. else:
  57. pdbFile = PDBFile(sys.argv[1])