Skip to content

Commit

Permalink
Merge pull request #599 from materialsproject/fake_run_vasp-incar_exc…
Browse files Browse the repository at this point in the history
…lude

Add keyword `incar_exclude: Sequence[str] = None` to `fake_run_vasp()`
  • Loading branch information
janosh authored Oct 30, 2023
2 parents 472116e + c2ecc3e commit 1249ee0
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 16 deletions.
10 changes: 9 additions & 1 deletion src/atomate2/vasp/flows/matpes.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from jobflow import Flow, Maker

from atomate2.vasp.jobs.matpes import MatPesGGAStaticMaker, MatPesMetaGGAStaticMaker
from atomate2.vasp.sets.matpes import MatPesGGAStaticSetGenerator

if TYPE_CHECKING:
from pathlib import Path
Expand All @@ -37,7 +38,14 @@ class MatPesGGAPlusMetaGGAStaticMaker(Maker):
"""

name: str = "MatPES GGA plus meta-GGA static"
static1: Maker | None = field(default_factory=MatPesGGAStaticMaker)
static1: Maker | None = field(
default_factory=lambda: MatPesGGAStaticMaker(
# write WAVECAR so we can pass as pre-conditioned starting point to static2
input_set_generator=MatPesGGAStaticSetGenerator(
user_incar_settings={"LWAVE": True}
),
)
)
static2: Maker = field(
default_factory=lambda: MatPesMetaGGAStaticMaker(
# could copy CHGCAR from GGA to meta-GGA directory too but is redundant
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ LMAXMIX = 6
LMIXTAU = True
LORBIT = 11
LREAL = False
LWAVE = False
LWAVE = True
NELM = 200
NSW = 0
PREC = Accurate
Expand Down
16 changes: 13 additions & 3 deletions tests/vasp/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ def _run(ref_paths, fake_run_vasp_kwargs=None):
def fake_run_vasp(
ref_path: Path,
incar_settings: Sequence[str] = None,
incar_exclude: Sequence[str] = None,
check_inputs: Sequence[Literal["incar", "kpoints", "poscar", "potcar"]] = _VFILES,
clear_inputs: bool = True,
):
Expand All @@ -140,6 +141,9 @@ def fake_run_vasp(
incar_settings
A list of INCAR settings to check. Defaults to None which checks all settings.
Empty list or tuple means no settings will be checked.
incar_exclude
A list of INCAR settings to exclude from checking. Defaults to None, meaning
no settings will be excluded.
check_inputs
A list of vasp input files to check. Supported options are "incar", "kpoints",
"poscar", "potcar", "wavecar".
Expand All @@ -149,7 +153,7 @@ def fake_run_vasp(
logger.info("Running fake VASP.")

if "incar" in check_inputs:
check_incar(ref_path, incar_settings)
check_incar(ref_path, incar_settings, incar_exclude)

if "kpoints" in check_inputs:
check_kpoints(ref_path)
Expand All @@ -175,12 +179,18 @@ def fake_run_vasp(
logger.info("Generated fake vasp outputs")


def check_incar(ref_path: Path, incar_settings: Sequence[str]):
def check_incar(
ref_path: Path, incar_settings: Sequence[str], incar_exclude: Sequence[str]
) -> None:
user_incar = Incar.from_file("INCAR")
ref_incar_path = ref_path / "inputs" / "INCAR"
ref_incar = Incar.from_file(ref_incar_path)
defaults = {"ISPIN": 1, "ISMEAR": 1, "SIGMA": 0.2}
for key in list(user_incar) if incar_settings is None else incar_settings:

keys_to_check = (
set(user_incar) if incar_settings is None else set(incar_settings)
) - set(incar_exclude or [])
for key in keys_to_check:
user_val = user_incar.get(key, defaults.get(key))
ref_val = ref_incar.get(key, defaults.get(key))
if user_val != ref_val:
Expand Down
4 changes: 4 additions & 0 deletions tests/vasp/flows/test_matpes.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ def test_matpes_gga_plus_meta_gga_static_maker(mock_vasp, clean_dir, vasp_test_d
assert len(flow) == 2
assert [job.name for job in flow] == list(ref_paths)

# make sure first static has LWAVE=True so we can pass its WAVECAR to second static
# as pre-conditioned starting point
assert flow[0].maker.input_set_generator.user_incar_settings["LWAVE"] is True

# ensure flow runs successfully
responses = run_locally(flow, create_folders=True, ensure_success=True)

Expand Down
18 changes: 7 additions & 11 deletions tests/vasp/jobs/test_matpes.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,16 @@ def test_matpes_static_maker_default_values(maker_cls: BaseVaspMaker):

def test_matpes_gga_static_maker(mock_vasp, clean_dir, vasp_test_dir):
# map from job name to directory containing reference input/output files
ref_paths = {"MatPES GGA static": "matpes_pbe_r2scan_flow/pbe_static"}
gga_job_name = "MatPES GGA static"
ref_paths = {gga_job_name: "matpes_pbe_r2scan_flow/pbe_static"}
si_struct = Structure.from_file(
f"{vasp_test_dir}/matpes_pbe_r2scan_flow/pbe_static/inputs/POSCAR"
)

# settings passed to fake_run_vasp; adjust these to check for certain INCAR settings
fake_run_vasp_kwargs = {key: {"incar_settings": []} for key in ref_paths}

mock_vasp(ref_paths, fake_run_vasp_kwargs)
# exclude LWAVE from INCAR checking since it defaults to False in MatPesGGAStatic
# but is overridden to True in the MatPES static flow to speed up SCF convergence
# of 2nd static, but we use the same reference input files in both tests
mock_vasp(ref_paths, {gga_job_name: {"incar_exclude": ["LWAVE"]}})

job = MatPesGGAStaticMaker().make(si_struct)

Expand All @@ -110,12 +111,7 @@ def test_matpes_meta_gga_static_maker(mock_vasp, clean_dir, vasp_test_dir):
f"{vasp_test_dir}/matpes_pbe_r2scan_flow/r2scan_static/inputs/POSCAR"
)

# settings passed to fake_run_vasp; adjust these to check for certain INCAR settings
fake_run_vasp_kwargs = {
key: {"incar_settings": ["GGA", "METAGGA", "ALGO"]} for key in ref_paths
}

mock_vasp(ref_paths, fake_run_vasp_kwargs)
mock_vasp(ref_paths)

job = MatPesMetaGGAStaticMaker().make(si_struct)

Expand Down

0 comments on commit 1249ee0

Please sign in to comment.