Skip to main content
This page provides complete, runnable examples for different molecular optimization tasks.

Basic Example: TPSA + Weight Optimization

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

Oracle Implementation

mol_opt/example_run.py

Running the Optimization

Usage

This will run 3 optimization runs with different random seeds and save logs to results/.

QED Optimization Example

Optimize molecules for drug-likeness using the QED (Quantitative Estimate of Drug-likeness) metric.

Similarity-Constrained Optimization

Generate molecules similar to a reference compound while optimizing a property.

Multi-Property Optimization

Optimize for multiple properties with weighted combination.

Complete Script Template

Here’s a complete template you can adapt for your own objectives:
complete_template.py

Usage

Advanced: Docking Oracle Example

For computationally expensive oracles like docking, consider caching and parallelization:

Tips for Your Own Examples

Begin with a simple oracle (e.g., single RDKit property) to verify your setup works before implementing complex objectives.
Always check mol_buffer before computing scores. Docking and other expensive calculations should never be repeated.
Wrap scoring in try-except and return 0 for failures. Log errors for debugging but don’t crash the optimization.
Implement good logging in log_intermediate(). Track top-1, top-10, and top-100 scores to see if optimization is working.
Run optimization 3-5 times with different seeds and report average/best results for reproducibility.
  • Fast oracles (RDKit properties): 10K-20K calls
  • Medium oracles (ML predictions): 5K-10K calls
  • Slow oracles (docking): 500-2K calls

Next Steps

Design Your Oracle

Learn more about oracle design patterns and best practices

Tune Hyperparameters

Optimize the configuration for your specific use case