Skip to content

Commit

Permalink
Fix theochem#173 by updating import-resources API
Browse files Browse the repository at this point in the history
This arises from pull-request theochem#174. Rather than using an older
version of import-resources. This fixed the issue to the current
API
  • Loading branch information
Ali-Tehrani committed Aug 3, 2023
1 parent 0f6d0d4 commit ba662cd
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
5 changes: 2 additions & 3 deletions src/grid/angular.py
Expand Up @@ -68,7 +68,7 @@
from bisect import bisect_left

import numpy as np
from importlib_resources import path
from importlib_resources import files

from grid.basegrid import Grid

Expand Down Expand Up @@ -554,8 +554,7 @@ def _load_precomputed_angular_grid(degree: int, size: int, use_spherical: bool):
raise ValueError(f"Given size={size} is not supported, choose from {npoints}")
# load npz file corresponding to the given degree & size
filename = f"{type}_{degree}_{size}.npz"
with path(file_path, filename) as npz_file:
data = np.load(npz_file)
data = np.load(files(file_path).joinpath(filename))
if len(data["weights"]) == 1:
return data["points"], np.ones(len(data["points"])) * data["weights"]
return data["points"], data["weights"]
11 changes: 5 additions & 6 deletions src/grid/atomgrid.py
Expand Up @@ -22,7 +22,7 @@
from typing import Union

import numpy as np
from importlib_resources import path
from importlib_resources import files
from scipy.interpolate import CubicSpline
from scipy.spatial.transform import Rotation as R

Expand Down Expand Up @@ -173,11 +173,10 @@ def from_preset(
center = np.zeros(3, dtype=float) if center is None else np.asarray(center, dtype=float)
cls._input_type_check(rgrid, center)
# load radial points and
with path("grid.data.prune_grid", f"prune_grid_{preset}.npz") as npz_file:
data = np.load(npz_file)
# load predefined_radial sectors and num_of_points in each sectors
rad = data[f"{atnum}_rad"]
npt = data[f"{atnum}_npt"]
data = np.load(files("grid.data.prune_grid").joinpath(f"prune_grid_{preset}.npz"))
# load predefined_radial sectors and num_of_points in each sectors
rad = data[f"{atnum}_rad"]
npt = data[f"{atnum}_npt"]

degs = AngularGrid.convert_angular_sizes_to_degrees(npt, use_spherical)
rad_degs = AtomGrid._find_l_for_rad_list(rgrid.points, rad, degs)
Expand Down
5 changes: 2 additions & 3 deletions src/grid/hirshfeld.py
Expand Up @@ -21,7 +21,7 @@


import numpy as np
from importlib_resources import path
from importlib_resources import files
from scipy.interpolate import CubicSpline


Expand All @@ -34,8 +34,7 @@ def __init__(self):
@staticmethod
def _load_npz_proatom(num):
"""Return radial grid points and neutral density for a given atomic number."""
with path("grid.data.proatoms", f"a{num:03d}.npz") as fname:
data = np.load(fname)
data = np.load(files("grid.data.proatoms").joinpath(f"a{num:03d}.npz"))
return data["r"], data["dn"]

@staticmethod
Expand Down

0 comments on commit ba662cd

Please sign in to comment.