Install & Compatibility
Where this runs
No compatibility data collected yet for this library.
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
CHGNetCalculator
✓ from chgnet.model import CHGNetCalculator
✗ from chgnet import CHGNetCalculator
CHGNetCalculator is in chgnet.model submodule.
CHGNet
✓ from chgnet.model import CHGNet
✗ from chgnet import CHGNet
CHGNet class is in chgnet.model.
Structure
✓ from pymatgen.core import Structure
Correct import for pymatgen Structure.
Quickstart: Load pretrained CHGNet model, create a pymatgen Structure, and compute energy/forces/magmoms.
from chgnet.model import CHGNet, CHGNetCalculator
from pymatgen.core import Structure
import numpy as np
# Load pretrained model
chgnet = CHGNet.load()
# Create a simple structure (e.g., diamond cubic Si)
lattice = [[0, 2.73, 2.73], [2.73, 0, 2.73], [2.73, 2.73, 0]]
species = ['Si', 'Si']
coords = [[0, 0, 0], [1.365, 1.365, 1.365]]
structure = Structure(lattice, species, coords)
# Create calculator and compute
calculator = CHGNetCalculator(chgnet)
structure.calc = calculator
energy = structure.get_potential_energy()
forces = structure.get_forces()
magmoms = structure.get_magnetic_moments()
print(f"Energy: {energy:.4f} eV")
print(f"Forces: {forces}")
Debug
Known issues
breakingCHGNet version 0.4.0 changed the model directory structure and removed the old 'chgnet.graph' module.fixUpdate imports: use 'chgnet.model' and 'chgnet.data' instead of 'chgnet.graph'.
affects: <=0.3.x to 0.4.x
gotchaThe CHGNetCalculator expects atom positions in Angstroms, not Bohr. Ensure your structure uses Angstrom units.fixVerify that the pymatgen Structure is in Angstroms (default) or convert using structure.scale_lattice().
affects: all
gotchaCHGNet is pretrained primarily for inorganic solids. Use with molecules or organic crystals may yield poor accuracy.fixConsider using a fine-tuned model or a different potential for molecular systems.
affects: all
deprecatedThe 'from chgnet.model import CHGNet' method is deprecated in favor of 'CHGNet.load()'.fixUse CHGNet.load() to instantiate the model.
affects: 0.4.x
Errors
Common errors & fixes
ImportError: cannot import name 'CHGNetCalculator' from 'chgnet'
Incorrect import path; CHGNetCalculator is in chgnet.model.
fixUse: from chgnet.model import CHGNetCalculator
RuntimeError: Model not loaded. Use CHGNet.load() first.
Trying to instantiate CHGNet directly without loading pretrained weights.
fixUse chgnet = CHGNet.load() instead of chgnet = CHGNet()
AttributeError: 'Structure' object has no attribute 'get_potential_energy'
CHGNetCalculator not attached to the structure.
fixAssign calculator: structure.calc = CHGNetCalculator(chgnet)
Upgrade
Version history
0.4.2latest on PyPI · released Sep 22, 2025
Audit
Dependencies
torchrequiredRequired for model inference
pymatgenrequiredStructure object handling
aseoptionalAlternative structure/converter