Overview

In computational chemistry and AI drug discovery, visualization pipelines are often brittle; breaking on edge cases or failing silently when processing millions of molecules for training data.

I built molecular-string-renderer to treat molecular visualization as a strict software engineering problem. It is a highly configurable wrapper around RDKit that standardizes the conversion of text-based chemical representations (SMILES, InChI, SELFIES) into raster and vector graphics, degrading gracefully on inputs RDKit cannot vectorize.

Features

The design choices below exist to keep a million-molecule batch from failing on one bad input:

1. Strategy Pattern for SVG Generation

RDKit’s vector rendering can sometimes fail on complex molecular topologies. I implemented a Hybrid Strategy so that a single molecule RDKit cannot vectorize does not fail the batch:

  • Vector Strategy: Attempts to generate a true, scalable vector graphic.
  • Raster Fallback: If the vector engine fails, the system automatically renders a high-res PNG and embeds it transparently into the SVG container.

2. Native Generative AI Support

With the rise of Large Language Models in chemistry, SELFIES (Self-Referencing Embedded Strings) has become a standard output format. This library handles SELFIES natively, managing the decoding and sanitization lifecycle internally so that ML training loops can simply “pass strings and get images.”

3. Strict Configuration Contracts

The library uses Pydantic models (RenderConfig, ParserConfig, OutputConfig) to enforce strict data contracts. This ensures that visualization parameters are validated before any heavy computation begins, preventing runtime errors deep in a batch job.

Usage

Published on PyPI, with a CLI and a Python API:

pip install molecular-string-renderer
mol-render "CCO" -o ethanol.png