Pymol silent mode and hydrogen_add threshold

master
Thomas Forest 2019-09-13 00:30:32 +02:00
parent ea766855d7
commit 488dfa74a1
1 changed files with 19 additions and 13 deletions

View File

@ -27,12 +27,15 @@ class PDBFile:
break
return(Metadata)
def getAtoms(self):
def getAtoms(self, filename):
self.atoms = []
self.residues = []
temp_atoms = []
count_h = 0
for line in self.rawLines:
if line.startswith("ATOM" or "HETATM"):
if(line[76:78].strip()=="H"):
count_h+=1
atom = Atom(atom_id = int(line[6:11].strip()),
atom_name = line[12:16].strip(),
res_name = line[17:20].strip(),
@ -53,17 +56,23 @@ class PDBFile:
temp_atoms.append(atom)
# last residue
self.residues.append(Residue(temp_atoms))
# hydrogens should represent in average 50% of total atoms... We use 30% threshold...
if(count_h/len(temp_atoms)<0.30):
#if(output_pdb==None):
print("Need to add hydrogens ! If you want the modified PDB file, please use the -o output.pdb argument")
self.add_hydrogens(filename)
def check_hydrogens(self, atoms):
return true
print("ENTER CHECK HYDROGEN")
return True
def add_hydrogens(self, filename, output_pdb=None):
pymol.finish_launching(['pymol', '-qc'])
pymol.cmd.load(filename)
pymol.cmd.select("nitrogens", selection='name n')
pymol.cmd.select("nitrogens",'name n')
pymol.cmd.h_add("nitrogens")
pymol.cmd.select('hydrogens',selection='name h')
pymol.stored.pos = []
pymol.cmd.iterate_state(1, 'hydrogens', 'stored.pos.append([name,resi,x,y,z])')
pymol.cmd.iterate_state(1, "hydrogens", 'stored.pos.append([name,resi,x,y,z])')
if(output_pdb!=None):
pymol.cmd.save(output_file)
return(pymol.stored.pos)
@ -71,13 +80,10 @@ class PDBFile:
def __init__(self, filename, output_pdb=None):
self.rawLines = self.getContent(filename)
self.Metadata = self.getHeader()
self.getAtoms()
for elem in self.Metadata :
print(self.Metadata[elem], end="")
if(self.check_hydrogens(self.atoms)==False):
if(output_pdb==None):
print("Need to add hydrogens ! If you want the modified PDB file, please use the -o output.pdb argument")
self.add_hydrogens(filename)
self.getAtoms(filename)
# for elem in self.Metadata :
# print(self.Metadata[elem], end="")
if __name__ == "__main__":
if(len(sys.argv)<2):