Thomas Forest пре 5 година
родитељ
комит
f19f25a3bf
3 измењених фајлова са 35 додато и 3 уклоњено
  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 Прегледај датотеку


+ 21 - 0
src/atom.py Прегледај датотеку

@@ -18,3 +18,24 @@ class Atom:
18 18
         self.TEMP_FACT = TEMP_FACT
19 19
         self.ELEM_SYMBOL = ELEM_SYMBOL
20 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 Прегледај датотеку

@@ -32,7 +32,8 @@ class PDBFile:
32 32
 
33 33
     def getAtoms(self):
34 34
         self.ATOMS = []
35
-        
35
+        self.RESIDUES = []
36
+        tempAtoms = []
36 37
         for line in self.rawLines:
37 38
             if line.startswith("ATOM" or "HETATM"):
38 39
                 atom = Atom(ATOM_ID = int(line[6:11].strip()),
@@ -50,8 +51,17 @@ class PDBFile:
50 51
                             ELEM_SYMBOL = line[76:78].strip(),
51 52
                             ATOM_CHARGE = line[78:80].strip())
52 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 65
     def __init__(self, filename):
56 66
         self.rawLines = self.getContent(filename)
57 67
         self.Metadata = self.getHeader()
@@ -66,3 +76,4 @@ if __name__ == "__main__":
66 76
               "call structure and parameters.")
67 77
     else:
68 78
         pdbFile = PDBFile(sys.argv[1])
79
+        print(pdbFile.RESIDUES[0].ATOMS["N"].COORD_X)