From 1659eda8f309db9a5e10e1ba6eea55a2ef7a91c2 Mon Sep 17 00:00:00 2001 From: Edan Bainglass Date: Thu, 16 Jan 2025 16:09:01 +0000 Subject: [PATCH] Add guards on null active eigenvalues --- .../configuration/advanced/hubbard/hubbard.py | 6 ++++-- .../configuration/advanced/hubbard/model.py | 19 +++++++++++-------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/aiidalab_qe/app/configuration/advanced/hubbard/hubbard.py b/src/aiidalab_qe/app/configuration/advanced/hubbard/hubbard.py index 9170e9e81..b7dce95a1 100644 --- a/src/aiidalab_qe/app/configuration/advanced/hubbard/hubbard.py +++ b/src/aiidalab_qe/app/configuration/advanced/hubbard/hubbard.py @@ -39,10 +39,12 @@ def render(self): ) self.eigenvalues_help = ipw.HTML(""" -
+
For transition metals and lanthanoids, the starting eigenvalues can be defined (magnetic calculation).
- It is useful to suggest the desired orbital occupations when the default choice takes another path. + It is useful to suggest the desired orbital occupations when the default choice takes another path. +
+ To do so, tick the checkbox below and set the desired eigenvalues to a value other than -1 (unset).
""") self.define_eigenvalues_checkbox = ipw.Checkbox( diff --git a/src/aiidalab_qe/app/configuration/advanced/hubbard/model.py b/src/aiidalab_qe/app/configuration/advanced/hubbard/model.py index 12672457e..7d9768816 100644 --- a/src/aiidalab_qe/app/configuration/advanced/hubbard/model.py +++ b/src/aiidalab_qe/app/configuration/advanced/hubbard/model.py @@ -66,15 +66,18 @@ def update(self, specific=""): # noqa: ARG002 self.needs_eigenvalues_widget = len(self.applicable_kind_names) > 0 def get_active_eigenvalues(self): - active_eigenvalues = [ - orbital_eigenvalue - for element_eigenvalues in self.eigenvalues - for spin_row in element_eigenvalues - for orbital_eigenvalue in spin_row - if orbital_eigenvalue[-1] != -1 - ] + if not ( + active_eigenvalues := [ + orbital_eigenvalue + for element_eigenvalues in self.eigenvalues + for spin_row in element_eigenvalues + for orbital_eigenvalue in spin_row + if orbital_eigenvalue[-1] != -1 + ] + ): + return [] eigenvalues_array = np.array(active_eigenvalues, dtype=object) - new_shape = (np.prod(eigenvalues_array.shape[:-1]), 4) + new_shape = (int(np.prod(eigenvalues_array.shape[:-1])), 4) return eigenvalues_array.reshape(new_shape).tolist() def set_active_eigenvalues(self, eigenvalues: list):