Skip to content

Commit

Permalink
Replace deprecated ExpCellFilter with FrechetCellFilter (#4105)
Browse files Browse the repository at this point in the history
* `pre-commit migrate-config`

* `pre-commit autoupdate`

* Replace deprecated `ExpCellFilter` with `FrechetCellFilter`

* Fix test for new `FrechetCellFilter`

* `dos2unix`

---------

Co-authored-by: Shyue Ping Ong <[email protected]>
  • Loading branch information
ab5424 and shyuep authored Oct 22, 2024
1 parent e67e0b5 commit 08c1207
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
20 changes: 17 additions & 3 deletions src/pymatgen/core/structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,21 @@ def _relax(
self,
calculator: Literal["M3GNet", "gfn2-xtb"] | Calculator,
relax_cell: bool = True,
optimizer: str | Optimizer = "FIRE",
optimizer: Literal[
"BFGS",
"BFGSLineSearch",
"CellAwareBFGS",
"FIRE",
"FIRE2",
"GPMin",
"GoodOldQuasiNewton",
"LBFGS",
"LBFGSLineSearch",
"MDMin",
"ODE12r",
"QuasiNewton",
]
| Optimizer = "FIRE",
steps: int = 500,
fmax: float = 0.1,
stress_weight: float = 0.01,
Expand Down Expand Up @@ -825,7 +839,7 @@ def _relax(
Structure | Molecule: Relaxed structure or molecule
"""
from ase import optimize
from ase.constraints import ExpCellFilter
from ase.filters import FrechetCellFilter
from ase.io import read
from ase.optimize.optimize import Optimizer

Expand Down Expand Up @@ -874,7 +888,7 @@ def is_ase_optimizer(key):
if relax_cell:
if is_molecule:
raise ValueError("Can't relax cell for a Molecule")
ecf = ExpCellFilter(atoms)
ecf = FrechetCellFilter(atoms)
dyn = opt_class(ecf, **opt_kwargs)
else:
dyn = opt_class(atoms, **opt_kwargs)
Expand Down
2 changes: 1 addition & 1 deletion tests/core/test_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -1785,7 +1785,7 @@ def test_relax_ase_return_traj(self):
assert {*relaxed.calc.results} >= {"energy", "energies", "free_energy"}
assert relaxed.calc.parameters == {"asap_cutoff": False}
assert relaxed.dynamics["optimizer"] == "FIRE"
assert len(traj) == 7
assert len(traj) == 15
assert traj[0] != traj[-1]
os.remove("opt.traj") # fails if file missing

Expand Down

0 comments on commit 08c1207

Please sign in to comment.