The draw command is a straight Tcl function which is meant to simplify the interface to the graphics command as well as provide a base for extensions to the standard graphics primitives.
The format of the draw command is:
Unlike the graphics command, draw does not take a molecule index by default. Instead, it searches for the last graphical molecule with the name ``graphics'' and uses that. (If such a molecule doesn't exist, it is created.) The basic commands are identical to those used by graphics. However, if the command doesn't work or doesn't exists, VMD tries to find an extension draw function.
This is done by searching for a function of the form vmd_draw_$command. If the function exists, it is called with the first parameter the molecule index and the rest are the arguments from the original draw call.
Here's an example which extends the draw command to include an ``arrow'' primitive.
proc vmd_draw_arrow {mol start end} { # an arrow is made of a cylinder and a cone set middle [vecadd $start [vecscale 0.9 [vecsub $end $start]]] graphics $mol cylinder $start $middle radius 0.15 graphics $mol cone $middle $end radius 0.25 }and here's one which adds the ``color'' option to the ``cylinder primitive. It works because the draw command tries the ``graphics'' command and fails, because the ``color'' option doesn't exist. At that point, the extensions are checked.
proc vmd_draw_cylinder {mol start end args} { if [expr [llength $args] % 2] { error "draw: cylinder: incorrect argument list" } # start the construction of the graphics command set opts [list graphics $mol cylinder] lappend opts $start $end # search for the "color" option while {[string compare $args {}]} { # get the parameter and value set a [lvarpop args] set b [lvarpop args] # check if it is the color command if [string compare $a "color"] { # if it isn't, save the options lappend opts $a $b } else { # otherwise, save the color set color $b } } # call the graphics commands graphics $mol color $color eval $opts }