From bb96f932e06086d67b89b515d431a35723f3906d Mon Sep 17 00:00:00 2001 From: esoteric-ephemera Date: Wed, 10 Jan 2024 14:21:16 -0800 Subject: [PATCH 1/2] Ensure auto_ismear = False for all MP workflows, correct test data, remove dependence on deprecated pkg_resources --- src/atomate2/cp2k/sets/base.py | 6 +++--- src/atomate2/vasp/sets/base.py | 4 ++-- src/atomate2/vasp/sets/matpes.py | 6 +++--- src/atomate2/vasp/sets/mp.py | 14 +++++++++++--- .../vasp/Si_mp_gga_relax/GGA_Relax_1/inputs/INCAR | 4 ++-- .../pbesol_pre_relax/inputs/INCAR | 2 +- .../Si_mp_meta_gga_relax/r2scan_relax/inputs/INCAR | 2 +- tests/vasp/sets/test_mp.py | 2 +- 8 files changed, 24 insertions(+), 16 deletions(-) diff --git a/src/atomate2/cp2k/sets/base.py b/src/atomate2/cp2k/sets/base.py index f6954abc72..870f906a66 100644 --- a/src/atomate2/cp2k/sets/base.py +++ b/src/atomate2/cp2k/sets/base.py @@ -5,13 +5,13 @@ import os from copy import deepcopy from dataclasses import dataclass, field +from importlib.resources import files as get_mod_path from pathlib import Path from typing import Any import numpy as np from monty.io import zopen from monty.serialization import loadfn -from pkg_resources import resource_filename from pymatgen.core.structure import Molecule, Structure from pymatgen.io.core import InputGenerator, InputSet from pymatgen.io.cp2k.inputs import ( @@ -29,8 +29,8 @@ from atomate2 import SETTINGS -_BASE_CP2K_SET = loadfn(resource_filename("atomate2.cp2k.sets", "BaseCp2kSet.yaml")) -_BASE_GAPW_SET = loadfn(resource_filename("atomate2.cp2k.sets", "BaseAllSet.yaml")) +_BASE_CP2K_SET = loadfn(get_mod_path("atomate2.cp2k.sets") / "BaseCp2kSet.yaml") +_BASE_GAPW_SET = loadfn(get_mod_path("atomate2.cp2k.sets") / "BaseAllSet.yaml") class Cp2kInputSet(InputSet): diff --git a/src/atomate2/vasp/sets/base.py b/src/atomate2/vasp/sets/base.py index e3fa21d298..942eda1bfb 100644 --- a/src/atomate2/vasp/sets/base.py +++ b/src/atomate2/vasp/sets/base.py @@ -7,6 +7,7 @@ import warnings from copy import deepcopy from dataclasses import dataclass, field +from importlib.resources import files as get_mod_path from itertools import groupby from pathlib import Path from typing import TYPE_CHECKING, Any @@ -14,7 +15,6 @@ import numpy as np from monty.io import zopen from monty.serialization import loadfn -from pkg_resources import resource_filename from pymatgen.electronic_structure.core import Magmom from pymatgen.io.core import InputGenerator, InputSet from pymatgen.io.vasp import Incar, Kpoints, Outcar, Poscar, Potcar, Vasprun @@ -34,7 +34,7 @@ from pymatgen.core import Structure -_BASE_VASP_SET = loadfn(resource_filename("atomate2.vasp.sets", "BaseVaspSet.yaml")) +_BASE_VASP_SET = loadfn(get_mod_path("atomate2.vasp.sets") / "BaseVaspSet.yaml") class VaspInputSet(InputSet): diff --git a/src/atomate2/vasp/sets/matpes.py b/src/atomate2/vasp/sets/matpes.py index 67dc3410ae..736f72edd3 100644 --- a/src/atomate2/vasp/sets/matpes.py +++ b/src/atomate2/vasp/sets/matpes.py @@ -7,10 +7,10 @@ from __future__ import annotations from dataclasses import dataclass, field +from importlib.resources import files as get_mod_path from typing import TYPE_CHECKING from monty.serialization import loadfn -from pkg_resources import resource_filename from atomate2.vasp.sets.base import VaspInputGenerator @@ -21,10 +21,10 @@ # POTCAR section comes from PARENT but atomate2 does not support inheritance yet _BASE_MATPES_PBE_STATIC_SET_NO_POTCAR = loadfn( - resource_filename("pymatgen.io.vasp", "MatPESStaticSet.yaml") + get_mod_path("pymatgen.io.vasp") / "MatPESStaticSet.yaml" ) _POTCAR_BASE_FILE = f"{_BASE_MATPES_PBE_STATIC_SET_NO_POTCAR['PARENT']}.yaml" -_POTCAR_SET = loadfn(resource_filename("pymatgen.io.vasp", _POTCAR_BASE_FILE)) +_POTCAR_SET = loadfn(get_mod_path("pymatgen.io.vasp") / _POTCAR_BASE_FILE) _BASE_MATPES_PBE_STATIC_SET = {**_POTCAR_SET, **_BASE_MATPES_PBE_STATIC_SET_NO_POTCAR} diff --git a/src/atomate2/vasp/sets/mp.py b/src/atomate2/vasp/sets/mp.py index 3e4abc8a47..8ff1029c6d 100644 --- a/src/atomate2/vasp/sets/mp.py +++ b/src/atomate2/vasp/sets/mp.py @@ -9,10 +9,10 @@ from __future__ import annotations from dataclasses import dataclass, field +from importlib.resources import files as get_mod_path from typing import TYPE_CHECKING from monty.serialization import loadfn -from pkg_resources import resource_filename from atomate2.vasp.sets.core import RelaxSetGenerator, StaticSetGenerator @@ -21,10 +21,10 @@ from pymatgen.io.vasp import Outcar, Vasprun _BASE_MP_GGA_RELAX_SET = loadfn( - resource_filename("atomate2.vasp.sets", "BaseMPGGASet.yaml") + get_mod_path("atomate2.vasp.sets") / "BaseMPGGASet.yaml" ) _BASE_MP_R2SCAN_RELAX_SET = loadfn( - resource_filename("atomate2.vasp.sets", "BaseMPR2SCANRelaxSet.yaml") + get_mod_path("atomate2.vasp.sets") / "BaseMPR2SCANRelaxSet.yaml" ) @@ -33,7 +33,9 @@ class MPGGARelaxSetGenerator(RelaxSetGenerator): """Class to generate MP-compatible VASP GGA relaxation input sets.""" config_dict: dict = field(default_factory=lambda: _BASE_MP_GGA_RELAX_SET) + auto_ismear: bool = False auto_kspacing: bool = True + inherit_incar: bool | None = False @dataclass @@ -41,7 +43,9 @@ class MPGGAStaticSetGenerator(StaticSetGenerator): """Class to generate MP-compatible VASP GGA static input sets.""" config_dict: dict = field(default_factory=lambda: _BASE_MP_GGA_RELAX_SET) + auto_ismear: bool = False auto_kspacing: bool = True + inherit_incar: bool | None = False def get_incar_updates( self, @@ -87,8 +91,10 @@ class MPMetaGGAStaticSetGenerator(StaticSetGenerator): """Class to generate MP-compatible VASP GGA static input sets.""" config_dict: dict = field(default_factory=lambda: _BASE_MP_R2SCAN_RELAX_SET) + auto_ismear: bool = False auto_kspacing: bool = True bandgap_tol: float = 1e-4 + inherit_incar: bool | None = False def get_incar_updates( self, @@ -145,7 +151,9 @@ class MPMetaGGARelaxSetGenerator(RelaxSetGenerator): config_dict: dict = field(default_factory=lambda: _BASE_MP_R2SCAN_RELAX_SET) bandgap_tol: float = 1e-4 + auto_ismear: bool = False auto_kspacing: bool = True + inherit_incar: bool | None = False def get_incar_updates( self, diff --git a/tests/test_data/vasp/Si_mp_gga_relax/GGA_Relax_1/inputs/INCAR b/tests/test_data/vasp/Si_mp_gga_relax/GGA_Relax_1/inputs/INCAR index 8368b4e030..6e1fbb6731 100644 --- a/tests/test_data/vasp/Si_mp_gga_relax/GGA_Relax_1/inputs/INCAR +++ b/tests/test_data/vasp/Si_mp_gga_relax/GGA_Relax_1/inputs/INCAR @@ -3,7 +3,7 @@ EDIFF = 0.0001 ENCUT = 520 IBRION = 2 ISIF = 3 -ISMEAR = 0 +ISMEAR = -5 ISPIN = 2 LASPH = True LORBIT = 11 @@ -14,4 +14,4 @@ MAGMOM = 2*0.6 NELM = 100 NSW = 99 PREC = Accurate -SIGMA = 0.2 +SIGMA = 0.05 diff --git a/tests/test_data/vasp/Si_mp_meta_gga_relax/pbesol_pre_relax/inputs/INCAR b/tests/test_data/vasp/Si_mp_meta_gga_relax/pbesol_pre_relax/inputs/INCAR index f682301652..189d6d470f 100644 --- a/tests/test_data/vasp/Si_mp_meta_gga_relax/pbesol_pre_relax/inputs/INCAR +++ b/tests/test_data/vasp/Si_mp_meta_gga_relax/pbesol_pre_relax/inputs/INCAR @@ -22,4 +22,4 @@ MAGMOM = 2*0.6 NELM = 200 NSW = 99 PREC = Accurate -SIGMA = 0.2 +SIGMA = 0.05 diff --git a/tests/test_data/vasp/Si_mp_meta_gga_relax/r2scan_relax/inputs/INCAR b/tests/test_data/vasp/Si_mp_meta_gga_relax/r2scan_relax/inputs/INCAR index 7a2c6583db..70878e6b66 100644 --- a/tests/test_data/vasp/Si_mp_meta_gga_relax/r2scan_relax/inputs/INCAR +++ b/tests/test_data/vasp/Si_mp_meta_gga_relax/r2scan_relax/inputs/INCAR @@ -5,7 +5,7 @@ ENAUG = 1360.0 ENCUT = 680.0 IBRION = 2 ISIF = 3 -ISMEAR = -5 +ISMEAR = 0 ISPIN = 2 KSPACING = 0.28253269576667883 LAECHG = True diff --git a/tests/vasp/sets/test_mp.py b/tests/vasp/sets/test_mp.py index 086fb7b5c6..709e3e3c15 100644 --- a/tests/vasp/sets/test_mp.py +++ b/tests/vasp/sets/test_mp.py @@ -51,7 +51,7 @@ def test_mp_sets(set_generator: VaspInputGenerator) -> None: else "PBE" ) assert mp_set.inherit_incar is False - assert mp_set.auto_ismear is True + assert mp_set.auto_ismear is False assert mp_set.auto_kspacing is True assert mp_set.force_gamma is True assert mp_set.auto_lreal is False From 3d00f3e5e032c25ac2f1122f76f4558805fb2399 Mon Sep 17 00:00:00 2001 From: esoteric-ephemera Date: Wed, 10 Jan 2024 14:42:50 -0800 Subject: [PATCH 2/2] Add frozen model to forcefield elastic wf test to ensure it doesn't fail in CI when model can't be downloaded --- tests/forcefields/flows/test_elastic.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/tests/forcefields/flows/test_elastic.py b/tests/forcefields/flows/test_elastic.py index 9285a0d1c8..c90b3a72c6 100644 --- a/tests/forcefields/flows/test_elastic.py +++ b/tests/forcefields/flows/test_elastic.py @@ -1,3 +1,5 @@ +from pathlib import Path + from jobflow import run_locally from pymatgen.symmetry.analyzer import SpacegroupAnalyzer @@ -5,16 +7,26 @@ from atomate2.forcefields.flows.elastic import ElasticMaker from atomate2.forcefields.jobs import MACERelaxMaker +_mace_model_path = ( + f"{Path(__file__).parent.parent.parent}/test_data/forcefields/mace/MACE.model" +) + def test_elastic_wf_with_mace(clean_dir, si_structure): si_prim = SpacegroupAnalyzer(si_structure).get_primitive_standard_structure() job = ElasticMaker( bulk_relax_maker=MACERelaxMaker( - relax_cell=True, relax_kwargs={"fmax": 0.00001} + relax_cell=True, + relax_kwargs={"fmax": 0.00001}, + model=_mace_model_path, + model_kwargs={"default_dtype": "float64"}, ), elastic_relax_maker=MACERelaxMaker( - relax_cell=False, relax_kwargs={"fmax": 0.00001} + relax_cell=False, + relax_kwargs={"fmax": 0.00001}, + model=_mace_model_path, + model_kwargs={"default_dtype": "float64"}, ), ).make(si_prim)