Using advanced methods of computer graphics for crystallographic needs

Michal Hušák

Department of Solid State Chemistry, Prague Institute of Chemical Technology, Technique 5, 166 28 Prague 6, Czech Republic
E-mail:
husakm@vscht.cz - http://www.ccp14.ac.uk/ccp/web-mirrors/marchingcube-fourierviewer/~husakm/Public/MarchingCubeELD/MarchingCubeELD.htm

OpenGL – the way to get speed

Crystallographers often need to visualize really complex objects. Typical examples of such objects are molecular structures, electron density maps or even the complete arrangement of all atoms inside a part of the crystal. Without seen the picture of such models, it is often really difficult to interpret the data.

It is possible to catch much more from the image when a real time manipulation is possible. It means that we need the very fast creation of graphics. Due to development hardware for computer games, very fast graphic operations are now possible even on a standard PC.

Graphics can be generated not only by the computer CPU, but by a special processors on the graphic card. Such processors can do this job usually much more faster than CPU. To be able to use the power of these specialized processors we must use an API compatible with the graphics card drivers during code development. Two of the most important API's for communication with graphic hardware exist now: OpenGL and Microsoft DirectX. In OpenGL it is possible to do the same as under DirectX; and in addition the code written in OpenGL is often compatible with non-Microsoft operating systems (e.g., Linux, IRIX). From this point of view the only API suitable for crystallographic applications graphic acceleration is OpenGL .

What can OpenGL do for you? It can take care of super fast drawing of all the geometric primitives – lines, spheres, planes, triangles, etc. In addition it can take care of a lot of other effect like simulating the lighting of your objects, selecting objects and object manipulation. The best support for OpenGL exists in C and C++ programming languages. There exist interfaces for communication with OpenGL API for other coding languages as well, (e.g. Delphi and for Visual Basic).

Using OpenGL programs in your code require several steps. At first you must initialize the OpenGL hardware engine and attach it to your output window. This step is OS specific and the correct command sequence differs for each operating system. The next step is to determine the view on the scene (your virtual camera position and the size of the scene). The last step is the sequence for the geometric primitives drawing. Code sequence for drawing a line from point X1,Y1,Z1 to point X2,Y2,Z2 can look e.g. like this:

 glBegin(GL_LINES);
glVertex3f(X1,Y1,Z1);
glVertex3f(X2,Y2,Z2);
glEnd();

The best method to start with OpenGL coding is to study freely available source code tutorials. One of the best collection of such tutorials is on following webpage: http://nehe.gamedev.net/. You can find on this webpage how to initialize OpenGL under Windows, MacOS and typical UNIX systems as well as complete sample codes showing simple and very advanced OpenGL coding techniques. The official source of OpenGL information could be found on http://www.opengl.org/ and in written form in the excellent "Red Book" (Ref. 1). A very good book about using OpenGL under Windows in combination with MFC is "OpenGL Programming for Windows 95 and Windows NT", by Ron Fosner" (Ref. 2).

Almost all modern molecular visualization and crystallographic programs already use OpenGL for graphic acceleration. Examples of freely available programs are VMD, MolMol or the whole crystallographic determination package CRYSTALS. From commercial programs the OpenGL is used in almost all ACCELRYS software products (e.g. DS Viewer PRO) or in the CSD database GUI - ConQuest . The author of this article had developed a MCE code (Pic 1.) using OpenGL for very fast and interactive electron density map visualization.

[output from MCE]

Pic 1: Example of an output from a MCE program using fast OpenGL hardware-accelerated output for interactive difference electron density map visualization. This code is a part of latest CRYSTALS release .

Stereoscopic visualization

Even when you have very fast graphics and can perform real time manipulation, your output will look 2D and flat. Thus to catch some important futures from such output (e.g. molecular interactions, chirality, docking conditions) is almost impossible. The human brain needs 2 different views on the object from each eye to be able to synthesize a true 3D image in the mind.

