Set Key

From PyMOLWiki
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

set_key binds a Python function or PyMOL command to a key press. Such key binding customization is typically done with your pymolrc startup script.

Changes with PyMOL version:

  • 1.8: decorator support
  • 1.7: second argument can also be a string in PyMOL command syntax

PyMOL API

cmd.set_key(string key, function fn, tuple arg=(), dict kw={})

Also supported since PyMOL 1.7:

cmd.set_key(string key, string command)

Decorator support since PyMOL 1.8:

cmd.set_key(string key)(function fn)

PyMOL Command (since PyMOL 1.7)

set_key key, command

Examples

from pymol import cmd

# define a custom function which colors a selection blue
def make_it_blue(selection): cmd.color("blue", selection)

# color "object1" blue when the F1 key is pressed
cmd.set_key( 'F1' , make_it_blue, [ "object1" ] )
# zoom on everything
cmd.set_key( 'CTRL-C' , cmd.zoom )
# turn camera by 90 degrees
cmd.set_key( 'ALT-A' , cmd.turn, ('x',90) )
# zoom on first ligand when pressing F1 (PyMOL 1.7+)
set_key F1, zoom byres (first organic), animate=1
# zoom on first ligand when pressing F1 (all PyMOL versions)
cmd.set_key('F1', cmd.zoom, ['byres (first organic)'], {'animate': 1})
# decorator syntax (PyMOL 1.8+)
@cmd.set_key('F1')
def zoom_ligand():
    cmd.zoom('byres (first organic)', animate=1)

KEYS WHICH CAN BE REDEFINED

F1 to F12
left, right, pgup, pgdn, home, insert
CTRL-A to CTRL-Z 
ALT-0 to ALT-9, ALT-A to ALT-Z

See Also