From b3f06c86011e0ed0b1ad627707969574e32637a3 Mon Sep 17 00:00:00 2001 From: Janosh Riebesell Date: Fri, 1 Nov 2024 09:33:09 -0400 Subject: [PATCH 1/5] ruff --- .pre-commit-config.yaml | 6 +++--- src/atomate2/ase/jobs.py | 4 ++-- src/atomate2/ase/md.py | 4 ++-- src/atomate2/common/flows/mpmorph.py | 11 +++++------ src/atomate2/common/jobs/eos.py | 4 ++-- src/atomate2/common/jobs/mpmorph.py | 2 +- src/atomate2/vasp/flows/ferroelectric.py | 3 +-- tests/forcefields/flows/test_mpmorph.py | 2 +- tests/vasp/flows/test_mpmorph.py | 4 ++-- tests/vasp/test_sets.py | 10 +++++----- 10 files changed, 24 insertions(+), 26 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 34d76577e9..6488c348ff 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.6.9 + rev: v0.7.1 hooks: - id: ruff args: [--fix] @@ -17,7 +17,7 @@ repos: - id: end-of-file-fixer - id: trailing-whitespace - repo: https://github.com/asottile/blacken-docs - rev: 1.18.0 + rev: 1.19.1 hooks: - id: blacken-docs additional_dependencies: [black] @@ -30,7 +30,7 @@ repos: - id: rst-directive-colons - id: rst-inline-touching-normal - repo: https://github.com/pre-commit/mirrors-mypy - rev: v1.11.2 + rev: v1.13.0 hooks: - id: mypy files: ^src/ diff --git a/src/atomate2/ase/jobs.py b/src/atomate2/ase/jobs.py index 35cdc9b126..ffeac5c326 100644 --- a/src/atomate2/ase/jobs.py +++ b/src/atomate2/ase/jobs.py @@ -3,7 +3,7 @@ from __future__ import annotations import logging -from abc import ABCMeta, abstractmethod +from abc import ABC, abstractmethod from dataclasses import dataclass, field from typing import TYPE_CHECKING @@ -29,7 +29,7 @@ @dataclass -class AseMaker(Maker, metaclass=ABCMeta): +class AseMaker(Maker, ABC): """ Define basic template of ASE-based jobs. diff --git a/src/atomate2/ase/md.py b/src/atomate2/ase/md.py index 25123f08e0..439e73075a 100644 --- a/src/atomate2/ase/md.py +++ b/src/atomate2/ase/md.py @@ -7,7 +7,7 @@ import os import sys import time -from abc import ABCMeta, abstractmethod +from abc import ABC, abstractmethod from collections.abc import Sequence from dataclasses import dataclass, field from enum import Enum @@ -79,7 +79,7 @@ class DynamicsPresets(Enum): @dataclass -class AseMDMaker(AseMaker, metaclass=ABCMeta): +class AseMDMaker(AseMaker, ABC): """ Perform MD with the Atomic Simulation Environment (ASE). diff --git a/src/atomate2/common/flows/mpmorph.py b/src/atomate2/common/flows/mpmorph.py index 46b04101f6..80f6aa76b9 100644 --- a/src/atomate2/common/flows/mpmorph.py +++ b/src/atomate2/common/flows/mpmorph.py @@ -13,7 +13,7 @@ from __future__ import annotations -from abc import ABCMeta, abstractmethod +from abc import ABC, abstractmethod from dataclasses import dataclass, field from typing import TYPE_CHECKING, Literal @@ -165,9 +165,8 @@ def make( structure=deformed_structures[index].final_structure, prev_dir=None, ) - md_job.name = ( - f"{self.name} {md_job.name} {len(working_outputs['relax']['volume'])+1}" - ) + n_volumes = len(working_outputs["relax"]["volume"]) + 1 + md_job.name = f"{self.name} {md_job.name} {n_volumes}" working_outputs["relax"]["energies"].append(md_job.output.output.energy) working_outputs["relax"]["volume"].append(md_job.output.structure.volume) @@ -186,7 +185,7 @@ def make( @dataclass -class MPMorphMDMaker(Maker, metaclass=ABCMeta): +class MPMorphMDMaker(Maker, ABC): """Base MPMorph flow for amorphous solid equilibration. This flow uses NVT molecular dynamics to: @@ -399,7 +398,7 @@ def make( @dataclass -class SlowQuenchMaker(Maker, metaclass=ABCMeta): +class SlowQuenchMaker(Maker, ABC): """Slow quench from high to low temperature structures. Quenches a provided structure with a molecular dynamics diff --git a/src/atomate2/common/jobs/eos.py b/src/atomate2/common/jobs/eos.py index 1c593a9899..3dd52eedc6 100644 --- a/src/atomate2/common/jobs/eos.py +++ b/src/atomate2/common/jobs/eos.py @@ -2,7 +2,7 @@ from __future__ import annotations -from abc import ABCMeta, abstractmethod +from abc import ABC, abstractmethod from typing import TYPE_CHECKING import numpy as np @@ -23,7 +23,7 @@ from pymatgen.core import Structure -class EOSPostProcessor(MSONable, metaclass=ABCMeta): +class EOSPostProcessor(MSONable, ABC): """ Fit data to an EOS. diff --git a/src/atomate2/common/jobs/mpmorph.py b/src/atomate2/common/jobs/mpmorph.py index 23ea719f18..1f35c184ea 100644 --- a/src/atomate2/common/jobs/mpmorph.py +++ b/src/atomate2/common/jobs/mpmorph.py @@ -261,7 +261,7 @@ def get_entry_from_dict(chem_env: str) -> dict | None: for ielt in range(2, len(composition)): for combo in combinations(composition, ielt): chem_env_key = _get_chem_env_key_from_composition( - Composition({spec: 1 for spec in combo}), + Composition(dict.fromkeys(combo, 1)), ignore_oxi_states=ignore_oxi_states, ) diff --git a/src/atomate2/vasp/flows/ferroelectric.py b/src/atomate2/vasp/flows/ferroelectric.py index 3168d55f76..ce7db46266 100644 --- a/src/atomate2/vasp/flows/ferroelectric.py +++ b/src/atomate2/vasp/flows/ferroelectric.py @@ -125,8 +125,7 @@ def make( add_interp_flow.output, ) - jobs.append(add_interp_flow) - jobs.append(pol_analysis) + jobs += (add_interp_flow, pol_analysis) return Flow( jobs=jobs, diff --git a/tests/forcefields/flows/test_mpmorph.py b/tests/forcefields/flows/test_mpmorph.py index eec87c3e99..4ac6fade09 100644 --- a/tests/forcefields/flows/test_mpmorph.py +++ b/tests/forcefields/flows/test_mpmorph.py @@ -132,7 +132,7 @@ def test_mpmorph_mlff_maker(ff_name, si_structure, test_dir, clean_dir): ) task_docs = {} for uuid, job_name in uuids.items(): - for _i, mp_job_name in enumerate(main_mp_morph_job_names): + for mp_job_name in main_mp_morph_job_names: if mp_job_name in job_name: task_docs[mp_job_name] = response[uuid][1].output break diff --git a/tests/vasp/flows/test_mpmorph.py b/tests/vasp/flows/test_mpmorph.py index 19053bf91f..1de148656c 100644 --- a/tests/vasp/flows/test_mpmorph.py +++ b/tests/vasp/flows/test_mpmorph.py @@ -147,7 +147,7 @@ def test_vasp_mpmorph( assert all( task_docs[ "MP Morph VASP Equilibrium Volume Maker " - f"Convergence MPMorph VASP MD Maker {1+idx}" + f"Convergence MPMorph VASP MD Maker {1 + idx}" ].output.energy == pytest.approx(ref_eos["energy"][idx]) for idx in range(3) @@ -156,7 +156,7 @@ def test_vasp_mpmorph( assert all( task_docs[ "MP Morph VASP Equilibrium Volume Maker " - f"Convergence MPMorph VASP MD Maker {1+idx}" + f"Convergence MPMorph VASP MD Maker {1 + idx}" ].output.structure.volume == pytest.approx(ref_eos["volume"][idx]) for idx in range(3) diff --git a/tests/vasp/test_sets.py b/tests/vasp/test_sets.py index 867562a9d2..1cb3ba33bb 100644 --- a/tests/vasp/test_sets.py +++ b/tests/vasp/test_sets.py @@ -83,13 +83,13 @@ def test_user_incar_settings(): static_set_generator = StaticSetGenerator(user_incar_settings=uis) incar = static_set_generator.get_input_set(structure, potcar_spec=True)["INCAR"] - for key in uis: + for key, val in uis.items(): if isinstance(incar[key], str): - assert incar[key].lower() == uis[key].lower() - elif isinstance(uis[key], dict): - assert incar[key] == [uis[key][str(site.specie)] for site in structure] + assert incar[key].lower() == val.lower() + elif isinstance(val, dict): + assert incar[key] == [val[str(site.specie)] for site in structure] else: - assert incar[key] == uis[key] + assert incar[key] == val @pytest.mark.parametrize( From 8195da810273caf02346542cf7228999626e09a9 Mon Sep 17 00:00:00 2001 From: Janosh Riebesell Date: Fri, 1 Nov 2024 09:38:10 -0400 Subject: [PATCH 2/5] fix PYI063 Use PEP 570 syntax for positional-only arguments --- src/atomate2/ase/schemas.py | 2 +- src/atomate2/forcefields/schemas.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/atomate2/ase/schemas.py b/src/atomate2/ase/schemas.py index 3bce7e443d..2a63ecfefd 100644 --- a/src/atomate2/ase/schemas.py +++ b/src/atomate2/ase/schemas.py @@ -99,7 +99,7 @@ class AseBaseModel(BaseModel): ) molecule: Optional[Molecule] = Field(None, description="The molecule at this step.") - def model_post_init(self, __context: Any) -> None: + def model_post_init(self, context: Any, /) -> None: """Establish alias to structure and molecule fields.""" if self.structure is None and isinstance(self.mol_or_struct, Structure): self.structure = self.mol_or_struct diff --git a/src/atomate2/forcefields/schemas.py b/src/atomate2/forcefields/schemas.py index a66785b8b8..d5a152c7f7 100644 --- a/src/atomate2/forcefields/schemas.py +++ b/src/atomate2/forcefields/schemas.py @@ -22,7 +22,7 @@ class ForcefieldResult(AseResult): None, description="The structure in the final trajectory frame." ) - def model_post_init(self, __context: Any) -> None: + def model_post_init(self, context: Any, /) -> None: """Populate final_structure attr.""" self.final_structure = getattr( self, "final_structure", self.final_mol_or_struct From 0cbf44c8fbc4050144f6ca3ef2d76a7e24e4030b Mon Sep 17 00:00:00 2001 From: Janosh Riebesell Date: Fri, 1 Nov 2024 10:06:14 -0400 Subject: [PATCH 3/5] single source of truth for optional deps in pyproject.toml --- pyproject.toml | 52 ++++++++++++++------------------------------------ 1 file changed, 14 insertions(+), 38 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 9cd0c04f4c..6e34e18d1f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -40,7 +40,7 @@ dependencies = [ [project.optional-dependencies] abinit = ["abipy>=0.9.3"] amset = ["amset>=0.4.15", "pydash"] -cclib = ["cclib"] +cclib = ["cclib>=1.8.1"] mp = ["mp-api>=0.37.5"] phonons = ["phonopy>=1.10.8", "seekpath"] lobster = ["ijson>=3.2.2", "lobsterpy>=0.4.0"] @@ -51,16 +51,26 @@ defects = [ ] forcefields = [ "ase>=3.23.0", - "calorine<=2.2.1", + "calorine>=3.0", "chgnet>=0.2.2", "mace-torch>=0.3.3", - "torchdata<=0.7.1", "matgl>=1.1.3", + "torchdata<=0.7.1", # quippy-ase support for py3.12 tracked in https://github.com/libAtoms/QUIP/issues/645 "quippy-ase>=0.9.14; python_version < '3.12'", "sevenn>=0.9.3", "torchdata<=0.7.1", # TODO: remove when issue fixed ] +strict-forcefields = [ + "calorine==3.0", + "chgnet==0.4.0", + "mace-torch==0.3.7", + "matgl==1.1.3", + "quippy-ase==0.9.14; python_version < '3.12'", + "sevenn==0.10.0", + "torch==2.5.0", + "torchdata==0.7.1", # TODO: remove when issue fixed +] ase = ["ase>=3.23.0"] # tblite py3.12 support tracked in https://github.com/tblite/tblite/issues/198 ase-ext = ["tblite>=0.3.0; python_version < '3.12'"] @@ -92,41 +102,7 @@ tests = [ "pytest==8.3.3", ] strict = [ - "PyYAML==6.0.2", - "ase==3.23.0", - "cclib==1.8.1", - "click==8.1.7", - "custodian==2024.10.16", - "dscribe==2.1.1", - "emmet-core==0.84.2", - "ijson==3.3.0", - "jobflow==0.1.18", - "lobsterpy==0.4.9", - "mdanalysis==2.7.0", - "monty==2024.7.30", - "mp-api==0.42.2", - "numpy", - "openmm-mdanalysis-reporter==0.1.0", - "openmm==8.1.1", - "phonopy==2.27.0", - "pydantic-settings==2.6.0", - "pydantic==2.9.2", - "pymatgen-analysis-defects==2024.7.19", - "pymatgen==2024.10.3", - "python-ulid==3.0.0", - "seekpath==2.1.0", - "tblite==0.3.0; python_version < '3.12'", - "typing-extensions==4.12.2", -] -strict-forcefields = [ - "calorine==3.0", - "chgnet==0.4.0", - "mace-torch>=0.3.6", - "matgl==1.1.3", - "quippy-ase==0.9.14; python_version < '3.12'", - "sevenn==0.10.0", - "torch==2.5.0", - "torchdata==0.7.1", # TODO: remove when issue fixed + "atomate2[forcefields, docs, cclib, defects, lobster, openmm, mp, defects, ase, ase-ext]", ] [project.scripts] From 11c5a283557eb68d4f8e0b9ce4c1a95158406451 Mon Sep 17 00:00:00 2001 From: Janosh Riebesell Date: Fri, 1 Nov 2024 10:10:46 -0400 Subject: [PATCH 4/5] revert to mace-torch==0.3.6, 0.3.7 still unreleased --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 6e34e18d1f..10f7fb84bc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -64,7 +64,7 @@ forcefields = [ strict-forcefields = [ "calorine==3.0", "chgnet==0.4.0", - "mace-torch==0.3.7", + "mace-torch==0.3.6", "matgl==1.1.3", "quippy-ase==0.9.14; python_version < '3.12'", "sevenn==0.10.0", From 7d08efe45edf78c5cec51534e0708b6dc4bd5be6 Mon Sep 17 00:00:00 2001 From: Janosh Riebesell Date: Fri, 1 Nov 2024 10:19:32 -0400 Subject: [PATCH 5/5] fix typo defects -> phonons --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 10f7fb84bc..355916f1fc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -102,7 +102,7 @@ tests = [ "pytest==8.3.3", ] strict = [ - "atomate2[forcefields, docs, cclib, defects, lobster, openmm, mp, defects, ase, ase-ext]", + "atomate2[forcefields, docs, cclib, phonons, lobster, openmm, mp, defects, ase, ase-ext]", ] [project.scripts]