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 optimizing 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 huge 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 all-in-one 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.

Why PaiNN instead of MACE?

Models such as MACE use higher-order equivariant features and richer angular bases, which can deliver strong accuracy but come with significantly more complicated tensor algebra, larger hidden states, and higher per-step cost—especially on CPUs. Hadronis is deliberately focused on very low-latency, single-configuration inference, so a compact PaiNN-style architecture offers a better trade-off between physical inductive bias, implementation complexity, and raw speed. In practice this 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

At a high level, Hadronis turns a single molecular configuration into per-atom (and optionally aggregated) predictions via the following stages:

graph LR
    A[Atomic numbers Z, atomic positions R]
        --> B[Neighbor list (cutoff, max_neighbors)]
    B --> C[Pairwise distances d_ij]
    C --> D[RBF expansion RBF_i(d_ij)]
    D --> E[PaiNN interaction blocks (message passing + updates)]
    E --> F[Per-atom outputs (e.g. energies, features)]
    F --> G[Optional aggregation (sum/mean over atoms)]
  • 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_i(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.

Chemistry Domain Knowledge

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_i(d) = \exp(-\gamma (d - \mu_i)^2)$

      where $d$ is the interatomic distance, $\mu_i$ is the center of the $i$-th basis function, and $\gamma$ 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 underlying PaiNN-style architecture is designed to respect the fundamental symmetries of molecular systems: predictions are invariant to global translations and rotations of the molecule, and (ideally) to permutations of atoms within a molecule that leave the physical system unchanged. In practice, this means the model learns on relative geometry and composition rather than arbitrary coordinate frames or atom orderings, which is essential for chemically meaningful generalisation.
  • 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.

Why This Cutoff?

  • Chemistry: Typical covalent bond lengths are 1–2 Å; non-covalent interactions (e.g., van der Waals) extend to 3–5 Å.
  • Use Case: The default cutoff is tuned to include all atoms that can influence local electronic structure or molecular properties, maximizing predictive power for quantum chemistry, drug design, and materials science.

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.

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,
)
  • Graph Construction: The engine automatically builds a graph using atomic positions and applies the cutoff to define edges.
  • Inference: The GNN processes the graph, aggregating neighbor information for each atom.

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)

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 Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

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

Uploaded CPython 3.12Windows x86-64

hadronis-0.1.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (674.1 kB view details)

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

hadronis-0.1.0-cp312-cp312-macosx_11_0_arm64.whl (627.8 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

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

Uploaded CPython 3.11Windows x86-64

hadronis-0.1.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (674.7 kB view details)

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

hadronis-0.1.0-cp311-cp311-macosx_11_0_arm64.whl (626.5 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

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

Uploaded CPython 3.10Windows x86-64

hadronis-0.1.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (673.3 kB view details)

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

hadronis-0.1.0-cp310-cp310-macosx_11_0_arm64.whl (625.3 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: hadronis-0.1.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.1.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 e0406983faa305d92cc9ae939351a5ce49e1a2ad1f4a5327e49f28a4e9ef0ee3
MD5 caee46f980d8bd5ed1e7d7d91ed5f6ec
BLAKE2b-256 3ab4b81ca4090567aa6d3956cf1c269177b0ce408fa431af1a953f9d834a6012

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for hadronis-0.1.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 693156fee1523337464caa7f726561a1c171c7561571abf31b487471427e1919
MD5 039a6dc5e0ab6da98ef775b4bb99bd9c
BLAKE2b-256 e4c169d863b8417d6166be0b0f7ed3b85df3d7f519e0efbbbcac05828088e372

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for hadronis-0.1.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7808d7be36894f05ba64994d72643ffa5efe749008c1f7de9dd3049a1e01efaa
MD5 c7ad97ac144524e231c910086d1e9b2b
BLAKE2b-256 38fd17c157fe1d44f7c1d2eddfe913cfee35d7b5f006d806c5b0d49f782738f9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: hadronis-0.1.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.1.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 bce071a53538210b8a580ed84d1ad08cc9da6193549269aabace8e2e15f61b40
MD5 d9ac2afc3d6113cd8852f9f5436c2580
BLAKE2b-256 f068fc4b51573f176835d1653b8bac35dddb422b446027f40b6c2161e4a83667

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for hadronis-0.1.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 c39789da0f5e278011f5791c836ad3d10a4eab82c401944415daf75dcfa1207d
MD5 41b176cc921f2b5d8fa4a1c1c06004cf
BLAKE2b-256 5a467954d66a8631755f6f191dd68c913b1a35bf67f871a549780e6134550d7a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for hadronis-0.1.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0ba69c6c336af2552c3278787af740a2b8b3d9f5da15b3ed8467ae8d7a0ed10a
MD5 7c35485c0ef8da715f19f9d03dfce3ba
BLAKE2b-256 02b39afdf8614a0db3ecd115f0ca260c7c198ed72cdaec2986fe12a5ca7dd062

See more details on using hashes here.

File details

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

File metadata

  • Download URL: hadronis-0.1.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.1.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 c0e0e52895f0589acb9c846cb637f18faebab8bc7050bd87f5ffa9b0c55cdce0
MD5 85d35f5c9d6e6fcc187b7b3f1414a8e1
BLAKE2b-256 7ed8543a228dfd2f695a7b322f2190987c06242a1b9884a87f4cde1a613edd83

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for hadronis-0.1.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 a3ce311e8fff3c321adbf6deb0a7090b44ca1a7995150f8f99dd03657761b45d
MD5 c4a81b49034c394fe32ceda77910f29a
BLAKE2b-256 28039eafc6254060185f15d7986048d26ea4b42e26447ae1554f0a4769aad56d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for hadronis-0.1.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 fb4dc6deef53bb6c8ab6283e418979009d521aa84ca779785ad448c1edb377c7
MD5 4c5e0543e77b0490a625087e4943ec75
BLAKE2b-256 04c56d69e698465ae8b651cfc70c2d34d5da140e3522768812f4ce78465e135b

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