From 55ccc9c59c26b17406f655c637330420a6a6b398 Mon Sep 17 00:00:00 2001 From: acrutt Date: Wed, 27 Jul 2022 10:51:26 -0700 Subject: [PATCH] Avoid error from electrodes that contain redox active species that are not transition metals --- emmet-core/emmet/core/electrode.py | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/emmet-core/emmet/core/electrode.py b/emmet-core/emmet/core/electrode.py index b9b3504f58..a4b8d2b166 100644 --- a/emmet-core/emmet/core/electrode.py +++ b/emmet-core/emmet/core/electrode.py @@ -289,19 +289,22 @@ def from_entries( # Check if more than one working ion per transition metal and warn warnings = [] - transition_metal_fraction = sum( - [ - discharge_comp.get_atomic_fraction(element) - for element in discharge_comp - if element.is_transition_metal - ] - ) - if ( - discharge_comp.get_atomic_fraction(working_ion_ele) - / transition_metal_fraction - > 1.0 - ): - warnings.append("More than one working ion per transition metal") + if any([element.is_transition_metal for element in discharge_comp]): + transition_metal_fraction = sum( + [ + discharge_comp.get_atomic_fraction(element) + for element in discharge_comp + if element.is_transition_metal + ] + ) + if ( + discharge_comp.get_atomic_fraction(working_ion_ele) + / transition_metal_fraction + > 1.0 + ): + warnings.append("More than one working ion per transition metal") + else: + warnings.append("Transition metal not found") return cls( battery_id=battery_id,