Skip to main content

xnn

Machine-learning interatomic potentials for molecules and materials behind one PyTorch interface.

x in xnn refers to the neural network model architectures: g stands for graph, d for dense, c for convolutional, ff for classical force-fields, hybrid for mixed models, all sharing one data object, one trainer and one deployment path. This categorization is reflected in the package structure.

Documentation: https://molssi-ai.github.io/xnn/

Installation

pip install xnns                  # core (torch, numpy, pyyaml)
pip install "xnns[gnn,ase]"       # + e3nn for NequIP/MACE/Allegro, + ASE calculator
pip install -e ".[all]"           # from a clone: everything, for development

The distribution is xnns; the import name and the command line are xnn.

Design principles

  1. One data object. Every model takes an AtomicGraph and returns {"node_energy", "energy"}. Periodicity lives only in the edge vectors, so molecules and crystals look the same to a model.
  2. Featurizers are first-class. Descriptors (symmetry functions, AEV) and equivariant edge features (spherical harmonics, Cartesian monomials) are standalone modules that models compose and you can inspect on their own.
  3. Forces and stress in one place. ForceStressOutput differentiates any model's energy for forces and stress; models never implement them. Wrappers in the same style add long-range electrostatics (LES) and DFT-D3 / DFT-D4 dispersion to any model.
  4. One config, three frontends. @register_model exposes a model to the YAML, argparse and Hydra interfaces, all of which fill one Config dataclass.

Load data

Structures are plain dictionaries (pos, atomic_numbers, optional cell, pbc and energy / forces / stress targets), any ASE-readable file, or a dataset from the hub:

from xnn.common.data import AtomicDataset, load_dataset

# From a list of structures dict
data = AtomicDataset(structures, cutoff=5.0)

# From a file (e.g., .extxyz, .cif, VASP, ...)
data = AtomicDataset.from_file("trajectory.extxyz", cutoff=5.0)

# From the xnn data hub (e.g., RMD17 dataset)
data = load_dataset("rmd17", molecule="aspirin", split="train", cutoff=5.0)

Train

from xnn.common.config import Config
from xnn.common.train import Trainer

# Initialize the configuration
cfg = Config()

# Set the model and data configuration
cfg.model.name = "nequip"
cfg.model.extra = {"species": [1, 6, 8], "l_max": 2}
cfg.data.batch_size = 16

# Train the model
Trainer(cfg, data).fit()

or from the command line: xnn train --config configs/train.yaml --set optim.epochs=50.

Pretrained models

from xnn.common.models import from_pretrained, list_models

# Foundation models, xnn models, local cache
list_models()

# MACE-MP / MACE-OFF, converted once and cached
model = from_pretrained("mace-off23-small")

# Your own checkpoints
model = from_pretrained("runs/exp/best.pt")

Benchmark

Score pre-trained checkpoints on one dataset (energy / force / stress MAE, MSE or RMSE, per atom or as atomization energies), tabulated per model and written to CSV, JSON or Markdown:

xnn benchmark --config configs/benchmark.yaml

Deploy

from xnn.common.deploy import XNNCalculator, export_to_lammps

# Export as ASE calculator
atoms.calc = XNNCalculator(model, cutoff=5.0)

# Export to LAMMPS (TorchScript)
export_to_lammps(model, cutoff=5.0, path="deployed.pt")

xnn mdi --ckpt runs/exp/best.pt serves a model to an external MD code through the MolSSI Driver Interface.

Models

Family Models
Add-ons for any model (common) LES long-range electrostatics; DFT-D3 (zero, BJ, mzero, op damping) and DFT-D4 dispersion
Graph networks (gnn) NequIP, MACE, Allegro, CACE
Descriptor networks (dnn) ANI (ANI-1, ANI-1x, ANI-1ccx, ANI-2x), PhysNet, HDNNP*
Convolutional (cnn) SchNet*
Force fields (ffnn) ReaxFF / ReaxFF-nn, OPLS-AA / L-OPLS, DREIDING
Hybrid (hybrid) BAMBOO

* under development. Each model is checked against its reference code or paper (examples/fidelity_checks/). NequIP, MACE and Allegro also export to TorchScript / LAMMPS; the others deploy through ASE.

Examples and tests

Executed notebooks for every model are under examples/ (pip install -e ".[examples]"); examples/quickstart.py is a minimal script. Run the tests with pytest tests/.

License

MIT

How to cite

If you use xnn in your work, please cite it as:

@software{Mostafanejad:2026:xnn,
  author  = {Mostafanejad, Mohammad},
  title   = {xnn: Machine-learning interatomic potentials for molecules and materials},
  year    = {2026},
  version = {0.5.0},
  url     = {https://github.com/molssi-ai/xnn}
}

Author: Mohammad Mostafanejad, The Molecular Sciences Software Institute (MolSSI)

Metadata

Release files for xnns 0.6.0

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

Source distribution (sdist)

Source distribution for xnns 0.6.0
File Size Uploaded
xnns-0.6.0.tar.gz 1.4 MB Details

Built distribution (wheel)

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

Total release size: 2.7 MB

Release files / xnns-0.6.0.tar.gz

Download URL xnns-0.6.0.tar.gz
Size 1.4 MB
Tags Source
SHA-256 checksum
How to use checksums
3235f9aef429693aa8a3d13fbcd075c985d9dd1b6d3f02e14550f3f77c001fd1
BLAKE2b-256 checksum
How to use checksums
b1a3e11b867dc94c5b8e62803a423a79590034817b5c12f1e135638892675b12
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 Oct 3, 2026.

Transparency log

Release files / xnns-0.6.0-py3-none-any.whl

Download URL xnns-0.6.0-py3-none-any.whl
Size 1.3 MB
Tags Python 3
SHA-256 checksum
How to use checksums
f1c85c9cb974b8892c3efeaece0aeafa3b34158240eb4669c372ec2d7ff46a11
BLAKE2b-256 checksum
How to use checksums
92479b6be496b731eb54ecf4be9eb3046f5068c8e00bf9df0e645f833906aeff
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 Oct 3, 2026.

Transparency log

Release history Release notifications | RSS feed

0.13.0

2 release files

0.12.0

2 release files

0.11.2

2 release files

0.11.1

2 release files

0.11.0

2 release files

0.10.0

2 release files

0.9.0

2 release files

0.8.0

2 release files

0.7.0

2 release files

This release

0.6.0 This release

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.0

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