Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
C

chgnet

> DevOps
Open source

Pretrained universal neural network potential for charge-informed atomistic modeling https://chgnet.lbl.gov

394 stars0 likes1 views
WebsiteGitHub

About

Pretrained universal neural network potential for charge-informed atomistic modeling https://chgnet.lbl.gov

CHGNet

A pretrained universal neural network potential for charge-informed atomistic modeling (see publication)

Crystal Hamiltonian Graph neural Network is pretrained on the GGA/GGA+U static and relaxation trajectories from Materials Project, a comprehensive dataset consisting of more than 1.5 Million structures from 146k compounds spanning the whole periodic table.

CHGNet highlights its ability to study electron interactions and charge distribution in atomistic modeling with near DFT accuracy. The charge inference is realized by regularizing the atom features with DFT magnetic moments, which carry rich information about both local ionic environments and charge distribution.

Pretrained CHGNet achieves excellent performance on materials stability prediction from unrelaxed structures according to Matbench Discovery [repo].

Example notebooks

Notebooks Google Colab Descriptions
CHGNet Basics Open in Google Colab Examples for loading pre-trained CHGNet, predicting energy, force, stress, magmom as well as running structure optimization and MD.
Tuning CHGNet Open in Google Colab Examples of fine tuning the pretrained CHGNet to your system of interest.
Visualize Relaxation Open in Google Colab Crystal Toolkit app that visualizes convergence of atom positions, energies and forces of a structure during CHGNet relaxation.
Phonon DOS + Bands Open in Google Colab Use CHGNet with the atomate2 phonon workflow based on finite displacements as implemented in Phonopy to calculate phonon density of states and band structure for Si (mp-149).
Elastic tensor + bulk/shear modulus Open in Google Colab Use CHGNet with the atomate2 elastic workflow based on a stress-strain approach to calculate elastic tensor and derived bulk and shear modulus for Si (mp-149).

Installation

bash
pip install chgnet

if PyPI installation fails or you need the latest main branch commits, you can install from source:

bash
pip install git+https://github.com/CederGroupHub/chgnet

CHGNet runs on CPU, NVIDIA GPUs (CUDA), Intel GPUs (XPU) and Apple silicon (MPS). The device is picked automatically and can be overridden per call with use_device=... or globally with the CHGNET_DEVICE environment variable.

Tutorials and Docs

See the sciML webinar tutorial on 2023-11-02 and API docs.

Usage

Available Pretrained Models

CHGNet provides several pretrained models for different use cases:

python
from chgnet.model.model import CHGNet

# Load the latest CHGNet model (default: 0.3.0)
chgnet = CHGNet.load()
# Load specific CHGNet versions
chgnet = CHGNet.load(model_name='r2scan')

Model Details:

  • '0.3.0' (default): MPtrj-pretrained CHGNet
  • '0.2.0' : Deprecated MPtrj version for backward compatibility with NMI paper
  • 'r2scan' : R2SCAN level model transfer learned from MP-R2SCAN dataset

Besides these checkpoints, we also have new CHGNet implementation and checkpoints based on the MatPES dataset available in the MatGL repo. The MatPES trained model are expected to be significantly better than MPtrj trained models in non-ground-state calculations like Molecular Dynamics.

Direct Inference (Static Calculation)

Pretrained CHGNet can predict the energy (eV/atom), force (eV/A), stress (GPa) and magmom ($\mu_B$) of a given structure.

python
from chgnet.model.model import CHGNet
from pymatgen.core import Structure

chgnet = CHGNet.load()
structure = Structure.from_file('examples/mp-18767-LiMnO2.cif')
prediction = chgnet.predict_structure(structure)

for key, unit in [
    ("energy", "eV/atom"),
    ("forces", "eV/A"),
    ("stress", "GPa"),
    ("magmom", "mu_B"),
]:
    print(f"CHGNet-predicted {key} ({unit}):\n{prediction[key[0]]}\n")

Molecular Dynamics

Charge-informed molecular dynamics can be simulated with pretrained CHGNet through ASE python interface (see below), or through LAMMPS.

…

The MD defaults to the available accelerator (CUDA, then Intel XPU), to manually set the device to cpu, cuda, xpu or mps: MolecularDynamics(use_device='cpu'). The device can also be set globally with the CHGNET_DEVICE environment variable.

MD outputs are saved to the ASE trajectory file, to visualize the MD trajectory and magnetic moments after the MD run:

python
from ase.io.trajectory import Trajectory
from pymatgen.io.ase import AseAtomsAdaptor
from chgnet.utils import solve_charge_by_mag

traj = Trajectory("md_out.traj")
mag = traj[-1].get_magnetic_moments()

# get the non-charge-decorated structure
structure = AseAtomsAdaptor.get_structure(traj[-1])
print(structure)

# get the charge-decorated structure
struct_with_chg = solve_charge_by_mag(structure)
print(struct_with_chg)

To manipulate the MD trajectory, convert to other data formats, calculate mean square displacement, etc, please refer to ASE trajectory documentation.

Structure Optimization

CHGNet can perform fast structure optimization and provide site-wise magnetic moments. This makes it ideal for pre-relaxation and MAGMOM initialization in spin-polarized DFT.

python
from chgnet.model import StructOptimizer

relaxer = StructOptimizer()
result = relaxer.relax(structure)
print("CHGNet relaxed structure", result["final_structure"])
print("relaxed total energy in eV:", result['trajectory'].energies[-1])

Available Weights

CHGNet 0.3.0 is released with new pretrained weights! (release date: 10/22/23)

CHGNet.load() now loads 0.3.0 by default, previous 0.2.0 version can be loaded with CHGNet.load('0.2.0')

  • CHGNet_0.3.0
  • CHGNet_0.2.0

Model Training / Fine-tune

Fine-tuning will help achieve better accuracy if a high-precision study is desired. To train/tune a CHGNet, you need to define your data in a pytorch Dataset object. The example datasets are provided in data/dataset.py

…

Notes for Training

Check fine-tuning example notebook

  1. The target quantity used for training should be energy/atom (not total energy) if you're fine-tuning the pretrained CHGNet.
  2. The pretrained dataset of CHGNet comes from GGA+U DFT with MaterialsProject2020Compatibility corrections applied. The parameter for VASP is described in MPRelaxSet. If you're fine-tuning with MPRelaxSet, it is recommended to apply the MP2020 compatibility to your energy labels so that they're consistent with the pretrained dataset.
  3. If you're fine-tuning to functionals other than GGA, we recommend you refit the AtomRef.
  4. CHGNet stress is in units of GPa, and the unit conversion has already been included in dataset.py. So VASP stress can be directly fed to StructureData
  5. To save time from graph

Issues· 4 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Pythonatomistic-simulationscharge-distributioncharge-transportcomputational-materials-science

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
CategoryDevOps
PricingOpen source

> Related tools

D
Docker
容器化平台,标准化应用交付
G
GitHub Actions
GitHub 原生 CI/CD 工作流
N
Nginx
高性能 Web 服务器与反向代理