Random SMILES trace explorer

Loading RDKit...

Traversal replay

Random SMILES
-
Unvisited
Active
Finished
0/0
Phase
Waiting...
Current Event
-
-
Recursion Stack

    How It Works

    Why randomize?

    This page illustrates the RDKit random SMILES generation algorithm (implemented in Canon.cpp). You usually want a SMILES string to be unique so everyone writes the same string for the same drug. But in machine learning, unique is bad. We actually want chaos. By generating ten different valid strings for a single molecule, we force AI models to learn the actual chemical structure rather than just memorizing text patterns.

    The graph problem

    At its core, a molecule is just a graph: atoms are nodes, bonds are edges. To write a SMILES string, the computer has to flatten that web into a single line of text by walking from atom to atom. This visualizer breaks that walk down into two steps so you can see how the computer handles the tricky parts.

    Phase 1: The scout

    Before writing anything, we have to solve the ring problem. If a computer blindly followed bonds around a ring like benzene, it would loop forever. To fix this, the algorithm runs a quick scout mission using a depth-first search. It sprints through the molecule leaving markers behind. As soon as it hits a marker it placed earlier, it knows it found a loop. It flags that bond as a ring closure, which becomes the numbers in the SMILES string.

    Phase 2: The build

    With the rings marked, the algorithm walks the graph again to generate the text. Since this is a random generator, it rolls a die at every intersection to decide where to go next.

    • The main path: It prints atom symbols as it walks.
    • Branching: When it hits a fork, it picks one path now and shoves the others into a backpack (a memory stack) to visit later. These saved paths become the branches in parentheses.
    • Ring closures: When it reaches a bond flagged by the scout in phase 1, it stops and prints a number instead of walking across it.
    Summary
    Ready when RDKit loads.
    
          
    Trace JSON
    Waiting...
    Init Preview
    -