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
215 stars 55 forks source link

Replace ase `ExpCellFilter` with `FrechetCellFilter` in `StructOptimizer` #101

Closed janosh closed 7 months ago

janosh commented 7 months ago

ase's ExpCellFilter.get_forces returns inconsistent gradients with central differences which was fixed in a new FrechetCellFilter added by @lan496 in https://gitlab.com/ase/ase/-/merge_requests/3024. See https://gitlab.com/ase/ase/-/issues/1321 for bug details.

This PR replaces ExpCellFilter with FrechetCellFilter in StructOptimizer.relax().

I see a noticeable improvement in CHGNet phonon predictions for SiO2 from this change alone (everything else kept fixed). That's PBE (minus non-analytical correction) in blue and CHGNet in red.

ExpCellFilter (old)

sio2-chgnet-phonon-exp

FrechetCellFilter (new)

sio2-chgnet-phonon-frechet

lan496 commented 7 months ago

Just out of curiosity, I understand the improvement in the SiO2's phonon band structure (especially around optic modes) comes better relaxed cell. So, do ExpCellFilter and FrechetCellFilter return a something different lattice constants after structural relaxation?

janosh commented 7 months ago

@lan496 Yes, slightly different (and much faster):

from ase.filters import ExpCellFilter, FrechetCellFilter
from pymatgen.core import Structure

from chgnet import ROOT
from chgnet.model import CHGNet, StructOptimizer

relaxer = StructOptimizer()
chgnet = CHGNet.load()

structure = Structure.from_file(f"{ROOT}/examples/mp-18767-LiMnO2.cif")
structure.perturb(0.1)
for ase_filter in (ExpCellFilter, FrechetCellFilter):
    result = relaxer.relax(structure, verbose=False, ase_filter=ase_filter)
    print(
        f"\n{ase_filter.__name__} took {len(result['trajectory'])} steps. Relaxed structure:"
    )
    print(result["final_structure"])
ExpCellFilter took 52 steps. Relaxed structure:
Full Formula (Li2 Mn2 O4)
Reduced Formula: LiMnO2
abc   :   2.872010   4.650813   5.834364
angles:  89.984000  90.166300  89.959166
pbc   :       True       True       True
Sites (8)
  #  SP            a          b         c      magmom
---  ----  ---------  ---------  --------  ----------
  0  Li+    0.466097   0.471908  0.378517  0.00247121
  1  Li+    0.979868   0.970313  0.606578  0.00228718
  2  Mn3+   0.484925   0.498502  0.859377  3.87809
  3  Mn3+   0.984186   0.998235  0.126078  3.87656
  4  O2-    0.483681   0.009578  0.350723  0.0461
  5  O2-   -0.012445   0.497563  0.093668  0.0405012
  6  O2-    0.484366  -0.001507  0.89173   0.0405898
  7  O2-    0.982041   0.509921  0.634653  0.0462106

FrechetCellFilter took 26 steps. Relaxed structure:
Full Formula (Li2 Mn2 O4)
Reduced Formula: LiMnO2
abc   :   2.876522   4.657650   5.839542
angles:  90.012820  90.017011  90.010059
pbc   :       True       True       True
Sites (8)
  #  SP            a          b         c      magmom
---  ----  ---------  ---------  --------  ----------
  0  Li+    0.452761   0.467844  0.381994  0.00225034
  1  Li+    0.976853   0.965974  0.60083   0.0018343
  2  Mn3+   0.487451   0.500263  0.862042  3.87584
  3  Mn3+   0.987112   0.997857  0.123798  3.89048
  4  O2-    0.483031   0.008843  0.349475  0.0478891
  5  O2-   -0.008411   0.502525  0.095111  0.0408283
  6  O2-    0.489891  -7.2e-05   0.890263  0.0426996
  7  O2-    0.984032   0.51128   0.637812  0.0465174
lan496 commented 7 months ago

@janosh Thank you for your detail script. Glad to hear the new filter is working well!