From a33c5f37aba0f2da7ef03f705a0172534c34ca08 Mon Sep 17 00:00:00 2001 From: Toon Verstraelen Date: Sat, 22 Jun 2024 19:45:30 +0200 Subject: [PATCH] Fix compatibility issues with latest version of dependencies --- .pre-commit-config.yaml | 2 +- src/denspart/adapters/gpaw.py | 8 ++++---- src/denspart/adapters/test/test_horton3.py | 15 +++++---------- 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2003c10..edd5d18 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -25,7 +25,7 @@ repos: hooks: - id: remove-crlf - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.4.9 + rev: v0.4.10 hooks: - id: ruff-format - id: ruff diff --git a/src/denspart/adapters/gpaw.py b/src/denspart/adapters/gpaw.py index 3bfa354..3206352 100644 --- a/src/denspart/adapters/gpaw.py +++ b/src/denspart/adapters/gpaw.py @@ -23,7 +23,7 @@ import numpy as np from ase.units import Bohr from gpaw import restart -from gpaw.utilities import unpack2 +from gpaw.utilities import unpack_density from grid.atomgrid import AtomGrid from grid.onedgrid import OneDGrid from grid.rtransform import HyperbolicRTransform @@ -216,11 +216,11 @@ def get_atomic_grid_data(calc): atom_data = {} if calc.wfs.nspins == 1: - atom_data["dm"] = unpack2(calc.density.D_asp.get(iatom)[0])[order][:, order] + atom_data["dm"] = unpack_density(calc.density.D_asp.get(iatom)[0])[order][:, order] else: # spin-summed and spin-difference atomic density matrices. - dma = unpack2(calc.density.D_asp.get(iatom)[0])[order][:, order] - dmb = unpack2(calc.density.D_asp.get(iatom)[1])[order][:, order] + dma = unpack_density(calc.density.D_asp.get(iatom)[0])[order][:, order] + dmb = unpack_density(calc.density.D_asp.get(iatom)[1])[order][:, order] atom_data["dm"] = dma + dmb atom_data["spindm"] = dma - dmb assert atom_data["dm"].shape == (setup.ni, setup.ni) diff --git a/src/denspart/adapters/test/test_horton3.py b/src/denspart/adapters/test/test_horton3.py index a56f681..846d31c 100644 --- a/src/denspart/adapters/test/test_horton3.py +++ b/src/denspart/adapters/test/test_horton3.py @@ -19,11 +19,10 @@ """Test the input preparation with HORTON3 modules.""" import os -from importlib import resources +from importlib.resources import as_file, files import numpy as np import pytest -from iodata.utils import FileFormatWarning from numpy.testing import assert_allclose from ..horton3 import main @@ -118,12 +117,10 @@ @pytest.mark.parametrize("fn_wfn", FILENAMES) def test_from_horton3_density(fn_wfn, tmpdir): - with resources.path("iodata.test.data", fn_wfn) as fn_full: + with as_file(files("iodata.test.data").joinpath(fn_wfn)) as fn_full: fn_density = os.path.join(tmpdir, "density.npz") - with pytest.warns(None) as record: + with pytest.warns(): main([str(fn_full), fn_density]) - if len(record) == 1: - assert issubclass(record[0].category, FileFormatWarning) assert os.path.isfile(fn_density) data = dict(np.load(fn_density)) @@ -133,12 +130,10 @@ def test_from_horton3_density(fn_wfn, tmpdir): @pytest.mark.parametrize("fn_wfn", ["hf_sto3g.fchk", "water_sto3g_hf_g03.fchk"]) def test_from_horton3_all(fn_wfn, tmpdir): - with resources.path("iodata.test.data", fn_wfn) as fn_full: + with as_file(files("iodata.test.data").joinpath(fn_wfn)) as fn_full: fn_density = os.path.join(tmpdir, "density.npz") - with pytest.warns(None) as record: + with pytest.warns(): main([str(fn_full), fn_density, "-s", "-g", "-o"]) - if len(record) == 1: - assert issubclass(record[0].category, FileFormatWarning) assert os.path.isfile(fn_density) data = dict(np.load(fn_density))