CederGroupHub / chgnet

Pretrained universal neural network potential for charge-informed atomistic modeling https://chgnet.lbl.gov
https://doi.org/10.1038/s42256-023-00716-3
Other
226 stars 61 forks source link

CHGNet fails for isolated atoms #35

Closed mhellstr closed 1 year ago

mhellstr commented 1 year ago

If I run a calculation on an isolated atom I get the ValueError below. This issue might happen for example during molecular dynamics.

Example:

from ase import Atoms
from chgnet.model.dynamics import CHGNetCalculator

atoms = Atoms(
    symbols=["H"], 
    positions=[[0., 0., 0.]], 
    cell=[[100.0, 0, 0], [0, 100, 0], [0, 0, 100]]
)
atoms.calc = CHGNetCalculator(use_device="cpu")
print(atoms)
print(atoms.get_potential_energy())

Output:

CHGNet initialized with 400,438 parameters
CHGNet will run on cpu
Atoms(symbols='H', pbc=False, cell=[100.0, 100.0, 100.0], calculator=CHGNetCalculator(...))
Traceback (most recent call last):
  File "./single-atom.py", line 12, in <module>
    print(atoms.get_potential_energy())
  File "/home/hellstrom/ams2023.202.r112966/bin/python3.8/lib/python3.8/site-packages/ase/atoms.py", line 731, in get_potential_energy
    energy = self._calc.get_potential_energy(self)
  File "/home/hellstrom/ams2023.202.r112966/bin/python3.8/lib/python3.8/site-packages/ase/calculators/calculator.py", line 709, in get_potential_energy
    energy = self.get_property('energy', atoms)
  File "/home/hellstrom/ams2023.202.r112966/bin/python3.8/lib/python3.8/site-packages/ase/calculators/calculator.py", line 737, in get_property
    self.calculate(atoms, [name], system_changes)
  File "/home/hellstrom/Work/python/chgnet/model/dynamics.py", line 111, in calculate
    graph = self.model.graph_converter(structure)
  File "/home/hellstrom/.scm/python/AMS2023.2.venv/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1130, in _call_impl
    return forward_call(*input, **kwargs)
  File "/home/hellstrom/Work/python/chgnet/graph/converter.py", line 111, in forward
    raise ValueError(msg)
ValueError: graph_id=None has isolated atom with r_cutoff=5, should be skipped
BowenD-UCB commented 1 year ago

This is a expected error since the system is an isolated H atom, and the pretrained CHGNet can not be used to calculate such scenarios. If you palce two H atoms in the cell less than r_cutoff apart, CHGNet will run with no error.

Note that CHGNet is based on graph neural networks which depend on message passing within 5A cutoff. As a result atoms without any neighbors in 5A will never enter the convolution functions in CHGNet. Another reason is that CHGNet is trained on condensed matter from Materials Project, which doesn't contain isolated-atom phases.

mhellstr commented 1 year ago

I appreciate that, but technically it would be helpful if the code didn't crash and instead the energy for an isolated atom is whatever the atomic reference is (and 0 forces). For example if one wants to calculate atomization energies (of diamond or other materials).

Here is a figure for a dissociation curve of H2, it would be nice to continue the graph to infinity:

image

BowenD-UCB commented 1 year ago

Hi,

Sorry for the late reply. I personally think this will be quite dangerous feature to add. Extending the graph to infinitity might make the graph you showed look nice, but it's really not reliable considering there are certain long range interaction that CHGNet is not able to capture. While CHGNet is a universal potential based on one of the largest crystal database, it is important to decide whether it's reliable to apply to the system of interest. Again, our dataset is mainly based on condensed phases from Materials Project. Systematic benchmark needs to be done for reliable calculation on out-of-distribution tasks, like the long H - H bond you have shown. The error message is added here to avoid such use cases.

janosh commented 1 year ago

Related: https://github.com/materialsvirtuallab/matgl/pull/85 is an active PR and discussion about how to treat isolated atoms.

BowenD-UCB commented 1 year ago

This is now further addressed in: https://github.com/CederGroupHub/chgnet/commit/a96d37a0dddcdd4ee38150aed4d09b7bbd886194