Skip to content

Commit b04c43e

Browse files
matthewkunerpre-commit-ci[bot]esoteric-ephemera
authored
Update vasprun.converged_ionic logic when EDIFFG=0, REDO of PR materialsproject#3765 (materialsproject#3783)
* init commit * add back type hints accidentally removed * pre-commit auto-fixes * Fix lobster test --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: esoteric-ephemera <[email protected]>
1 parent 1367746 commit b04c43e

File tree

4 files changed

+25
-3
lines changed

4 files changed

+25
-3
lines changed

pymatgen/io/vasp/outputs.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -609,15 +609,24 @@ def converged_electronic(self) -> bool:
609609
def converged_ionic(self) -> bool:
610610
"""
611611
Returns:
612-
bool: True if ionic step convergence has been reached, i.e. that vasp
612+
bool: True if ionic step convergence has been reached, i.e. VASP
613613
exited before reaching the max ionic steps for a relaxation run.
614-
In case IBRION=0 (MD) True if the max ionic steps are reached.
614+
In case IBRION=0 (MD) or EDIFFG=0, returns True if the max ionic steps are reached.
615615
"""
616616
nsw = self.parameters.get("NSW", 0)
617617
ibrion = self.parameters.get("IBRION", -1 if nsw in (-1, 0) else 0)
618618
if ibrion == 0:
619619
return nsw <= 1 or self.md_n_steps == nsw
620620

621+
# context re EDIFFG: the use case for EDIFFG=0 is to ensure a relaxation runs for
622+
# NSW steps (the non-AIMD way to generate a relaxation trajectory with DFT). In
623+
# that case, user isn't worried about convergence w.r.t. forces or energy. The
624+
# next if statement prevents custodian from trying to correct the calc because
625+
# Vasprun.converged_ionic = False.
626+
ediffg = self.parameters.get("EDIFFG", 1)
627+
if ibrion in {1, 2} and ediffg == 0:
628+
return nsw <= 1 or nsw == len(self.ionic_steps)
629+
621630
return nsw <= 1 or len(self.ionic_steps) < nsw
622631

623632
@property
Binary file not shown.

tests/io/vasp/test_outputs.py

+13
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,19 @@ def test_vasprun_md(self):
7676
assert vasp_run.md_n_steps == 10
7777
assert vasp_run.converged_ionic
7878

79+
def test_vasprun_ediffg_set_to_0(self):
80+
# Test for case where EDIFFG is set to 0. This should pass if all ionic steps
81+
# complete and are electronically converged.
82+
print(list(os.walk(VASP_OUT_DIR)))
83+
vasp_run = Vasprun(f"{VASP_OUT_DIR}/vasprun.ediffg_set_to_0.xml.gz")
84+
assert len(vasp_run.ionic_steps) == 3
85+
assert vasp_run.final_energy == approx(-34.60164204)
86+
assert vasp_run.converged_ionic is True
87+
assert vasp_run.converged_electronic is True
88+
assert vasp_run.converged is True
89+
assert vasp_run.parameters["EDIFFG"] == 0
90+
assert vasp_run.parameters["EDIFF"] == 1e-5
91+
7992
def test_bad_random_seed(self):
8093
vasp_run = Vasprun(f"{VASP_OUT_DIR}/vasprun.bad_random_seed.xml.gz")
8194
assert vasp_run.incar["ISMEAR"] == 0

tests/io/vasp/test_sets.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1960,7 +1960,7 @@ def test_potcar(self):
19601960
assert self.lobsterset2.potcar.symbols == ["Fe_pv", "P", "O"]
19611961
# test if error raised contains correct potcar symbol for K element as PBE_54 set
19621962
with pytest.raises(
1963-
OSError, match="You do not have the right POTCAR with functional='PBE_54' and symbol='K_sv'"
1963+
RuntimeError, match="You do not have the right POTCAR with functional='PBE_54' and symbol='K_sv'"
19641964
):
19651965
_ = self.lobsterset9.potcar.symbols
19661966

0 commit comments

Comments
 (0)