@@ -31,6 +31,7 @@ def show_contacts(selection,selection2,result="contacts",cutoff=3.6, bigcutoff =
3131 print ('selection = "' + selection + '"' )
3232 print ('selection2 = "' + selection2 + '"' )
3333
34+ result = cmd .get_legal_name (result )
3435
3536 #if the group of contacts already exist, delete them
3637 cmd .delete (result )
@@ -189,7 +190,7 @@ def show_contacts(selection,selection2,result="contacts",cutoff=3.6, bigcutoff =
189190'''
190191
191192class Show_Contacts :
192- ''' Main Pymol Plugin Class '''
193+ ''' Tk version of the Plugin GUI '''
193194 def __init__ (self , app ):
194195 parent = app .root
195196 self .parent = parent
@@ -247,7 +248,7 @@ def button_pressed(self, result):
247248 def populate_ligand_select_list (self ):
248249 ''' Go thourgh the loaded objects in PyMOL and add them to the selected list. '''
249250 #get the loaded objects
250- loaded_objects = [ name for name in cmd . get_names ( 'all' ) if '_cluster_' not in name ]
251+ loaded_objects = _get_select_list ()
251252
252253 self .select_object_combo_box .clear ()
253254 self .select_object_combo_box2 .clear ()
@@ -257,9 +258,81 @@ def populate_ligand_select_list(self):
257258 self .select_object_combo_box2 .insert ('end' , ob )
258259
259260
261+ def _get_select_list ():
262+ '''
263+ Get either a list of object names, or a list of chain selections
264+ '''
265+ loaded_objects = [name for name in cmd .get_names ('all' , 1 ) if '_cluster_' not in name ]
266+
267+ # if single object, try chain selections
268+ if len (loaded_objects ) == 1 :
269+ chains = cmd .get_chains (loaded_objects [0 ])
270+ if len (chains ) > 1 :
271+ loaded_objects = ['{} & chain {}' .format (loaded_objects [0 ], chain ) for chain in chains ]
272+
273+ return loaded_objects
274+
275+
276+ class Show_Contacts_Qt_Dialog (object ):
277+ ''' Qt version of the Plugin GUI '''
278+ def __init__ (self ):
279+ from pymol .Qt import QtWidgets
280+ dialog = QtWidgets .QDialog ()
281+ self .setupUi (dialog )
282+ self .populate_ligand_select_list ()
283+ dialog .accepted .connect (self .accept )
284+ dialog .exec_ ()
285+
286+ def accept (self ):
287+ s1 = self .select_object_combo_box .currentText ()
288+ s2 = self .select_object_combo_box2 .currentText ()
289+ show_contacts (s1 , s2 , '%s_%s' % (s1 , s2 ))
290+
291+ def populate_ligand_select_list (self ):
292+ loaded_objects = _get_select_list ()
293+
294+ self .select_object_combo_box .clear ()
295+ self .select_object_combo_box2 .clear ()
296+
297+ self .select_object_combo_box .addItems (loaded_objects )
298+ self .select_object_combo_box2 .addItems (loaded_objects )
299+
300+ if len (loaded_objects ) > 1 :
301+ self .select_object_combo_box2 .setCurrentIndex (1 )
302+
303+ def setupUi (self , Dialog ):
304+ # Based on auto-generated code from ui file
305+ from pymol .Qt import QtCore , QtWidgets
306+ Dialog .resize (400 , 50 )
307+ self .gridLayout = QtWidgets .QGridLayout (Dialog )
308+ label = QtWidgets .QLabel ("Select loaded object:" , Dialog )
309+ self .gridLayout .addWidget (label , 0 , 0 , 1 , 1 )
310+ self .select_object_combo_box = QtWidgets .QComboBox (Dialog )
311+ sizePolicy = QtWidgets .QSizePolicy (QtWidgets .QSizePolicy .Expanding , QtWidgets .QSizePolicy .Fixed )
312+ self .select_object_combo_box .setSizePolicy (sizePolicy )
313+ self .select_object_combo_box .setEditable (True )
314+ self .gridLayout .addWidget (self .select_object_combo_box , 0 , 1 , 1 , 1 )
315+ label = QtWidgets .QLabel ("Select loaded object:" , Dialog )
316+ self .gridLayout .addWidget (label , 1 , 0 , 1 , 1 )
317+ self .select_object_combo_box2 = QtWidgets .QComboBox (Dialog )
318+ self .select_object_combo_box2 .setSizePolicy (sizePolicy )
319+ self .select_object_combo_box2 .setEditable (True )
320+ self .gridLayout .addWidget (self .select_object_combo_box2 , 1 , 1 , 1 , 1 )
321+ self .buttonBox = QtWidgets .QDialogButtonBox (Dialog )
322+ self .buttonBox .setOrientation (QtCore .Qt .Horizontal )
323+ self .buttonBox .setStandardButtons (QtWidgets .QDialogButtonBox .Cancel | QtWidgets .QDialogButtonBox .Ok )
324+ self .gridLayout .addWidget (self .buttonBox , 2 , 0 , 1 , 2 )
325+ self .buttonBox .accepted .connect (Dialog .accept )
326+ self .buttonBox .rejected .connect (Dialog .reject )
260327
261328
262329def __init__ (self ):
330+ try :
331+ from pymol .plugins import addmenuitemqt
332+ addmenuitemqt ('Show Contacts' , Show_Contacts_Qt_Dialog )
333+ return
334+ except Exception as e :
335+ print (e )
263336 self .menuBar .addmenuitem ('Plugin' , 'command' , 'Show Contacts' , label = 'Show Contacts' , command = lambda s = self : Show_Contacts (s ))
264337
265338
0 commit comments