ChemGrapher: Optical Graph Recognition of Chemical Compounds by Deep Learning

Martijn Oldenhof, Adam Arany, Yves Moreau, Jaak SimmarXiv 2020 · DOI

TL;DR

ChemGrapher is a novel deep learning pipeline designed to extract the underlying graph structure of chemical compounds from static images. By combining semantic segmentation with specialized classification networks, it significantly outperforms traditional OCR-based tools, particularly in capturing tricky details like bond multiplicity and stereochemistry.

What Problem Does This Paper Address?

In the world of drug discovery, chemical structures are the primary language of data. While modern databases use machine-readable formats like SMILES or MOLfiles, a massive amount of legacy knowledge remains "trapped" in millions of scientific PDF images.

Existing tools for Optical Structure Recognition (OSR), such as the well-known OSRA, typically rely on traditional computer vision and hard-coded expert rules. These systems often stumble when faced with different rendering styles, leading to errors in bond multiplicity (single vs. double bonds) or missing stereochemical information (the 3D orientation of atoms). ChemGrapher aims to replace these rigid expert systems with a flexible, data-driven deep learning approach that can learn to "see" chemistry across various visual styles.

Methods

The authors propose a two-stage deep learning architecture that prioritizes spatial interpretability over simple "image-to-text" translation.

  1. Semantic Segmentation: The first stage uses a deep convolutional neural network (CNN) to perform pixel-wise labeling. It segments the input image into three distinct channels: atom locations, bond locations, and charges. To capture the necessary context without losing resolution, the authors utilized dilated convolutions, a technique that allows the network's receptive field to grow exponentially. The specific architecture is summarized in the table below:
Summary of the layers of the segmentation network
  1. Component Classification: Once the image is segmented, the system identifies "candidate" locations for atoms and bonds. For each candidate, a small "cut-out" of both the original image and the segmented map is fed into one of three specialized classification networks ($c_A$ for atoms, $c_B$ for bonds, and $c_C$ for charges).
The atom classification pipeline ($c_A$)

As shown in Figure 1, the atom classifier uses both the raw image and the segmentation map to decide exactly which atom type (e.g., Carbon, Oxygen, Nitrogen) is present. A similar approach is used for bonds (Figure 2), where the network uses two rectangles to encode the direction and type of bond, which is crucial for identifying stereoisomers.

The bond classification pipeline ($c_B$)

Datasets

Training deep networks for pixel-wise segmentation requires a massive amount of labeled data, which doesn't exist for real-world chemical journal images. To solve this, the authors:

  • Sampled 1.9 million structures from the ChEMBL database.
  • Used RDKit to synthetically render these structures into images.
  • Modified the RDKit drawing code to automatically generate the "ground truth" pixel-wise labels ($L^a, L^b, L^c$) for atoms, bonds, and charges.
  • Evaluated the final model on both synthetic sets (1,000 images per style) and a manually curated set of 61 real-world images from journal articles.

Key Insights and Ideas

  • Hybrid Approach: By separating segmentation from classification, the model remains interpretable. You can literally see where the model thinks an atom is before it tries to name it.
  • Robustness to Imperfect Segmentation: The authors found that the classification networks are remarkably resilient. Even if the initial segmentation is slightly messy, the second-stage classifiers can often correct the error by looking back at the original high-resolution image cut-out.
  • Stereochemistry via Geometry: Instead of just predicting a label, the bond classifier uses geometric highlights (two rectangles meeting in the middle) to explicitly learn the directionality of wedge and dash bonds, which are essential for biological activity.

Key Results

ChemGrapher demonstrated a clear advantage over the industry-standard OSRA:

  • Synthetic Benchmarks: Across three different rendering styles, ChemGrapher consistently achieved lower error rates. For example, in "Style 1" images containing stereochemistry, OSRA had a 47.9% error rate, while ChemGrapher dropped this to 16.0%.
  • Real-World Performance: On the challenging test set of 61 journal article images, ChemGrapher correctly identified the full graph for 46 images, compared to 42 for OSRA.
  • F1 Scores: The classification networks achieved near-perfect F1 scores (often >0.95) for common atoms and bonds, showing that the "cut-out" strategy is highly effective.

Limitations and Future Work

Despite its success, ChemGrapher has room to grow. The authors noted that the model currently struggles with thick lines used for bonds in certain publication styles. Furthermore, because the model was trained primarily on RDKit-generated images, it inherits a slight "synthetic bias."

Future work will focus on weakly supervised learning, allowing the model to learn from images where only the final graph is known, rather than requiring perfect pixel-by-pixel segmentation labels. This would allow the model to fine-tune itself directly on the vast diversity of real-world journal styles.

Summary updated

BibTeX
@misc{oldenhof2020chemgrapher,
  author = {Martijn Oldenhof and Adam Arany and Yves Moreau and Jaak Simm},
  title = {{ChemGrapher: Optical Graph Recognition of Chemical Compounds by Deep Learning}},
  year = {2020},
  eprint = {2002.09914},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2002.09914},
}
Figure