Browse Source

Residues class creation

Thomas Forest 5 years ago
parent
commit
f19f25a3bf
3 changed files with 35 additions and 3 deletions
  1. BIN
      src/__pycache__/atom.cpython-36.pyc
  2. 21 0
      src/atom.py
  3. 14 3
      src/pdb.py

BIN
src/__pycache__/atom.cpython-36.pyc View File


+ 21 - 0
src/atom.py View File

18
         self.TEMP_FACT = TEMP_FACT
18
         self.TEMP_FACT = TEMP_FACT
19
         self.ELEM_SYMBOL = ELEM_SYMBOL
19
         self.ELEM_SYMBOL = ELEM_SYMBOL
20
         self.ATOM_CHARGE = ATOM_CHARGE
20
         self.ATOM_CHARGE = ATOM_CHARGE
21
+
22
+class Residue:
23
+    def __init__(self, atomsList):
24
+        self.ATOMS = {}
25
+        for atom in atomsList:
26
+            self.ATOMS[atom.ATOM_NAME] = atom
27
+            if atom.ATOM_NAME == "N":
28
+                self.N = atom
29
+            if atom.ATOM_NAME == "CA":
30
+                self.CA = atom
31
+            if atom.ATOM_NAME == "C":
32
+                self.C = atom
33
+            if atom.ATOM_NAME == "O":
34
+                self.O = atom
35
+            if atom.ATOM_NAME == "CB":
36
+                self.CB = atom
37
+            if atom.ATOM_NAME == "CG1":
38
+                self.CG1 = atom
39
+            if atom.ATOM_NAME == "CG2":
40
+                self.CG2 = atom
41
+            

+ 14 - 3
src/pdb.py View File

32
 
32
 
33
     def getAtoms(self):
33
     def getAtoms(self):
34
         self.ATOMS = []
34
         self.ATOMS = []
35
-        
35
+        self.RESIDUES = []
36
+        tempAtoms = []
36
         for line in self.rawLines:
37
         for line in self.rawLines:
37
             if line.startswith("ATOM" or "HETATM"):
38
             if line.startswith("ATOM" or "HETATM"):
38
                 atom = Atom(ATOM_ID = int(line[6:11].strip()),
39
                 atom = Atom(ATOM_ID = int(line[6:11].strip()),
50
                             ELEM_SYMBOL = line[76:78].strip(),
51
                             ELEM_SYMBOL = line[76:78].strip(),
51
                             ATOM_CHARGE = line[78:80].strip())
52
                             ATOM_CHARGE = line[78:80].strip())
52
                 self.ATOMS.append(atom)
53
                 self.ATOMS.append(atom)
53
-                      
54
-    
54
+                # get the current indice of atom
55
+                i = self.ATOMS.index(atom)
56
+                # if this is a brand new residue
57
+                if(len(self.ATOMS)>1
58
+                   and atom.RES_SEQ_NB != self.ATOMS[i-1].RES_SEQ_NB):
59
+                    self.RESIDUES.append(Residue(tempAtoms))
60
+                    tempAtoms=[]
61
+                tempAtoms.append(atom)
62
+        # last residue
63
+        self.RESIDUES.append(Residue(tempAtoms))
64
+       
55
     def __init__(self, filename):
65
     def __init__(self, filename):
56
         self.rawLines = self.getContent(filename)
66
         self.rawLines = self.getContent(filename)
57
         self.Metadata = self.getHeader()
67
         self.Metadata = self.getHeader()
66
               "call structure and parameters.")
76
               "call structure and parameters.")
67
     else:
77
     else:
68
         pdbFile = PDBFile(sys.argv[1])
78
         pdbFile = PDBFile(sys.argv[1])
79
+        print(pdbFile.RESIDUES[0].ATOMS["N"].COORD_X)