Skip to main content

DeePMD-kit plugin for graph neural network models.

Project description

DeePMD-kit plugin for various graph neural network models

DOI:10.1021/acs.jcim.4c02441 Citations conda install PyPI - Version

deepmd-gnn is a DeePMD-kit plugin for various graph neural network (GNN) models, which connects DeePMD-kit and atomistic GNN packages by enabling GNN models in DeePMD-kit.

Supported packages and models include:

After installing the plugin, you can train the GNN models using DeePMD-kit, run active learning cycles for the GNN models using DP-GEN, and perform simulations with MACE and NequIP models using molecular dynamic packages supported by DeePMD-kit, such as LAMMPS and AMBER. You can follow DeePMD-kit documentation to train the GNN models using its PyTorch backend, after using the specific model parameters.

Highlights

The official MACE and NequIP packages remain the reference implementations of their model architectures. DeePMD-GNN focuses on what is useful beyond the standalone official workflows: bringing those equivariant GNN models into the DeePMD-kit ecosystem for training, active learning, and production molecular simulations.

  • Unified DeePMD-kit workflow: train and freeze MACE or NequIP models with dp --pt train and dp --pt freeze, using DeePMD-kit data pipelines, inputs, losses, and model serialization instead of maintaining a separate workflow for each upstream package.
  • Broader MD engine access: run frozen GNN models through molecular dynamics interfaces supported by DeePMD-kit, including LAMMPS and AMBER, rather than relying only on the engines and plugins maintained by the official MACE or NequIP projects.
  • Parallel periodic simulations: use DeePMD-kit's message-passing communication path for LAMMPS/MPI runs. MACE and NequIP models advertise their message passing to DeePMD-kit, so ghost-atom features can be exchanged between message-passing layers through border_op.
  • Active learning and QM/MM integration: plug MACE or NequIP models into DP-GEN active learning loops and DeePMD-kit DPRc/AmberTools workflows through the same interface used by other DeePMD-kit models.
  • Deployment-oriented MACE extras: export MACE models with the DeePMD-kit/LAMMPS PyTorch exportable backend (pt_expt), train with optional cuEquivariance acceleration, use DeePMD-kit's torch.compile path, and conservatively convert selected official MACE-OFF checkpoints for downstream validation in DeePMD-kit-supported engines.

Credits

If you use this software, please cite the following paper:

  • Jinzhe Zeng, Timothy J. Giese, Duo Zhang, Han Wang, Darrin M. York, DeePMD-GNN: A DeePMD-kit Plugin for External Graph Neural Network Potentials, J. Chem. Inf. Model., 2025, 65, 7, 3154-3160, DOI: 10.1021/acs.jcim.4c02441. Citations

Installation

Install via conda

If you are in a conda environment where DeePMD-kit is already installed from the conda-forge channel, you can use conda to install the DeePMD-GNN plugin:

conda install deepmd-gnn -c conda-forge

Build from source

First, clone this repository:

git clone https://gitlab.com/RutgersLBSR/deepmd-gnn
cd deepmd-gnn

Python interface plugin

Python 3.10 or above is required. A C++ compiler that supports C++ 17 is required. NVCC is required to build CUDA OPs.

pip install .

Only PyTorch 2.10 or above is supported.

C++ interface plugin

DeePMD-kit version should be v3.0.0b4 or later.

Follow DeePMD-kit documentation to install DeePMD-kit C++ interface with PyTorch backend support and other related MD packages. After that, you can build the plugin

# Assume libtorch has been contained in CMAKE_PREFIX_PATH
mkdir -p build
cd build
cmake .. -D CMAKE_INSTALL_PREFIX=/prefix/to/install
cmake --build . -j8
cmake --install .

libdeepmd_gnn.so will be installed into the directory you assign. When using any DeePMD-kit C++ interface, set the following environment variable in advance:

export DP_PLUGIN_PATH=/prefix/to/install/lib/libdeepmd_gnn.so

Usage

Follow Parameters section to prepare a DeePMD-kit input file.

dp --pt train input.json
dp --pt freeze

