Browse Source

Pymol silent mode and hydrogen_add threshold

Thomas Forest 5 years ago
parent
commit
488dfa74a1
1 changed files with 19 additions and 13 deletions
  1. 19 13
      src/pdb.py

+ 19 - 13
src/pdb.py View File

1
 # custom imports
1
 # custom imports
2
 from atom import *
2
 from atom import *
3
 import sys
3
 import sys
4
-import pymol
4
+import pymol 
5
 #import collections
5
 #import collections
6
 class PDBFile:
6
 class PDBFile:
7
     def getContent(self, filename):
7
     def getContent(self, filename):
27
                 break     
27
                 break     
28
         return(Metadata)
28
         return(Metadata)
29
 
29
 
30
-    def getAtoms(self):
30
+    def getAtoms(self, filename):
31
         self.atoms = []
31
         self.atoms = []
32
         self.residues = []
32
         self.residues = []
33
         temp_atoms = []
33
         temp_atoms = []
34
+        count_h = 0
34
         for line in self.rawLines:
35
         for line in self.rawLines:
35
             if line.startswith("ATOM" or "HETATM"):
36
             if line.startswith("ATOM" or "HETATM"):
37
+                if(line[76:78].strip()=="H"):
38
+                    count_h+=1
36
                 atom = Atom(atom_id = int(line[6:11].strip()),
39
                 atom = Atom(atom_id = int(line[6:11].strip()),
37
                             atom_name = line[12:16].strip(),
40
                             atom_name = line[12:16].strip(),
38
                             res_name = line[17:20].strip(),
41
                             res_name = line[17:20].strip(),
53
                 temp_atoms.append(atom)
56
                 temp_atoms.append(atom)
54
         # last residue
57
         # last residue
55
         self.residues.append(Residue(temp_atoms))
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
     def check_hydrogens(self, atoms):
65
     def check_hydrogens(self, atoms):
58
-        return true
66
+        print("ENTER CHECK HYDROGEN")
67
+        return True
59
 
68
 
60
     def add_hydrogens(self, filename, output_pdb=None):
69
     def add_hydrogens(self, filename, output_pdb=None):
70
+        pymol.finish_launching(['pymol', '-qc'])
61
         pymol.cmd.load(filename)
71
         pymol.cmd.load(filename)
62
-        pymol.cmd.select("nitrogens", selection='name n')  
72
+        pymol.cmd.select("nitrogens",'name n')  
63
         pymol.cmd.h_add("nitrogens")
73
         pymol.cmd.h_add("nitrogens")
64
-        pymol.cmd.select('hydrogens',selection='name h')
65
         pymol.stored.pos = []
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
         if(output_pdb!=None):
76
         if(output_pdb!=None):
68
             pymol.cmd.save(output_file)
77
             pymol.cmd.save(output_file)
69
         return(pymol.stored.pos)
78
         return(pymol.stored.pos)
71
     def __init__(self, filename, output_pdb=None):
80
     def __init__(self, filename, output_pdb=None):
72
         self.rawLines = self.getContent(filename)
81
         self.rawLines = self.getContent(filename)
73
         self.Metadata = self.getHeader()
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
 if __name__ == "__main__":
88
 if __name__ == "__main__":
83
     if(len(sys.argv)<2):
89
     if(len(sys.argv)<2):