Skip to main content

High-performance Geometric GNN Engine

Project description

Hadronis

PyPI version Python versions PyPI downloads CodSpeed

A minimal, CPU-Optimized PaiNN Inference Pipeline for Molecular Graph Neural Networks

Overview

Hadronis is a low-latency, single-molecule all-in-one inference pipeline for molecular graph neural networks (GNNs), designed for CPU-bound scientific computing where per-configuration evaluation time matters. It currently targets a PaiNN-style equivariant architecture rather than arbitrary GNNs, letting the implementation focus on a single, well-motivated model family instead of reimplementing a generic GNN framework. It combines the speed of C++ with the flexibility of Python, targeting real-world chemistry and physics applications.

Why Hadronis?

Many molecular ML applications now require fast, per-configuration evaluations rather than just large-batch screening. Examples include molecular dynamics (MD) and Monte Carlo simulations with learned potentials, real-time exploration of potential energy surfaces, and tight control loops where a single molecule (or a small system) must be evaluated at every step. In these regimes, the primary constraint is latency per inference rather than total throughput over large libraries.

Hadronis focuses on this setting: a compact, CPU-optimized structure → properties engine that can sit inside inner simulation loops or interactive workflows, providing geometry-aware predictions (for example, energies, forces, or other observables) for a single molecular configuration at a time. It is intended to be embedded in MD or other simulation codes as a surrogate for more expensive electronic-structure calculations when appropriate, or as a fast pre-screening layer to decide when higher-level methods should be called.

At the same time, Hadronis is explicitly not a drop-in replacement for first-principles methods or experimental data. Using AI to evaluate molecular configurations carries risks: systematic biases in the training data, failure modes on out-of-distribution chemistry, and feedback loops where a simulator or generator over-optimizes for the surrogate model instead of real physics. The goal is therefore to provide a transparent, well-engineered inference pipeline that is easy to benchmark, stress-test, and validate against trusted reference methods, not to claim ground truth on its own.

Core Model: PaiNN

Hadronis is optimized around PaiNN-like message passing for molecular systems. PaiNN provides a strong balance between physical inductive bias and engineering practicality:

  • Equivariance built-in: PaiNN operates on scalar and vector features in a way that is invariant to global rotations and translations of the molecular geometry. This is a natural fit for 3D chemistry, where predictions should not depend on how a molecule is oriented in space.
  • Compact and efficient: Compared to very large graph transformers or attention-based 3D models, PaiNN-style networks are relatively lightweight in parameter count and memory footprint. This makes them well-suited to high-throughput, CPU-oriented screening where throughput and latency matter.
  • Targeted, not “framework-y”: By committing to a PaiNN-style architecture, Hadronis can specialize data layouts, neighbor list construction, and kernel implementations for this one family of models instead of trying to be a general-purpose GNN engine (which frameworks like PyTorch Geometric already cover). The goal is a small, focused runtime for fast, robust inference—not a full training ecosystem.

Compared to models such as MACE, which use higher-order equivariant features and richer angular bases, this PaiNN-style focus trades some architectural complexity for lower per-step cost—especially on CPUs. That makes it easier to hand-optimise kernels, control memory use, and port weights between reference PyTorch implementations and the C++ runtime, while still retaining the key geometric equivariances needed for molecular modeling.

Architecture

Architecture (single configuration → prediction)

Architecture

Stage Transformation Description
1. Input (Z, R) → neighbor list Atomic numbers Z and positions R for a single configuration.
2. Neighbor graph neighbor list → distances dᵢⱼ Build a fixed-size neighbor list (cutoff, max_neighbors) and compute interatomic distances.
3. RBF features dᵢⱼ → RBFᵢ(dᵢⱼ) Expand distances into radial basis function features.
4. PaiNN blocks RBF features → learned features Apply PaiNN-style equivariant message passing and feature updates.
5. Per-atom outputs features → per-atom scalars Map final features to per-atom predictions (e.g. energy contributions).
6. Aggregation per-atom → global Optionally aggregate (e.g. sum) to obtain global quantities.
  • Inputs (Z, R): A single frame of atomic numbers and 3D coordinates for one molecule or configuration.
  • Neighbor list: For each atom, Hadronis builds a fixed-size list of nearby atoms based on a distance cutoff and max_neighbors, which drives both accuracy and performance.
  • Distances and RBFs: Interatomic distances along edges are expanded into a bank of radial basis functions RBFᵢ(d), giving a smooth, expressive representation of local geometry.
  • PaiNN interaction blocks: Stacked PaiNN-style layers update scalar and vector features using equivariant message passing over the neighbor graph, encoding chemistry-aware local environments.
  • Readout and aggregation: Final features are mapped to per-atom scalars (e.g. energy contributions) and optionally aggregated (e.g. summed) to produce global quantities.

