From: John Stone (johns_at_ks.uiuc.edu)
Date: Mon Sep 19 2005 - 10:41:28 CDT

Jeffrey,
  There's not really an easy way to perform the calculation you're asking
for when displaying in perspective mode, which is why VMD doesn't do it.
The problem is that the projection of the bounds of the molecule into the
viewing frustum depends on the projection being used. If you want to
determine the projection to use based on the bounds, that's a much more
data intensive problem, particularly if you want the edges of the molecule
very tight with the edges of the windows and you want it to work well for
all possible molecular representations one might display without having to
recalculate the view when one chooses a new representation.

If perspective projection isn't important to you, then you should be able
to do this MUCH more easily using the orthographic projection mode.
If you're not familiar with building 3-D projection matrices, grab a copy of
"Computer Graphics, Principles and Practice" by Foley, van Dam, et al.

You could find the X and Y axis projected extents simply by transforming
the atom coordinates by the projection matrices and finding the min/max
for each. From there you could calculate a scaling factor, but you'll have
to keep in mind that if you're doing a perspective projection, that won't
actually work correctly, and so you'd need to compute it iteratively until
you converge. That solution would work fine for orthographic projections
however. You'll also need to leave slack for unusually fat representations.
For perspective projections, you might find it easier just to translate
the molecule forward or back, calculating the intersection of the view
frustum with the atoms on the front edge. That way you could avoid
messing with the projection matrix and just move the molecule fore and aft
to get it near to the bounds of the view frustum.

  John Stone
  vmd_at_ks.uiuc.edu

On Sat, Sep 17, 2005 at 10:12:41AM -0500, Jeffrey Tseng wrote:
> Hi, John
> Thanks,
>
> >you
> > could calculate your own view matrices based on the extents of the
> > molecule and force VMD to use your view.
>
>
> Is there any example to calculate the view matrices ?
>
> If using "scale by or scale to", it ends up many times "try and error".
>
> Is it possible to find the x-axis (width) and y-axis (height) of the
> molecular from the "current viewpoint" such that I can scale the
> molecular to fit the screen ?
>
> -Jeffrey

-- 
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_at_ks.uiuc.edu                 Phone: 217-244-3349
  WWW: http://www.ks.uiuc.edu/~johns/      Fax: 217-244-6078