Skip to content

Commit

Permalink
Hubbard: change int values of eigenvalues to float (#1178)
Browse files Browse the repository at this point in the history
The values for starting_ns_eigenvalue should be floats, not integers.

Previously, the app had two issues:

It was sending integers instead of floats.
It assigned spin-up as 0 and spin-down as 1, which is not the convention in QE.
Additionally, the test was incorrectly checking spin-down as 1.

This PR updates the values to floats and corrects the tests accordingly.
  • Loading branch information
AndresOrtegaGuerrero authored Feb 21, 2025
1 parent 082185f commit dc1f333
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
14 changes: 7 additions & 7 deletions src/aiidalab_qe/app/configuration/advanced/hubbard/hubbard.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def _build_hubbard_widget(self):
def _build_eigenvalues_widget(self):
def update(index, spin, state, symbol, value):
eigenvalues = [*self._model.eigenvalues]
eigenvalues[index][spin][state] = [state + 1, spin, symbol, value]
eigenvalues[index][spin - 1][state] = [state + 1, spin, symbol, value]
return eigenvalues

children = []
Expand Down Expand Up @@ -178,17 +178,17 @@ def update(index, spin, state, symbol, value):
lambda eigenvalues,
kind_index=kind_index,
state_index=state_index: str(
eigenvalues[kind_index][0][state_index][-1]
int(eigenvalues[kind_index][0][state_index][-1])
),
lambda value,
kind_index=kind_index,
state_index=state_index,
kind_name=kind_name: update(
kind_index,
0,
1,
state_index,
kind_name,
int(value),
float(value),
),
],
)
Expand All @@ -211,17 +211,17 @@ def update(index, spin, state, symbol, value):
lambda eigenvalues,
kind_index=kind_index,
state_index=state_index: str(
eigenvalues[kind_index][1][state_index][-1]
int(eigenvalues[kind_index][1][state_index][-1])
),
lambda value,
kind_index=kind_index,
state_index=state_index,
kind_name=kind_name: update(
kind_index,
1,
2,
state_index,
kind_name,
int(value),
float(value),
),
],
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def _define_default_eigenvalues(self):
[state + 1, spin, kind_name, -1] # default eigenvalue
for state in range(num_states)
]
for spin in range(2) # spin up and down
for spin in [1, 2] # spin up and down
]
for kind_name, num_states in self.applicable_kind_names # transition metals and lanthanoids
]
Expand Down
13 changes: 10 additions & 3 deletions tests/configuration/test_advanced.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,15 @@ def test_advanced_hubbard_settings(generate_structure_data):
Co_spin_down_row.children[3].value = "1"
Co_spin_down_row.children[5].value = "1"

Co_spin_up_row = Co_eigenvalues.children[0]
Co_spin_up_row.children[1].value = "0"
Co_spin_up_row.children[3].value = "0"
Co_spin_up_row.children[5].value = "0"
assert model.get_active_eigenvalues() == [
(1, 1, "Co", 1),
(3, 1, "Co", 1),
(5, 1, "Co", 1),
(1, 1, "Co", 0.0),
(3, 1, "Co", 0.0),
(5, 1, "Co", 0.0),
(1, 2, "Co", 1.0),
(3, 2, "Co", 1.0),
(5, 2, "Co", 1.0),
]

0 comments on commit dc1f333

Please sign in to comment.