-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPDB_Writer.py
59 lines (50 loc) · 2.44 KB
/
PDB_Writer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
class DataWriter:
def __init__(self, ligandList, receptorList, ligandDecompResults, recDecompResults):
self.ligandList = ligandList
self.receptorList = receptorList
self.ligandDecompResults = ligandDecompResults
self.recDecompResults = recDecompResults
self.files = ['ligand.dat', 'receptor.dat']
self.results = [ligandDecompResults, recDecompResults]
self.WriteDat()
self.WriteGBSAonPDB()
def WriteDat(self):
i = 0
with open('ligand.dat', 'w') as file:
file.write('Residue\tGBSA\n')
for segid, res_list in self.ligandList.items():
for res in res_list:
file.write(res + "\t" + str(self.ligandDecompResults[i]) + '\n')
i += 1
i = 0
with open('receptor.dat', 'w') as file:
file.write('Residue\tGBSA\n')
for segid, res_list in self.receptorList.items():
for res in res_list:
file.write(res + "\t" + str(self.recDecompResults[i]) + '\n')
i += 1
def WriteGBSAonPDB(self):
with open('ligand.pdb', 'r') as input_file, open('GBSA_on_PDB.pdb', 'w') as output_file:
residuo_corrente = None
indice_valore = 0
for line in input_file:
if line.startswith('ATOM') or line.startswith('HETATM'):
residuo = line[17:26].strip()
if residuo != residuo_corrente:
occupancy_value = self.ligandDecompResults[indice_valore]
indice_valore += 1
residuo_corrente = residuo
line = line[:60] + " " + str(round(occupancy_value, 2)) + line[66:]
output_file.write(line)
with open('receptor.pdb', 'r') as input_file, open('GBSA_on_PDB.pdb', 'a') as output_file:
residuo_corrente = None
indice_valore = 0
for line in input_file:
if line.startswith('ATOM') or line.startswith('HETATM'):
residuo = line[17:26].strip()
if residuo != residuo_corrente:
occupancy_value = self.recDecompResults[indice_valore]
indice_valore += 1
residuo_corrente = residuo
line = line[:60] + " " + str(round(occupancy_value, 2)) + line[66:]
output_file.write(line)