CCL: show ruler in VMD
- From: John Stone <johns()ks.uiuc.edu>
- Subject: CCL: show ruler in VMD
- Date: Fri, 1 Jun 2007 14:11:07 -0500
Hi,
My coworker Jordi wrote up a useful VMD script for displaying a
"ruler" grid that automatically rescales along with the molecule.
This script could be modified slightly to draw various other scale bars
if you prefer something different, but it should be a good starting
point as it handles the trickiest parts such as automatically updating
when the user zooms in and out etc. I've attached the script to this email.
Cheers,
John Stone
vmd[A]ks.uiuc.edu
On Wed, May 30, 2007 at 09:33:09AM +0300, Liisa laakkonen
llaakkon::cc.helsinki.fi wrote:
>
> Sent to CCL by: Liisa laakkonen [llaakkon===cc.helsinki.fi]
> Hello Yubo,
>
> I've done the angstrom ruler simply by building a dummy pdb with
> enough points to measure the desired distance, and displaying it side
> by side with my molecule. Works equally well for a compass.
>
> Greetings,
> Liisa
>
> liisa.laakkonen ~ helsinki.fi
>
> On Tue, May 29, 2007 at 09:29:44AM -0400, Chelsey Crosse cmcrosse*_*mtu.edu
wrote:
> > Yubo,
> >
> > The only way that I know of to put a ruler in VMD by opening the Tcl
> > console and drawing it in yourself. However, I'm not positive about
> > how accurate you can make it.
> >
> > Chelsey
> >
> > On 25 May 2007, at 10:17, Yubo Fan yubofan(0)mail.chem.tamu.edu wrote:
> >
> > > Hello,
> > >
> > > A quick question about VMD. Is there any way to show ruler (ie
> > > angstroms in unit) in VMD window?
> > >
> > > Thanks,
> > >
> > > Yubo
> > > ============================================================
> > > Dr. Yubo Fan Email: yubofan^^^mail.chem.tamu.edu
> > > Department of Chemistry Tel: 1-979-845-5237
> > > Texas A&M University
> > > College Station, TX 77843
> > > ============================================================
> > >
> >
>
>
--
NIH Resource for Macromolecular Modeling and Bioinformatics
Beckman Institute for Advanced Science and Technology
University of Illinois, 405 N. Mathews Ave, Urbana, IL 61801
Email: johns[A]ks.uiuc.edu Phone: 217-244-3349
WWW: http://www.ks.uiuc.edu/~johns/ Fax: 217-244-6078
# Overlays
# Author: Jordi Cohen
#
# For now, implements a grid overlay
namespace eval ::Overlays:: {
set grid_on 0
set grid_dirty 1 ;# ruler needs a refresh
set grid_scale 0
set grid_scale_graphics_id -1
set grid_mol -1
}
proc ::Overlays::setup_grid {} {
variable grid_mol
variable grid_on
variable grid_dirty
set top [molinfo top]
set grid_mol [mol new]
mol rename $grid_mol "Grid"
if {$top >= 0} {
mol top $top
molinfo $grid_mol set scale_matrix [molinfo $top get scale_matrix]
}
redraw_grid
trace add variable ::vmd_logfile write ::Overlays::logfile_cb
set grid_on 1
set grid_dirty 1
}
proc ::Overlays::remove_grid {} {
variable grid_mol
variable grid_on
trace remove variable ::vmd_logfile write ::Overlays::logfile_cb
mol delete $grid_mol
set grid_on 0
}
proc ::Overlays::redraw_grid {} {
variable grid_mol
variable grid_on
variable grid_scale
variable grid_dirty
variable grid_scale_graphics_id
molinfo $grid_mol set center_matrix [list [transidentity]]
molinfo $grid_mol set rotate_matrix [list [transidentity]]
molinfo $grid_mol set global_matrix [list [transidentity]]
set realscale [lindex [molinfo $grid_mol get scale_matrix] 0 0 0]
set scale [expr round(-log10($realscale))-1]
if {$scale != $grid_scale} {set grid_dirty 1}
set display_ratio [expr 1.*[lindex [display get size] 0]/[lindex [display get
size] 1]]
set div [expr pow(10,$scale)]
if {$grid_dirty} {
set grid_scale $scale
set minx [expr -200*$div]
set maxx [expr 200*$div]
set miny [expr -50*$div]
set maxy [expr 50*$div]
graphics $grid_mol delete all
graphics $grid_mol color gray
# draw material Transparent
for {set tick $minx} {$tick <= $maxx} {set tick [expr $tick + $div]} {
graphics $grid_mol line [list $tick $miny 0] [list $tick $maxy 0] width 1
style dashed
}
for {set tick $miny} {$tick <= $maxy} {set tick [expr $tick + $div]} {
graphics $grid_mol line [list $minx $tick 0] [list $maxx $tick 0] width 1
style dashed
}
draw color gray
# draw material Opaque
for {set tick $minx} {$tick <= $maxx} {set tick [expr $tick + 10.*$div]}
{
graphics $grid_mol line [list [expr $tick] $miny 0] [list [expr $tick]
$maxy 0] width 2
}
for {set tick $miny} {$tick <= $maxy} {set tick [expr $tick + 10.*$div]}
{
graphics $grid_mol line [list $minx $tick 0] [list $maxx $tick 0] width 2
}
set grid_scale_graphics_id [graphics $grid_mol text [list [expr
1.2*$display_ratio/$realscale] [expr -1.4/$realscale] 0] "[format
"%g" $div]A" size 0.8]
set grid_dirty 0
} else {
graphics $grid_mol delete $grid_scale_graphics_id
set grid_scale_graphics_id [graphics $grid_mol text [list [expr
1.2*$display_ratio/$realscale] [expr -1.4/$realscale] 0] "[format
"%g" $div]A" size 0.8]
}
}
proc ::Overlays::logfile_cb { args } {
variable grid_mol
# Check for display transforms
if { [string match "rotate*" $::vmd_logfile] || [string match
"translate*" $::vmd_logfile] || \
[string match "scale*" $::vmd_logfile] || [string match
"display*" $::vmd_logfile]} {
redraw_grid
}
}
proc ::Overlays::overlay {args} {
variable grid_mol
variable grid_on
set overlay [lindex $args 0]
set state [string is true [lindex $args 1]]
if {"$overlay" == "grid"} {
if {$state} {
if {$grid_on} {remove_grid}
setup_grid
} else {
if {$grid_on} {remove_grid}
}
} else {
puts "overlay: Unknown overlay"
}
}
proc overlay {args} {
eval ::Overlays::overlay $args
}
overlay grid on