Quick-and-dirty molfile rendering

Delphi source code released under a BSD-style license that (imperfectly!) renders an MDL molfile with minimal parsing overhead. Latest upload was done on 2008-10-01.

Download source code from here.

The following shows how a molecule loses display features when rendered with this code.

[Image: High fidelity rendering of molfile.]

High fidelity rendering of example molfile (ISIS/Draw).

[Image: Low fidelity rendering of molfile.]

Low fidelity rendering of example molfile (MolRenderer.pas).

All bonds are displayed as single bonds, there are no charges and no implicit hydrogens etc. However, it is useful enough if you only need a rough outline of the molecule in a fast prototype client.

Example usage of the rendering code:


var
  Renderer: TMolRenderer;
begin
  Renderer := TMolRenderer.Create;

  SL := TStringList.Create;
  try
    SL.LoadFromFile('test.mol');
    Renderer.LoadMolfile(SL);
  finally
    SL.Free;
  end;

  Renderer.PaintOnCanvas(MainForm.Canvas, Rect(50, 50, 300, 230));

  Renderer.Free;
end;

The renderer scales the drawing to within the bounding box specified. Atom text labels use the font already specified by the Canvas.