Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CHGNet fails for isolated atoms #35

Closed
mhellstr opened this issue Jun 12, 2023 · 5 comments
Closed

CHGNet fails for isolated atoms #35

mhellstr opened this issue Jun 12, 2023 · 5 comments
Labels
invalid This doesn't seem right wontfix This will not be worked on

Comments

@mhellstr
Copy link

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
Copy link
Collaborator

BowenD-UCB commented Jun 12, 2023

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.

@janosh janosh added invalid This doesn't seem right wontfix This will not be worked on labels Jun 13, 2023
@mhellstr
Copy link
Author

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
Copy link
Collaborator

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
Copy link
Collaborator

janosh commented Jun 21, 2023

Related: materialsvirtuallab/matgl#85 is an active PR and discussion about how to treat isolated atoms.

@BowenD-UCB
Copy link
Collaborator

This is now further addressed in:
a96d37a

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This doesn't seem right wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

3 participants