Pārlūkot izejas kodu

Pymol silent mode and hydrogen_add threshold

Thomas Forest 5 gadus atpakaļ
vecāks
revīzija
488dfa74a1
1 mainītis faili ar 19 papildinājumiem un 13 dzēšanām
  1. 19 13
      src/pdb.py

+ 19 - 13
src/pdb.py Parādīt failu

@@ -1,7 +1,7 @@
1 1
 # custom imports
2 2
 from atom import *
3 3
 import sys
4
-import pymol
4
+import pymol 
5 5
 #import collections
6 6
 class PDBFile:
7 7
     def getContent(self, filename):
@@ -27,12 +27,15 @@ class PDBFile:
27 27
                 break     
28 28
         return(Metadata)
29 29
 
30
-    def getAtoms(self):
30
+    def getAtoms(self, filename):
31 31
         self.atoms = []
32 32
         self.residues = []
33 33
         temp_atoms = []
34
+        count_h = 0
34 35
         for line in self.rawLines:
35 36
             if line.startswith("ATOM" or "HETATM"):
37
+                if(line[76:78].strip()=="H"):
38
+                    count_h+=1
36 39
                 atom = Atom(atom_id = int(line[6:11].strip()),
37 40
                             atom_name = line[12:16].strip(),
38 41
                             res_name = line[17:20].strip(),
@@ -53,17 +56,23 @@ class PDBFile:
53 56
                 temp_atoms.append(atom)
54 57
         # last residue
55 58
         self.residues.append(Residue(temp_atoms))
59
+        # hydrogens should represent in average 50% of total atoms... We use 30% threshold...
60
+        if(count_h/len(temp_atoms)<0.30):
61
+            #if(output_pdb==None):
62
+            print("Need to add hydrogens ! If you want the modified PDB file, please use the -o output.pdb argument")
63
+            self.add_hydrogens(filename)
56 64
 
57 65
     def check_hydrogens(self, atoms):
58
-        return true
66
+        print("ENTER CHECK HYDROGEN")
67
+        return True
59 68
 
60 69
     def add_hydrogens(self, filename, output_pdb=None):
70
+        pymol.finish_launching(['pymol', '-qc'])
61 71
         pymol.cmd.load(filename)
62
-        pymol.cmd.select("nitrogens", selection='name n')  
72
+        pymol.cmd.select("nitrogens",'name n')  
63 73
         pymol.cmd.h_add("nitrogens")
64
-        pymol.cmd.select('hydrogens',selection='name h')
65 74
         pymol.stored.pos = []
66
-        pymol.cmd.iterate_state(1, 'hydrogens', 'stored.pos.append([name,resi,x,y,z])')
75
+        pymol.cmd.iterate_state(1, "hydrogens", 'stored.pos.append([name,resi,x,y,z])')
67 76
         if(output_pdb!=None):
68 77
             pymol.cmd.save(output_file)
69 78
         return(pymol.stored.pos)
@@ -71,13 +80,10 @@ class PDBFile:
71 80
     def __init__(self, filename, output_pdb=None):
72 81
         self.rawLines = self.getContent(filename)
73 82
         self.Metadata = self.getHeader()
74
-        self.getAtoms()
75
-        for elem in self.Metadata :    
76
-            print(self.Metadata[elem], end="")
77
-        if(self.check_hydrogens(self.atoms)==False):
78
-            if(output_pdb==None):
79
-                print("Need to add hydrogens ! If you want the modified PDB file, please use the -o output.pdb argument")
80
-            self.add_hydrogens(filename)
83
+        self.getAtoms(filename)
84
+        # for elem in self.Metadata : 
85
+        #     print(self.Metadata[elem], end="")
86
+        
81 87
 
82 88
 if __name__ == "__main__":
83 89
     if(len(sys.argv)<2):