MX Snippets Part 1: Generate Molecular Fingerprints From the Command Line

January 11, 2010

Molecular fingerprints play an important role in cheminformatics. MX, the high-performance cheminformatics toolkit written in Java, comes complete with the ability to generate molecular fingerprints. This article, the first of a new series discussing MX through compilable snippets of Java code, shows how to interactively test fingerprints in MX through a simple command-line utility.

What the Program Does

From the command line, the program accepts a SMILES string as input and returns the indices of all bits set using the MX PathFingerprinter:

$ java -cp .:mx-1.0-beta-2.jar FPTest
{185, 293, 595, 742, 927}
{185, 293, 338, 595, 742, 927}
{185, 194, 293, 338, 595, 742, 927}
> exit

After entering a SMILES string, the program prints out the indices of all of the bits set in a 1024-bit fingerprint. As you can see, each fingerprint in the progression pentane >hexane >cyclohexane is a superset of its predecessors. This is, of course, the feature that makes fingerprints so useful for substructure search.

Note: the MX SMILES parser is only partially implemented at the moment and will not accept isotopes, stereochemistry, or lower-case atom labels.

Create a Workspace

Create a workspace and download the MX jarfile:

$ mkdir fptest
$ cd fptest
$ wget

The Code

Create a file called '' containing:

import java.util.BitSet;

public class FPTest {
  private static PathFingerprinter fingerprinter = new PathFingerprinter();

  public static void main(String[] args) {
    try {
      BufferedReader in = new BufferedReader(new InputStreamReader(;
      String str = "";
      while (str != null) {
          System.out.print("> ");
          str = in.readLine();
    } catch (IOException e) {
  public static void processInput(String input) {
    if ("exit".equals(input)) {
    Molecule molecule =;
    BitSet fp = fingerprinter.getFingerprint(molecule);


$ javac -cp mx-1.0-beta-2.jar


A good fingerprint generator is a powerful item in any cheminformatics toolbox. This tutorial has shown a simple method for getting started with fingerprints using MX.