A frozen model file named frozen_model.pth will be generated. You can use it in the MD packages or other interfaces. For details, follow DeePMD-kit documentation.

Exporting MACE models with the PyTorch exportable backend

MACE models can also be trained and frozen with DeePMD-kit's PyTorch exportable backend (pt_expt):

dp --pt-expt train input.json
dp --pt-expt freeze -o frozen_model.pt2

Use this path when you need a .pt2 model for the DeePMD-kit/LAMMPS PyTorch exportable runtime. The pt_expt path currently supports MACE models; NequIP models should still use the regular --pt workflow.

The pt_expt workflow requires DeePMD-kit 3.2.0 or later. Multi-layer MACE models include the extra communication artifact needed by LAMMPS/MPI inside the exported .pt2 package, so the resulting file can be passed to LAMMPS in the same way as other DeePMD-kit frozen models.

Training MACE with cuEquivariance

MACE training can use cuEquivariance kernels when the installed MACE package provides CuEquivarianceConfig and the cuEquivariance runtime packages are available. Install the matching extra for the CUDA runtime used by PyTorch:

pip install "deepmd-gnn[cueq]"

The cueq extra installs the CUDA 12 cuEquivariance op package. For CUDA 11 environments, use deepmd-gnn[cueq-cu11] instead. When installing from a source checkout, use pip install ".[cueq]" or pip install ".[cueq-cu11]".

Then enable it in the model section:

"model": {
  "type": "mace",
  "enable_cueq": true
}

Then train with either PyTorch backend:

dp --pt train input.json
dp --pt-expt train input.json

On a single RTX 5090, using the water example data with sel = "auto", hidden_irreps = "128x0e + 128x1o", batch_size = 1, and disp_freq = 100, 2000-step runs were used to sample steady-state training speed:

backend cuEquivariance steady avg after step 300 speedup
dp --pt no 0.1955 s/step 1.00x
dp --pt yes 0.1061 s/step 1.84x
dp --pt-expt no 0.2025 s/step 1.00x
dp --pt-expt yes 0.1007 s/step 2.01x

The cuEquivariance effect is similar in both backends, but not bit-for-bit identical: in this run, the steady cuEquivariance speed differed by about 5%. The first cuEquivariance step includes a one-time kernel initialization cost (about 56 s in this run), which is amortized over long training jobs.

cuEquivariance accelerates training only. When freezing a checkpoint whose input had "enable_cueq": true, deepmd-gnn disables cuEquivariance for the frozen model and converts the MACE weights back to the e3nn format. This lets both dp --pt freeze and dp --pt-expt freeze export normally, but the frozen model does not use cuEquivariance kernels.

Training MACE with torch.compile

MACE training through the pt_expt backend can use DeePMD-kit's native torch.compile path. Enable it in the training section:

"training": {
  "enable_compile": true
}

Then run the regular exportable-backend training command:

dp --pt-expt train input.json

On a single RTX 5090, using the water example data with sel = "auto", hidden_irreps = "128x0e + 128x1o", batch_size = 1, and disp_freq = 100, a 2000-step run was used to sample the steady-state training speed:

mode steady avg after step 200 speedup
eager pt_expt 0.2030 s/step 1.00x
torch.compile 0.1495 s/step 1.36x

The first compiled step includes a one-time Inductor trace/compile cost (97.17 s in this run), which is amortized over normal long training jobs.

Do not enable enable_cueq and enable_compile together for now. With cuEquivariance enabled, DeePMD-kit's symbolic make_fx compile trace fails in the cuEquivariance uniform_1d fake-tensor path with a data-dependent symbolic shape guard.

Running LAMMPS + GNN models with period boundary conditions

GNN models use message passing neural networks, so the neighbor list built with traditional cutoff radius will not work, since the ghost atoms also need to build neighbor list. The MACE and NequIP models work like regular DeePMD-kit message-passing models. No extra environment variable is needed when freezing the model. They advertise message passing to DeePMD-kit, so LAMMPS can use the regular neighbor list with a cutoff radius of $r_c$ and DeePMD-kit communicates the ghost-atom features through MPI between message-passing layers. This requires a DeePMD-kit build whose LAMMPS/PyTorch interface provides the message-passing communication op, border_op.

