-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGUICards.py
More file actions
389 lines (367 loc) · 17 KB
/
GUICards.py
File metadata and controls
389 lines (367 loc) · 17 KB
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
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
# Python imports
import pickle
import os
import sys
import parms
import copy
import string
import math
# dependency imports
from Tkinter import *
import tkFileDialog
import Pmw
# module imports
sys.path.append('./Applications/AlignmentEditor')
#sys.path.append('./Applications/Dynamics')
#import DynamicsViewer
sys.path.append('./Tools/Selection')
import SystemSelectionDialog
# holds a set of GUI Cards
class CardFrame(Frame):
def __init__(self, parent, my_system, master_window, standard_cards=1):
""" initialize the information (card) holder of the system window """
self.parent = parent
self.system = my_system
self.standard_cards = standard_cards
self.master_window = master_window # any transient windows should be transient to this
Frame.__init__(self, parent, height=3)
self.proteinCardList = []
self.nucleotideChainCardList = []
self.CFSCardlist = []
if self.system != None:
self.reloadSystem(self.system, 0)
def removeCards(self):
try:
self.systemCard
except (AttributeError):
return # no system is present
else:
self.systemCard.pack_forget()
self.systemCard.destroy()
del self.systemCard
try:
self.ligandCardList
except (AttributeError):
pass
else:
self.ligandCardList.pack_forget()
self.ligandCardList.destroy()
del self.ligandCardList
for card in self.proteinCardList:
card.pack_forget()
card.destroy()
del card
for card in self.nucleotideChainCardList:
card.pack_forget()
card.destroy()
del card
for card in self.CFSCardlist:
card.pack_forget()
card.destroy()
del card
def reloadSystem(self, my_system, reload=1): # reload should be 0 if initializing
""" destroy any old cards (if reload) and open GUIcards for a new system"""
if (reload):
self.removeCards()
self.system = my_system
if self.standard_cards:
self.systemCard = SystemCard(self, self.system)
self.systemCard.pack(expand=YES, fill=X)
self.proteinCardList = []
for p in self.system.ProteinList:
self.proteinCardList.append(ProteinCard(self, p))
self.proteinCardList[len(self.proteinCardList)-1].pack(expand=YES, fill=X)
self.nucleotideChainCardList = []
for n in self.system.NucleotideChainList:
self.nucleotideChainCardList.append(NucleotideChainCard(self, n))
self.nucleotideChainCardList[len(self.nucleotideChainCardList)-1].pack(expand=YES, fill=X)
if len(self.system.LigandList) > 0:
self.ligandCardList = LigandCard(self, self.system.LigandList)
self.ligandCardList.pack(expand=YES, fill=X)
self.CFSCardlist = []
class Card(Frame):
def __init__(self, parent, select_command):
Frame.__init__(self, parent, borderwidth=0, height=1)
self.parent = parent
if select_command != None:
# make a button for selection
self.select_button = Button(self, bitmap='gray12', width=14, height=14)
self.select_button.config(command=select_command)
self.select_button.pack(side=LEFT, anchor=W, expand=NO)
def tearoff(self):
m = self.item.__module__
pchain_buffer = [] # holds pchains,nchains,ligands,waters
if m=="System":
for pchain_index in range(len(self.item.ProteinList)):
if self.item.ProteinList[pchain_index].selected > 0:
pchain_buffer.append(self.item.ProteinList[pchain_index])
self.item.ProteinList = self.item.ProteinList[:pchain_index] + self.item.ProteinList[pchain_index+1:]
def remove_tags(self):
for tagn in self.block_holder.tag_names():
self.block_holder.tag_delete(tagn)
def select(self):
# deselect the card's item
if self.select_button.cget('bitmap') == 'gray12':
self.select_button.config(bitmap='gray75')
m = self.item.__module__
if m=="MolecularComponents.classProtein" or m=="MolecularComponents.classNucleotideChain" or m=="System":
if self.item.selected == 1:
self.item.deselect()
else:
for i in self.item:
if i.selected == 1:
i.deselect()
# select the whole chain
elif self.select_button.cget('bitmap') == 'gray75':
self.select_button.config(bitmap='gray12')
m = self.item.__module__
if m == "MolecularComponents.classProtein" or m=="MolecularComponents.classNucleotideChain" or m=="System":
self.item.select()
else:
for i in self.item:
i.select()
self.parent.parent.parent.viewer.update_view()
class SystemCard(Card):
def __init__(self, parent, system):
Card.__init__(self, parent, self.select)
self.item = system
self.parent = parent
self.info_button = Menubutton(self, bitmap='info', direction=RIGHT,
relief=RAISED,width=17, height=17)
self.info_button.pack(side=LEFT, anchor=W, expand=NO)
self.info_button.menu = Menu(self.info_button, tearoff=0)
self.info_button["menu"] = self.info_button.menu
self.info_button.menu.add_command(label="save system", command=self.save_system)
self.info_button.menu.add_command(label="show header", command=self.view_header)
# make a button for selection
self.selection_button = Button(self, text='SELECTION', height=1)
self.selection_button.config(command=self.launch_selection_dialog)
self.selection_button.pack(side=LEFT,expand=NO)
# make a button for tearing off
self.tear_off_button = Button(self, bitmap='gray12', width=14, height=14)
self.tear_off_button.config(command=self.tearoff)
self.tear_off_button.pack(side=RIGHT, anchor=E, expand=NO)
# create a label object as the title
name_string = 'System'
self.title = Label(self, height=1, width=6, text=name_string)
self.title.pack(side=LEFT, anchor=W, expand=NO)
#def view_MD(self):
# reload(DynamicsViewer)
# self.MD_viewer = DynamicsViewer.MDViewer(self.item)
def launch_selection_dialog(self):
reload(SystemSelectionDialog)
self.selection_top = Toplevel()
geometry_string = "%dx%d%+d%+d" %(440,300,1,220) # width,height,x-offset,y-offset
self.selection_top.geometry(geometry_string)
self.selection_top.wm_transient(self.parent.master_window) # transient to the System window
self.selection_top.title('Select Molecules, Residues, and Atoms')
self.selection_dialog = SystemSelectionDialog.SystemSelectionDialog(self.parent.master_window.viewer, self.selection_top, self.item)
self.selection_dialog.pack(expand='yes', fill='both')
def view_header(self):
win_title = 'Header for %s'%(self.item.filename)
dialog = Pmw.TextDialog(self.parent, scrolledtext_labelpos = 'n', title = win_title, defaultbutton = 0, master=self.parent.master_window)
hdr = ""
for line in self.item.HeaderLines:
hdr = hdr + string.strip(line) + '\n'
dialog.insert('end', hdr)
def save_system(self):
system_save_name = tkFileDialog.asksaveasfilename(title = 'Save System', defaultextension='.sps', filetypes=[("SPADE Pickled System", "*.sps"),("all files", "*")])
self.item.save_system(system_save_name)
class backCard(Frame):
def __init__(self, parent, frame_to_remove):
Frame.__init__(self, parent, borderwidth=0, height=1)
self.frame_to_remove = frame_to_remove
self.parent = parent
# make a button to recreate the system cards
self.back_button = Button(self, text='System View', width=11, height=1)
self.back_button.config(command=self.recreate_system_cards)
self.back_button.pack(side=LEFT, anchor=W, expand=NO)
def recreate_system_cards(self):
self.frame_to_remove.pack_forget()
self.frame_to_remove.destroy()
del self.frame_to_remove
self.pack_forget()
self.destroy()
self.parent.reloadSystem(self.parent.system, 0)
class ProteinCard(Card):
def __init__(self, parent, chain):
Card.__init__(self, parent, self.select)
self.chain = chain
# make a button for showing additional information
self.info_button = Menubutton(self, bitmap='info', direction=RIGHT,
relief=RAISED,width=17, height=17)
self.info_button.pack(side=LEFT, anchor=W, expand=NO)
self.info_button.menu = Menu(self.info_button, tearoff=0)
self.info_button["menu"] = self.info_button.menu
self.info_button.menu.add_command(label="default colors", command=self.default_colors)
self.info_button.menu.add_command(label="color by type", command=self.color_by_type)
# make a button for tearing off
self.tear_off_button = Button(self, bitmap='gray12', width=14, height=14)
self.tear_off_button.config(command=self.tearoff)
self.tear_off_button.pack(side=RIGHT, anchor=E, expand=NO)
self.item = chain
# create a label object as the title
name_string = 'Prot ' + self.item.chain_name
col3 = self.item.get_chain_color()
bg_color = "#%02x%02x%02x"%(int(col3[0]*256),int(col3[1]*256),int(col3[2]*256))
self.title = Label(self, height=1, width=6, text=name_string, bg=bg_color)
self.title.pack(side=LEFT, anchor=W, expand=NO)
# add a scrollbar
self.xsbar = Scrollbar(self, orient='horizontal')
self.xsbar.pack(side=LEFT)
# create a text object for the sequence
self.block_holder = Text(self, height=1, wrap=NONE)
self.block_holder.insert('1.0', self.item.get_sequence())
self.block_holder.pack(expand=YES, fill=X, anchor=N)
# associate the scrollbar with the textbox
self.xsbar.config(command=self.block_holder.xview)
self.block_holder.config(xscrollcommand=self.xsbar.set)
self.block_holder.config(state=DISABLED)
def default_colors(self):
self.remove_tags()
self.parent.system.color_ribbon_by_chain()
for rez in self.item.residues:
for atom in rez.atoms:
atom.vtk_arg_list[0][1] = atom.get_color('cpk')
self.item.update_atom_actors()
for rez in self.item.residues:
rez.update_actors()
self.parent.parent.parent.viewer.update()
def color_by_type(self):
buried = ['A','C','F','I','L','M','V','W']
uncharged = ['G','N','P','Q','S','T','Y']
chargedminus = ['D','E']
chargedplus = ['H','K','R']
colors = ['cyan','orange','red','yellow']
# first color the letters in the card
cntr = 0
for c in self.block_holder.get('1.0', END+'-1c'):
str = "1.%d"%cntr
if c in buried:
self.block_holder.tag_add('buried', str)
elif c in uncharged:
self.block_holder.tag_add('uncharged', str)
elif c in chargedminus:
self.block_holder.tag_add('chargedminus', str)
elif c in chargedplus:
self.block_holder.tag_add('chargedplus', str)
cntr = cntr + 1
self.block_holder.tag_config('buried', background=colors[0])
self.block_holder.tag_config('uncharged', background=colors[1])
self.block_holder.tag_config('chargedminus', background=colors[2])
self.block_holder.tag_config('chargedplus', background=colors[3])
# now change the colors of all of the residues
for rez in self.item.residues:
c = rez.res_type1
if c in buried:
rez.vtk_arg_list[2][2] = [0.5,0.75,1.0]
elif c in uncharged:
rez.vtk_arg_list[2][2] = [1.0,0.5,0.0]
elif c in chargedminus:
rez.vtk_arg_list[2][2] = [0.9,0.2,0.2]
elif c in chargedplus:
rez.vtk_arg_list[2][2] = [1.0,1.0,0.2]
# and recolor the atoms by type
for rez in self.item.residues:
for atom in rez.atoms:
atom.vtk_arg_list[0][1] = atom.get_color('typ')
rez.update_actors()
self.item.update_atom_actors()
self.parent.parent.parent.viewer.screen.Render()
class NucleotideChainCard(Card):
def __init__(self, parent, chain):
Card.__init__(self, parent, self.select)
# make a button for showing additional information
self.info_button = Menubutton(self, bitmap='info', direction=RIGHT,
relief=RAISED,width=17, height=17)
self.info_button.pack(side=LEFT, anchor=W, expand=NO)
self.info_button.menu = Menu(self.info_button, tearoff=0)
self.info_button["menu"] = self.info_button.menu
self.info_button.menu.add_command(label="default colors", command=self.remove_tags)
# make a button for tearing off
self.tear_off_button = Button(self, bitmap='gray12', width=14, height=14)
self.tear_off_button.config(command=self.tearoff)
self.tear_off_button.pack(side=RIGHT, anchor=E, expand=NO)
self.item = chain
# create a label object as the title
name_string = 'Nuc ' + self.item.chain_name + ' '
self.title = Label(self, height=1, width=6, text=name_string)
self.title.pack(side=LEFT, anchor=W, expand=NO)
# add a scrollbar
self.xsbar = Scrollbar(self, orient='horizontal')
self.xsbar.pack(side=LEFT)
# create a text object for the sequence
self.block_holder = Text(self, height=1, wrap=NONE)
self.block_holder.insert('1.0', self.item.get_sequence())
self.block_holder.pack(expand=YES, fill=X, anchor=N)
# associate the scrollbar with the textbox
self.xsbar.config(command=self.block_holder.xview)
self.block_holder.config(xscrollcommand=self.xsbar.set)
self.block_holder.config(state=DISABLED)
class LigandCard(Card):
def __init__(self, parent, ligandList):
Card.__init__(self, parent, self.select_all)
# make a button for showing additional information
self.info_button = Menubutton(self, bitmap='info', direction=RIGHT,
relief=RAISED,width=17, height=17)
self.info_button.pack(side=LEFT, anchor=W, expand=NO)
self.info_button.menu = Menu(self.info_button, tearoff=0)
self.info_button["menu"] = self.info_button.menu
self.info_button.menu.add_command(label="default colors", command=self.remove_tags)
# make a button for tearing off
self.tear_off_button = Button(self, bitmap='gray12', width=14, height=14)
self.tear_off_button.config(command=self.tearoff)
self.tear_off_button.pack(side=RIGHT, anchor=E, expand=NO)
self.item = ligandList
# create a label object as the title
name_string = 'Ligand'
self.title = Label(self, height=1, width=6, text=name_string)
self.title.pack(side=LEFT, anchor=W, expand=NO)
# add a scrollbar
self.xsbar = Scrollbar(self, orient='horizontal')
self.xsbar.pack(side=LEFT)
# create a text object for the sequence
self.block_holder = Text(self, height=1, wrap=NONE)
self.block_holder.pack(expand=NO, fill=X, anchor=N)
self.ligbuttonlist = []
lig_index = 0
for lig in self.item:
# first enter the three letter name for the molecule
self.block_holder.insert(END,lig.res_type)
c_lambda = lambda lig_i=lig_index: self.select(lig_i)
self.ligbuttonlist.append(Button(self.block_holder, bitmap='gray12', width=8, height=8, command=c_lambda))
self.ligbuttonlist[len(self.ligbuttonlist)-1].pack(expand=NO,side=TOP,anchor=E)
self.block_holder.window_create(END, window=self.ligbuttonlist[len(self.ligbuttonlist)-1])
lig_index = lig_index + 1
# associate the scrollbar with the textbox
self.xsbar.config(command=self.block_holder.xview)
self.block_holder.config(xscrollcommand=self.xsbar.set)
self.block_holder.config(state=DISABLED)
def select_all(self):
if self.select_button.cget('bitmap') == 'gray12':
self.select_button.config(bitmap='gray75')
for i in range(0,len(self.item)):
if self.ligbuttonlist[i].cget('bitmap') == 'gray12':
self.ligbuttonlist[i].config(bitmap='gray75')
if self.item[i].selected == 1:
self.item[i].deselect()
elif self.select_button.cget('bitmap') == 'gray75':
self.select_button.config(bitmap='gray12')
for i in range(0,len(self.item)):
if self.ligbuttonlist[i].cget('bitmap') == 'gray75':
self.ligbuttonlist[i].config(bitmap='gray12')
if self.item[i].selected == 0:
self.item[i].select()
self.parent.parent.parent.viewer.update_view()
def select(self, lig_num):
# deselect the card's item
if self.ligbuttonlist[lig_num].cget('bitmap') == 'gray12':
self.ligbuttonlist[lig_num].config(bitmap='gray75')
if self.item[lig_num].selected == 1:
self.item[lig_num].deselect()
# select the whole chain
elif self.ligbuttonlist[lig_num].cget('bitmap') == 'gray75':
self.ligbuttonlist[lig_num].config(bitmap='gray12')
if self.item[lig_num].selected == 0:
self.item[lig_num].select()
self.parent.parent.parent.viewer.update_view()