Skip to content

Commit b1aca43

Browse files
committed
MAINT: Handle division by zero in calculate_debye_integral_n3, update docstrings/comments in plot_vt, and adjust tests (DebyeGruneisen)
1 parent 7297abf commit b1aca43

File tree

2 files changed

+458
-43
lines changed

2 files changed

+458
-43
lines changed

dfttk/debye.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def plot_vt(
113113
type: str,
114114
selected_temperatures: np.ndarray = None,
115115
selected_volumes: np.ndarray = None,
116-
) -> tuple[go.Figure, go.Figure]:
116+
) -> go.Figure:
117117
"""Plots the vibrational Helmholtz energy, entropy, or heat capacity as a function
118118
of temperature or volume.
119119
@@ -131,7 +131,7 @@ def plot_vt(
131131
(n_selected_volumes,). Defaults to None.
132132
133133
Raises:
134-
RuntimeError: If process() has not been called before plot().
134+
RuntimeError: If process() has not been called before plot_vt().
135135
ValueError: The `type` argument is not one of the allowed values.
136136
137137
Returns: Plotly figures as a function of temperature or volume.
@@ -154,7 +154,9 @@ def _nearest_indices(values: np.ndarray, selected: np.ndarray) -> list[int]:
154154
or self.entropies is None
155155
or self.heat_capacities is None
156156
):
157-
raise RuntimeError("DebyeGruneisen.process() must be called before plot().")
157+
raise RuntimeError(
158+
"DebyeGruneisen.process() must be called before plot_vt()."
159+
)
158160

159161
type_map = {
160162
"helmholtz_energy_vs_temperature": (
@@ -306,10 +308,19 @@ def calculate_debye_integral_n3(x_array: np.ndarray) -> np.ndarray:
306308
divided by the temperature. The Debye temperature is fixed for a given volume,
307309
and the temperature is varied.
308310
311+
ValueError: If any value in x_array is zero, since this would lead to division by
312+
zero in the formula.
313+
309314
Returns:
310315
Array of Debye integrals of order 3 corresponding to each value in x_array.
311316
"""
312317

318+
# Raise an error in any elements of x_array has any 0
319+
if np.any(x_array == 0):
320+
raise ValueError(
321+
"x_array must not contain any zero values to avoid division by zero."
322+
)
323+
313324
debye_integrals = np.zeros_like(x_array, dtype=float)
314325
for i, x in enumerate(x_array):
315326
factor = 3.0 / x**3

0 commit comments

Comments
 (0)