The methods for delivering to each eye different image are titled stereoscopic visualization. Following possibilities exist:

  • Shuterglasses. This method uses special glasses which are synchronized with the work of your PC monitor. Synchronization can be done with the help of IR emitter or by cable. The monitor usually works at image refresh rate 120 Hz or so. The glasses make visualization through left and right eye possible at a 60 Hz frequency. As the result, one eye only sees odd frames and the second only even frames. Modern graphics card with OpenGL stereoscopic support (Quadro, Oxygen, Wildcat) can do this job.
  • Polarized projection. This method is useful for large audience visualization. The left and right eye images are projected by 2 projectors with polarization filters. Both filters are 90 degree rotated. It is necessary to use specialized polarization glasses to view the images. Each eye sees the correct image only because the opposite one with different polarization is filtered. Graphic cards with dual output (Quadro) can create suitable output.
  • Autostereoscopic 3D monitors. The principle of this device is the projection of different images in different directions. No glasses are necessary to watch the effect. The monitors usually must track the user position and optimize the left-right image direction projection from this information (Pic. 2).

From existing software, the stereoscopic visualization is supported: VMD, MolMol, DS Viewer PRO or the protein structure solution system O.

[sutostereoscopic monitor]

Pic 2: Autostereoscopic monitor. (Image downloaded from SeeReal Technologies GmbH (former Dresden3D) - http://www.dresden3d.com/)

Advanced VR HW devices

To see your data in stereoscopic 3D is nice, but how would you like to be inside your model ? To be able to walk between atoms, touch your force field maps, listen to the force field intensities ? Even such things are possible …

One of the devices which can put you inside the data is the CAVE device. The CAVE is a cube and 5 to 8 walls of this cube could be used as stereoscopic projection screens (Pic. 3). The user is inside the cube, his position is tracked and superimposed in the virtual environment. The device is equipped with environmental sound system as well which can serve even to data "sonification". The user can be by the sound e.g. notified about the force field intensity in the current position.

[CAVE device]

Pic 3: The scheme of the CAVE device. (Image downloaded from Dave Pape CAVE - http://www.evl.uic.edu/pape/CAVE/)

The support for CAVE is built-in to VMD software and in the "Marching Cubes VR" software for electron map visualization developed by the author of this article (http://www.ccp14.ac.uk/tutorial/marchingcube/). Complete information about the CAVE device can be found at this link: http://evlweb.eecs.uic.edu/pape/CAVE/

[interface for MCE_VR]

Pic 4: Using the HMD as an interface for MCE_VR electron maps visualization software. The gun serves for placing atoms in correct positions in the model.

The main disadvantage of the CAVE device is that it is a big and expensive. The price acceptable VR alternative to CAVE is an HMD (Head Mounted Display). HMD can track the user motion just as well as CAVE. And it can produce stereoscopic image by the help of using 2 different screens for each eye. The main disadvantage of existing HMD is low field of view and low per eye graphic resolution. This could change in the near future due to new technologies used for microdisplays manufacturing. The "MCE_VR" code is an example of experimental program supporting output to VFX3D HMD (Pic. 4).

Another method for advanced object visualization is volumetric display. The principle of this display is a projection of the object on some 3Dimensional fast moving (rotating plane) or partially transparent (artificial fog) material usually by laser technology (Pic. 5).

[DNA visualised volumetrically]

Pic 5: DNA molecule visualized by a volumetric display. (Image downloaded from Actuality System Inc. - http://www.actuality-systems.com/)

References:

  1. The OpenGL Programming Guide 3rd Edition The Official Guide to Learning OpenGL Version 1.2, Mason Woo, OpenGL Architecture Review Board, Jackie Neider, Tom Davis, Dave Shreiner. Addison-Wesley, 1999
  2. OpenGL Programming for Windows 95 and Windows NT, by Ron Fosner. Addison-Wesley , 1996

The author would like to thank the Grant Agency of the Czech Republic (grant No. GACR: 203/01/0700)