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

unexpected relaxation steps #32

Closed Tinaatucsd closed 1 year ago

Tinaatucsd commented 1 year ago

I encountered an unexpected situation.

I am trying to use CHGNET for static calculations and compare the energy with DFT values. However, when I set steps=0, the relaxation process continues indefinitely, without being limited by the default 500 steps:

from chgnet.model import StructOptimizer

traj = StructOptimizer().relax(s, steps=0)

This behavior is not what I was expecting.

I wonder if this is intentional.

When I set steps = 1, the output appears as follows:

CrystalGraphConverter initialized with atom_cutoff5, bond_cutoff3
CHGNet initialized with 400438 Parameters, is_intensive=True
      Step     Time          Energy         fmax
*Force-consistent energies used in optimization.
FIRE:    0 21:32:17     -326.627214*       4.2172
FIRE:    1 21:32:17     -324.937722*      45.8358

This output is as expected.

Tinaatucsd commented 1 year ago

if I directly use prediction = chgnet.predict_structure(structure)

The energy is different from the initial step energy when using StructOptimizer().relax(s, steps=1)

janosh commented 1 year ago

That's a bug in ase.

    def run(self, fmax=0.05, steps=None):
        """ call Dynamics.run and keep track of fmax"""
        self.fmax = fmax
        if steps:
            self.max_steps = steps
        return Dynamics.run(self)

bool(0) == false so max_steps is not set when you pass steps=0.

Tinaatucsd commented 1 year ago

Cool! Thanks for the swift explanation!

But how about the second issue?

Two methods return different energies for the same structure.

janosh commented 1 year ago

How different are the energies and are you sure you're passing the same structure? Your variables are called differently (s and structure).

Tinaatucsd commented 1 year ago

Yes, I am sure I am passing the same structure.

Oops, excuse me, I found out the reason.

The relax method output is energy, while predict_structure output is energy per atom, I happen to use the structure with 102 atoms and misread the digit point.

For relaxmethod, here is the output:

  Step     Time          Energy         fmax

Force-consistent energies used in optimization. FIRE: 0 21:55:55 -326.627214 4.2172 FIRE: 1 21:55:55 -324.937722* 45.8358 -326.6272144317627

For predict_structure method

CHGNet-predicted energy=-3.2022275924682617