Difference between revisions of "Set Key"

From PyMOLWiki
Jump to navigation Jump to search
(updates)
 
Line 1: Line 1:
'''set_key''' binds a specific python function to a key press.
+
'''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 ==
  
===PYMOL API (ONLY)===
 
 
<source lang="python">
 
<source lang="python">
cmd.set_key( string key, function fn, tuple arg=(), dict kw={})
+
cmd.set_key(string key, function fn, tuple arg=(), dict kw={})
 
</source>
 
</source>
  
===PYTHON EXAMPLE===
+
''Also supported since PyMOL 1.7:''
 +
<source lang="python">
 +
cmd.set_key(string key, string command)
 +
</source>
 +
 
 +
''Decorator support since PyMOL 1.8:''
 +
<source lang="python">
 +
cmd.set_key(string key)(function fn)
 +
</source>
 +
 
 +
== PyMOL Command (since PyMOL 1.7) ==
 +
 
 +
set_key key, command
 +
 
 +
== Examples ==
 +
 
 
<source lang="python">
 
<source lang="python">
 
from pymol import cmd
 
from pymol import cmd
  
def make_it_blue(object): cmd.color("blue",object)
+
# 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" ] )
 
cmd.set_key( 'F1' , make_it_blue, [ "object1" ] )
# would turn object1 blue when the F1 key is pressed and
+
</source>
# (in order to use it one has to make a selection called
+
 
# object1)
+
<source lang="python">
+
# zoom on everything
cmd.set_key( 'F2' , make_it_blue, [ "object2" ] )
 
# would turn object2 blue when the F2 key is pressed.
 
 
 
cmd.set_key( 'CTRL-C' , cmd.zoom )   
 
cmd.set_key( 'CTRL-C' , cmd.zoom )   
 +
</source>
 +
 +
<source lang="python">
 +
# turn camera by 90 degrees
 
cmd.set_key( 'ALT-A' , cmd.turn, ('x',90) )
 
cmd.set_key( 'ALT-A' , cmd.turn, ('x',90) )
 
</source>
 
</source>
  
===KEYS WHICH CAN BE REDEFINED===
+
# zoom on first ligand when pressing F1 (PyMOL 1.7+)
 +
set_key F1, zoom byres (first organic), animate=1
 +
 
 +
<source lang="python">
 +
# zoom on first ligand when pressing F1 (all PyMOL versions)
 +
cmd.set_key('F1', cmd.zoom, ['byres (first organic)'], {'animate': 1})
 +
</source>
 +
 
 +
<source lang="python">
 +
# decorator syntax (PyMOL 1.8+)
 +
@cmd.set_key('F1')
 +
def zoom_ligand():
 +
    cmd.zoom('byres (first organic)', animate=1)
 +
</source>
 +
 
 +
== KEYS WHICH CAN BE REDEFINED ==
 
  F1 to F12
 
  F1 to F12
 
  left, right, pgup, pgdn, home, insert
 
  left, right, pgup, pgdn, home, insert
Line 30: Line 70:
 
  ALT-0 to ALT-9, ALT-A to ALT-Z
 
  ALT-0 to ALT-9, ALT-A to ALT-Z
  
===SEE ALSO===
+
== See Also ==
[[Button]] [[Check Key]]
+
 
 +
* [[alias]]
 +
* [[extend|cmd.extend]]
 +
* [[Button]]
 +
* [[Check Key]]
  
 
[[Category:Commands|Set Key]]
 
[[Category:Commands|Set Key]]

Latest revision as of 20:39, 6 March 2016

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