[Chimera-users] matching scale for different sessions

Thomas Goddard goddard at cgl.ucsf.edu
Mon May 16 13:26:44 PDT 2005


Hi Jinghua,

  Below is some Python code which adds two Chimera commands:

	setzoom <pixels-per-angstrom>

	windowsize <width-in-pixels> <height-in-pixels>

Put it in a file in your Chimera distribution

	chimera/share/zoom/ChimeraExtension.py

You'll need to make the directory zoom (directory name does not matter).

  There are some problems with these commands to be aware of.  The
setzoom command works correctly in orthographic camera mode, but not
perspective camera mode.  Use Favorites / Side View and switch to the
Camera tab and choose Projection: orthographic.  In perspective mode
objects closer to you eye appear bigger.  I tried to make the code
set the pixels per angstrom at a depth equal to the center of the bounding
box of your displayed models.  But by using the Chimera Scalebar tool I
can see it is not quite right.  By the way, you can use the Chimera Scalebar
tool (Tools / Utilities / Scalebar) to hand adjust the zoom to a standard
size.  You make the scale bar the width you want for the full window,
move it to center it, then zoom until it just touches the edges of the
window.  Kind of tedious.

  The windowsize command won't make the window have small horizontal
widths (less than about 400 pixels) if the command-line or status-line
are being displayed.  You can hide the status line using the
Favorites / Preferences / Messages / Show status line switch.  You can
hide the command line with Tools / Command Line / hide.  You can still
type commands with the command-line hidden.

  We'll try to include some better working versions of these commands in
a future release.

     Tom



-----
zoom/ChimeraExtension.py follows:

# ---------------------------------------------------------------------------
# The status line and command entry box at the bottom of the main Chimera
# window prevent the window from being resized by this code to a width
# smaller than about 450 pixels.  The status line can be turned off using
# Favorites / Preferences / Messages / Show status line, and the command-line
# can be hidden with Tools / Command-line / hide.  Commands can still be
# typed with the command-line hidden.
#
def set_window_size(cmd_name, args):

  try:
    width, height = map(int, args.split())
  except:
    from Midas.midas_text import error
    error('Syntax error: %s <width-in-pixels> <height-in-pixels>' % cmd_name)

  import chimera
  v = chimera.viewer
  v.windowSize = (width, height)

  #
  # If user resizes the main window by hand the above size will not take
  # effect unless we reset top level geometry.
  #
  from chimera import tkgui
  app = tkgui.app
  top = app.winfo_toplevel()
  top.wm_geometry('')

# ---------------------------------------------------------------------------
#
def set_camera_zoom(cmd_name, args):

  try:
    pixels_per_angstrom = float(args)
  except:
    from Midas.midas_text import error
    error('Syntax error: %s <pixels-per-angstrom>' % cmd_name)

  import chimera
  have_bbox, bbox = chimera.openModels.bbox()
  if not have_bbox:
    return

  v = chimera.viewer

  width, height = v.windowSize        # window size in pixels
  min_size = min(width,height)
  r = .5 * min_size / pixels_per_angstrom
    
  v.viewSize = r
  v.scaleFactor = 1
  v.camera.focal = bbox.center().z

# ---------------------------------------------------------------------------
#
import Midas.midas_text
Midas.midas_text.addCommand('windowsize', set_window_size)
Midas.midas_text.addCommand('setzoom', set_camera_zoom)


More information about the Chimera-users mailing list