Overview
The metrics module provides functions to evaluate the quality and diversity of generated molecules during optimization.top_auc
Calculates the area under the curve (AUC) for the top-N molecules over the optimization trajectory.Function Signature
Parameters
Dictionary mapping SMILES strings to tuples of
(score, call_index). Represents all molecules evaluated by the oracle.Format: {smiles: (score, index), ...}Number of top-scoring molecules to track for AUC calculation (e.g., 10 for top-10).
Whether optimization finished before reaching budget. If
True and len(buffer) < max_oracle_calls, the final top-N score is extrapolated to the full budget.Frequency for logging/sampling scores (e.g., 100 means sample every 100 oracle calls).
Maximum oracle budget. Used as the denominator for AUC normalization.
Returns
Normalized AUC score representing the average top-N performance over the optimization trajectory. Higher values indicate better and faster discovery of high-scoring molecules.
Behavior
- Orders molecules by oracle call index (temporal order)
- At each
freq_loginterval, identifies top-N molecules so far - Computes AUC using trapezoidal integration
- Normalizes by
max_oracle_calls
Example Usage
Use Cases
- Benchmark comparison: Compare different optimization algorithms
- Early stopping: Monitor if top-N performance plateaus
- Oracle efficiency: Measure how quickly high-scoring molecules are discovered
average_agg_tanimoto
Computes average aggregated Tanimoto similarity between generated molecules and a reference set.Function Signature
Parameters
Reference molecule fingerprints as a 2D array of shape
(n_reference, fingerprint_dim).Typically fingerprints from a known dataset or training set.Generated molecule fingerprints as a 2D array of shape
(n_generated, fingerprint_dim).Must have same fingerprint dimension as stock_vecs.Number of molecules to process at once. Larger batches are faster but use more memory.
Aggregation method for finding closest reference molecule:
"max": For each generated molecule, find maximum similarity to any reference molecule"mean": Average similarity to all reference molecules
Device for computation:
"cpu" or "cuda".Power for p-mean averaging:
(mean(x^p))^(1/p). Use p=1 for arithmetic mean.Returns
Average Tanimoto similarity score between 0.0 and 1.0. Higher values indicate generated molecules are more similar to the reference set.
Example Usage
Use Cases
- Novelty assessment: Low similarity to known molecules indicates novelty
- Scaffold hopping: Measure how different generated molecules are from starting structures
- Coverage: Check if generated molecules explore diverse chemical space
internal_diversity
Measures the internal diversity of a set of molecules based on pairwise Tanimoto distances.Function Signature
Parameters
Molecular fingerprints as a 2D array of shape
(n_molecules, fingerprint_dim).Device for computation:
"cpu" or "cuda".Fingerprint type (currently not used in implementation).
Power for p-mean averaging:
(mean(x^p))^(1/p).Returns
Internal diversity score between 0.0 and 1.0. Computed as:
diversity = 1 - (1/|A|²) Σ(x,y in A×A) Tanimoto(x, y)Higher values indicate more diverse molecule sets.Example Usage
Interpretation
- High diversity (greater than 0.7): Molecules are structurally different, good chemical space exploration
- Medium diversity (0.4-0.7): Moderate variation, typical for focused libraries
- Low diversity (less than 0.4): Very similar molecules, might indicate mode collapse
Use Cases
- Mode collapse detection: Monitor if optimization converges to similar molecules
- Library design: Ensure diverse compound libraries for screening
- Benchmarking: Compare diversity across different generation methods