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
220 stars 60 forks source link

Energy jump when bond_graph_len becomes zero #79

Closed PROA200 closed 10 months ago

PROA200 commented 10 months ago

Version

0.2.1

Which OS(es) are you using?

What happened?

When I compute the energy for a series of strained structures using CHGNet, I get a jump in the energy (and stress) when no edges remain in the bond graph (i.e., every pair of atoms is 3.0 A apart). This occurs silently, and I'm expecting the energy/stress to be smooth when the edges are broken. Am I missing something, or is there something wrong here?

Code snippet

import numpy as np
from pymatgen.core import Structure
from chgnet.model import CHGNet
import matplotlib.pyplot as plt

model = CHGNet.load()

distances = []
energies = []

struct = Structure(
    lattice=[
        [3.54216907, 0, 2.04507188],
        [1.18072406, 3.33958984, 2.04507188],
        [0, 0, 4.09014583],
    ],
    species=["Ag", "Br"],
    coords=[[0.0, 0.0, 0.0], [0.5, 0.5, 0.5]],
)

for strain in np.linspace(0, 0.1, 20):
    struct_copy = struct.copy()
    struct_copy.apply_strain(strain)
    distances.append(struct_copy.distance_matrix[0][1])
    energies.append(model.predict_structure(struct_copy)["e"])

plt.plot(distances, energies, "o-")
plt.gca().set(xlabel="Distance (Å)", ylabel="Energy (eV)")
plt.show()

gh-79

Log output

No response

Code of Conduct

BowenD-UCB commented 10 months ago

Hi,

Thanks a lot for reporting this issue, this is indeed a bug that leads to the concerning energy discontinuity in AgBr.

The energy jump becomes a serious issue in the AgBr structure because there exist a enormous sudden increase in the number of BondGraph edges at the discontinuity.

image

And we checked this issue is especially serious in AgBr composition, if we modify the composition the energy discontinuity is much smaller:

image

We will fix this bug and retrain the model, this will be released in the next release

janosh commented 10 months ago

Closed by 1a558ea.

BowenD-UCB commented 10 months ago

Additional notes for users concerned about this issue:

The discontinuity in the potential energy surface will only appear when a structure with a zero bond graph—meaning there are no paired atoms within 3 Å—transforms into a state with a non-zero bond graph (at least one pair of atoms within 3 Å).

This is particularly the case when applying strain to an AgBr structure. In general, especially during molecular dynamics simulations, it is highly unlikely to encounter structures with zero pairs within 3 Å. Therefore, even CHGNet versions <= 0.2.1 should work without issues for most use cases.

BowenD-UCB commented 10 months ago

This issue is now fully resolved: v0.3.0