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 ofMoleculeEntryobjects - If
False:__call__receives a list of SMILES strings
True when you need access to RDKit mol objects or fingerprints.Complete Example: TPSA + Weight Oracle
This example frommol_opt/example_run.py optimizes molecules for high TPSA (topological polar surface area) with molecular weight and ring constraints:
Using MoleculeEntry Objects
When you setself.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
Cache results in mol_buffer
Cache results in mol_buffer
Always check
mol_buffer before computing scores to avoid redundant calculations:Handle invalid molecules gracefully
Handle invalid molecules gracefully
Wrap scoring in try-except blocks and return 0 for invalid molecules:
Set realistic max_possible_oracle_score
Set realistic max_possible_oracle_score
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
Log intermediate results
Log intermediate results
Implement Track metrics like top-1, top-10, and top-100 average scores.
log_intermediate() to monitor progress:Use takes_entry for complex calculations
Use takes_entry for complex calculations
Set
takes_entry = True when you need:- RDKit mol objects for descriptor calculations
- Fingerprints for similarity comparisons
- Access to similar molecules used in generation
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