-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathalign-it.py
283 lines (223 loc) · 8.56 KB
/
align-it.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
from pymol.Qt import QtGui, QtCore, QtWidgets
import pymol
from pymol.cgo import *
import os
import sys
import re
def __init_plugin__(self=None):
from pymol import plugins
plugins.addmenuitemqt('AlignIt visualization plugin', alignit_plugin)
def alignit_plugin():
print("+++ Silicos-it::AlignIt Pymol Plugin (2019) +++")
print('creating dialog')
dialog = create_dialog()
dialog.show()
print('Finished')
def create_dialog():
dialog = QtWidgets.QDialog()
dialog.setWindowTitle('AlignIt Pymol plugin')
layout = QtWidgets.QVBoxLayout(dialog)
alignit = AlignItPlugin()
actions = {
'Read pharmacophore...': lambda: alignit.readAlignIt(dialog),
}
for name, action in actions.items():
btn = QtWidgets.QPushButton(name, dialog)
btn.pressed.connect(action)
layout.addWidget(btn)
return dialog
class AlignItPlugin:
def __init__(self):
self.phar = []
#------------------
def log(self, msg):
print(" * "+msg)
#TODO method 'err' ?
#------------------------------------------------------------------------------#
# Create Pharmacophore #
#------------------------------------------------------------------------------#
def runAlignIt(self, dialog):
#check if selection is made
if(not("sele" in pymol.cmd.get_names("selections"))):
self.log("ERROR: no selection 'sele' defined.")
sys.exit(1)
#get object-id from selection
list = pymol.cmd.index("sele")
id = list[0][0]
for x in list:
if x[0]!=id:
self.log("ERROR: multiple selection!")
sys.exit(1)
#add hydrogens and save in SDF format
pymol.cmd.h_add("sele")
pymol.cmd.save("/tmp/_tmp_AlignIt.sdf", "sele", "0", "mol")
pymol.cmd.remove("hydrogens in " + id)
#run Pharao
os.system("/usr/local/bin/align-it -d /tmp/_tmp_AlignIt.sdf -p /tmp/_tmp_AlignIt.phar")
file = open("/tmp/_tmp_AlignIt.phar")
#display results
if file != None:
self.parseFile(file)
file.close()
else:
self.log("ERROR: can't read pharmacophore file.")
# remove temporary files
os.system("rm /tmp/_tmp_AlignIt.sdf")
os.system("rm /tmp/_tmp_AlignIt.phar")
self.log("Done creating pharmacophore.")
pymol.cmd.center()
pymol.cmd.zoom()
#------------------------------------------------------------------------------#
# Read Pharmacophore #
#------------------------------------------------------------------------------#
def file_open(self, dialog):
file_dialog = QtWidgets.QFileDialog(dialog)
fileName, _ = QtWidgets.QFileDialog.getOpenFileName(dialog, 'Open File')
return fileName
def readAlignIt(self, dialog):
file = self.file_open(dialog)
print('file')
self.parseFile(file)
self.log("Done reading pharmacophore.")
pymol.cmd.center()
pymol.cmd.zoom()
#------------------------------------------------------------------------------#
# Create Exclusion Spheres #
#------------------------------------------------------------------------------#
def createExcl(self, dialog):
#check if selection is made
if(not("sele" in pymol.cmd.get_names("selections"))):
self.log("ERROR: no selection 'sele' defined.")
sys.exit(1)
pymol.cmd.select("_tmp_1_", "sele around 5 & !sele")
exclPoint = [ COLOR, 0.25, 0.25, 0.25 ]
c = 0
model = pymol.cmd.get_model("_tmp_1_")
for a in model.atom:
# add point to current phar
point = ("EXCL", a.coord[0], a.coord[1], a.coord[2], 1.4, "0", 0.0, 0.0, 0.0)
self.phar.append(point)
exclPoint.extend([ SPHERE, a.coord[0], a.coord[1], a.coord[2], 1.4])
c = c + 1
if(len(exclPoint) != 0 ):
pymol.cmd.load_cgo(exclPoint,"excl",1)
pymol.cmd.set('cgo_transparency',0.2,"excl")
pymol.cmd.delete("_tmp_1_")
self.log("Finished creating " + str(c) + " exclusion spheres.")
pymol.cmd.center()
pymol.cmd.zoom()
#------------------------------------------------------------------------------#
# Write Pharmacophore #
#------------------------------------------------------------------------------#
def writeAlignIt(self, dialog):
print('writeAlignIt')
with open('test.phar', 'w') as file:
file.write('Generated_by_AlignIt_Pymol_Plugin\n')
print(self.phar)
for p in self.phar:
print('writing phar line')
if(p[5] != "0"):
file.write(p[0]+'\t'+str(p[1])+'\t'+str(p[2])+'\t'+str(p[3])+'\t'+str(p[4])+'\t'+
str(p[5])+'\t'+str(p[6])+'\t'+str(p[7])+'\t'+str(p[8])+'\n')
else:
file.write(p[0]+'\t'+str(p[1])+'\t'+str(p[2])+'\t'+str(p[3])+'\t'+str(p[4])+'\t'+
str(p[5])+'\t'+"0.000"+'\t'+"0.000"+'\t'+"0.000"+'\n')
file.write('$$$$\n')
file.close()
self.log("Done writing pharmacophore.")
#------------------------------------------------------------------------------#
# parse .phar file #
#------------------------------------------------------------------------------#
def parseFile(self, filename):
# set colors
aromPoint = [ COLOR, 0.50, 0.85, 0.05 ]
lipoPoint = [ COLOR, 0.50, 0.10, 0.05 ]
hyblPoint = [ COLOR, 0.50, 0.50, 0.05 ]
hdonPoint = [ COLOR, 0.20, 0.65, 0.85 ]
haccPoint = [ COLOR, 0.80, 0.65, 0.85 ]
hybhPoint = [ COLOR, 0.50, 0.65, 0.85 ]
poscPoint = [ COLOR, 0.00, 0.00, 1.00 ]
negcPoint = [ COLOR, 1.00, 0.00, 0.00 ]
exclPoint = [ COLOR, 0.25, 0.25, 0.25 ]
normal = []
file = open(filename,'r')
id = file.readline()
id = id.rstrip()
#read pharmacophore points
for line in file:
if re.match("\$",line) == None:
strlist = line.split()
if len(strlist) >= 9:
x = float(strlist[1])
y = float(strlist[2])
z = float(strlist[3])
sigma = 1.0/float(strlist[4])
hasNormal = strlist[5]
if(re.match("AROM",strlist[0]) != None):
aromPoint.extend([SPHERE, x, y, z, sigma])
elif(re.match("LIPO",strlist[0]) != None ):
lipoPoint.extend([SPHERE, x, y, z, sigma])
elif(re.match("HYBL",strlist[0]) != None):
hyblPoint.extend([SPHERE, x, y, z, sigma])
elif(re.match("HDON",strlist[0]) != None):
hdonPoint.extend([SPHERE, x, y, z, sigma])
elif(re.match("HACC",strlist[0]) != None):
haccPoint.extend([SPHERE, x, y, z, sigma])
elif(re.match("HYBH",strlist[0]) != None):
hybhPoint.extend([SPHERE, x, y, z, sigma])
elif(re.match("POSC",strlist[0]) != None ):
poscPoint.extend([SPHERE, x, y, z, sigma])
elif(re.match("NEGC",strlist[0]) != None ):
negcPoint.extend([SPHERE, x, y, z, sigma])
elif(re.match("EXCL",strlist[0]) != None ):
exclPoint.extend([SPHERE, x, y, z, sigma])
else:
self.log("WARNING: unknown point.")
if(hasNormal == "1"):
normal.extend( [ CYLINDER,
x, y, z,
float(strlist[6]), float(strlist[7]), float(strlist[8]),
0.1,
1.0, 1.0, 0.0,
1.0, 1.0, 0.0
])
point = (strlist[0], x, y, z, sigma, hasNormal, float(strlist[6]), float(strlist[7]), float(strlist[8]))
self.phar.append(point)
else:
point= (strlist[0], x, y, z, sigma, hasNormal, 0.0, 0.0, 0.0)
self.phar.append(point)
else:
print(self.phar)
self.log("pharmacophore file parsed correctly.")
#load graphical objects into pymol
if ( len (normal) != 0 ):
pymol.cmd.load_cgo(normal,"normals_"+id,1)
pymol.cmd.set('cgo_transparency',0.0,"normals_"+id)
if ( len (aromPoint) >= 5 ):
pymol.cmd.load_cgo(aromPoint, "arom_"+id,1)
pymol.cmd.set('cgo_transparency',0.4,"arom_"+id)
if ( len (lipoPoint) >=5 ):
pymol.cmd.load_cgo(lipoPoint, "lipo_"+id,1)
pymol.cmd.set('cgo_transparency',0.4,"lipo_"+id)
if ( len (hyblPoint) >=5 ):
pymol.cmd.load_cgo(hyblPoint, "hybl_"+id,1)
pymol.cmd.set('cgo_transparency',0.4,"hybl_"+id)
if ( len (hdonPoint) >= 5 ):
pymol.cmd.load_cgo(hdonPoint, "hdon_"+id,1)
pymol.cmd.set('cgo_transparency',0.4,"hdon_"+id)
if ( len (haccPoint) >= 5 ):
pymol.cmd.load_cgo(haccPoint, "hacc_"+id,1)
pymol.cmd.set('cgo_transparency',0.4,"hacc_"+id)
if ( len (hybhPoint) >= 5 ):
pymol.cmd.load_cgo(hybhPoint, "hybh_"+id,1)
pymol.cmd.set('cgo_transparency',0.4,"hybh_"+id)
if ( len (poscPoint) >= 5 ):
pymol.cmd.load_cgo(poscPoint, "posc_"+id,1)
pymol.cmd.set('cgo_transparency',0.4,"posc_"+id)
if ( len (negcPoint) >= 5 ):
pymol.cmd.load_cgo(negcPoint, "negc_"+id,1)
pymol.cmd.set('cgo_transparency',0.4,"negc_"+id)
if ( len (exclPoint) >= 5 ):
pymol.cmd.load_cgo(exclPoint, "excl_"+id,1)
pymol.cmd.set('cgo_transparency',0.2,"excl_"+id)
file.close()