How
to get the Powermate Dial to play nicely with PyMol:
First, put lines similar to those in the example below into your
.pymolrc file (or however you get startup commands into
pymol). 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 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)
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]" \
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]" \
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]" \
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()
Then install the Powermate driver and reboot the system.
Open up "System Preferences" and you will find a new preference
pane called "PowerMate." When you open it up, you should see
something similar to what is pictured below. Use "Add
Settings" to add PyMol to the pulldown list you see when you go to
the "Global Settings pull-down".
"Setting" should now indicate "PyMOL" or "MacPyMOL".
Go below to "User Action" and set it to "Rotate Right" if it is not
already showing this. Then where it says "Computer Action",
change the selection at the tip of the arrow above from "No
Action"
as
is shown in the picture immediately below
to
"Send Key" as is shown in the third
picture.
Now press the "Change Key" button that is circled below.
This allows you to change the key from the default setting to
something more useful.
After you hit the "Change Key" button, you will get a second
dialog box as shown below. Where I have circled "F1", you
want to put in whatever you have chosen as the key equivalent with
the pymol set_key function. To do so, simply push the
relevant button on your keyboard. (You don't type into this
box.) Then hit the OK button.
Repeat this for "Rotate Left". I also programmed "Click and
Rotate Right (Left)" to send the "F3" ("F4") function keys that I
had programmed into pymol. This enables me to push down on
the dial to translate the molecule. Clicking the dial
(program Click to send F5) toggles between dialsets for x, y and
z.
