Skip to content

Commit a5ef4b4

Browse files
authored
Minor update to UFloat handling for cases where energy adjustment with std_dev=0 already present (#4406)
1 parent 2298dc6 commit a5ef4b4

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/pymatgen/entries/compatibility.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,9 @@ def get_correction(self, entry: ComputedEntry | ComputedStructureEntry) -> ufloa
288288
if len(comp) == 1: # Skip element entry
289289
return ufloat(0.0, np.nan)
290290

291-
correction = ufloat(0.0, 0.0)
291+
with warnings.catch_warnings():
292+
warnings.filterwarnings("ignore", message="Using UFloat")
293+
correction = ufloat(0.0, 0.0)
292294

293295
# Check for sulfide corrections
294296
if Element("S") in comp:

src/pymatgen/entries/computed_entries.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,9 @@ def correction(self) -> float:
364364
float: the total energy correction / adjustment applied to the entry in eV.
365365
"""
366366
# either sum of adjustments or ufloat with nan std_dev, so that no corrections still result in ufloat object:
367-
corr = sum(ufloat(ea.value, ea.uncertainty) for ea in self.energy_adjustments) or ufloat(0.0, np.nan)
367+
corr = sum(ufloat(ea.value, ea.uncertainty) for ea in self.energy_adjustments if ea.value) or ufloat(
368+
0.0, np.nan
369+
)
368370
return corr.nominal_value
369371

370372
@correction.setter
@@ -388,7 +390,7 @@ def correction_uncertainty(self) -> float:
388390
"""
389391
# either sum of adjustments or ufloat with nan std_dev, so that no corrections still result in ufloat object:
390392
unc = sum(
391-
(ufloat(ea.value, ea.uncertainty) if not np.isnan(ea.uncertainty) else ufloat(ea.value, 0))
393+
(ufloat(ea.value, ea.uncertainty) if not np.isnan(ea.uncertainty) and ea.value else ufloat(ea.value, 0))
392394
for ea in self.energy_adjustments
393395
) or ufloat(0.0, np.nan)
394396

0 commit comments

Comments
 (0)