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 1659eda
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 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
19 changes: 11 additions & 8 deletions src/aiidalab_qe/app/configuration/advanced/hubbard/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 1659eda

Please sign in to comment.