Overview
ChemLactica models can generate novel molecules based on conditional prompts that specify desired properties and structural similarities. The generation process uses the model’s understanding of SMILES notation and molecular properties learned during pretraining.Generation Function
The core generation functionality is provided by thegenerate() function in chemlactica/generation/generation.py:
generation.py:9
Basic Usage
Load Model and Generate
Generation in Optimization
During molecular optimization, generation happens within the optimization loop inchemlactica/mol_opt/optimization.py:
optimization.py:102
Extracting Generated SMILES
After generation, extract the SMILES string from the output:optimization.py:39
The model generates text between
[START_SMILES] and [END_SMILES] tags. Always validate the generated SMILES using RDKit before using them.Generation Parameters
Key parameters for molecule generation:int
default:"100"
Maximum number of new tokens to generate. SMILES strings typically require 50-100 tokens.
bool
default:"true"
Whether to use sampling. Set to
true for diverse molecule generation.float
default:"1.0"
Sampling temperature. Higher values (1.0-1.5) increase diversity. See Sampling Strategies.
float
default:"1.0"
Penalty for repeating tokens. Usually kept at 1.0 for molecule generation.
int
default:"20"
Token ID that signals end of generation. ChemLactica uses token ID 20.
Batch Generation
For efficient generation, process multiple prompts in batches:Context Length Management
ChemLactica models have a maximum context length of 2048 tokens:optimization.py:114
Example: Complete Generation Pipeline
Next Steps
Prompting
Learn how to format prompts with properties and similarity constraints
Sampling Strategies
Optimize generation quality with sampling parameters