Molecular Graph Representation

Hadronis builds molecular graphs from atomic coordinates and atomic numbers, representing each atom as a node and chemical bonds or spatial proximity as edges. The graph construction leverages domain knowledge:

  • Nodes: Atoms, defined by atomic number and 3D position.
  • Edges: Created using a distance-based cutoff, reflecting chemical bonding and physical interactions.
  • RBF Expansion:
    • Edge features are expanded using Radial Basis Functions (RBFs), a standard technique in molecular machine learning.

    • The typical RBF expansion formula is:

      RBFᵢ(d) = exp(-γ (d − μᵢ)²)

      where d is the interatomic distance, μᵢ is the center of the i-th basis function, and γ controls the width.

    • RBF expansion transforms raw interatomic distances into a smooth, differentiable feature space, improving the GNN’s ability to learn complex spatial relationships.

    • This is critical for capturing both short-range (covalent) and long-range (non-covalent) interactions.

  • Symmetries and invariances: The representation is compatible with PaiNN's equivariant architecture, which respects global translations and rotations of the molecule.
  • Cutoff Choice: The cutoff parameter (e.g., 1.2 Å for methane, 5.0 Å for large systems) is chosen to balance physical realism and computational efficiency. It captures both covalent bonds and relevant non-covalent interactions, ensuring the GNN sees all chemically meaningful neighbors without excessive noise.

Usage

Python Example (single molecule, low latency):

import hadronis
import numpy as np

engine = hadronis.compile(
	"painn.bin",
	cutoff=5.0,
    max_neighbors=64,
    n_threads=16
)

Z = np.array([6, 1, 1, 1, 1], dtype=np.int32)

R = np.array([
    [0.0, 0.0, 0.0],
    [0.6, 0.6, 0.6],
    [-0.6, -0.6, 0.6],
    [-0.6, 0.6, -0.6],
    [0.6, -0.6, -0.6],
], dtype=np.float32)

predictions = engine.predict(
    atomic_numbers=Z,
    positions=R,
)

MD-style inner loop (conceptual):

engine = hadronis.compile("painn.bin", cutoff=5.0)

Z = ...  # (n_atoms,) atomic numbers
R = R0   # (n_atoms, 3) initial positions

for step in range(n_steps):
    # advance positions using your integrator
    R = integrator_step(R)

    # low-latency single-configuration inference
    per_atom_pred = engine.predict(Z, R)
    total_pred = per_atom_pred.sum()

    # use `total_pred` (e.g. as an energy-like scalar)
    control_simulation(total_pred)

Limitations

The current graph construction and cutoff design are primarily targeted at neutral organic and small-molecule chemistry in gas-phase or simple solvent-like environments. Systems with strong ionic character, highly delocalised electronic structure, extended periodic materials, or exotic bonding patterns may require adapted featurisation, longer-range interaction models, or specialised training data before Hadronis can be used reliably.

License

