Skip to content

Commit

Permalink
Treatment for spglib v2.5.0 DeprecationWarning
Browse files Browse the repository at this point in the history
  • Loading branch information
atztogo committed Sep 10, 2024
1 parent 659ceec commit 2bdcc05
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 15 deletions.
25 changes: 14 additions & 11 deletions seekpath/hpkot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ def get_path(
eval_expr,
eval_expr_simple,
get_cell_params,
get_dot_access_dataset,
get_path_data,
get_reciprocal_cell_rows,
get_real_cell_from_reciprocal_rows,
Expand All @@ -162,22 +163,24 @@ def get_path(

# Symmetry analysis by SPGlib, get crystallographic lattice,
# and cell parameters for this lattice
dataset = spglib.get_symmetry_dataset(
structure_internal, symprec=symprec, angle_tolerance=angle_tolerance
dataset = get_dot_access_dataset(
spglib.get_symmetry_dataset(
structure_internal, symprec=symprec, angle_tolerance=angle_tolerance
)
)
if dataset is None:
raise SymmetryDetectionError(
"Spglib could not detect the symmetry of the system"
)
conv_lattice = dataset["std_lattice"]
conv_positions = dataset["std_positions"]
conv_types = dataset["std_types"]
conv_lattice = dataset.std_lattice
conv_positions = dataset.std_positions
conv_types = dataset.std_types
a, b, c, cosalpha, cosbeta, cosgamma = get_cell_params(conv_lattice)
spgrp_num = dataset["number"]
spgrp_num = dataset.number
# This is the transformation from the original to the crystallographic
# conventional (called std in spglib)
# Lattice^{crystallographic_bravais} = L^{original} * transf_matrix
transf_matrix = dataset["transformation_matrix"]
transf_matrix = dataset.transformation_matrix
volume_conv_wrt_original = np.linalg.det(transf_matrix)

# Get the properties of the spacegroup, needed to get the bravais_lattice
Expand Down Expand Up @@ -431,7 +434,7 @@ def get_path(
else:
raise ValueError(
"Unknown type '{}' for spacegroup {}".format(
bravais_lattice, dataset["number"]
bravais_lattice, dataset.number
)
)

Expand Down Expand Up @@ -515,7 +518,7 @@ def get_path(
#'transformation_matrix': transf_matrix,
"volume_original_wrt_conv": volume_conv_wrt_original,
"volume_original_wrt_prim": volume_conv_wrt_original * np.linalg.det(invP),
"spacegroup_number": dataset["number"],
"spacegroup_international": dataset["international"],
"rotation_matrix": dataset["std_rotation_matrix"],
"spacegroup_number": dataset.number,
"spacegroup_international": dataset.international,
"rotation_matrix": dataset.std_rotation_matrix,
}
9 changes: 5 additions & 4 deletions seekpath/hpkot/spg_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,14 @@ def get_spgroup_data_realtime():
"""
import json
import spglib
from .tools import get_dot_access_dataset

info = {}
for hall_n in range(1, 531):
data = spglib.get_spacegroup_type(hall_n)
number = data["number"]
int_short = data["international_short"]
pg_int = data["pointgroup_international"]
data = get_dot_access_dataset(spglib.get_spacegroup_type(hall_n))
number = data.number
int_short = data.international_short
pg_int = data.pointgroup_international

if number not in info:
info[int(number)] = (
Expand Down
30 changes: 30 additions & 0 deletions seekpath/hpkot/tools.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Various utilities."""

import numpy
import numpy.linalg
from math import sqrt
Expand Down Expand Up @@ -252,6 +253,35 @@ def check_spglib_version():
return spglib


def get_dot_access_dataset(dataset):
"""Return dataset with dot access.
From spglib 2.5, dataset is returned as dataclass.
To emulate it for older versions, this function is used.
"""
import spglib

try:
version = spglib.__version__
except NameError:
version = "1.8.0" # or older, version was introduced only recently

version_pieces = tuple(int(v) for v in version.split(".")[:3])
try:
if len(version_pieces) < 3:
raise ValueError
except ValueError:
raise ValueError("Unable to parse version number")

if version_pieces < (2, 5, 0):
from types import SimpleNamespace

return SimpleNamespace(**dataset)
else:
return dataset


def get_cell_params(cell):
r"""
Return (a,b,c,cosalpha,cosbeta,cosgamma) given a :math:`3\times 3` cell
Expand Down

0 comments on commit 2bdcc05

Please sign in to comment.