diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index adfd0d9521..4dd07e742f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,7 +3,7 @@ default_language_version: exclude: ^(.github/|tests/test_data/abinit/) repos: - repo: https://github.com/charliermarsh/ruff-pre-commit - rev: v0.3.4 + rev: v0.3.5 hooks: - id: ruff args: [--fix] diff --git a/src/atomate2/abinit/files.py b/src/atomate2/abinit/files.py index b8c7865267..af05b9f94d 100644 --- a/src/atomate2/abinit/files.py +++ b/src/atomate2/abinit/files.py @@ -21,13 +21,6 @@ from atomate2.abinit.sets.base import AbinitInputGenerator -__all__ = [ - "out_to_in", - "fname2ext", - "load_abinit_input", - "write_abinit_input_set", -] - logger = logging.getLogger(__name__) diff --git a/src/atomate2/abinit/jobs/core.py b/src/atomate2/abinit/jobs/core.py index 1f1ce1b71c..2e1e73d9d6 100644 --- a/src/atomate2/abinit/jobs/core.py +++ b/src/atomate2/abinit/jobs/core.py @@ -34,8 +34,6 @@ logger = logging.getLogger(__name__) -__all__ = ["StaticMaker", "NonSCFMaker", "RelaxMaker"] - @dataclass class StaticMaker(BaseAbinitMaker): diff --git a/src/atomate2/abinit/sets/base.py b/src/atomate2/abinit/sets/base.py index 2897acf1ba..a8f80da0e4 100644 --- a/src/atomate2/abinit/sets/base.py +++ b/src/atomate2/abinit/sets/base.py @@ -43,7 +43,6 @@ from pymatgen.core.structure import Structure -__all__ = ["AbinitInputSet", "AbinitInputGenerator"] logger = logging.getLogger(__name__) @@ -99,7 +98,7 @@ def write_input( zip_inputs=zip_inputs, ) del self.inputs["abinit_input.json"] - indir, outdir, tmpdir = self.set_workdir(workdir=directory) + indir, _outdir, _tmpdir = self.set_workdir(workdir=directory) if self.input_files: out_to_in( @@ -718,7 +717,7 @@ def _get_kpoints( if kconfig.get("line_density"): # handle line density generation kpath = HighSymmKpath(structure, **kconfig.get("kpath_kwargs", {})) - frac_k_points, k_points_labels = kpath.get_kpoints( + frac_k_points, _k_points_labels = kpath.get_kpoints( line_density=kconfig["line_density"], coords_are_cartesian=False ) base_kpoints = KSampling( diff --git a/src/atomate2/abinit/sets/core.py b/src/atomate2/abinit/sets/core.py index 458a02a954..184c6cc673 100644 --- a/src/atomate2/abinit/sets/core.py +++ b/src/atomate2/abinit/sets/core.py @@ -23,14 +23,8 @@ from pymatgen.io.abinit import PseudoTable from pymatgen.io.abinit.abiobjects import KSampling -__all__ = [ - "StaticSetGenerator", - "NonSCFSetGenerator", - "RelaxSetGenerator", -] - -GS_RESTART_FROM_DEPS: tuple = (f"{SCF}|{RELAX}|{MOLECULAR_DYNAMICS}:WFK|DEN",) +GS_RESTART_FROM_DEPS = (f"{SCF}|{RELAX}|{MOLECULAR_DYNAMICS}:WFK|DEN",) @dataclass @@ -123,13 +117,13 @@ def _get_nband(self, prev_outputs: list[str] | None) -> int: f"Should have exactly one previous output. Found {len(abinit_inputs)}" ) previous_abinit_input = next(iter(abinit_inputs.values())) - nband = previous_abinit_input.get( + n_band = previous_abinit_input.get( "nband", previous_abinit_input.structure.num_valence_electrons( previous_abinit_input.pseudos ), ) - return int(np.ceil(nband * self.nbands_factor)) + return int(np.ceil(n_band * self.nbands_factor)) @dataclass @@ -154,7 +148,7 @@ class NonScfWfqInputGenerator(AbinitInputGenerator): calc_type: str = "nscf_wfq" - wfq_tol: dict = field(default_factory=lambda: {"tolwfr": 1.0e-18}) + wfq_tol: dict = field(default_factory=lambda: {"tolwfr": 1e-18}) restart_from_deps: tuple = (f"{NSCF}:WFQ",) prev_outputs_deps: tuple = (f"{SCF}:DEN",) @@ -201,7 +195,7 @@ class RelaxSetGenerator(AbinitInputGenerator): factory: Callable = ion_ioncell_relax_input restart_from_deps: tuple = GS_RESTART_FROM_DEPS relax_cell: bool = True - tolmxf: float = 5.0e-5 + tolmxf: float = 5e-5 def get_abinit_input( self, diff --git a/src/atomate2/common/flows/eos.py b/src/atomate2/common/flows/eos.py index 6dc3d4531d..6248fd8d2f 100644 --- a/src/atomate2/common/flows/eos.py +++ b/src/atomate2/common/flows/eos.py @@ -36,7 +36,7 @@ class CommonEosMaker(Maker): initial_relax_maker : .Maker | None Maker to relax the input structure, defaults to None (no initial relaxation). eos_relax_maker : .Maker - Maker to relax deformationed structures for the EOS fit. + Maker to relax deformed structures for the EOS fit. static_maker : .Maker | None Maker to generate statics after each relaxation, defaults to None. strain : tuple[float] @@ -122,11 +122,11 @@ def make(self, structure: Structure, prev_dir: str | Path = None) -> Flow: if self.initial_relax_maker: # Cell without applied strain already included from relax/equilibrium steps. # Perturb this point (or these points) if included - zero_strain_mask = np.abs(strain_l) < 1.0e-15 + zero_strain_mask = np.abs(strain_l) < 1e-15 if np.any(zero_strain_mask): nzs = len(strain_l[zero_strain_mask]) shift = strain_delta / (nzs + 1.0) * np.linspace(-1.0, 1.0, nzs) - strain_l[np.abs(strain_l) < 1.0e-15] += shift + strain_l[np.abs(strain_l) < 1e-15] += shift deformation_l = [(np.identity(3) * (1.0 + eps)).tolist() for eps in strain_l] @@ -134,7 +134,7 @@ def make(self, structure: Structure, prev_dir: str | Path = None) -> Flow: transformations = apply_strain_to_structure(structure, deformation_l) jobs["utility"] += [transformations] - for idef in range(self.number_of_frames): + for frame_idx in range(self.number_of_frames): if self._store_transformation_information: with contextlib.suppress(Exception): # write details of the transformation to the @@ -144,13 +144,13 @@ def make(self, structure: Structure, prev_dir: str | Path = None) -> Flow: # is automatically converted to a "." in the filename. self.eos_relax_maker.write_additional_data[ "transformations:json" - ] = transformations.output[idef] + ] = transformations.output[frame_idx] relax_job = self.eos_relax_maker.make( - structure=transformations.output[idef].final_structure, + structure=transformations.output[frame_idx].final_structure, prev_dir=prev_dir, ) - relax_job.name += f" deformation {idef}" + relax_job.name += f" deformation {frame_idx}" jobs["relax"].append(relax_job) if self.static_maker: @@ -158,30 +158,32 @@ def make(self, structure: Structure, prev_dir: str | Path = None) -> Flow: structure=relax_job.output.structure, prev_dir=relax_job.output.dir_name, ) - static_job.name += f" {idef}" + static_job.name += f" {frame_idx}" jobs["static"].append(static_job) for key in job_types: - for i in range(len(jobs[key])): - flow_output[key]["energy"].append(jobs[key][i].output.output.energy) - flow_output[key]["volume"].append(jobs[key][i].output.structure.volume) - flow_output[key]["stress"].append(jobs[key][i].output.output.stress) + for idx in range(len(jobs[key])): + output = jobs[key][idx].output.output + flow_output[key]["energy"] += [output.energy] + flow_output[key]["volume"] += [output.structure.volume] + flow_output[key]["stress"] += [output.stress] if self.postprocessor is not None: - if len(jobs["relax"]) < self.postprocessor.min_data_points: + min_points = self.postprocessor.min_data_points + if len(jobs["relax"]) < min_points: raise ValueError( "To perform least squares EOS fit with " - f"{self.postprocessor.__class__}, you must specify " - f"self.number_of_frames >= {self.postprocessor.min_data_points}." + f"{type(self.postprocessor).__name__}, you must specify " + f"self.number_of_frames >= {min_points}." ) - postprocess = self.postprocessor.make(flow_output) - postprocess.name = self.name + " postprocessing" - flow_output = postprocess.output - jobs["utility"] += [postprocess] + post_process = self.postprocessor.make(flow_output) + post_process.name = self.name + " postprocessing" + flow_output = post_process.output + jobs["utility"] += [post_process] - joblist = [] + job_list = [] for key in jobs: - joblist += jobs[key] + job_list += jobs[key] - return Flow(jobs=joblist, output=flow_output, name=self.name) + return Flow(jobs=job_list, output=flow_output, name=self.name) diff --git a/src/atomate2/qchem/sets/base.py b/src/atomate2/qchem/sets/base.py index 9574c5f68b..0c01d9cacd 100644 --- a/src/atomate2/qchem/sets/base.py +++ b/src/atomate2/qchem/sets/base.py @@ -71,7 +71,7 @@ def write_input( for k, v in inputs.items(): if v is not None and (overwrite or not (directory / k).exists()): with zopen(directory / k, "wt") as f: - f.write(v.__str__()) + f.write(str(v)) elif not overwrite and (directory / k).exists(): raise FileExistsError(f"{directory / k} already exists.") diff --git a/src/atomate2/vasp/jobs/eos.py b/src/atomate2/vasp/jobs/eos.py index 95744041b8..ab2ea6b828 100644 --- a/src/atomate2/vasp/jobs/eos.py +++ b/src/atomate2/vasp/jobs/eos.py @@ -51,9 +51,11 @@ if TYPE_CHECKING: from atomate2.vasp.sets.base import VaspInputGenerator -# No prefix, base atomate 2 parameters + +copy_wavecar = lambda: {"additional_vasp_files": ("WAVECAR",)} # noqa: E731 +# No prefix, base atomate 2 parameters @dataclass class EosRelaxMaker(BaseVaspMaker): """ @@ -85,14 +87,10 @@ class EosRelaxMaker(BaseVaspMaker): name: str = "EOS GGA relax" input_set_generator: VaspInputGenerator = field(default_factory=EosSetGenerator) - copy_vasp_kwargs: dict = field( - default_factory=lambda: {"additional_vasp_files": ("WAVECAR",)} - ) + copy_vasp_kwargs: dict = field(default_factory=copy_wavecar) # MPLegacy prefix, legacy MP PBE-GGA - - @dataclass class MPLegacyEosRelaxMaker(BaseVaspMaker): """ @@ -126,9 +124,7 @@ class MPLegacyEosRelaxMaker(BaseVaspMaker): input_set_generator: VaspInputGenerator = field( default_factory=MPLegacyEosRelaxSetGenerator ) - copy_vasp_kwargs: dict = field( - default_factory=lambda: {"additional_vasp_files": ("WAVECAR",)} - ) + copy_vasp_kwargs: dict = field(default_factory=copy_wavecar) @dataclass @@ -164,14 +160,10 @@ class MPLegacyEosStaticMaker(BaseVaspMaker): input_set_generator: VaspInputGenerator = field( default_factory=MPLegacyEosStaticSetGenerator ) - copy_vasp_kwargs: dict = field( - default_factory=lambda: {"additional_vasp_files": ("WAVECAR",)} - ) + copy_vasp_kwargs: dict = field(default_factory=copy_wavecar) # MPGGA prefix, MP PBE-GGA compatible parameters - - @dataclass class MPGGAEosRelaxMaker(BaseVaspMaker): """ @@ -205,9 +197,7 @@ class MPGGAEosRelaxMaker(BaseVaspMaker): input_set_generator: VaspInputGenerator = field( default_factory=MPGGAEosRelaxSetGenerator ) - copy_vasp_kwargs: dict = field( - default_factory=lambda: {"additional_vasp_files": ("WAVECAR",)} - ) + copy_vasp_kwargs: dict = field(default_factory=copy_wavecar) @dataclass @@ -243,14 +233,10 @@ class MPGGAEosStaticMaker(BaseVaspMaker): input_set_generator: VaspInputGenerator = field( default_factory=MPGGAEosStaticSetGenerator ) - copy_vasp_kwargs: dict = field( - default_factory=lambda: {"additional_vasp_files": ("WAVECAR",)} - ) + copy_vasp_kwargs: dict = field(default_factory=copy_wavecar) # MPMetaGGA prefix, MP r2SCAN-meta-GGA compatible - - @dataclass class MPMetaGGAEosPreRelaxMaker(BaseVaspMaker): """ @@ -319,9 +305,7 @@ class MPMetaGGAEosRelaxMaker(BaseVaspMaker): input_set_generator: VaspInputGenerator = field( default_factory=MPMetaGGAEosRelaxSetGenerator ) - copy_vasp_kwargs: dict = field( - default_factory=lambda: {"additional_vasp_files": ("WAVECAR",)} - ) + copy_vasp_kwargs: dict = field(default_factory=copy_wavecar) @dataclass @@ -357,6 +341,4 @@ class MPMetaGGAEosStaticMaker(BaseVaspMaker): input_set_generator: VaspInputGenerator = field( default_factory=MPMetaGGAEosStaticSetGenerator ) - copy_vasp_kwargs: dict = field( - default_factory=lambda: {"additional_vasp_files": ("WAVECAR",)} - ) + copy_vasp_kwargs: dict = field(default_factory=copy_wavecar) diff --git a/src/atomate2/vasp/sets/eos.py b/src/atomate2/vasp/sets/eos.py index 44564928fa..3a5a0e8e7b 100644 --- a/src/atomate2/vasp/sets/eos.py +++ b/src/atomate2/vasp/sets/eos.py @@ -71,7 +71,7 @@ def get_incar_updates( "LCHARG": False, "ISIF": 3, "IBRION": 2, - "EDIFF": 1.0e-6, + "EDIFF": 1e-6, "ENCUT": 680, "ENAUG": 1360, "LREAL": False, @@ -83,8 +83,6 @@ def get_incar_updates( # MPLegacy prefix = MP PBE-GGA compatible with atomate implementation - - @dataclass class MPLegacyEosRelaxSetGenerator(VaspInputGenerator): """Class to generate atomate1-MP-compatible VASP GGA EOS relax input sets.""" @@ -128,7 +126,7 @@ def get_incar_updates( "LCHARG": False, "ISIF": 3, "IBRION": 2, - "EDIFF": 1.0e-6, + "EDIFF": 1e-6, "ENCUT": 600, "LREAL": False, "LWAVE": True, @@ -211,7 +209,7 @@ def get_incar_updates( return { "NSW": 0, "LCHARG": False, - "EDIFF": 1.0e-6, + "EDIFF": 1e-6, "ENCUT": 600, "LREAL": False, "LWAVE": False, @@ -223,8 +221,6 @@ def get_incar_updates( # MPGGA prefix = MP GGA compatible - - @dataclass class MPGGAEosRelaxSetGenerator(VaspInputGenerator): """Class to generate MP-compatible VASP GGA EOS relax input sets.""" @@ -268,7 +264,7 @@ def get_incar_updates( "LCHARG": False, "ISIF": 3, "IBRION": 2, - "EDIFF": 1.0e-6, + "EDIFF": 1e-6, "ALGO": "FAST", "LREAL": False, "LWAVE": True, @@ -322,7 +318,7 @@ def get_incar_updates( "NSW": 0, "LCHARG": False, "IBRION": -1, - "EDIFF": 1.0e-6, + "EDIFF": 1e-6, "ALGO": "NORMAL", "LREAL": False, "LWAVE": False, @@ -334,8 +330,6 @@ def get_incar_updates( # MPMetaGGA prefix = MP r2SCAN meta-GGA compatible - - @dataclass class MPMetaGGAEosStaticSetGenerator(VaspInputGenerator): """Class to generate MP-compatible VASP Meta-GGA static input sets.""" @@ -375,7 +369,7 @@ def get_incar_updates( A dictionary of updates to apply. """ return { - "EDIFF": 1.0e-6, + "EDIFF": 1e-6, "ALGO": "NORMAL", "GGA": None, # unset GGA, shouldn't be set anyway but best be sure "NSW": 0, @@ -447,7 +441,7 @@ def get_incar_updates( "NSW": 99, "ISIF": 3, "IBRION": 2, - "EDIFF": 1.0e-6, + "EDIFF": 1e-6, "LREAL": False, "ISMEAR": 0, "SIGMA": 0.05, @@ -511,7 +505,7 @@ def get_incar_updates( "NSW": 99, "ISIF": 3, "IBRION": 2, - "EDIFF": 1.0e-6, + "EDIFF": 1e-6, "EDIFFG": -0.05, "LREAL": False, "ISMEAR": 0, diff --git a/tests/abinit/jobs/test_base.py b/tests/abinit/jobs/test_base.py index ba3324beb0..7e4c5e7af2 100644 --- a/tests/abinit/jobs/test_base.py +++ b/tests/abinit/jobs/test_base.py @@ -59,10 +59,10 @@ def get_abinit_input( @dataclass class SomeMaker1(BaseAbinitMaker): name: str = "SomeMaker1 calculation" - input_set_generator: SomeAISG1 = field(default_factory=lambda: SomeAISG1()) + input_set_generator: SomeAISG1 = field(default_factory=SomeAISG1) @dataclass class SomeMaker2(BaseAbinitMaker): name: str = "SomeMaker2 calculation" - input_set_generator: SomeAISG2 = field(default_factory=lambda: SomeAISG2()) + input_set_generator: SomeAISG2 = field(default_factory=SomeAISG2) diff --git a/tests/vasp/flows/test_eos.py b/tests/vasp/flows/test_eos.py index 54a63ecb10..d8524d20df 100644 --- a/tests/vasp/flows/test_eos.py +++ b/tests/vasp/flows/test_eos.py @@ -12,7 +12,7 @@ expected_incar_relax = { "ISIF": 3, "IBRION": 2, - "EDIFF": 1.0e-6, + "EDIFF": 1e-6, "ISMEAR": 0, "SIGMA": 0.05, "LMAXMIX": 6, @@ -61,10 +61,12 @@ def test_mp_eos_double_relax_maker(mock_vasp, clean_dir, vasp_test_dir): for uuid in responses: assert isinstance(responses[uuid][1].output, TaskDoc) - taskdocs = [responses[uuid][1].output for uuid in responses] + task_docs = [responses[uuid][1].output for uuid in responses] # ensure that output structure of first relaxation is fed to second - assert structure_equality(taskdocs[1].input.structure, taskdocs[0].output.structure) + assert structure_equality( + task_docs[1].input.structure, task_docs[0].output.structure + ) assert len(responses) == len(ref_paths) @@ -75,7 +77,7 @@ def test_mp_eos_maker( mock_vasp, clean_dir, vasp_test_dir, - nframes: int = 2, + n_frames: int = 2, linear_strain: tuple = (-0.05, 0.05), ): base_ref_path = "Si_EOS_MP_GGA/" @@ -90,7 +92,7 @@ def test_mp_eos_maker( f"mp-149-PBE-EOS_MP_GGA_relax_{idx + 1}" ) - for idx in range(nframes): + for idx in range(n_frames): ref_paths[f"EOS MP GGA relax deformation {idx}"] = ( f"mp-149-PBE-EOS_Deformation_Relax_{idx}" ) @@ -125,7 +127,7 @@ def test_mp_eos_maker( # cannot perform least-squares fit for four parameters with only 3 data points flow = MPGGAEosMaker( static_maker=static_maker, - number_of_frames=nframes, + number_of_frames=n_frames, linear_strain=linear_strain, postprocessor=PostProcessEosPressure(), _store_transformation_information=False, diff --git a/tests/vasp/jobs/test_eos.py b/tests/vasp/jobs/test_eos.py index c4905bcbce..d66e494372 100644 --- a/tests/vasp/jobs/test_eos.py +++ b/tests/vasp/jobs/test_eos.py @@ -10,7 +10,7 @@ expected_incar_relax = { "ISIF": 3, "IBRION": 2, - "EDIFF": 1.0e-6, + "EDIFF": 1e-6, "ISMEAR": 0, "SIGMA": 0.05, "LMAXMIX": 6,