-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8f820e7
commit ef9d5a3
Showing
9 changed files
with
346 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from aiidalab_qe.common.panel import OutlinePanel | ||
from aiidalab_widgets_base import ComputationalResourcesWidget | ||
|
||
from .result import Result | ||
from .workchain import workchain_and_builder | ||
|
||
|
||
class BaderOutline(OutlinePanel): | ||
title = "Bader charge analysis" | ||
help = """""" | ||
|
||
|
||
pp_code = ComputationalResourcesWidget( | ||
description="pp.x", | ||
default_calc_job_plugin="quantumespresso.pp", | ||
) | ||
|
||
bader_code = ComputationalResourcesWidget( | ||
description="bader", | ||
default_calc_job_plugin="bader", | ||
) | ||
|
||
|
||
bader = { | ||
"outline": BaderOutline, | ||
"code": {"pp": pp_code, "bader": bader_code}, | ||
"result": Result, | ||
"workchain": workchain_and_builder, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
from aiida.plugins import WorkflowFactory | ||
from aiida_quantumespresso.common.types import ElectronicType, SpinType | ||
from aiida import orm | ||
|
||
QeBaderWorkChain = WorkflowFactory("bader.qe") | ||
|
||
|
||
def check_codes(pw_code, pp_code, bader_code): | ||
"""Check that the codes are installed on the same computer.""" | ||
if ( | ||
not any( | ||
[ | ||
pw_code is None, | ||
pp_code is None, | ||
bader_code is None, | ||
] | ||
) | ||
and len( | ||
set( | ||
( | ||
pw_code.computer.pk, | ||
pp_code.computer.pk, | ||
bader_code.computer.pk, | ||
) | ||
) | ||
) | ||
!= 1 | ||
): | ||
raise ValueError( | ||
"All selected codes must be installed on the same computer. This is because the " | ||
"Bader calculations rely on large files that are not retrieved by AiiDA." | ||
) | ||
|
||
|
||
def get_builder(codes, structure, parameters, **kwargs): | ||
from copy import deepcopy | ||
|
||
pw_code = codes.get("pw") | ||
pp_code = codes.get("pp") | ||
bader_code = codes.get("bader") | ||
check_codes(pw_code, pp_code, bader_code) | ||
protocol = parameters["workchain"]["protocol"] | ||
|
||
scf_overrides = deepcopy(parameters["advanced"]) | ||
|
||
overrides = { | ||
"scf": scf_overrides, | ||
"pp": { | ||
"parameters": orm.Dict( | ||
{ | ||
"INPUTPP": {"plot_num": 21}, | ||
"PLOT": {"iflag": 3}, | ||
} | ||
), | ||
"metadata": { | ||
"options": { | ||
"resources": { | ||
"num_machines": 1, | ||
"num_mpiprocs_per_machine": 1, | ||
}, | ||
} | ||
}, | ||
}, | ||
} | ||
if pp_code is not None and bader_code is not None: | ||
builder = QeBaderWorkChain.get_builder_from_protocol( | ||
pw_code=pw_code, | ||
pp_code=pp_code, | ||
bader_code=bader_code, | ||
structure=structure, | ||
protocol=protocol, | ||
electronic_type=ElectronicType(parameters["workchain"]["electronic_type"]), | ||
spin_type=SpinType(parameters["workchain"]["spin_type"]), | ||
initial_magnetic_moments=parameters["advanced"]["initial_magnetic_moments"], | ||
overrides=overrides, | ||
**kwargs, | ||
) | ||
else: | ||
raise ValueError("The pp_code and bader_code are required.") | ||
return builder | ||
|
||
|
||
workchain_and_builder = { | ||
"workchain": QeBaderWorkChain, | ||
"exclude": ("clean_workdir", "structure", "relax"), | ||
"get_builder": get_builder, | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
default_inputs: | ||
clean_workdir: False | ||
scf: | ||
pw: | ||
parameters: | ||
CONTROL: | ||
restart_mode: from_scratch | ||
pp: | ||
parameters: | ||
INPUTPP: | ||
plot_num: 21 | ||
PLOT: | ||
ifloag: 3 | ||
metadata: | ||
options: | ||
resources: | ||
num_machines: 1 | ||
max_wallclock_seconds: 43200 # Twelve hours | ||
withmpi: True | ||
bader: | ||
metadata: | ||
options: | ||
resources: | ||
num_machines: 1 | ||
max_wallclock_seconds: 43200 # Twelve hours | ||
withmpi: True | ||
default_protocol: moderate | ||
protocols: | ||
moderate: | ||
description: 'Protocol to perform a projected density of states calculation at normal precision at moderate computational cost.' | ||
precise: | ||
description: 'Protocol to perform a projected density of states structure calculation at high precision at higher computational cost.' | ||
fast: | ||
description: 'Protocol to perform a projected density of states structure calculation at low precision at minimal computational cost for testing purposes.' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
--- | ||
label: bader | ||
description: Bader charge analysis | ||
default_calc_job_plugin: bader | ||
computer: localhost | ||
filepath_executable: /home/jovyan/.conda/envs/quantum-espresso-7.2/bin/bader | ||
prepend_text: | | ||
eval "$(conda shell.posix hook)" | ||
conda activate quantum-espresso-7.2 | ||
export OMP_NUM_THREADS=1 | ||
append_text: ' ' |
Oops, something went wrong.