Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix RuntimeError triggered in CI of downstream packages #3664

Merged
merged 7 commits into from
Mar 1, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ def __init__(
if central_site is None:
raise ValueError("The centroid includes the central site but no central site is given")
total += self.bare_centre
self.centre = total / (np.float_(len(bare_coords)) + 1.0)
self.centre = total / (np.float64(len(bare_coords)) + 1.0)
else:
self.centre = total / np.float_(len(bare_coords))
self.centre = total / np.float64(len(bare_coords))
elif centering_type == "central_site":
if include_central_site_in_centroid:
raise ValueError(
Expand All @@ -138,9 +138,9 @@ def __init__(
if central_site is None:
raise ValueError("The centroid includes the central site but no central site is given")
total += self.bare_centre
self.centre = total / (np.float_(len(bare_coords)) + 1.0)
self.centre = total / (np.float64(len(bare_coords)) + 1.0)
else:
self.centre = total / np.float_(len(bare_coords))
self.centre = total / np.float64(len(bare_coords))
self._bare_coords = self.bare_points_without_centre
self._coords = self._bare_coords - self.centre
self.central_site = self.bare_central_site - self.centre
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -631,12 +631,12 @@ def __init__(self, coefficients, p1=None, p2=None, p3=None):
raise ValueError("Normal vector is equal to 0.0")
if self.normal_vector[non_zeros[0]] < 0.0:
self.normal_vector = -self.normal_vector
dd = -np.float_(coefficients[3]) / norm_v
dd = -np.float64(coefficients[3]) / norm_v
else:
dd = np.float_(coefficients[3]) / norm_v
dd = np.float64(coefficients[3]) / norm_v
self._coefficients = np.array(
[self.normal_vector[0], self.normal_vector[1], self.normal_vector[2], dd],
np.float_,
np.float64,
)
self._crosses_origin = np.isclose(dd, 0.0, atol=1e-7, rtol=0.0)
self.p1 = p1
Expand Down
2 changes: 1 addition & 1 deletion pymatgen/analysis/elasticity/elastic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1080,7 +1080,7 @@ def get_diff_coeff(hvec, n=1):
hvec (1D array-like): sampling stencil
n (int): degree of derivative to find
"""
hvec = np.array(hvec, dtype=np.float_)
hvec = np.array(hvec, dtype=np.float64)
acc = len(hvec)
exp = np.column_stack([np.arange(acc)] * acc)
a = np.vstack([hvec] * acc) ** exp
Expand Down
8 changes: 4 additions & 4 deletions pymatgen/analysis/ewald.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,8 @@ def _calc_recip(self):
"""
n_sites = len(self._struct)
prefactor = 2 * pi / self._vol
e_recip = np.zeros((n_sites, n_sites), dtype=np.float_)
forces = np.zeros((n_sites, 3), dtype=np.float_)
e_recip = np.zeros((n_sites, n_sites), dtype=np.float64)
forces = np.zeros((n_sites, 3), dtype=np.float64)
coords = self._coords
rcp_latt = self._struct.lattice.reciprocal_lattice
recip_nn = rcp_latt.get_points_in_sphere([[0, 0, 0]], [0, 0, 0], self._gmax)
Expand Down Expand Up @@ -363,9 +363,9 @@ def _calc_real_and_point(self):
force_pf = 2 * self._sqrt_eta / sqrt(pi)
coords = self._coords
n_sites = len(self._struct)
e_real = np.empty((n_sites, n_sites), dtype=np.float_)
e_real = np.empty((n_sites, n_sites), dtype=np.float64)

forces = np.zeros((n_sites, 3), dtype=np.float_)
forces = np.zeros((n_sites, 3), dtype=np.float64)

qs = np.array(self._oxi_states)

Expand Down
16 changes: 8 additions & 8 deletions pymatgen/analysis/graphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -654,8 +654,8 @@ def map_indices(grp):
atoms = len(grp) - 1
offset = len(self.structure) - atoms

for i in range(atoms):
grp_map[i] = i + offset
for idx in range(atoms):
grp_map[idx] = idx + offset

return grp_map

Expand Down Expand Up @@ -1011,7 +1011,7 @@ def types_of_coordination_environments(self, anonymous=False):

if anonymous:
mapping = {centre_sp: "A"}
available_letters = [chr(66 + i) for i in range(25)]
available_letters = [chr(66 + idx) for idx in range(25)]
for label in labels:
sp = label[1]
if sp not in mapping:
Expand Down Expand Up @@ -2164,8 +2164,8 @@ def map_indices(grp):
atoms = len(grp) - 1
offset = len(self.molecule) - atoms

for i in range(atoms):
grp_map[i] = i + offset
for idx in range(atoms):
grp_map[idx] = idx + offset

return grp_map

Expand Down Expand Up @@ -2298,9 +2298,9 @@ def replace_group(
sizes[neighbor[2]] = len(nx.descendants(disconnected, neighbor[2]))

keep = max(sizes, key=lambda x: sizes[x])
for i in sizes:
if i != keep:
to_remove.add(i)
for idx in sizes:
if idx != keep:
to_remove.add(idx)

self.remove_nodes(list(to_remove))
self.substitute_group(
Expand Down
24 changes: 12 additions & 12 deletions pymatgen/analysis/interface_reactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,30 +155,30 @@ def get_kinks(self) -> list[tuple[int, float, float, Reaction, float]]:
react_kink = [self._get_reaction(x) for x in x_kink]
num_atoms = [(x * self.comp1.num_atoms + (1 - x) * self.comp2.num_atoms) for x in x_kink]
energy_per_rxt_formula = [
energy_kink[i]
* self._get_elem_amt_in_rxn(react_kink[i])
/ num_atoms[i]
energy_kink[idx]
* self._get_elem_amt_in_rxn(react_kink[idx])
/ num_atoms[idx]
* InterfacialReactivity.EV_TO_KJ_PER_MOL
for i in range(2)
for idx in range(2)
]
else:
for i in reversed(critical_comp):
for idx in reversed(critical_comp):
# Gets mixing ratio x at kinks.
c = self.pd.pd_coords(i)
x = float(np.linalg.norm(c - c2_coord) / np.linalg.norm(c1_coord - c2_coord))
coords = self.pd.pd_coords(idx)
mixing_ratio = float(np.linalg.norm(coords - c2_coord) / np.linalg.norm(c1_coord - c2_coord))
# Modifies mixing ratio in case compositions self.comp1 and
# self.comp2 are not normalized.
x = x * n2 / (n1 + x * (n2 - n1))
n_atoms = x * self.comp1.num_atoms + (1 - x) * self.comp2.num_atoms
mixing_ratio = mixing_ratio * n2 / (n1 + mixing_ratio * (n2 - n1))
n_atoms = mixing_ratio * self.comp1.num_atoms + (1 - mixing_ratio) * self.comp2.num_atoms
# Converts mixing ratio in comp1 - comp2 tie line to that in
# c1 - c2 tie line.
x_converted = self._convert(x, self.factor1, self.factor2)
x_converted = self._convert(mixing_ratio, self.factor1, self.factor2)
x_kink.append(x_converted)
# Gets reaction energy at kinks
normalized_energy = self._get_energy(x)
normalized_energy = self._get_energy(mixing_ratio)
energy_kink.append(normalized_energy)
# Gets balanced reaction at kinks
rxt = self._get_reaction(x)
rxt = self._get_reaction(mixing_ratio)
react_kink.append(rxt)
rxt_energy = normalized_energy * self._get_elem_amt_in_rxn(rxt) / n_atoms
energy_per_rxt_formula.append(rxt_energy * self.EV_TO_KJ_PER_MOL)
Expand Down