[Chimera-users] Per-model clipping plane command

Thomas Goddard goddard at cgl.ucsf.edu
Thu Nov 2 12:07:45 PST 2006

Hi Jeff,

  There isn't yet a Chimera command for per-model clipping.
Below is some Python code that can do it.  Open a density map
and then open this Python code in Chimera to clip it.  Some
more code can make it loop through different depths.  There is
some trickiness to making it update the graphics window in such
a loop.  Ask for details if you want that.


> From: Jeff
> To: <goddard at cgl.ucsf.edu>
> Subject: per-model clipping plane question (or similar)
> Date: Thu, 2 Nov 2006 10:54:26 -0800
> hi Tom,
> was wondering if I can control the per-model clipping plane
> orientation/parameters/etc via command line or shortcuts -
> would like to be able to methodically push a clipping plane in 'slab mode'
> through my model to compare it w/ other 2D/projection tools I use - I know I
> can click 'orient' on the model and it will orient to a default
> position/rotation (and I can click orient on the per-model clipping plane
> and therefore register them both), but is there then a way that I can
> specify (say, along one axis, like z) where the slab/clipping plane is
> positioned, like in pixels? 
> can I control the angular position of the clipping plane via command line,
> too?
> thanks,
> Jeff

Python code clip.py.

# -----------------------------------------------------------------------------
# Python function to control per-model clipping (like menu entry
# Tools / Depiction / Per-Model Clipping).  The clip plane rotates with
# the model (PDB structure, density map, ...).
# Parameters:
#   model is a Chimera Model
#   origin is (x,y,z) of point on clip plane.
#   normal is (nx,ny,nz) pointing towards clipped (invisible) half of plane.
#   slab_thickness is in data length units (usually Angstroms).
# Origin and normal are relative to the data coordinate system, for example,
# the x,y,z coordinates of a PDB atoms or axes of a density map.  The clip
def set_clipping(model, origin, normal, slab_thickness = None):

  p = model.clipPlane
  from chimera import Point, Vector
  p.origin = Point(*origin)
  p.normal = Vector(*normal)
  model.clipPlane = p
  model.useClipPlane = True
  if slab_thickness == None:
    model.useClipThickness = False
    model.clipThickness = slab_thickness
    model.useClipThickness = True

# -----------------------------------------------------------------------------
# Cap holes left when clipping a surface.  Controls graphical interface
# shown by menu entry Tools / Depiction / Surface Capping.
# Parameters:
#   cap_color is (r,g,b) or (r,g,b,a) where values in range 0-1
#   cap_mesh is True or False for mesh or solid cap appearance
#   cap_subdivision of 2 makes cap mesh twice as fine for detailed coloring.
#   cap_offset in data length units (usually Angstroms) for large models
#     sometimes needs to be larger to avoid cap itself being clipped due to
#     finite floating point precision in OpenGL.
def show_surface_caps(show, cap_color = None, cap_mesh = False,
                      cap_subdivision = 1, cap_offset = 0.001):

  from SurfaceCap.gui import capper_dialog
  d = capper_dialog(create = True)
  use_color = (cap_color != None)
  if use_color:
  if cap_mesh:

# -----------------------------------------------------------------------------
# Example using set_clipping().
from chimera import openModels
mlist = openModels.list()
m = mlist[0]
set_clipping(m, (.5,0,1), (0,1,1), 8)
show_surface_caps(True, (1,0,0), True)        # Red mesh caps

More information about the Chimera-users mailing list