mol2ps

a freeware tool for 2D depiction of molecular structures


mol2ps is a freely available command-line utility program which reads molecular structure files in different formats (see below) and generates Postscript output for 2D display. The Postscript file can then be used e.g. for creating a bitmap file, using a Postscript interpreter like Ghostscript.

As an example, the following 2D representation of caffeine in PNG (Portable Network Graphics) format was created from the corresponding MDL molfile (PubChem CID 2519), using mol2ps in combination with Ghostscript:

Caffeine 2D structure

As input files, MDL molfiles and SD files (*.mol, *.sdf; 2D and 3D), Alchemy molfiles (*.mol), and Sybyl mol2 files (*.mol2) are accepted by mol2ps, the preferred format is the MDL molfile format. At present, it is not intended to extend the number of supported input file formats, as there are powerful file format converters available, such as OpenBabel. Starting with mol2ps version 0.2, also reactions are supported in MDL reactionfile (*.rxn) and RD file (*.rdf) format. An example is shown below.

reaction

The main purpose of mol2ps is to create small, but high-quality 2D pictures of molecules for display on web pages. Especially for web-based molecular structure databases it is quite useful to have pre-built pictures for display in hitlists instead of invoking browser plugins, Java applets, or server-side programs for display of the individual structures. A description of how such structure databases can be created with free software is given here.

Availability

mol2ps is freely available under the terms of the GNU General Public License (GPL), for a detailed description of this license, please visit http://www.gnu.org/copyleft/gpl.html.
It is written in Pascal and it was compiled with the Free Pascal compiler for the following platforms: Linux (x86), FreeBSD (x86), Mac OS X (x86)  and Windows (Win32 console application). You may use it on your own risk, there is no warranty for anything.

Download

source code: mol2ps.pas 
Linux (i386) executable: mol2ps-latest-linux-i386.gz 
FreeBSD (i386) executable: mol2ps-latest-freebsd-i386.gz 
Mac OS X (x86) executable: mol2ps-latest-macosx-x86.gz 
Win32 console application: mol2ps-latest-win32.zip 
example color definition file: color.conf

Installation

Download the appropriate compressed binary file for your system, uncompress it and rename the resulting executable file into mol2ps (for Linux, Mac OS X, or FreeBSD), for Windows there is no need to rename the extracted file, mol2ps.exe. Copy this program file into a directory which is in your search path (e.g., /usr/local/bin or C:\UTIL). There are no additional files or libraries required.

Usage (command-line options)

mol2ps can be invoked with the following arguments (version 0.2)
mol2ps [options] <filename>
where <filename> is the file containing the molecular structure
 (supported formats: MDL *.mol or *.sdf, Alchemy *.mol, Sybyl *.mol2)
 if <filename> is "-" (without quotes), the program reads from standard input
valid options are:
  -R (reaction mode, for MDL rxn and rdf files)
  --font=<Helvetica|Times>, default: Helvetica
  --fontsize=<any number in points>, default: 14
  --fontsizesmall=<any number in points>, default: 9 (for subscripts)
  --linewidth=<n.n>, default: 1.0 (linewidth in points; use 1 decimal)
  --rotate=<auto|auto3Donly|n,n,n>, default: auto (n,n,n specifies the
    angles to rotate the molecule around the X, Y, and Z axis (in degrees)
  --autoscale=<on|off>, default: on (scales the molecule to fit the natural
    C-C bond length)
  --striphydrogen=<on|off>, default: on (strips all explicit H atoms)
  --hydrogenonhetero=<on|off>, default: on (adds H to all hetero atoms)
  --hydrogenonmethyl=<on|off>, default: on (adds H to all methyl C atoms)
  --hydrogenonstereo=<on|off>, default: on (shows H if bond is "up" or "down")
  --showmolname=<on|off>, default: off (prints name above the structure)
  --atomnumbers=<on|off>, default: off (prints atom numbers)
  --bondnumbers=<on|off>, default: off (prints bond numbers)
  --sgroups=<on|off>, default: on (uses Sgroup abbreviations if present)
  --color=</path/to/color.conf>, default: no colors for atoms labels

Postscript output will be written to standard output. To write it to a file, enter something like the following:
mol2ps mymolecule.mol > mymolecule.ps

Finetuning

The program attempts by default to orient the molecule in a suitable way if it contains a ring structure. Especially with 3D molfiles, this is quite useful, but sometimes can give unsatisfactory results. Please inspect the generated Postscript file with a text editor: in the file header, the applied angles of rotation around the X, Y, and Z axis are noted as Postscript comments (lines starting with a % sign). You can take these values as starting points for some manual optimization, using the command-line argument "--rotate=" (see above), for example --rotate=10,-23,75 (which would rotate the structure by 10° around X, -23° around Y, and 75° around Z).

Useful Perl scripts for batch processing

If you want to convert an MDL molfile or an entire SD file directly into 2D bitmap pictures in PNG format, take a look at the Perl script mol2png.pl. For conversion of an already existing Postscript file into a PNG image file, the script ps2png.pl is available. These scripts use Ghostscript not only for rastering, but also to determine suitable dimensions of the output bitmap file (using the "bbox" device of Ghostscript). Of course, the resulting PNG bitmap files can be converted into any other bitmap format (such as GIF) by almost any graphics conversion utility program.


mol2ps
was written by Norbert Haider, Department of Drug and Natural Product Synthesis, University of Vienna, Austria. You can contact me by e-mail: norbert.haider@univie.ac.at (no spam, no viruses, no HTML mails, please).

N. Haider, 2005-09-21; last update: 2011-03-04