PowerMate Dial OS X

From PyMOLWiki
Jump to: navigation, search

Link to W. G. Scott's web page (off site). Use of the script below is explained in that link. Briefly, the PowerMate driver must be installed and configured as explained in detail in that link before this script will work.

Pymol lets you define some keys (the function keys, ALT-[A-Z,0-9], left, right, up, down, etc) as pythonic pymol commands, like those below. I chose 2 degree increments for rotation and 0.5 for translations because these values give a visually smooth response, but change this to suit your own taste. Type

help set_key 

in pymol for more information.

The code below dynamically assigns functions to the four programmed keys by running python scripts in pymol to reset the key bindings. Clicking the Powermate dial to activate the toggle function (assigned to F5) allows you to toggle cyclically through dial functionality options, thus giving you three sets of rotations and translations.

In other words, turn the dial right or left to rotate in the plus y or minus y directions. Push down while turning right or left to get the plus and minus y translations. Click the dial (press down and release rapidly) to toggle to an analogous dial set for z, and then click again for x, and then again for y.

from pymol import cmd
 
# Define aliases for mapping in [x,y,z] rotations and translations into a single Powermate
# dial.  Toggling between the three is possible if you then assign these to special keys.
 
# Functions for x,y,z rotations and translations using Powermate dial
# Program F1 and F2 for Rotate Right and Rotate Left
# Program F3 and F4 for Click & Rotate Right and Click & Rotate Left
# Program F5 for  Click  (to toggle between dialsets)
 
# dialset = 2
 
def dialx(): \
    global dialset \
    dialset = 1 \
    cmd.set_key ('F1', cmd.turn,('x',-2.0)) \
    cmd.set_key ('F2', cmd.turn,('x',2.0)) \
    cmd.set_key ('F3', cmd.move,('x',-0.5)) \
    cmd.set_key ('F4', cmd.move,('x',0.5)) \
    print "dialset ", dialset, " [ X ]\n" \
    return dialset
 
def dialy(): \
    global dialset \
    dialset = 2 \
    cmd.set_key ('F1', cmd.turn,('y',-2.0)) \
    cmd.set_key ('F2', cmd.turn,('y',2.0)) \
    cmd.set_key ('F3', cmd.move,('y',-0.5)) \
    cmd.set_key ('F4', cmd.move,('y',0.5)) \
    print "dialset ", dialset, " [ Y ]\n" \
    return dialset
 
 
def dialz(): \
    global dialset \
    dialset = 3 \
    cmd.set_key ('F1', cmd.turn,('z',-2.0)) \
    cmd.set_key ('F2', cmd.turn,('z',2.0)) \
    cmd.set_key ('F3', cmd.move,('z',-0.5)) \
    cmd.set_key ('F4', cmd.move,('z',0.5)) \
    print "dialset ", dialset, " [ Z ]\n" \
    return dialset
 
def toggle_dial(): \
    if dialset == 1 : \
        print "Changing to y" \
        dialy() \
    elif dialset == 2 : \
        print "Changing to z" \
        dialz() \
    elif dialset == 3 : \
        print "Changing to x" \
        dialx() \
    else: print "Dial assignment isn't working"
 
 
cmd.set_key ('F5', toggle_dial)
 
# Start default dial state for rotate y  (arbitrary choice)
 
dialy()
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox