Wednesday, March 21, 2012

Solvent-Excluded Surface Rendering in Chemkit

Yesterday I merged a new topic branch which added support for rendering solvent-excluded surfaces to chemkit. The surface rendering functionality is available through the new GraphicsPymolSurfaceItem class which is so named because it makes use of PyMOL's surface meshing library.

Below is an example image (available in chemkit's graphics item gallery) showing the new solvent-excluded surface:

This is a significant change as it is the first major chemkit feature contributed from an outside developer. I'd like to give a large thank you to Wenlin Wang for his hard work on writing this new surface visualization class.

The new class is quite easy to use with chemkit's graphics view framework. The following code shows how to load a uridine molecule and render a translucent  solvent-accessible surface over an opaque ball and stick model.

int main(int argc, char *argv[])
  QApplication app(argc, argv);

  // read molecule from file
  boost::shared_ptr<Molecule> molecule = 

  // create graphics view
  GraphicsView view;

  // create molecule item
  GraphicsMoleculeItem *moleculeItem = 
      new GraphicsMoleculeItem(molecule.get());

  // create surface item
  GraphicsPymolSurfaceItem *surfaceItem =
      new GraphicsPymolSurfaceItem(molecule.get());

  return app.exec();

Which will produce the following image:

Using the GraphicsPymolSurfaceItem::setQuality() method allows for the rendering quality of the surface to be adjusted through a variety of levels. The image above only shows the "good" quality, which is the middle on the scale that ranges from "miserable" and "more miserable" to "perfect" and "impractical".

Also, surface visualization support for the chemkit-builder application (which now resides in a separate repository here) will be integrated soon. Let me (and Wenlin!) know what you think. As always, feedback is greatly appreciated.