MIT OR Apache-2.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hadronis-0.3.0.tar.gz (134.2 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

hadronis-0.3.0-cp312-cp312-win_amd64.whl (2.0 MB view details)

Uploaded CPython 3.12Windows x86-64

hadronis-0.3.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (673.7 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

hadronis-0.3.0-cp312-cp312-macosx_11_0_arm64.whl (627.4 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

hadronis-0.3.0-cp311-cp311-win_amd64.whl (2.0 MB view details)

Uploaded CPython 3.11Windows x86-64

hadronis-0.3.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (674.4 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

hadronis-0.3.0-cp311-cp311-macosx_11_0_arm64.whl (626.1 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

hadronis-0.3.0-cp310-cp310-win_amd64.whl (2.0 MB view details)

Uploaded CPython 3.10Windows x86-64

hadronis-0.3.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (673.0 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

hadronis-0.3.0-cp310-cp310-macosx_11_0_arm64.whl (625.0 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

Details for the file hadronis-0.3.0.tar.gz.

File metadata

  • Download URL: hadronis-0.3.0.tar.gz
  • Upload date:
  • Size: 134.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for hadronis-0.3.0.tar.gz
Algorithm Hash digest
SHA256 3e1cb77e2ccc71030a75e15bcf38e7ff4e4bfd81bb30ffc1db48b345f41ce89c
MD5 6e2085ed4551e6acfe533a1a4fe7d553
BLAKE2b-256 d43f83379593bda3fed2ecbdd8953946b24bc00213b8af300d88d9da63617a62

See more details on using hashes here.

File details

Details for the file hadronis-0.3.0-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: hadronis-0.3.0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 2.0 MB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for hadronis-0.3.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 0e2546750547b17ceaba78fb62e9ac7834c54c01a326d0ad291f452ed9e9f147
MD5 4318975ebe0c5e20ad63e51fc7eccd8b
BLAKE2b-256 bc4144aa4a762e59d514783f0d71e07f3f012e4d687dd90d368d204a3ce64bdd

See more details on using hashes here.

File details

Details for the file hadronis-0.3.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for hadronis-0.3.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 25d365b624d41854f62e94e1338aaf67a3f65774606e2eb7e75307d06ee12d2d
MD5 d00a137bbaece88812f22ff399885635
BLAKE2b-256 45427de4a393d20fe306c55f753515f63d6618146dff2a63ca78a214e2db3aef

See more details on using hashes here.

File details

Details for the file hadronis-0.3.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for hadronis-0.3.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 366af2078db0206deea5d3f797ff84283026f92eb6539de871c9c13cc3640151
MD5 c01092a4578761538867957e2a6e485a
BLAKE2b-256 c6744090c5d04da2ad7e7b3c9bb45d662a11d492799b735aedabc15156eccdf6

See more details on using hashes here.

File details

Details for the file hadronis-0.3.0-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: hadronis-0.3.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 2.0 MB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for hadronis-0.3.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 596a97b0d9fb419b714705f65457e24ae8d25f69d36800534847b8f99076b445
MD5 f8f27b46b81d9f61c6958f1ed1bc2c07
BLAKE2b-256 dcaaec1f3558d77248b78a1f68d4ddf9d5dd37a781c48ad6034cedf2a1331146

See more details on using hashes here.

File details

Details for the file hadronis-0.3.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for hadronis-0.3.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 3b99e2abda1c4dc20e18e625ec1ca46684b2fe4ddfc935660beff399343d9f99
MD5 8c268812d0f79713a4b2149cb7afa465
BLAKE2b-256 ed743b62932a3cb13eaecf4c488b900f76254ef3f25126d2e3683787a49fef1f

See more details on using hashes here.

File details

Details for the file hadronis-0.3.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for hadronis-0.3.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 729691bf9f3a5e1c7422e66d209b780efcd625b827861bec31aea2eaf6ca620b
MD5 cb11c824cd607e3c52a7546a805fdbd0
BLAKE2b-256 7bc2bec24ef7b4f9485250280d4c3abc1962de4388d3898d2a433f7ae033652a

See more details on using hashes here.

File details

Details for the file hadronis-0.3.0-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: hadronis-0.3.0-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 2.0 MB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for hadronis-0.3.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 58729db5024234652833b9f1a299c213c7ce6a7ef04dabaee2413675a742d036
MD5 adbcf7df4ef3d4364290c1668802e7e3
BLAKE2b-256 8a1cd78b122e50b3a2ba756c32127e6ac0a9731a1f97228b317844ed0dc7dfec

See more details on using hashes here.

File details

Details for the file hadronis-0.3.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for hadronis-0.3.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 e608374748e0c155298066d9c81e4383db149cd547fab4da5064faaeef5cc34f
MD5 aada96ca5d9bcb984d36084570e665a4
BLAKE2b-256 e2b13fe265941b006686a216d92c679d7a644db93754bc0c8ee94c0750ed9ffa

See more details on using hashes here.

File details

Details for the file hadronis-0.3.0-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for hadronis-0.3.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 34af5d4a66626d4f94ee464dce3cfcac3890bc75036c65237ec2b7a8d0af23dc
MD5 586939335cde0ba64aa6e5b4c6c9130d
BLAKE2b-256 9dfaaf6030c77f0d3d80107922783255991140f904abede286cf28f19a9d904d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page