[vtk-developers] vtkChemistry update

David Lonie loniedavid at gmail.com
Mon Jun 27 17:33:22 EDT 2011


Hi list,

The vtkChemistry kit is coming along well, I think we have a good
design that will provide an easy but powerful API for developers.
Before I get into specifics, I want to thank everyone at Kitware who
was a part of my visit to Clifton Park the other week -- I had a lot
of fun and it was great to meet many of you. I've wrapped up a lot of
the molecular structure rendering code since then, and would like to
share the current state of the project.

The current code (on github[1]) provides vtkMolecule, vtkAtom, and
vtkBond to build and store molecular structure. Building a molecule
can be as simple as:

vtkMolecule *mol = vtkMolecule::New();
vtkAtom h1 = mol->AddAtom(1, 0.0, 0.0, -0.5);
vtkAtom h2 = mol->AddAtom(1, 0.0, 0.0,  0.5);
vtkBond b  = mol->AddBond(h1, h2, 1);

to create a molecule with two hydrogens, one angstrom apart on the
z-axis, connected with a single bond. Another addition is the
vtkPeriodicTable class, which parses the Blue Obelisk Data
Repository[2] to provide convenient access to information about the
elements. Using the vtkAtom interface along with vtkPeriodicTable, it
is possible to specify atoms in the in other ways that make writing
vtkMolecule sources easier. For instance, the h1 atom above could be
created by:

vtkAtom h1 = mol->AddAtom();
vtkNew<vtkPeriodicTable> pTab;
h1.SetAtomicNumber([pTab->GetAtomicNumber("Hydrogen"));
h1.SetPosition(0.0, 0.0, -0.5);

We also wanted to perform vector operations more easily when
constructing / analyzing molecules, so vtkVector is getting an
upgrade. The changes to the vtkVector API enables more flexible
specification of, for instance, the atomic position of h2 from the
earlier example:

vtkAtom h2 = mol->AddAtom();
h2.SetAtomicNumber(pTab->GetAtomicNumber("h"));
vtkVector3d displacement (0.0, 0.0, 1.0);
h2.SetPosition(h1.GetPositionAsVector3d() + displacement);

The other major class in the vtkChemistry kit is vtkMoleculeMapper,
which provides a simple way to render a molecule using standard
methods, as well customization options to create more complex
renderings. Mapping of atoms to their familar colors is handled by
accessing the Blue Obelisk rgb data through vtkPeriodicTable. I put
together some of the test images from the vtkChemistry unit tests in
my blog to show some of the standard rendering styles[3], as well as
some more complex examples of what can be done. I've also added a
basic CML file reader, vtkCMLMoleculeReader, so an entire pipeline
(stopping at actor) to render a molecule can be as simple as:

  vtkNew<vtkCMLMoleculeReader> cmlSource;
  cmlSource->SetFileName("path to my cml file");

  vtkNew<vtkMoleculeMapper> molmapper;
  molmapper->SetInput(cmlSource->GetOutput());
  molmapper->UseBallAndStickSettings();

  vtkNew<vtkActor> actor;
  actor->SetMapper(molmapper.GetPointer());
  ...

The vtkMoleculeMapper currently creates and replays display lists
using vtkGlyph3DMapper to render the molecules quickly. We may be
extending it to use point sprites when rendering larger molecules
later in the project, too.

This week I've started working on electronic structure visualization,
which is essentially manipulating 3D vtkImageData that are created by
sampling the molecule's electronic wavefunctions. Interfacing Marcus's
OpenQube library to vtkChemistry is my first goal, then we'll add some
custom mapping functionality to simplify and tune the
selection/generation of these data sets.

The code is on github if anyone is interested[1], I welcome any and
all feedback!

Dave

[1] http://github.com/dlonie/VTK/tree/chemistry-unstable
[2] http://sourceforge.net/projects/bodr/
[3] http://davidlonie.blogspot.com/2011/06/overdue-update-gsocvtkchemistry.html



More information about the vtk-developers mailing list