Skip to main content
The oracle is the core component that evaluates generated molecules and guides the optimization process. It defines what makes a molecule “good” for your specific use case.

Oracle Interface

An oracle must implement the following interface:

Required Attributes

int
required
The maximum number of molecules to evaluate before stopping optimization
int
required
How often to log intermediate results (e.g., every 100 molecules)
Dict
required
Dictionary to store all evaluated molecules and their scores. Keys are SMILES strings.
float
required
Upper bound on oracle scores. Used to guide the optimization process.
bool
default:"False"
  • If True: __call__ receives a list of MoleculeEntry objects
  • If False: __call__ receives a list of SMILES strings
Set to True when you need access to RDKit mol objects or fingerprints.

Complete Example: TPSA + Weight Oracle

This example from mol_opt/example_run.py optimizes molecules for high TPSA (topological polar surface area) with molecular weight and ring constraints:

Using MoleculeEntry Objects

When you set self.takes_entry = True, your oracle receives MoleculeEntry objects that provide:
str
Canonicalized SMILES string
rdkit.Chem.Mol
RDKit molecule object for property calculations
rdkit.DataStructs.ExplicitBitVect
Morgan fingerprint (radius=2, nBits=2048)
float
Oracle score (you set this in your __call__ method)
List[MoleculeEntry]
Similar molecules used in the prompt for generation

Oracle Design Patterns

Pattern 1: Property-Based Oracle

Optimize for molecular properties calculable from RDKit:

Pattern 2: Docking Score Oracle

Optimize for protein-ligand docking:

Pattern 3: Multi-Objective Oracle

Optimize for multiple objectives with weighted combination:

Best Practices

Always check mol_buffer before computing scores to avoid redundant calculations:
Wrap scoring in try-except blocks and return 0 for invalid molecules:
The algorithm uses this to guide generation. Set it to:
  • The theoretical maximum if known
  • A reasonable upper bound based on your domain knowledge
  • Slightly above the best score you expect to achieve
Implement log_intermediate() to monitor progress:
Track metrics like top-1, top-10, and top-100 average scores.
Set takes_entry = True when you need:
  • RDKit mol objects for descriptor calculations
  • Fingerprints for similarity comparisons
  • Access to similar molecules used in generation
Set takes_entry = False (default) for simple SMILES-based oracles.

Next Steps

Run Optimization

Learn how to use your oracle with the optimize() function

See Complete Examples

Explore full working examples with different oracle types