Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

MinervaChem - a python library for cheminformatics and machine learning

Minervachem implements Graphlet Fingerprints and other utilities cheminformatics and chemical machine learning.

This is an alpha release, so be prepared for breaking changes -- keep track of what version you are using if you need to maintain consistency.

Installation

  1. Clone this repo and cd into it
  2. uv sync --all-extras

Optional Add-ons

Getting started with minervachem

We recommend looking through and running the notebooks in the demos/ directory for a detailed introduction to minervachem's funcitonality.

Running Reddit Demo

Graphlets

uv run python demos/reddit_example/reddit_graphlets_example.py

Benchmark

uv run python demos/reddit_example/reddit_individual_graphs_benchmark.py demos/reddit_example/reddit_graphs_benchmarks

Highlights

Constructing graphlet fingerprints

Fingerprinter classes provide reusable objects for generating molecular fingerprints, including the graphlet fingerprints described in our manuscript.

from rdkit.Chem import MolFromSmiles, AddHs
from minervachem.fingerprinters import GraphletFingerprinter

# Benzene
mol = AddHs(MolFromSmiles('c1ccccc1'))

# Reusable Fingerprinter object 
fingerprinter = GraphletFingerprinter(max_len=3)

# Fingerprints are a map from fragment IDs to fragment counts.
# The fragments are identified by their number of atoms and a hash.
fp, bi = fingerprinter(mol)
print(fp)
>>> {(3, 10387847931347882557): 6,
>>>  (2, 10630435057451682469): 6,
>>>  (2, 11665740151475091393): 6,
>>>  (3, 14577436124092730684): 12,
>>>  (1, 20784809936286627226): 6,
>>>  (1, 12794648790135253294): 6}

# We can visualize the above dictiory with a plotting method
from minervachem.plotting import plot_fingerprint
plot_fingerprint(mol, fingerprinter)

A plot of the molecular graphlets of benzene up to size 3 atoms, their counts, and their identifiers

scikit-learn transformers

We can quickly construct feature matrices for machine learning from a set of molecules using minervachem's provided sklearn-style transformers:

from minervachem.transformers import FingerprintFeaturizer

mols = [MolFromSmiles(s) for s in [
    'c1ccccc1',
    'NCNOCOC',
    'CN1C=NC2=C1C(=O)N(C(=O)N2C)C',
    'CNO',
]]

featurizer = FingerprintFeaturizer(
    fingerprinter, 
    n_jobs=2 # parallelism for large datasets
)

# FingerprintFeaturizer implements the sklearn transformer API
feature_matrix = featurizer.fit_transform(mols)
# which generates sparse integer matrices by default
feature_matrix
>>> <4x39 sparse matrix of type '<class 'numpy.int64'>'
	with 44 stored elements in Compressed Sparse Row format>

Building Interpretable Machine Learning Models

Model fitting

After constructing a dataset through the methods above, we can use minervachem to fit an interpretable ML model.

The below is a snippet from the demo notebook which fits a hierarchical linear model with ~6,000 coefficients to ~100,000 molecules from QM9.

import minervachem
from sklearn.linear_model import Ridge
from minervachem.regressors import HierarchicalResidualModel
from minervachem.plotting import parity_plot_train_test


# build a higherarchical residual model
# using a ridge regressor base model 
base_model = Ridge(fit_intercept=False, 
                   alpha=1e-5,
                   solver='sparse_cg')
hmodel = HierarchicalResidualModel(regressor=base_model,verbose=1)
hmodel.fit(X_train,y_train,levels=featurizer.bit_sizes_)

# visualize the train and test performance with 
# minervachem's plotting methods
parity_plot_train_test([X_train, X_test], 
                       [y_train, y_test],
                       hmodel, 
                       figsize=(12, 4),
                       xlab='DFT (kcal/mol)', 
                       ylab='Linear Model (kcal/mol)', 
                       title='Hierarchical Model Prediction');   

Hierarchical model performance

Model interpretations

Linear models are interpretable, but 6,000 coefficients is too many to look at all at once. (The most accurate models in our manuscript had >100,000 coefficients.) So, we use minervachem's projection methods to visualize atom- or bond-level contributions to model predictions for a set of molecules.

First we construct the Directed-Acyclic-Graph (DAG) between molecular graphlets that defines our projection operation:

from minervachem.graphlet_dags import GraphletDAG, draw_projected_coefs

# Construct the DAG relating larger graphlets to smaller ones
# for each molecule
dags = []
for mol in mols:
    dag =  GraphletDAG(mol,
                       fingerprinter=featurizer.fingerprinter, # the fingerprinter that creates the graphlets
                       bit_ids=featurizer.bit_ids_, # The bit ids for the features used in the model training
                       coef=hmodel.coef_ # The model coefficients as an array.
                     )
    dags.append(dag)

draw_projected_coefs(dags,
                     level=2, # bond-level interpretations (atom-level is 1)
                    )

Hierarhcical model interpretation

Citation

If you use minervachem in your work, please cite our paper

@article{tynes2024linear,
  title={Linear Graphlet Models for Accurate and Interpretable Cheminformatics},
  author={Tynes, Michael and Taylor, Michael G and Janssen, Jan and Burrill, Daniel J and Perez, Danny and Yang, Ping and Lubbers, Nicholas},
  journal={ChemRxiv preprint},
  doi={10.26434/chemrxiv-2024-r81c8},
  url={dx.doi.org/10.26434/chemrxiv-2024-r81c8},
  year={2024}
}

minervachem is released under the BSD-3 License. See LICENSE.txt for the full license.

The copyright to minervachem is owned by Triad National Security, LLC and is released for open source use as project number O04631.

© 2023. Triad National Security, LLC. All rights reserved. This program was produced under U.S. Government contract 89233218CNA000001 for Los Alamos National Laboratory (LANL), which is operated by Triad National Security, LLC for the U.S. Department of Energy/National Nuclear Security Administration. All rights in the program are. reserved by Triad National Security, LLC, and the U.S. Department of Energy/National Nuclear Security Administration. The Government is granted for itself and others acting on its behalf a nonexclusive, paid-up, irrevocable worldwide license in this material to reproduce, prepare. derivative works, distribute copies to the public, perform publicly and display publicly, and to permit. others to do so.

Release files for minervachem 0.0.3a3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for minervachem 0.0.3a3
File Size Uploaded
minervachem-0.0.3a3.tar.gz 5.7 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for minervachem 0.0.3a3
File Interpreter ABI Platform
minervachem-0.0.3a3-py3-none-any.whl Python 3 none any Details

Total release size: 9.6 MB

Release files / minervachem-0.0.3a3.tar.gz

Download URL minervachem-0.0.3a3.tar.gz
Size 5.7 MB
Tags Source
SHA-256 checksum
How to use checksums
14b254e6bca70b1b9cafd2c62a5073b57ad4f94e685b7bbfae3fe60865e7f115
BLAKE2b-256 checksum
How to use checksums
255f1afbbff76f553d9f29cdf42f7085f8c88f33267c9c160e81e0dbee13c945
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 21, 2026.

Transparency log

Release files / minervachem-0.0.3a3-py3-none-any.whl

Download URL minervachem-0.0.3a3-py3-none-any.whl
Size 3.9 MB
Tags Python 3
SHA-256 checksum
How to use checksums
4357090609af9ef2d388ebefac21305bc53d7987919961637f864692ae02bddc
BLAKE2b-256 checksum
How to use checksums
1b241429f9db6e764828f80b64f21c4f58c9ad091aed3f9089e352f61f7bad63
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 21, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.0.3a3 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page