When border_op communication is available, DeePMD-kit/LAMMPS uses that MPI-capable path. The atom-map path is a serial fallback for runs that do not receive a DeePMD message-passing comm_dict; it maps ghost atoms to their corresponding real atoms on the same process and is not a substitute for MPI communication. Request the mapping when using this fallback in LAMMPS (also requires DeePMD-kit v3.0.0rc0 or above).

atom_modify map array

Parameters

MACE

To use the MACE model, set "type": "mace" in the model section of the training script. Below is default values for the MACE model, most of which follows default values in the MACE package:

"model": {
  "type": "mace",
  "type_map": [
    "O",
    "H"
  ],
  "r_max": 5.0,
  "sel": "auto",
  "num_radial_basis": 8,
  "num_cutoff_basis": 5,
  "max_ell": 3,
  "interaction": "RealAgnosticResidualInteractionBlock",
  "num_interactions": 2,
  "hidden_irreps": "128x0e + 128x1o",
  "pair_repulsion": false,
  "distance_transform": "None",
  "correlation": 3,
  "gate": "silu",
  "MLP_irreps": "16x0e",
  "radial_type": "bessel",
  "radial_MLP": [64, 64, 64],
  "std": 1.0,
  "precision": "float32",
  "enable_cueq": false
}

NequIP

"model": {
  "type": "nequip",
  "type_map": [
    "O",
    "H"
  ],
  "r_max": 5.0,
  "sel": "auto",
  "num_layers": 4,
  "l_max": 2,
  "num_features": 32,
  "nonlinearity_type": "gate",
  "parity": true,
  "num_basis": 8,
  "BesselBasis_trainable": true,
  "PolynomialCutoff_p": 6,
  "invariant_layers": 2,
  "invariant_neurons": 64,
  "use_sc": true,
  "irreps_edge_sh": "0e + 1e",
  "feature_irreps_hidden": "32x0o + 32x0e + 32x1o + 32x1e",
  "chemical_embedding_irreps_out": "32x0e",
  "conv_to_output_hidden_irreps_out": "16x0e",
  "precision": "float32"
}

DPRc support

In deepmd-gnn, the GNN model can be used in a DPRc way. Type maps that starts with m (such as mH) or OW or HW will be recognized as MM types. Two MM atoms will not build edges with each other. Such GNN+DPRc model can be directly used in AmberTools24.

Conservative MACE-OFF checkpoint loading

deepmd_gnn.mace_off provides a conservative bridge from selected official MACE-OFF checkpoints into DeePMD-GNN. The goal is to recover the parts that are really stored in the checkpoint while avoiding guesses about wrapper-only runtime semantics.

In practice, this path intentionally does less inference than the broader DPRc/QM/MM machinery:

  • it infers ordinary element type_map entries from checkpoint atomic_numbers
  • it restores checkpoint-side model semantics such as avg_num_neighbors from the original ScaleShiftMACE object instead of reusing DeePMD's runtime neighbor cap
  • it requires an explicit sel value, because sel is a DeePMD runtime neighbor-list cap and is not stored in the MACE-OFF checkpoint
  • it does not infer DPRc/MM labels such as mH, mC, HW, or OW
  • load_mace_off_model() keeps the original eager MACE checkpoint model inside the wrapper for closer native/wrapper parity, while convert_mace_off_to_deepmd() scripts the model only at export time
  • it uses torch.load(..., weights_only=False) to recover the original ScaleShiftMACE object, so callers should only use trusted checkpoints

Example:

deepmd-gnn mace-off convert mace_off23_small_dp.pt --model off23_small --sel 64

This produces a scripted DeePMD-GNN wrapper. That serialization step is useful, but it is still a good idea to validate the final downstream workflow you care about (for example in LAMMPS or AMBER).

Examples

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

deepmd_gnn-0.2.0.tar.gz (2.2 MB view details)

Uploaded Source

Built Distributions

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

deepmd_gnn-0.2.0-py2.py3-none-win_amd64.whl (77.5 kB view details)

Uploaded Python 2Python 3Windows x86-64

