Registry / ai-ml / chgnet

chgnet

JSON →
library0.4.2pypypi✓ verified 88d ago

CHGNet (Charge-informed Graph Neural Network) is a pretrained universal neural network potential for charge-informed atomistic modeling. Version 0.4.2 supports Python >=3.10 and provides models for energy, forces, stresses, and charge predictions. Released under the CederGroupHub.

pip install chgnet
INSTALL
IMPORT
SIG · CHGNET
C
chgnet
ai-mlpythonv0.4.2
harness data pending
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.
fix
Update 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.
fix
Verify 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.
fix
Consider 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()'.
fix
Use 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.
fix
Use: from chgnet.model import CHGNetCalculator
RuntimeError: Model not loaded. Use CHGNet.load() first.
Trying to instantiate CHGNet directly without loading pretrained weights.
fix
Use chgnet = CHGNet.load() instead of chgnet = CHGNet()
AttributeError: 'Structure' object has no attribute 'get_potential_energy'
CHGNetCalculator not attached to the structure.
fix
Assign 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
Agent activity
49 hits · last 30 days
node
41
Anthropic
1
OpenAI (training)
1
Resources
chgnet — pip install chgnet · libregistry