From: Norman Geist (
Date: Thu Mar 02 2017 - 07:19:40 CST

Regarding the VMD source code, the Display->Resetview function uses the zoom calculated from the largest dimension from the molecules bounding box as a devider to 1.5 (e.g. 1.8 for a closer zoom). So an autozoom function would be easy to write.


Example derived from my userani movie system which uses everything visible to compute the bounding box (except periodic images):


proc AutoScaleAllVisible {{zoom_factor 1}} {

  set prog 1

  set me [lindex [info level [info level]] 0]


  set minX "false"

  set minY "false"

  set maxX "false"

  set maxY "false"

  set zoom [expr 1.8 * $zoom_factor]


  #compute bb for all visible stuff

  set mols [molinfo list]

  foreach molid $mols {

    if {[molinfo $molid get displayed] && [molinfo $molid get numframes] > 0} {

      set num_reps [molinfo $molid get numreps]

      if {$num_reps > 0} {

     set seltext ""

     for {set i 0} {$i<$num_reps} {incr i} {

       if {[mol showrep $molid $i]} {

         if {[string length $seltext] > 0} { set seltext "$seltext or " }

         set temp [molinfo $molid get "{selection $i}"]

         set seltext "${seltext}(${temp})"




      if {[string length $seltext] > 0} {

     set sel [atomselect $molid ($seltext)]

     set mm [measure minmax $sel]

     $sel delete

     set minXtemp [lindex [lindex $mm 0] 0]

     set minYtemp [lindex [lindex $mm 0] 1]

     set maxXtemp [lindex [lindex $mm 1] 0]

     set maxYtemp [lindex [lindex $mm 1] 1]

     set minX [expr $minXtemp < $minX || $minX == "false" ? $minXtemp : $minX]

     set minY [expr $minYtemp < $minY || $minY == "false" ? $minYtemp : $minY]

     set maxX [expr $maxXtemp > $maxX || $maxX == "false" ? $maxXtemp : $maxX]

     set maxY [expr $maxYtemp > $maxY || $maxY == "false" ? $maxYtemp : $maxY]




  if {$minX != "false"} {#true for 1 true for all

    set rangeX [expr $maxX - $minX]

    set rangeY [expr $maxY - $minY]

    set maxrange [expr max($rangeX,$rangeY)]

    set target [expr $zoom/$maxrange]

    set cscale [lindex [lindex [lindex [molinfo top get scale_matrix] 0] 0] 0]

    set nscale [expr $target + (($cscale - $target) * pow(abs($prog-1.),$prog))]

    eval "scale to $nscale"

  } else {

      puts "$me: nothing seems to be visible!"





Norman Geist


Von: [] Im Auftrag von Stefan Doerr
Gesendet: Donnerstag, 2. März 2017 11:30
Betreff: vmd-l: Zoom-to-fit before rendering


Hi, I was wondering if there is some functionality in VMD to zoom the scene to match the content.


My problem is the following:

I render automatically through Tachyon multiple molecules but depending on their size some of them fill the picture and some are much smaller. I can auto-crop the image then with imagemagic but I end up with some pictures looking high resolution and others super-low (since I cropped the large empty space around them).


The solution would be to automatically zoom until all molecules fit exactly in the rendered image resolution but I don't know how to do that.