deepmd_gnn-0.2.0-py2.py3-none-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (157.0 kB view details)

Uploaded Python 2Python 3manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

deepmd_gnn-0.2.0-py2.py3-none-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl (149.9 kB view details)

Uploaded Python 2Python 3manylinux: glibc 2.24+ ARM64manylinux: glibc 2.28+ ARM64

deepmd_gnn-0.2.0-py2.py3-none-macosx_11_0_arm64.whl (74.9 kB view details)

Uploaded Python 2Python 3macOS 11.0+ ARM64

File details

Details for the file deepmd_gnn-0.2.0.tar.gz.

File metadata

  • Download URL: deepmd_gnn-0.2.0.tar.gz
  • Upload date:
  • Size: 2.2 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for deepmd_gnn-0.2.0.tar.gz
Algorithm Hash digest
SHA256 09ab8abb3d66fa024c6f0f95c0d67ccf7d923f9fae33ba6190db46512c436b39
MD5 5a41f44f3321f6c1da39f1945651f57d
BLAKE2b-256 176e87c9f0973022f4994d135c03ca95c5ae2e203e4d3280500ad7b8e6252071

See more details on using hashes here.

Provenance

The following attestation bundles were made for deepmd_gnn-0.2.0.tar.gz:

Publisher: release.yaml on deepmodeling/deepmd-gnn

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file deepmd_gnn-0.2.0-py2.py3-none-win_amd64.whl.

File metadata

  • Download URL: deepmd_gnn-0.2.0-py2.py3-none-win_amd64.whl
  • Upload date:
  • Size: 77.5 kB
  • Tags: Python 2, Python 3, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for deepmd_gnn-0.2.0-py2.py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 17cf50039efe6ef145b1071d0a7de53a48ff145444259b78af0298222038e860
MD5 a22040af6d7108066bb03c47f7aae6f5
BLAKE2b-256 cabae8c7f93852a67934ab4b856ef79bdfdcb1a5967b59762507eb4edd88e9be

See more details on using hashes here.

Provenance

The following attestation bundles were made for deepmd_gnn-0.2.0-py2.py3-none-win_amd64.whl:

Publisher: release.yaml on deepmodeling/deepmd-gnn

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file deepmd_gnn-0.2.0-py2.py3-none-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for deepmd_gnn-0.2.0-py2.py3-none-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 6bbfadf1e8463ad5f8d4c28fec3404445ed336f758ef9299e02fed18fc715d6e
MD5 f1d105f349ba2fedf0f9357a0c9c169f
BLAKE2b-256 f5a71c522a14efdb00f636ff7185aa209f154f585e1fa0de266bc2987043f4f7

See more details on using hashes here.

Provenance

The following attestation bundles were made for deepmd_gnn-0.2.0-py2.py3-none-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl:

Publisher: release.yaml on deepmodeling/deepmd-gnn

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file deepmd_gnn-0.2.0-py2.py3-none-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for deepmd_gnn-0.2.0-py2.py3-none-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 88e73025b1b1c9b2785aa67c088a9a888c8d93c60ef49fc69d631ac38c479a51
MD5 00280d3719000f978e18a22cffd73185
BLAKE2b-256 34803feabb307dab3bb8739494aa2273c12bc6c14669667aa0b0c9ffafe9cc52

See more details on using hashes here.

Provenance

The following attestation bundles were made for deepmd_gnn-0.2.0-py2.py3-none-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl:

Publisher: release.yaml on deepmodeling/deepmd-gnn

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file deepmd_gnn-0.2.0-py2.py3-none-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for deepmd_gnn-0.2.0-py2.py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b6950db60641e5eb9a132ea9a5ecc67c9ff4bb226d0c7010bdb4c9d6febf1044
MD5 736e80aa445b8c0e43b32d26ae63d530
BLAKE2b-256 5836fca33d7762a0447e7b9e1166f61950119217cce5281bea745515e633c4e3

See more details on using hashes here.

Provenance

The following attestation bundles were made for deepmd_gnn-0.2.0-py2.py3-none-macosx_11_0_arm64.whl:

Publisher: release.yaml on deepmodeling/deepmd-gnn

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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