Inferensys

Glossary

SELFIES

SELFIES (SELF-referencIng Embedded Strings) is a 100% robust molecular string representation where every syntactically valid string corresponds to a valid molecular graph, eliminating the invalid outputs common with SMILES-based generative models.
Knowledge engineer constructing knowledge base on laptop, document hierarchy visible, casual office setup.
MOLECULAR REPRESENTATION

What is SELFIES?

A 100% robust molecular string representation where every syntactically valid string corresponds to a valid molecular graph, eliminating the invalid outputs common with SMILES-based generative models.

SELFIES (SELF-referencIng Embedded Strings) is a molecular string representation designed with a formal grammar that guarantees 100% syntactic and semantic validity. Unlike SMILES, where arbitrary character mutations frequently produce invalid molecular graphs, every syntactically valid SELFIES string maps unambiguously to a valid molecule. This is achieved through a derivation rule system where each symbol encodes a state transition, ensuring that the string's construction inherently respects valence constraints and bonding rules.

This robustness makes SELFIES ideal for generative models like variational autoencoders and language models, as the output space is entirely valid, eliminating the need for post-hoc sanitization. Derived from a formal context-free grammar, SELFIES represents atoms and bonds as a sequence of tokens that self-reference the current valence state, enabling direct mutation and crossover operations in genetic algorithms without producing chemical nonsense.

ROBUST MOLECULAR REPRESENTATION

Key Features of SELFIES

SELFIES (SELF-referencIng Embedded Strings) is a 100% robust molecular string representation where every syntactically valid string corresponds to a valid molecular graph, eliminating the invalid outputs common with SMILES-based generative models.

01

100% Syntactic Robustness

The defining feature of SELFIES is its guaranteed validity: every string generated from the SELFIES grammar corresponds to a valid molecular graph. This is achieved through a formal context-free grammar where derivation rules enforce valence constraints and bonding rules at the token level. Unlike SMILES, where a single misplaced character can produce an invalid molecule, SELFIES eliminates the need for post-hoc validity checks or rejection sampling during generative modeling.

02

Semantically Invalid SELFIES

While all SELFIES strings are syntactically valid, they can be semantically invalid. This occurs when a string represents a chemically unreasonable molecule, such as one with strained rings, charged species with missing counterions, or violations of the octet rule. The distinction is critical: syntactic validity guarantees a molecular graph exists, but semantic validity requires additional chemical filters or property predictors to assess drug-likeness or synthetic accessibility.

03

Derivation Rules and Grammar

SELFIES uses a formal grammar with derivation rules that map each symbol to a specific graph-construction operation. Key rule types include:

  • Atom symbols: Add an atom with a specified valence state (e.g., [C], [N], [O])
  • Bond symbols: Specify the bond order between the most recently added atom and a previous atom (e.g., [=C], [#N])
  • Branch symbols: Open and close branches for ring closures and side chains ([Branch1], [Ring1])
  • State symbols: Modify atom states like charge or isotope without altering connectivity
04

SELFIES vs. SMILES Comparison

PropertySMILESSELFIES
Validity guaranteeNoYes (100%)
Human readabilityHighLow
String lengthShorterLonger
Generative model compatibilityRequires validity filtersNative support
CanonicalizationComplex algorithmsGrammar-defined

SELFIES strings are typically 1.5-2x longer than equivalent SMILES, but the robustness trade-off is essential for variational autoencoders (VAEs), generative adversarial networks (GANs), and reinforcement learning pipelines where invalid outputs waste compute and degrade training.

05

Encoding and Decoding Pipeline

The SELFIES pipeline operates in three stages:

  1. Encoding: A SMILES string is parsed into a molecular graph, then converted to a SELFIES string using the derivation grammar
  2. Manipulation: The SELFIES string is tokenized into a sequence of symbols for use in sequence-based deep learning models (LSTMs, Transformers, VAEs)
  3. Decoding: The generated SELFIES string is deterministically converted back to a molecular graph, then optionally to SMILES for visualization

This bidirectional mapping ensures lossless conversion between representations while maintaining the robustness guarantee throughout the generative process.

06

Applications in Generative Chemistry

SELFIES is particularly valuable in de novo drug design pipelines where generative models explore chemical space:

  • Variational Autoencoders: The continuous latent space can be freely sampled without producing invalid molecules
  • Reinforcement Learning: Reward functions can focus on property optimization rather than validity penalties
  • Genetic Algorithms: Crossover and mutation operations always produce valid offspring
  • Language Models: Autoregressive generation with SELFIES tokens guarantees valid outputs at every step

Libraries such as selfies (Python) and integrations with RDKit, DeepChem, and GuacaMol support adoption.

MOLECULAR REPRESENTATION ROBUSTNESS

SELFIES vs. SMILES: A Technical Comparison

A feature-by-feature comparison of the SELFIES and SMILES molecular string representations, highlighting key differences in validity, generative suitability, and structural expressiveness.

FeatureSELFIESSMILESDeepSMILES

100% Syntactic Validity

100% Semantic Validity

Robust to Random Mutation

Direct Generative Model Output

Human Readability

Canonicalization Support

Explicit Hydrogen Encoding

Invalid Output Rate in VAEs

< 0.1%

~5-15%

~1-5%

SELFIES DEEP DIVE

Frequently Asked Questions

Explore the core mechanics, advantages, and practical applications of the SELFIES molecular representation—a 100% robust string encoding that guarantees every syntactically valid output corresponds to a valid molecular graph.

SELFIES (Self-Referencing Embedded Strings) is a 100% robust molecular string representation where every syntactically valid string corresponds to a valid molecular graph, completely eliminating the syntactic and semantic errors common with SMILES strings. Unlike SMILES, which uses a context-free grammar requiring complex parsing rules for ring closures and branching, SELFIES is derived from a formal grammar that enforces valence constraints directly in its derivation rules. This means a randomly generated or mutated SELFIES string will always decode into a physically valid molecule, making it uniquely suited for generative models and evolutionary algorithms in de novo drug design. The representation stores atoms and bonds as tokens in a sequence, with a self-referencing mechanism that tracks the current state of the molecular graph during construction, preventing invalid valence states or dangling bonds.

Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.