page_title: Molecular graphics
section_title: Simple
hierarchical_section_title: Molecular graphics / Algorithms / Simple
caption_attribution_description: stick model of caffeine drawn in Jmol
context_page_description: Molecular graphics is the discipline and philosophy of studying molecules and their properties through graphical representation. IUPAC limits the definition to representations on a "graphical display device". Ever since Dalton's atoms and Kekulé's benzene, there has been a rich history of hand-drawn atoms and molecules, and these representations have had an important influence on modern molecular graphics. Note, however, that many molecular graphics programs and systems have close coupling between the graphics and editing commands or calculations such as in molecular modelling.
context_section_description: In early displays only vectors could be drawn e.g. (Fig. 7) which are easy to draw because no rendering or hidden surface removal is required.
  On vector machines the lines would be smooth but on raster devices Bresenham's algorithm is used (note the "jaggies" on some of the bonds, which can be largely removed with antialiasing software.)
  Atoms can be drawn as circles, but these should be sorted so that those with the largest z-coordinates (nearest the screen) are drawn last. Although imperfect, this often gives a reasonably attractive display. Other simple tricks which do not include hidden surface algorithms are:
  coloring each end of a bond with the same color as the atom to which it is attached (Fig. 7).
  drawing less than the whole length of the bond (e.g. 10–90%) to simulate the bond sticking out of a circle.
  adding a small offset white circle within the circle for an atom to simulate reflection.
  Typical pseudocode for creating Fig. 7 (to fit the molecule exactly to the screen):
  // Assume:
  // Atoms with x, y, z coordinates (Angstrom) and elementSymbol
  // bonds with pointers/references to atoms at ends
  // table of colors for elementTypes
  // find limits of molecule in molecule coordinates as xMin, yMin, xMax, yMax
  scale = min(xScreenMax / (xMax − xMin), yScreenMax / (yMax − yMin))
  xOffset = −xMin × scale
  yOffset = −yMin × scale
  for each bond in bonds do
      atom0 = bond.getAtom(0)
      atom1 = bond.getAtom(1)
      x0 = xOffset + atom0.getX() × scale
      y0 = yOffset + atom0.getY() × scale // (1)
      x1 = xOffset + atom1.getX() × scale
      y1 = yOffset + atom1.getY() × scale // (2)
      x1 = atom1.getX()
      y1 = atom1.getY()
      xMid = (x0 + x1) / 2
      yMid = (y0 + y1) / 2
      color0 = ColorTable.getColor(atom0.getSymbol())
      drawLine(color0, x0, y0, xMid, yMid)
      color1 = ColorTable.getColor(atom1.getSymbol())
      drawLine(color1, x1, y1, xMid, yMid)
  Note that this assumes the origin is in the bottom left corner of the screen, with Y up the screen. Many graphics systems have the origin at the top left, with Y down the screen. In this case the lines (1) and (2) should have the y coordinate generation as:
  y0 = yScreenMax -(yOffset + atom0.getY() * scale) // (1)
  y1 = yScreenMax -(yOffset + atom1.getY() * scale) // (2)
  Changes of this sort change the handedness of the axes so it is easy to reverse the chirality of the displayed molecule unless care is taken.
caption: Fig. 7. Stick model of caffeine drawn in Jmol.
exif: {}