Skip to main content

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

dict
required
Dictionary mapping SMILES strings to tuples of (score, call_index). Represents all molecules evaluated by the oracle.Format: {smiles: (score, index), ...}
int
required
Number of top-scoring molecules to track for AUC calculation (e.g., 10 for top-10).
bool
required
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.
int
required
Frequency for logging/sampling scores (e.g., 100 means sample every 100 oracle calls).
int
required
Maximum oracle budget. Used as the denominator for AUC normalization.

Returns

float
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

  1. Orders molecules by oracle call index (temporal order)
  2. At each freq_log interval, identifies top-N molecules so far
  3. Computes AUC using trapezoidal integration
  4. 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

numpy.ndarray
required
Reference molecule fingerprints as a 2D array of shape (n_reference, fingerprint_dim).Typically fingerprints from a known dataset or training set.
numpy.ndarray
required
Generated molecule fingerprints as a 2D array of shape (n_generated, fingerprint_dim).Must have same fingerprint dimension as stock_vecs.
int
default:"5000"
Number of molecules to process at once. Larger batches are faster but use more memory.
str
default:"'max'"
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
str
default:"'cpu'"
Device for computation: "cpu" or "cuda".
int
default:"1"
Power for p-mean averaging: (mean(x^p))^(1/p). Use p=1 for arithmetic mean.

Returns

float
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

numpy.ndarray
required
Molecular fingerprints as a 2D array of shape (n_molecules, fingerprint_dim).
str
default:"'cpu'"
Device for computation: "cpu" or "cuda".
str
default:"'morgan'"
Fingerprint type (currently not used in implementation).
int
default:"1"
Power for p-mean averaging: (mean(x^p))^(1/p).

Returns

float
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

Example: Comprehensive Evaluation