This is a read-only mirror of pymolwiki.org

Difference between revisions of "Set Key"

From PyMOL Wiki
Jump to navigation Jump to search
 
m (1 revision)
 
(9 intermediate revisions by 5 users not shown)
Line 1: Line 1:
===DESCRIPTION===
+
'''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.
  "set_key" binds a specific python function to a key press.
 
 
===PYMOL API (ONLY)===
 
<source lang="python">
 
  cmd.set_key( string key, function fn, tuple arg=(), dict kw={})
 
</python?>
 
  
===PYTHON EXAMPLE===
+
''Changes with PyMOL version:''
<source lang="python">
 
  from pymol import cmd
 
 
  def color_blue(object): cmd.color("blue",object)
 
 
  cmd.set_key( 'F1' , make_it_blue, ( "object1" ) )
 
  // would turn object1 blue when the F1 key is pressed and
 
 
  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( 'ALT-A' , cmd.turn, ('x',90) )
 
</source>
 
  
===KEYS WHICH CAN BE REDEFINED===
+
* 1.8: decorator support
+
* 1.7: second argument can also be a string in PyMOL command syntax
  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===
 
 
  [[Cmd button]]
 
  
[[Category:Commands|set_key]]
+
== PyMOL API ==
 +
 
 +
<source lang="python">
 +
cmd.set_key(string key, function fn, tuple arg=(), dict kw={})
 +
</source>
 +
 
 +
''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">
 +
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" ] )
 +
</source>
 +
 
 +
<source lang="python">
 +
# zoom on everything
 +
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) )
 +
</source>
 +
 
 +
# 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
 +
left, right, pgup, pgdn, home, insert
 +
CTRL-A to CTRL-Z
 +
ALT-0 to ALT-9, ALT-A to ALT-Z
 +
 
 +
== See Also ==
 +
 
 +
* [[alias]]
 +
* [[extend|cmd.extend]]
 +
* [[Button]]
 +
* [[Check Key]]
 +
 
 +
[[Category:Commands|Set Key]]

Latest revision as of 03:47, 7 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