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

Add HP plugin #650

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ aiidalab_qe.properties =
xps = aiidalab_qe.plugins.xps:xps
electronic_structure = aiidalab_qe.plugins.electronic_structure:electronic_structure
xas = aiidalab_qe.plugins.xas:xas
hp = aiidalab_qe.plugins.hp:hp

[aiidalab]
title = Quantum ESPRESSO
Expand Down
1 change: 1 addition & 0 deletions src/aiidalab_qe/common/setup_codes.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"pw2wannier90",
"q2r",
"xspectra",
"hp",
)


Expand Down
24 changes: 24 additions & 0 deletions src/aiidalab_qe/plugins/hp/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from aiidalab_qe.common.panel import OutlinePanel
from aiidalab_widgets_base import ComputationalResourcesWidget

from .result import Result
from .workchain import workchain_and_builder


class HpOutline(OutlinePanel):
title = "HP calculation"
help = """"""


hp_code = ComputationalResourcesWidget(
description="hp.x",
default_calc_job_plugin="quantumespresso.hp",
)


hp = {
"outline": HpOutline,
"code": {"hp": hp_code},
"result": Result,
"workchain": workchain_and_builder,
}
67 changes: 67 additions & 0 deletions src/aiidalab_qe/plugins/hp/result.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import ipywidgets as ipw
from aiidalab_qe.common.panel import ResultPanel


class Result(ResultPanel):
title = "Bader Charge"
workchain_labels = ["bader"]

def __init__(self, node=None, **kwargs):
super().__init__(node=node, **kwargs)
self.summary_view = ipw.HTML()

def _update_view(self):
structure = self.node.inputs.bader.structure
bader_charge = self.outputs.bader.bader.bader_charge.get_array("charge")
self._generate_table(structure, bader_charge)
self.children = [
ipw.HBox(
children=[self.summary_view],
layout=ipw.Layout(justify_content="space-between", margin="10px"),
),
]

def _generate_table(self, structure, bader_charge):
# get index and element form AiiDA StructureData
site_index = [site.kind_name for site in structure.sites]

# Start of the HTML string for the table
html_str = """<div class="custom-table" style="padding-top: 0px; padding-bottom: 0px">
<h4>Bader Charge Table</h4>
<style>
.custom-table table, .custom-table th, .custom-table td {
border: 1px solid black;
border-collapse: collapse;
text-align: left;
padding: 8px;
}
.custom-table th, .custom-table td {
min-width: 120px;
word-wrap: break-word;
}
.custom-table table {
width: 100%;
font-size: 0.8em;
}
</style>
<table>
<tr>
<th>Site Index</th>
<th>Element</th>
<th>Bader Charge</th>
</tr>"""

# Add rows to the table based on the bader_charge
for i in range(len(site_index)):
html_str += f"""
<tr>
<td>{i}</td>
<td>{site_index[i]}</td>
<td>{bader_charge[i]:1.3f}</td>
</tr>"""

# Close the table and div tags
html_str += """
</table>
</div>"""
self.summary_view = ipw.HTML(html_str)
68 changes: 68 additions & 0 deletions src/aiidalab_qe/plugins/hp/workchain.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
from aiida_quantumespresso_hp.workflows.hp.main import HpWorkChain


def check_codes(pw_code, hp_code):
"""Check that the codes are installed on the same computer."""
if (
not any(
[
pw_code is None,
hp_code is None,
]
)
and len(
set(
(
pw_code.computer.pk,
hp_code.computer.pk,
)
)
)
!= 1
):
raise ValueError(
"All selected codes must be installed on the same computer. This is because the "
"HP calculations rely on large files that are not retrieved by AiiDA."
)


def get_builder(codes, structure, parameters, **kwargs):
pw_code = codes.get("pw")
hp_code = codes.get("hp")
check_codes(pw_code, hp_code)
protocol = parameters["workchain"]["protocol"]

overrides = {
"parallelize_atoms": True,
"parallelize_qpoints": True,
"hp": {
"hubbard_structure": structure,
"metadata": {
"options": {
"resources": {
"num_machines": 1,
"num_mpiprocs_per_machine": 2,
},
}
},
},
"qpoints_distance": 1000, # to get few q points
}
if hp_code is not None:
builder = HpWorkChain.get_builder_from_protocol(
code=hp_code,
protocol=protocol,
overrides=overrides,
**kwargs,
)
else:
raise ValueError("The hp_code and bader_code are required.")
return builder


workchain_and_builder = {
"workchain": HpWorkChain,
"exclude": ("clean_workdir", "structure", "relax"),
"get_builder": get_builder,
"input_from_ctx": {"hp.parent_folder": "scf_folder"},
}
6 changes: 5 additions & 1 deletion src/aiidalab_qe/workflows/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,8 @@ def inspect_relax(self):
f"PwRelaxWorkChain failed with exit status {workchain.exit_status}"
)
return self.exit_codes.ERROR_SUB_PROCESS_FAILED_RELAX

# save the remote folder so that the next workchain can use it
self.ctx.scf_folder = workchain.outputs.remote_folder
if "output_structure" in workchain.outputs:
self.ctx.current_structure = workchain.outputs.output_structure
self.ctx.current_number_of_bands = (
Expand All @@ -228,6 +229,9 @@ def run_plugin(self):
)
inputs.metadata.call_link_label = name
inputs.structure = self.ctx.current_structure
# set the scf parent folder and other inputs from the context
for key, value in entry_point.get("input_from_ctx", {}).items():
setattr(inputs, key, self.ctx[value])
inputs = prepare_process_inputs(plugin_workchain, inputs)
running = self.submit(plugin_workchain, **inputs)
self.report(f"launching plugin {name} <{running.pk}>")
Expand Down
Loading