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

Replace ase ExpCellFilter with FrechetCellFilter in StructOptimizer #101

Merged
merged 7 commits into from
Dec 7, 2023

Conversation

janosh
Copy link
Collaborator

@janosh janosh commented Dec 7, 2023

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

@janosh janosh added fix Bug fix PRs ase Atomic simulation environment relax Structure optimization labels Dec 7, 2023
@janosh janosh enabled auto-merge (squash) December 7, 2023 20:00
@janosh janosh merged commit ff636fa into main Dec 7, 2023
7 checks passed
@janosh janosh deleted the exp-to-frechet-ase-filter branch December 7, 2023 21:07
@lan496
Copy link

lan496 commented Dec 8, 2023

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

janosh commented Dec 8, 2023

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

lan496 commented Dec 8, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ase Atomic simulation environment fix Bug fix PRs relax Structure optimization
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants