|
@@ -1,33 +1,33 @@
|
1
|
1
|
# custom imports
|
2
|
2
|
from atom import *
|
|
3
|
+# import libs
|
3
|
4
|
import sys
|
4
|
|
-import pymol
|
5
|
|
-#import collections
|
|
5
|
+import pymol
|
|
6
|
+
|
6
|
7
|
class PDBFile:
|
7
|
|
- def getContent(self, filename):
|
|
8
|
+ def get_content(self, filename):
|
8
|
9
|
with open(filename) as f:
|
9
|
10
|
return(f.readlines())
|
10
|
11
|
|
11
|
|
- def getHeader(self):
|
12
|
|
- #Metadata = collections.namedtuple("Metadata", ["header", "compound", "source", "author"])
|
13
|
|
- Metadata = {}
|
|
12
|
+ def get_header(self):
|
|
13
|
+ metadata = {}
|
14
|
14
|
for line in self.rawLines:
|
15
|
15
|
# no need to continue if meta are complete
|
16
|
|
- if(len(Metadata) <4):
|
|
16
|
+ if(len(metadata) <4):
|
17
|
17
|
if(line[0:10] == "HEADER "):
|
18
|
|
- Metadata['header']=line
|
|
18
|
+ metadata['header']=line
|
19
|
19
|
elif(line[0:10] == "COMPND 2"):
|
20
|
|
- Metadata['compound']=line
|
|
20
|
+ metadata['compound']=line
|
21
|
21
|
elif(line[0:10] == "SOURCE 2"):
|
22
|
|
- Metadata['source']=line
|
|
22
|
+ metadata['source']=line
|
23
|
23
|
elif(line[0:10] == "AUTHOR "):
|
24
|
|
- Metadata['author']=line
|
|
24
|
+ metadata['author']=line
|
25
|
25
|
else:
|
26
|
26
|
# if meta are complete, stop parsing
|
27
|
27
|
break
|
28
|
|
- return(Metadata)
|
|
28
|
+ return(metadata)
|
29
|
29
|
|
30
|
|
- def getAtoms(self, filename):
|
|
30
|
+ def get_atoms(self, filename):
|
31
|
31
|
self.atoms = []
|
32
|
32
|
self.residues = []
|
33
|
33
|
temp_atoms = []
|
|
@@ -56,10 +56,12 @@ class PDBFile:
|
56
|
56
|
temp_atoms.append(atom)
|
57
|
57
|
# last residue
|
58
|
58
|
self.residues.append(Residue(temp_atoms))
|
59
|
|
- # hydrogens should represent in average 50% of total atoms... We use 30% threshold...
|
|
59
|
+ # hydrogens should represent in average 50% of total atoms...
|
|
60
|
+ # We use 30% threshold...
|
60
|
61
|
if(count_h/len(temp_atoms)<0.30):
|
61
|
62
|
#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
|
+ print("Need to add hydrogens ! If you want the modified PDB file, "
|
|
64
|
+ "please use the -o output.pdb argument")
|
63
|
65
|
self.add_hydrogens(filename)
|
64
|
66
|
|
65
|
67
|
def check_hydrogens(self, atoms):
|
|
@@ -71,25 +73,36 @@ class PDBFile:
|
71
|
73
|
pymol.cmd.load(filename)
|
72
|
74
|
pymol.cmd.select("nitrogens",'name n')
|
73
|
75
|
pymol.cmd.h_add("nitrogens")
|
74
|
|
- pymol.stored.pos = []
|
75
|
|
- pymol.cmd.iterate_state(1, "hydrogens", 'stored.pos.append([name,resi,x,y,z])')
|
|
76
|
+ pymol.stored.pos = {}
|
|
77
|
+ pymol.cmd.iterate_state(1, "hydrogens",
|
|
78
|
+ 'stored.pos[resi] = []; ' \
|
|
79
|
+ 'stored.pos[resi].append(name,resi,x,y,z) '\
|
|
80
|
+ 'if resi not in stored.pos.keys() ' \
|
|
81
|
+ 'else ' \
|
|
82
|
+ 'stored.pos[resi].append([name,resi,x,y,z])')
|
76
|
83
|
if(output_pdb!=None):
|
77
|
84
|
pymol.cmd.save(output_file)
|
|
85
|
+ for resi in self.residues:
|
|
86
|
+ if(str(resi.resid) in pymol.stored.pos.keys()):
|
|
87
|
+ # iterate over residue H atoms
|
|
88
|
+ for hydrogen in pymol.stored.pos[str(resi.resid)]:
|
|
89
|
+ atom = Atom(atom_id = len(self.atoms)+1,
|
|
90
|
+ atom_name = "H",
|
|
91
|
+ res_name = resi.res_name,
|
|
92
|
+ chain_id = resi.chain_id,
|
|
93
|
+ res_seq_nb = resi.resid,
|
|
94
|
+ coordinates = [hydrogen[2],
|
|
95
|
+ hydrogen[3],
|
|
96
|
+ hydrogen[4]])
|
|
97
|
+ # add hydrogen to atoms list
|
|
98
|
+ self.atoms.append(atom)
|
|
99
|
+ resi.atoms[atom.atom_name] = atom
|
78
|
100
|
return(pymol.stored.pos)
|
79
|
|
-
|
|
101
|
+
|
80
|
102
|
def __init__(self, filename, output_pdb=None):
|
81
|
|
- self.rawLines = self.getContent(filename)
|
82
|
|
- self.Metadata = self.getHeader()
|
83
|
|
- self.getAtoms(filename)
|
84
|
|
- # for elem in self.Metadata :
|
85
|
|
- # print(self.Metadata[elem], end="")
|
|
103
|
+ self.rawLines = self.get_content(filename)
|
|
104
|
+ self.metadata = self.get_header()
|
|
105
|
+ self.get_atoms(filename)
|
|
106
|
+ # for elem in self.metadata :
|
|
107
|
+ # print(self.metadata[elem], end="")
|
86
|
108
|
|
87
|
|
-
|
88
|
|
-if __name__ == "__main__":
|
89
|
|
- if(len(sys.argv)<2):
|
90
|
|
- print("Not enough arguments! Run with --help to learn more about proper"
|
91
|
|
- "call structure and parameters.")
|
92
|
|
- else:
|
93
|
|
- pdbFile = PDBFile(sys.argv[1])
|
94
|
|
- print(pdbFile.residues[15].atoms["C"].coord_x)
|
95
|
|
- print(pdbFile.add_hydrogens(sys.argv[1])[3])
|