Chapter 5. Rendering Chemical System Data

The ChemDisplay node renders atoms, bonds, atom labels, and bond labels accessed from the ChemBaseData-derived node according to the display parameters in the ChemDisplayParam, ChemColor, and ChemRadii nodes. This chapter describes how to use ChemDisplay to render all or part of a chemical system data.

Rendering the Chemical System Data

The ChemDisplay node has four fields that specify the portions of the chemical system data you want to render:

MFVec2i    atomIndex
MFVec2i    bondIndex
MFVec2i    atomLabelIndex
MFVec2i    bondLabelIndex

These fields refer to the atoms, bonds, atom labels, and bond labels, respectively, in a ChemBaseData-derived node (the data node). For example, to render the first 10 atoms of a data node, you use a statement similar to the following:

chemDisplay->atomIndex.set1Value(0, 0, 10);

Specifying the Chemical System Data to Render

To understand how to specify which parts of a chemical system to render, you need to understand the set1Value() method in the MFVec2i class.

MFVec2i is a multiple-value field that contains any number of two-dimensional integer vectors. The MFVec2i class has several methods to fill in the array maintained by MFVec2i. Although there are several definitions of set1Value(), this chapter uses only the following definition:

void set1Value(int index, int32_t i, int32_t j)

For the use of MFVec2i in ChemDisplay, the arguments to this set1Value() method should be thought of as:

void set1Value(int index, int32_t start, int32_t length)

The first argument, index, identifies the position of the entry within the array maintained by MFVec2i, for example, the first position is 0, the second is 1, and so forth.

The second argument, start, is the first item of a given type to render, where “type” refers to atoms, bonds, atom labels, or bond labels, depending on the particular MFVec2i field. The length argument specifies how many items of that type after and including the first to render. For example, the following line of code renders atoms 2, 3, 4, 5, 6, and 7:

chemDisplay->atomIndex.set1Value(0, 2, 6);

If you want to render various portions of the chemical system, you use multiple entries in the appropriate MFVec2i field, for example:

chemDisplay->atomIndex.set1Value(0, 2, 6);
chemDisplay->atomIndex.set1Value(1, 20, 6);
chemDisplay->atomIndex.set1Value(2, 31,CHEM_DISPLAY_USE_REST_OF_ATOMS);

These lines of code render atoms 2, 3, 4, 5, 6, 7, 20, 21, 22, 23, 24, 25, 31, and the rest of the atoms in the chemical system. Notice that when the variable CHEM_DISPLAY_USE_REST_OF_ATOMS is specified, ChemDisplay determines the number of remaining atoms. You can use this variable, as shown in the following code sample, to display all of the atoms and atom labels in a chemical system:

chemDisplay->atomIndex.set1Value(0, 0, CHEM_DISPLAY_USE_REST_OF_ATOMS);
chemDisplay->atomLabelIndex.set1Value(0, 0,
    CHEM_DISPLAY_USE_REST_OF_ATOMS);

There is a similar variable for bonds: CHEM_DISPLAY_USE_REST_OF_BONDS. To display all bonds and bond labels, use the following lines of code:

chemDisplay->bondIndex.set1Value(0, 0,CHEM_DISPLAY_USE_REST_OF_BONDS);
chemDisplay->bondLabelIndex.set1Value(0, 0,     CHEM_DISPLAY_USE_REST_OF_BONDS));

ChemDisplay, by default, renders all of the atoms, bonds, and labels in a chemical system. While the atomLabelIndex and bondLabelIndex fields in ChemDisplay determine which atom and bond labels can be displayed, the showAtomLabels and showBondLabels fields in ChemDisplayParam toggle the display of these labels on or off.

ChemDisplay Methods

The following table describes the methods in the ChemDisplay node.

Table 5-1. ChemDisplay Method Descriptions

Methods in ChemDisplay

Descriptions

ChemDisplay()

Creates an instance of the ChemDisplay node; this is the class constructor.

getNumberOfAtoms()

Returns the number of atoms accessed by the ChemDisplay node.

getNumberOfBonds()

Returns the number of bonds accessed by the ChemDisplay node.

getNumberOfAtomLabels()

Returns the number of atom labels accessed by the ChemDisplay node.

getNumberOfBondLabels()

Returns the number of bond labels accessed by the ChemDisplay node.

As shown above, the atoms, bonds, and labels accessed by a particular instance of ChemDisplay can be a subset of the total number of atoms, bonds, and labels in the chemical system. The getNumberOf...() methods return how many atoms, bonds, and labels are used in a specific instance of ChemDisplay.