Abstract
We describe the current state of the SELFIES library (version 2.1.1), highlighting advances in its underlying algorithms, design, and API. By ensuring that every possible string represents a physically valid molecule, SELFIES provides a 100% robust representation for molecular machine learning, overcoming the inherent fragility of the industry-standard SMILES format.
Introduction: The Problem of Molecular Fragility
In cheminformatics, molecules are traditionally represented using SMILES (Simplified Molecular Input Line Entry System). While human-readable, SMILES is remarkably fragile; a single missing bracket or misplaced digit results in a syntax error. Furthermore, syntactically "correct" SMILES can still represent chemically impossible structures, such as an oxygen atom with three double bonds.
When training generative models (e.g., GANs or VAEs) for drug discovery, these models often waste significant computational resources learning the complex syntax of SMILES. SELFIES (Self-Referencing Embedded Strings) addresses this by shifting the burden of validity from the model to the representation itself. Any combination of SELFIES tokens is guaranteed to map to a chemically valid molecular graph.
Methodology: A Robust Grammar
The core of SELFIES is a Chomsky type-2 context-free grammar augmented with self-referencing functions. Unlike SMILES, which uses matching pairs to define branches and rings, SELFIES employs a "look-ahead" mechanism. When a [Branch] or [Ring] token appears, the subsequent tokens are interpreted as numeric values defining the branch length or ring target.
Key Improvements in Version 2.1.1
- Internal Graph Representation: The library now utilizes directed molecular graphs internally, making translations between SMILES and SELFIES more efficient and flexible.
- Expanded Chemical Support: Version 2.1.1 handles aromaticity (via automatic kekulization), isotopes, formal charges, radicals, and complex stereochemistry.
- Customizable Semantic Constraints: Users can now define their own valency rules. This allows researchers to enforce specific constraints for unusual chemistry where atoms require non-standard numbers of bonds.
- Attribution: A new feature enables models to "explain" translations by tracing which input tokens are responsible for specific output tokens.
Benchmarking and Results
To evaluate performance, the authors utilized the Developmental Therapeutics Program (DTP) open compound collection, containing over 300,000 diverse SMILES strings tested for anti-cancer and anti-AIDS activity.
- 100% Validity: In random string generation tests, SELFIES consistently achieved 100% validity, whereas SMILES validity often dropped below 10% as string length increased.
- High Efficiency: Despite being implemented in pure Python, the library is highly optimized. A "roundtrip" translation (SMILES to SELFIES and back) of the entire 300,000-molecule DTP dataset took only 252 seconds on standard hardware.
- Scaling: By filtering the token alphabet to remove low-valence atoms, the library can generate valid, extremely large molecules (hundreds of atoms) from relatively short strings.
Discussion and Future Work
SELFIES operates on the principle of "robustness as a constraint." By making invalidity impossible, researchers can utilize simpler models that are forced to explore only the space of valid chemistry. While the default settings are optimized for standard organic chemistry, the new custom constraint system allows for the representation of hypervalent molecules.
Future work aims to extend the SELFIES grammar to support polymers, crystals, non-covalent interactions (such as protein-ligand binding), and the encoding of chemical reactions within a robust string format.
Summary updated