Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HubbardStructureData reach by StructureBrowserWidget #718

Merged
merged 19 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
424d822
HubbardStructureData reach by StructureBrowserWidget
AndresOrtegaGuerrero May 3, 2024
13835eb
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 3, 2024
1d657e4
modification of qe_app wc
AndresOrtegaGuerrero May 3, 2024
ede7fdd
Merge branch 'mod/structure_browser_widget' of https://github.com/aii…
AndresOrtegaGuerrero May 3, 2024
d202567
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 3, 2024
95f8731
set U values from HubbardStructure data
AndresOrtegaGuerrero May 3, 2024
ccbf3f3
Merge branch 'mod/structure_browser_widget' of https://github.com/aii…
AndresOrtegaGuerrero May 3, 2024
ce5b74c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 3, 2024
154c95b
if hubbard parameters are the same, keep the same structure
AndresOrtegaGuerrero May 3, 2024
c0108b0
use func name as set_parameters_from_hubbardstructure
AndresOrtegaGuerrero May 3, 2024
28be809
allowing override to set the U values for HubbardStructureData
AndresOrtegaGuerrero May 3, 2024
0fd4c7e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 3, 2024
4623da7
modification of logic
AndresOrtegaGuerrero May 3, 2024
242a02d
Merge branch 'mod/structure_browser_widget' of https://github.com/aii…
AndresOrtegaGuerrero May 3, 2024
3e1466e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 3, 2024
6e85b6b
moving logic up
AndresOrtegaGuerrero May 3, 2024
e61af72
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 3, 2024
2894624
simply logic
AndresOrtegaGuerrero May 3, 2024
5885b06
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/aiidalab_qe/app/configuration/advanced.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from aiidalab_qe.common.panel import Panel
from aiidalab_qe.common.setup_pseudos import PseudoFamily
from aiidalab_qe.common.widgets import HubbardWidget

from aiida_quantumespresso.data.hubbard_structure import HubbardStructureData
from .pseudos import PseudoFamilySelector, PseudoSetter


Expand Down Expand Up @@ -285,9 +285,12 @@ def _update_input_structure(self, change):
self._update_settings_from_protocol(self.protocol)
self._display_mesh()
self.hubbard_widget.update_widgets(change["new"])
if isinstance(self.input_structure, HubbardStructureData):
self.override.value = True
else:
self.magnetization.input_structure = None
self.pseudo_setter.structure = None
self.hubbard_widget.update_widgets(None)

@tl.observe("electronic_type")
def _electronic_type_changed(self, change):
Expand Down
10 changes: 9 additions & 1 deletion src/aiidalab_qe/app/structure/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

from aiidalab_qe.app.utils import get_entry_items
from aiidalab_qe.common import AddingTagsEditor
from aiida_quantumespresso.data.hubbard_structure import HubbardStructureData

# The Examples list of (name, file) tuple curretly passed to
# StructureExamplesWidget.
Expand Down Expand Up @@ -53,7 +54,14 @@ def __init__(self, description=None, **kwargs):
importers = [
StructureUploadWidget(title="Upload file"),
OptimadeQueryWidget(embedded=False),
StructureBrowserWidget(title="AiiDA database"),
StructureBrowserWidget(
title="AiiDA database",
query_types=(
aiida.orm.StructureData,
aiida.orm.CifData,
HubbardStructureData,
),
),
StructureExamplesWidget(title="From Examples", examples=Examples),
]
# add plugin specific structure importers
Expand Down
2 changes: 1 addition & 1 deletion src/aiidalab_qe/app/submission/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ def _update_process_label(self) -> dict:
return ""
formula = self.input_structure.get_formula()
properties = [
p for p in self.input_parameters["workchain"]["properties"] if p != "realx"
p for p in self.input_parameters["workchain"]["properties"] if p != "relax"
]
relax_type = self.input_parameters["workchain"].get("relax_type")
if relax_type != "none":
Expand Down
19 changes: 18 additions & 1 deletion src/aiidalab_qe/common/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
)
from IPython.display import HTML, Javascript, clear_output, display
from pymatgen.core.periodic_table import Element
from aiida_quantumespresso.data.hubbard_structure import HubbardStructureData


__all__ = [
"CalcJobOutputFollower",
Expand Down Expand Up @@ -1130,6 +1132,20 @@ def update_widgets(self, change):
clear_output()
display(self.eigen_values_widget)

if isinstance(self.input_structure, HubbardStructureData):
self.set_parameters_from_hubbardstructure(self.input_structure)

def set_parameters_from_hubbardstructure(self, hubbard_structure):
hubbard_parameters = hubbard_structure.hubbard.dict()["parameters"]
parameters = {
f"{hubbard_structure.sites[item['atom_index']].kind_name} - {item['atom_manifold']}": item[
"value"
]
for item in hubbard_parameters
}
self.set_hubbard_widget(parameters)
self.activate_hubbard.value = True

def toggle_hubbard_widgets(self, change):
"""
Toggle the visibility of the Hubbard widgets based on the value of check box.
Expand Down Expand Up @@ -1251,13 +1267,14 @@ def reset(self):
"""Reset the widget."""
self.activate_hubbard.value = False
self.eigenvalues_label.value = False
self.input_structure = None
self.hubbard_widget = self.create_hubbard_widget()
self.eigen_values_widget = self.create_eigenvalues_widget()
with self.hubbard_widget_out:
clear_output()
with self.eigen_values_widget_out:
clear_output()
if isinstance(self.input_structure, HubbardStructureData):
self.set_parameters_from_hubbardstructure(self.input_structure)

@property
def hubbard_dict(self) -> dict:
Expand Down
18 changes: 15 additions & 3 deletions src/aiidalab_qe/workflows/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,22 @@ def get_builder_from_protocol(
hubbard_type="U",
use_kinds=True,
)
hubbard_structure.store()
builder.structure = hubbard_structure
if hubbard_structure.hubbard == structure.hubbard:
builder.structure = structure
else:
hubbard_structure.store()
builder.structure = hubbard_structure
Copy link
Member

@superstar54 superstar54 May 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Raise error when structure is a normal StructureData, which doesn't have hubbard. I think you don't need check the hubbard here, because you need to use the newly created hubbard_structure.

Suggested change
if hubbard_structure.hubbard == structure.hubbard:
builder.structure = structure
else:
hubbard_structure.store()
builder.structure = hubbard_structure
hubbard_structure.store()
builder.structure = hubbard_structure


# No Hubbard parameters specified
else:
builder.structure = structure
# If using a HubbardStructureData create a new StructureData
if isinstance(structure, HubbardStructureData):
temp_structure = structure.get_ase()
new_structure = StructureData(ase=temp_structure)
new_structure.store()
builder.structure = new_structure
else:
builder.structure = structure
# relax
relax_overrides = {
"base": parameters["advanced"],
Expand Down
Loading