Quick start
This guide walks you through creating a complete molecular optimization pipeline using ChemLactica. You’ll learn how to define an oracle function, configure the optimization algorithm, and generate molecules optimized for specific properties.Overview
Molecular optimization with ChemLactica requires two main components:- Oracle: Evaluates the quality of generated molecules based on your target properties
- Configuration: Defines hyperparameters for the optimization algorithm
Step 1: Define your oracle
The oracle is responsible for evaluating molecules and assigning scores. Here’s a complete example that optimizes for TPSA (Topological Polar Surface Area) and molecular weight:The oracle’s
__call__ method receives a list of MoleculeEntry objects and must return a list of scores. Set takes_entry = True to receive MoleculeEntry objects instead of SMILES strings.Step 2: Create a configuration file
Create a YAML file to define the optimization hyperparameters. Here’s an example configuration for Chemlactica-125M:model_hparams.yaml
Key configuration parameters
- pool_size: Number of top molecules to maintain in the pool
- num_similars: Number of similar molecules to include in prompts
- num_gens_per_iter: Number of molecules to generate per iteration
- generation_temperature: Sampling temperature for diversity
- strategy: Use
[rej-sample-v2]for fine-tuning during optimization, or[default]for generation-only
Step 3: Run the optimization
Now put it all together in a complete script:example_run.py
Step 4: Execute the optimization
Run your optimization script:./results directory.
Understanding the output
During optimization, you’ll see periodic logs showing:- avg_top1: Best molecule score found so far
- avg_top10: Average score of top 10 molecules
- avg_top100: Average score of top 100 molecules
Advanced usage
Using different models
To use Chemlactica-1.3B or Chemma-2B, simply change the checkpoint paths in your config:Custom property constraints
Modify the oracle to optimize for different properties:Generation-only mode
For faster execution without fine-tuning, use the default strategy:Next steps
Advanced optimization
Explore complex oracles for docking, multi-objective optimization, and more
Fine-tuning
Learn how to fine-tune ChemLactica on your own molecular datasets
Test suite
Check out comprehensive examples in the ChemLacticaTestSuite repository
Paper
Read the full research paper for technical details