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
|
# demonstrate how to capture PyMOL's atom selection events
from pymol.wizard import Wizard
from pymol import cmd
import pymol
sele_name = "lb" # must be set to "lb" for now...
class PickWizard(Wizard):
def set_buttons(self):
# just use selections (disable atom and bond picking)
cmd.button('m','ctrl','+lb')
cmd.button('r','ctrl','none')
cmd.button('r','ctsh','none')
def get_prompt(self):
# returns prompt for the viewer window (optional)
if sele_name in cmd.get_names('selections'):
n_atom = cmd.count_atoms(sele_name)
else:
n_atom = 0
if n_atom:
list = cmd.identify(sele_name)
return ["%d atoms selected..."%n_atom,str(list)]
else:
return ["Please select some atoms..."]
def do_select(self,name):
# handle mouse selection callback
if not sele_name in cmd.get_names('selections'):
cmd.select(sele_name,'none')
cmd.enable(sele_name)
cmd.refresh_wizard()
def get_panel(self):
return [
[ 1, 'Example Wizard',''],
[ 2, 'Clear Selection',
'cmd.delete("'+sele_name+'");cmd.refresh_wizard()'],
]
wiz = PickWizard()
# make this the active wizard
cmd.set_wizard(wiz)
# reconfigure the mouse panel
wiz.set_buttons()
|