Skip to content

Commit

Permalink
Add guards on null active eigenvalues
Browse files Browse the repository at this point in the history
  • Loading branch information
edan-bainglass committed Jan 16, 2025
1 parent 891d378 commit 31dcb93
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 14 deletions.
6 changes: 4 additions & 2 deletions src/aiidalab_qe/app/configuration/advanced/hubbard/hubbard.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@ def render(self):
)

self.eigenvalues_help = ipw.HTML("""
<div style="line-height: 1.4; margin-bottom: 5px;">
<div style="line-height: 1.4; margin: 10px 0 5px;">
For transition metals and lanthanoids, the starting eigenvalues can be defined (magnetic calculation).
<br>
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.
<br>
To do so, tick the checkbox below and set the desired eigenvalues to a value other than -1 (unset).
</div>
""")
self.define_eigenvalues_checkbox = ipw.Checkbox(
Expand Down
24 changes: 15 additions & 9 deletions src/aiidalab_qe/app/configuration/advanced/hubbard/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,22 @@ 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)
return eigenvalues_array.reshape(new_shape).tolist()
new_shape = (int(np.prod(eigenvalues_array.shape[:-1])), 4)
return [
tuple(eigenvalue)
for eigenvalue in eigenvalues_array.reshape(new_shape).tolist()
]

def set_active_eigenvalues(self, eigenvalues: list):
eigenvalues_array = np.array(eigenvalues, dtype=object)
Expand Down
6 changes: 3 additions & 3 deletions tests/configuration/test_advanced.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def test_advanced_hubbard_settings(generate_structure_data):
Co_spin_down_row.children[5].value = "1"

assert model.get_active_eigenvalues() == [
[1, 1, "Co", 1],
[3, 1, "Co", 1],
[5, 1, "Co", 1],
(1, 1, "Co", 1),
(3, 1, "Co", 1),
(5, 1, "Co", 1),
]

0 comments on commit 31dcb93

Please sign in to comment.