Skip to content

Commit

Permalink
Remove BadPoscarWarning when POSCAR elements set by POTCAR (#3662)
Browse files Browse the repository at this point in the history
* remove BadPoscarWarning when elements set by POTCAR

* ruffin' it (get it?)
  • Loading branch information
esoteric-ephemera committed Feb 29, 2024
1 parent 512813d commit 8fd181b
Show file tree
Hide file tree
Showing 27 changed files with 29 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
1 change: 0 additions & 1 deletion dev_scripts/potcar_scrambler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion pymatgen/analysis/chemenv/utils/scripts_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""This module contains some script utils that are used in the chemenv package."""


from __future__ import annotations

import re
Expand Down
1 change: 0 additions & 1 deletion pymatgen/analysis/ferroelectricity/polarization.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
determine the spontaneous polarization because it serves as a reference point.
"""


from __future__ import annotations

from typing import TYPE_CHECKING
Expand Down
1 change: 0 additions & 1 deletion pymatgen/analysis/functional_groups.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Determine functional groups present in a Molecule."""


from __future__ import annotations

import copy
Expand Down
1 change: 0 additions & 1 deletion pymatgen/analysis/thermochemistry.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""A module to perform experimental thermochemical data analysis."""


from __future__ import annotations

from pymatgen.core.composition import Composition
Expand Down
1 change: 0 additions & 1 deletion pymatgen/apps/battery/plotter.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""This module provides plotting capabilities for battery related applications."""


from __future__ import annotations

import matplotlib.pyplot as plt
Expand Down
1 change: 0 additions & 1 deletion pymatgen/cli/pmg_potcar.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

"""Implementation for `pmg potcar` CLI."""


from __future__ import annotations

import os
Expand Down
1 change: 1 addition & 0 deletions pymatgen/io/aims/outputs.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions pymatgen/io/aims/parsers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""AIMS output parser, taken from ASE with modifications."""

from __future__ import annotations

import gzip
Expand Down
1 change: 1 addition & 0 deletions pymatgen/io/aims/sets/base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Module defining base FHI-aims input set and generator."""

from __future__ import annotations

import copy
Expand Down
1 change: 1 addition & 0 deletions pymatgen/io/aims/sets/bs.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Input sets for band structure calculations."""

from __future__ import annotations

from dataclasses import dataclass
Expand Down
1 change: 1 addition & 0 deletions pymatgen/io/aims/sets/core.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Module defining core FHI-aims input set generators."""

from __future__ import annotations

from dataclasses import dataclass
Expand Down
6 changes: 3 additions & 3 deletions pymatgen/io/cif.py
Original file line number Diff line number Diff line change
Expand Up @@ -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("<sup>", "")
] = 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("<sup>", "")] = (
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])
Expand Down
1 change: 0 additions & 1 deletion pymatgen/io/feff/outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
Currently supports the xmu.dat, ldos.dat output files are for non-spin case.
"""


from __future__ import annotations

import re
Expand Down
7 changes: 4 additions & 3 deletions pymatgen/io/lammps/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
1 change: 0 additions & 1 deletion pymatgen/io/lmto.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
Structure object in the pymatgen.electronic_structure.cohp.py module.
"""


from __future__ import annotations

import re
Expand Down
1 change: 1 addition & 0 deletions pymatgen/io/pwmat/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""This package implements modules for input and output to and from PWmat."""

from __future__ import annotations

from .inputs import AtomConfig
Expand Down
11 changes: 5 additions & 6 deletions pymatgen/io/vasp/inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
6 changes: 2 additions & 4 deletions pymatgen/symmetry/groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
1 change: 0 additions & 1 deletion pymatgen/util/io_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""This module provides utility classes for io operations."""


from __future__ import annotations

import os
Expand Down
1 change: 0 additions & 1 deletion tests/analysis/diffraction/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""TODO: Modify module doc."""


from __future__ import annotations

__author__ = "Shyue Ping Ong"
Expand Down
1 change: 0 additions & 1 deletion tests/apps/borg/test_queen.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Created on Mar 18, 2012."""


from __future__ import annotations

import unittest
Expand Down
7 changes: 5 additions & 2 deletions tests/command_line/test_bader_caller.py
Original file line number Diff line number Diff line change
Expand Up @@ -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="")
1 change: 1 addition & 0 deletions tests/io/aims/test_sets/test_bs_generator.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests the band structure input set generator"""

from __future__ import annotations

from pathlib import Path
Expand Down
1 change: 1 addition & 0 deletions tests/io/aims/test_sets/test_gw_generator.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests the GW input set generator"""

from __future__ import annotations

from pathlib import Path
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""The test of input sets generating from restart information"""

from __future__ import annotations

from pathlib import Path
Expand Down

0 comments on commit 8fd181b

Please sign in to comment.