OverviewThere are many ways in which the VMD molecular visualization and analysis software can be customized. Here are a few examples from my personal setup or prepared in collaboration with VMD users, some of which are quite unusual. Delayed InitializationColor to element or name or type assignments cannot be changed until the corresponding lists have been initialized. However, the VMD init script ( after idle { color Name C green color Type C green color Name P purple color Type P purple}
Defining Colors for Any NameAnother side effect of the fact, that color categories are not initialized at startup time, is that one cannot set colors for entries that are not yet known. To work around this problem, we have to "fake" a molecule, which can be easily done with the "mol new atoms " syntax. Here is an example: after idle {
}
Desaturated ColorsVMD by default uses "pure" colors defined in RGB color space, i.e. red is coded as color change rgb 0 0.1 0.2 0.7 ;# blue
color change rgb 1 0.7 0.2 0.1 ;# red color change rgb 3 0.7 0.4 0.0 ;# orange color change rgb 4 0.8 0.7 0.1 ;# yellow color change rgb 7 0.1 0.7 0.2 ;# green color change rgb 10 0.1 0.7 0.8 ;# cyan color change rgb 11 0.6 0.1 0.6 ;# purpleMolecule Name in Window TitleOccasionally people ask, whether it would be possible to have VMD display the name of the active molecule in the title of the OpenGL window. While this would be best done from within VMD, this little hack only uses Tcl script. The downside is that it only works with machines that use the X window system and have the corresponding utilities installed. More precisely, it uses the # define global variable to store X window id.
global vmd_opengl_wid# callback function to be called when the top molecule changes global vmd_opengl_wid if {[molinfo num] < 1} return if {[llength $args] == 0} { set name [join [molinfo top get name]] } else { set name [lindex $args 0] if { [string equal $name vmd_molecule] } { set name [join [molinfo top get name]] } } if {$vmd_opengl_wid > 0} { catch {exec xprop -id $vmd_opengl_wid \ -set WM_NAME "VMD [vmdinfo version]: $name"} catch {exec xprop -id $vmd_opengl_wid \ -set WM_ICON_NAME $name} }
}# activate callback
after idle { global vmd_opengl_wid if {![catch {exec xwininfo -name \ "VMD [vmdinfo version] OpenGL Display"} val ]} { set vmd_opengl_wid [lindex $val 3] } vmd_change_opengl_name
}Adding HotkeysMany keypresses in VMD can be customized and thus offering to speed up frequently use operations significantly. In the examples below the keys 'o' and 'p' allow switching between orthographic and perspective display mode, respectively, 'd' toggles between GLSL and normal OpenGL rendering, and 'D' en- or disables depth cueing. user add key o {display projection orthographic}
user add key p {display projection perspective}user add key d { if {[display get rendermode] != "Normal" } {display rendermode Normal} {display rendermode GLSL}}Custom Actions at Molecule LoadOccasionally people ask about having performing custom actions, like having a different visualization than the default, whenever a molecule is loaded. Now several defaults can be changed, but the following scheme goes far beyond that and allows adding multiple representations and performing other scripted actions. In order for this to work, we have to put a trace on the variable vmd_initialize_structure, but calling actions right away at that point would not work. We'll rather have to just schedule a call to a script whenever the main event handler is idle again. Here the procedure proc reset_viz {molid} { # operate only on existing molecules if {[lsearch [molinfo list] $molid] >= 0} { # delete all representations set numrep [molinfo $molid get numreps] for {set i 0} {$i < $numrep} {incr i} { mol delrep $i $molid } # add new representations mol color Name mol representation VDW 0.3 15.0 mol selection all mol material Opaque mol addrep $molid mol representation DynamicBonds 1.6 0.3 6.0 mol selection {name C} mol addrep $molid mol representation DynamicBonds 1.2 0.3 6.0 mol selection {name C H} mol addrep $molid } }proc reset_viz_proxy {args} { foreach {fname molid rw} $args {} eval "after idle {reset_viz $molid}"}## hook up the function.trace variable vmd_initialize_structure w reset_viz_proxy# take care of molecule loaded at start.after idle { reset_viz 0 } |
