Skip to main content

Pretrained Universal Neural Network Potential for Charge-informed Atomistic Modeling

Reason this release was yanked:

inconsistent with github release: https://github.com/CederGroupHub/chgnet/issues/125#issuecomment-1967859266

Project description

CHGNet

Tests Codacy Badge arXiv GitHub repo size PyPI Docs

A pretrained universal neural network potential for charge-informed atomistic modeling Logo Crystal Hamiltonian Graph neural Network is pretrained on the GGA/GGA+U static and relaxation trajectories from Materials Project, a comprehensive dataset consisting of 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 SOTA performance on materials stability prediction from unrelaxed structures according to Matbench Discovery [repo].

Example notebooks

Notebooks Links       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 that visualizes atom positions, energies and forces of a structure during CHGNet relaxation.

Installation

You can install chgnet through pip:

pip install chgnet

Docs

View API docs.

Usage

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.

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 in ("energy", "forces", "stress", "magmom"):
    print(f"CHGNet-predicted {key}={prediction[key[0]]}\n")

Molecular Dynamics

Charge-informed molecular dynamics can be simulated with pretrained CHGNet through ASE environment

from chgnet.model.model import CHGNet
from chgnet.model.dynamics import MolecularDynamics
from pymatgen.core import Structure
import warnings
warnings.filterwarnings("ignore", module="pymatgen")
warnings.filterwarnings("ignore", module="ase")

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

md = MolecularDynamics(
    atoms=structure,
    model=chgnet,
    ensemble="nvt",
    temperature=1000,  # in K
    timestep=2,  # in femto-seconds
    trajectory="md_out.traj",
    logfile="md_out.log",
    loginterval=100,
    use_device="cpu",  # use 'cuda' for faster MD
)
md.run(50)  # run a 0.1 ps MD simulation

Visualize the magnetic moments after the MD run

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)

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.

from chgnet.model import StructOptimizer

relaxer = StructOptimizer()
result = relaxer.relax(structure)
print("CHGNet relaxed structure", result["final_structure"])

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

from chgnet.data.dataset import StructureData, get_train_val_test_loader
from chgnet.trainer import Trainer

dataset = StructureData(
    structures=list_of_structures,
    energies=list_of_energies,
    forces=list_of_forces,
    stresses=list_of_stresses,
    magmoms=list_of_magmoms,
)
train_loader, val_loader, test_loader = get_train_val_test_loader(
    dataset, batch_size=32, train_ratio=0.9, val_ratio=0.05
)
trainer = Trainer(
    model=chgnet,
    targets="efsm",
    optimizer="Adam",
    criterion="MSE",
    learning_rate=1e-2,
    epochs=50,
    use_device="cuda",
)

trainer.train(train_loader, val_loader, test_loader)

Note

  1. The energy used for training should be energy/atom if you're fine-tuning the pretrained CHGNet.
  2. The pretrained dataset of CHGNet comes from GGA+U DFT with MaterialsProject2020Compatibility. 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 unit 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 conversion step for each training, we recommend you use GraphData defined in dataset.py, which reads graphs directly from saved directory. To create saved graphs, see examples/make_graphs.py.
  6. Apple’s Metal Performance Shaders MPS is currently disabled until a stable version of pytorch for MPS is released.

Reference

link to our paper: https://doi.org/10.48550/arXiv.2302.14231

Please cite the following:

@article{deng_2023_chgnet,
  title={{CHGNet: Pretrained universal neural network potential for charge-informed atomistic modeling}},
  author={Deng, Bowen and Zhong, Peichen and Jun, KyuJung and Riebesell, Janosh and Han, Kevin and Bartel, Christopher J and Ceder, Gerbrand},
  journal={arXiv preprint arXiv:2302.14231},
  year={2023},
  url = {https://arxiv.org/abs/2302.14231}
}

Development & Bugs

CHGNet is under active development, if you encounter any bugs in installation and usage, please open an issue. We appreciate your contributions!

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

chgnet-0.2.0.tar.gz (4.3 MB view hashes)

Uploaded Source

Built Distributions

chgnet-0.2.0-py3-none-any.whl (4.3 MB view hashes)

Uploaded Python 3

chgnet-0.2.0-cp311-cp311-win_amd64.whl (4.4 MB view hashes)

Uploaded CPython 3.11 Windows x86-64

chgnet-0.2.0-cp311-cp311-win32.whl (4.4 MB view hashes)

Uploaded CPython 3.11 Windows x86

chgnet-0.2.0-cp311-cp311-musllinux_1_1_x86_64.whl (4.8 MB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.1+ x86-64

chgnet-0.2.0-cp311-cp311-musllinux_1_1_i686.whl (4.8 MB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.1+ i686

chgnet-0.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.8 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

chgnet-0.2.0-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (4.8 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

chgnet-0.2.0-cp311-cp311-macosx_10_9_x86_64.whl (4.4 MB view hashes)

Uploaded CPython 3.11 macOS 10.9+ x86-64

chgnet-0.2.0-cp310-cp310-win_amd64.whl (4.4 MB view hashes)

Uploaded CPython 3.10 Windows x86-64

chgnet-0.2.0-cp310-cp310-win32.whl (4.4 MB view hashes)

Uploaded CPython 3.10 Windows x86

chgnet-0.2.0-cp310-cp310-musllinux_1_1_x86_64.whl (4.8 MB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ x86-64

chgnet-0.2.0-cp310-cp310-musllinux_1_1_i686.whl (4.8 MB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ i686

chgnet-0.2.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.8 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

chgnet-0.2.0-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (4.8 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

chgnet-0.2.0-cp310-cp310-macosx_10_9_x86_64.whl (4.4 MB view hashes)

Uploaded CPython 3.10 macOS 10.9+ x86-64

chgnet-0.2.0-cp39-cp39-win_amd64.whl (4.4 MB view hashes)

Uploaded CPython 3.9 Windows x86-64

chgnet-0.2.0-cp39-cp39-win32.whl (4.4 MB view hashes)

Uploaded CPython 3.9 Windows x86

chgnet-0.2.0-cp39-cp39-musllinux_1_1_x86_64.whl (4.8 MB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.1+ x86-64

chgnet-0.2.0-cp39-cp39-musllinux_1_1_i686.whl (4.8 MB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.1+ i686

chgnet-0.2.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.8 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

chgnet-0.2.0-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (4.8 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

chgnet-0.2.0-cp39-cp39-macosx_10_9_x86_64.whl (4.4 MB view hashes)

Uploaded CPython 3.9 macOS 10.9+ x86-64

Supported by

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