The popup menu in VMD has a number of default menu items and submenus, which cannot be changed. These are described in an earlier section. But you can add new submenus and items to this menu, and assign text commands to those items. When the items are selected by the user, the assigned text command will be executed as if it had been typed in at the console. In fact, with Tcl you can assign arbitrarily complex commands (such as scripts) to a single menu selection.
To add a menu to the main pop-up menu, use:
For example, lets suppose we want to make a menu of our
most often used structures. Then the command to accomplish this is:
user add menu Favorites
Since there isn't anything in the menu, it doesn't appear in the popup menu yet. To add items to the menu, use:
user add subitem Favorites BPTI {mol pdbload 9pti} user add subitem Favorites alanin {mol load pdb alanin.pdb} user add subitem Favorites bR {mol load pdb brH.pdb}
Enter these three lines and then bring up the popup menu. You should see the new menu item just above the ``Help'' lines. Unless you also happen to have these molecules available, the last two items probably won't work, but the first one should. Try it out.
You can also add a separator in the menu, using:
user add subseparator Favorites user add subitem Favorites Polio {mol pdbload 2plv}
As a second complete example, the code below will produce a cascading menu which allows you to quickly adjust the degree of transparency for transparenent objets (i.e. the default is .3, where 1.0 is opaque and 0.0 is invisible).
# Set the alpha value of the "transparent" materials
proc set_transparency_value {alpha} {
display update off
# change the opaquicity of the transparent colors
for {set color 17} {$color < 34} {incr color} {
color change alpha $color $alpha
}
# and the transparent color scale (66 to 97)
for {set color 66} {$color < 98} {incr color} {
color change alpha $color $alpha
}
display update on
}
user add menu Transparency
for {set i 1.0} {$i >= 0.0} {set i [expr $i - 0.1]} {
eval "user add subitem Transparency $i {
set_transparency_value $i}"
}
Unfortunately, the user modifiable popup menus are not hierarchical. There is no way to add a submenu to one of your own menus. They can only be added to the main popup menu. However, there is another place to add new menu items, the `User Commands' submenu of the main menu. ``Where is it?'' you ask? It doesn't contain anything, so it isn't displayed. You can add items to it just as you can to the main menu, but the commands are slightly different. Admittedly this is not an optimal solution. Future versions of VMD will use Tk menus to alleviate this problem. Until then though, here is a specification of the syntax.
To add an item to the `User Commands' menu:
To add a separator to the 'User Commands' menu:
The usage is the same as their related commands, so we won't
give a detailed example, but to see how it works, try this:
# Turn off the axis
user add item {Axes Off} axes location off
user add item {Axes On} axes location LowerLeft
# a break
user add separator
# delete all the loaded molecule
user add item {Zap Everything} {
foreach molecule [molinfo list] {
mol delete $molecule
}
}
Finally, if you wish to see the current definitions of the user-customized menu items, use the command