From 8fd181bbf312f4a0bfccebbf27b0f954d118947c Mon Sep 17 00:00:00 2001 From: Aaron Kaplan <33381112+esoteric-ephemera@users.noreply.github.com> Date: Thu, 29 Feb 2024 11:49:22 -0800 Subject: [PATCH] Remove BadPoscarWarning when POSCAR elements set by POTCAR (#3662) * remove BadPoscarWarning when elements set by POTCAR * ruffin' it (get it?) --- .pre-commit-config.yaml | 2 +- dev_scripts/potcar_scrambler.py | 1 - pymatgen/analysis/chemenv/utils/scripts_utils.py | 1 - pymatgen/analysis/ferroelectricity/polarization.py | 1 - pymatgen/analysis/functional_groups.py | 1 - pymatgen/analysis/thermochemistry.py | 1 - pymatgen/apps/battery/plotter.py | 1 - pymatgen/cli/pmg_potcar.py | 1 - pymatgen/io/aims/outputs.py | 1 + pymatgen/io/aims/parsers.py | 1 + pymatgen/io/aims/sets/base.py | 1 + pymatgen/io/aims/sets/bs.py | 1 + pymatgen/io/aims/sets/core.py | 1 + pymatgen/io/cif.py | 6 +++--- pymatgen/io/feff/outputs.py | 1 - pymatgen/io/lammps/utils.py | 7 ++++--- pymatgen/io/lmto.py | 1 - pymatgen/io/pwmat/__init__.py | 1 + pymatgen/io/vasp/inputs.py | 11 +++++------ pymatgen/symmetry/groups.py | 6 ++---- pymatgen/util/io_utils.py | 1 - tests/analysis/diffraction/__init__.py | 1 - tests/apps/borg/test_queen.py | 1 - tests/command_line/test_bader_caller.py | 7 +++++-- tests/io/aims/test_sets/test_bs_generator.py | 1 + tests/io/aims/test_sets/test_gw_generator.py | 1 + .../test_static_restart_from_relax_generator.py | 1 + 27 files changed, 29 insertions(+), 31 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 74778b0437d..1ae91e88764 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -8,7 +8,7 @@ ci: repos: - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.2.1 + rev: v0.3.0 hooks: - id: ruff args: [--fix, --unsafe-fixes] diff --git a/dev_scripts/potcar_scrambler.py b/dev_scripts/potcar_scrambler.py index ea9e3777d56..5fe40c3852d 100644 --- a/dev_scripts/potcar_scrambler.py +++ b/dev_scripts/potcar_scrambler.py @@ -15,7 +15,6 @@ class PotcarScrambler: - """ Takes a POTCAR and replaces its values with completely random values Does type matching and attempts precision matching on floats to ensure diff --git a/pymatgen/analysis/chemenv/utils/scripts_utils.py b/pymatgen/analysis/chemenv/utils/scripts_utils.py index 389cd261d2d..c538946d8a8 100644 --- a/pymatgen/analysis/chemenv/utils/scripts_utils.py +++ b/pymatgen/analysis/chemenv/utils/scripts_utils.py @@ -1,6 +1,5 @@ """This module contains some script utils that are used in the chemenv package.""" - from __future__ import annotations import re diff --git a/pymatgen/analysis/ferroelectricity/polarization.py b/pymatgen/analysis/ferroelectricity/polarization.py index 49fd7ef478d..349fc133827 100644 --- a/pymatgen/analysis/ferroelectricity/polarization.py +++ b/pymatgen/analysis/ferroelectricity/polarization.py @@ -43,7 +43,6 @@ determine the spontaneous polarization because it serves as a reference point. """ - from __future__ import annotations from typing import TYPE_CHECKING diff --git a/pymatgen/analysis/functional_groups.py b/pymatgen/analysis/functional_groups.py index a92b4c2f5aa..7242d13aa78 100644 --- a/pymatgen/analysis/functional_groups.py +++ b/pymatgen/analysis/functional_groups.py @@ -1,6 +1,5 @@ """Determine functional groups present in a Molecule.""" - from __future__ import annotations import copy diff --git a/pymatgen/analysis/thermochemistry.py b/pymatgen/analysis/thermochemistry.py index b467aea3351..0dd3eb8a6a9 100644 --- a/pymatgen/analysis/thermochemistry.py +++ b/pymatgen/analysis/thermochemistry.py @@ -1,6 +1,5 @@ """A module to perform experimental thermochemical data analysis.""" - from __future__ import annotations from pymatgen.core.composition import Composition diff --git a/pymatgen/apps/battery/plotter.py b/pymatgen/apps/battery/plotter.py index 30330697a87..8d77aeac0d2 100644 --- a/pymatgen/apps/battery/plotter.py +++ b/pymatgen/apps/battery/plotter.py @@ -1,6 +1,5 @@ """This module provides plotting capabilities for battery related applications.""" - from __future__ import annotations import matplotlib.pyplot as plt diff --git a/pymatgen/cli/pmg_potcar.py b/pymatgen/cli/pmg_potcar.py index b49e4d2da6a..66398ed62b1 100755 --- a/pymatgen/cli/pmg_potcar.py +++ b/pymatgen/cli/pmg_potcar.py @@ -2,7 +2,6 @@ """Implementation for `pmg potcar` CLI.""" - from __future__ import annotations import os diff --git a/pymatgen/io/aims/outputs.py b/pymatgen/io/aims/outputs.py index e9e7f040fcd..b6a189dece7 100644 --- a/pymatgen/io/aims/outputs.py +++ b/pymatgen/io/aims/outputs.py @@ -1,4 +1,5 @@ """A representation of FHI-aims output (based on ASE output parser).""" + from __future__ import annotations from typing import TYPE_CHECKING, Any diff --git a/pymatgen/io/aims/parsers.py b/pymatgen/io/aims/parsers.py index 9884c7c1c00..789f68fd531 100644 --- a/pymatgen/io/aims/parsers.py +++ b/pymatgen/io/aims/parsers.py @@ -1,4 +1,5 @@ """AIMS output parser, taken from ASE with modifications.""" + from __future__ import annotations import gzip diff --git a/pymatgen/io/aims/sets/base.py b/pymatgen/io/aims/sets/base.py index 9b205823d70..df8a8597159 100644 --- a/pymatgen/io/aims/sets/base.py +++ b/pymatgen/io/aims/sets/base.py @@ -1,4 +1,5 @@ """Module defining base FHI-aims input set and generator.""" + from __future__ import annotations import copy diff --git a/pymatgen/io/aims/sets/bs.py b/pymatgen/io/aims/sets/bs.py index ac0ef112bfb..89cab4f0ada 100644 --- a/pymatgen/io/aims/sets/bs.py +++ b/pymatgen/io/aims/sets/bs.py @@ -1,4 +1,5 @@ """Input sets for band structure calculations.""" + from __future__ import annotations from dataclasses import dataclass diff --git a/pymatgen/io/aims/sets/core.py b/pymatgen/io/aims/sets/core.py index 4c74c235439..e1b4880367a 100644 --- a/pymatgen/io/aims/sets/core.py +++ b/pymatgen/io/aims/sets/core.py @@ -1,4 +1,5 @@ """Module defining core FHI-aims input set generators.""" + from __future__ import annotations from dataclasses import dataclass diff --git a/pymatgen/io/cif.py b/pymatgen/io/cif.py index d332a10ef48..0ff60e099d2 100644 --- a/pymatgen/io/cif.py +++ b/pymatgen/io/cif.py @@ -445,9 +445,9 @@ def _sanitize_data(self, data): # Extract element name and its occupancy from the # string, and store it as a # key-value pair in "els_occ". - els_occu[ - str(re.findall(r"\D+", symbol_str_lst[elocc_idx].strip())[1]).replace("", "") - ] = float("0" + re.findall(r"\.?\d+", symbol_str_lst[elocc_idx].strip())[1]) + els_occu[str(re.findall(r"\D+", symbol_str_lst[elocc_idx].strip())[1]).replace("", "")] = ( + float("0" + re.findall(r"\.?\d+", symbol_str_lst[elocc_idx].strip())[1]) + ) x = str2float(data["_atom_site_fract_x"][idx]) y = str2float(data["_atom_site_fract_y"][idx]) diff --git a/pymatgen/io/feff/outputs.py b/pymatgen/io/feff/outputs.py index bc736a1cba0..7895f6c51fd 100644 --- a/pymatgen/io/feff/outputs.py +++ b/pymatgen/io/feff/outputs.py @@ -4,7 +4,6 @@ Currently supports the xmu.dat, ldos.dat output files are for non-spin case. """ - from __future__ import annotations import re diff --git a/pymatgen/io/lammps/utils.py b/pymatgen/io/lammps/utils.py index 53a07c10ba3..808f6cd68d2 100644 --- a/pymatgen/io/lammps/utils.py +++ b/pymatgen/io/lammps/utils.py @@ -309,9 +309,10 @@ def run(self, site_property: str | None = None) -> Molecule: """ with tempfile.TemporaryDirectory() as scratch_dir: self._write_input(input_dir=scratch_dir) - with open(os.path.join(scratch_dir, self.input_file)) as packmol_input, Popen( - self.packmol_bin, stdin=packmol_input, stdout=PIPE, stderr=PIPE - ) as proc: + with ( + open(os.path.join(scratch_dir, self.input_file)) as packmol_input, + Popen(self.packmol_bin, stdin=packmol_input, stdout=PIPE, stderr=PIPE) as proc, + ): stdout, stderr = proc.communicate() output_file = self.control_params["output"] if os.path.isfile(output_file): diff --git a/pymatgen/io/lmto.py b/pymatgen/io/lmto.py index 3c95376f936..89740618824 100644 --- a/pymatgen/io/lmto.py +++ b/pymatgen/io/lmto.py @@ -4,7 +4,6 @@ Structure object in the pymatgen.electronic_structure.cohp.py module. """ - from __future__ import annotations import re diff --git a/pymatgen/io/pwmat/__init__.py b/pymatgen/io/pwmat/__init__.py index 344ed9f9875..01fd80cfadc 100644 --- a/pymatgen/io/pwmat/__init__.py +++ b/pymatgen/io/pwmat/__init__.py @@ -1,4 +1,5 @@ """This package implements modules for input and output to and from PWmat.""" + from __future__ import annotations from .inputs import AtomConfig diff --git a/pymatgen/io/vasp/inputs.py b/pymatgen/io/vasp/inputs.py index f8969a79827..f7d2dbe5a05 100644 --- a/pymatgen/io/vasp/inputs.py +++ b/pymatgen/io/vasp/inputs.py @@ -263,9 +263,6 @@ def from_file(cls, filename, check_for_potcar=True, read_velocities=True, **kwar potcar = Potcar.from_file(sorted(potcars)[0]) names = [sym.split("_")[0] for sym in potcar.symbols] [get_el_sp(n) for n in names] # ensure valid names - warnings.warn( - "Cannot determine elements in POSCAR. Falling back to manual assignment.", BadPoscarWarning - ) except Exception: names = None with zopen(filename, mode="rt") as file: @@ -2714,7 +2711,9 @@ def run_vasp( if not vasp_cmd: raise RuntimeError("You need to supply vasp_cmd or set the PMG_VASP_EXE in .pmgrc.yaml to run VASP.") - with cd(run_dir), open(output_file, mode="w", encoding="utf-8") as stdout_file, open( - err_file, mode="w", encoding="utf-8", buffering=1 - ) as stderr_file: + with ( + cd(run_dir), + open(output_file, mode="w", encoding="utf-8") as stdout_file, + open(err_file, mode="w", encoding="utf-8", buffering=1) as stderr_file, + ): subprocess.check_call(vasp_cmd, stdout=stdout_file, stderr=stderr_file) diff --git a/pymatgen/symmetry/groups.py b/pymatgen/symmetry/groups.py index 4867193c062..8b6b40401b4 100644 --- a/pymatgen/symmetry/groups.py +++ b/pymatgen/symmetry/groups.py @@ -53,12 +53,10 @@ def __hash__(self) -> int: return len(self) @overload - def __getitem__(self, item: int) -> SymmOp: - ... + def __getitem__(self, item: int) -> SymmOp: ... @overload - def __getitem__(self, item: slice) -> Sequence[SymmOp]: - ... + def __getitem__(self, item: slice) -> Sequence[SymmOp]: ... def __getitem__(self, item: int | slice) -> SymmOp | Sequence[SymmOp]: return list(self.symmetry_ops)[item] diff --git a/pymatgen/util/io_utils.py b/pymatgen/util/io_utils.py index f3c839a1cf4..b59e2520727 100644 --- a/pymatgen/util/io_utils.py +++ b/pymatgen/util/io_utils.py @@ -1,6 +1,5 @@ """This module provides utility classes for io operations.""" - from __future__ import annotations import os diff --git a/tests/analysis/diffraction/__init__.py b/tests/analysis/diffraction/__init__.py index 6706a39d634..8303844e475 100644 --- a/tests/analysis/diffraction/__init__.py +++ b/tests/analysis/diffraction/__init__.py @@ -1,6 +1,5 @@ """TODO: Modify module doc.""" - from __future__ import annotations __author__ = "Shyue Ping Ong" diff --git a/tests/apps/borg/test_queen.py b/tests/apps/borg/test_queen.py index c6be59aa7be..1b33c8759b6 100644 --- a/tests/apps/borg/test_queen.py +++ b/tests/apps/borg/test_queen.py @@ -1,6 +1,5 @@ """Created on Mar 18, 2012.""" - from __future__ import annotations import unittest diff --git a/tests/command_line/test_bader_caller.py b/tests/command_line/test_bader_caller.py index 00ca00b3675..1abab791cd4 100644 --- a/tests/command_line/test_bader_caller.py +++ b/tests/command_line/test_bader_caller.py @@ -133,7 +133,10 @@ def test_atom_parsing(self): def test_missing_file_bader_exe_path(self): pytest.skip("doesn't reliably raise RuntimeError") # mock which("bader") to return None so we always fall back to use bader_exe_path - with patch("shutil.which", return_value=None), pytest.raises( - RuntimeError, match="BaderAnalysis requires the executable bader be in the PATH or the full path " + with ( + patch("shutil.which", return_value=None), + pytest.raises( + RuntimeError, match="BaderAnalysis requires the executable bader be in the PATH or the full path " + ), ): BaderAnalysis(chgcar_filename=f"{TEST_FILES_DIR}/CHGCAR.Fe3O4", bader_exe_path="") diff --git a/tests/io/aims/test_sets/test_bs_generator.py b/tests/io/aims/test_sets/test_bs_generator.py index 3a957e0b566..2dfe1e36b53 100644 --- a/tests/io/aims/test_sets/test_bs_generator.py +++ b/tests/io/aims/test_sets/test_bs_generator.py @@ -1,4 +1,5 @@ """Tests the band structure input set generator""" + from __future__ import annotations from pathlib import Path diff --git a/tests/io/aims/test_sets/test_gw_generator.py b/tests/io/aims/test_sets/test_gw_generator.py index 56a215dc039..a1f5fef8cac 100644 --- a/tests/io/aims/test_sets/test_gw_generator.py +++ b/tests/io/aims/test_sets/test_gw_generator.py @@ -1,4 +1,5 @@ """Tests the GW input set generator""" + from __future__ import annotations from pathlib import Path diff --git a/tests/io/aims/test_sets/test_static_restart_from_relax_generator.py b/tests/io/aims/test_sets/test_static_restart_from_relax_generator.py index bfa9623be8e..07d1e0ca295 100644 --- a/tests/io/aims/test_sets/test_static_restart_from_relax_generator.py +++ b/tests/io/aims/test_sets/test_static_restart_from_relax_generator.py @@ -1,4 +1,5 @@ """The test of input sets generating from restart information""" + from __future__ import annotations from pathlib import Path