Skip to content

Commit

Permalink
Adding Van del Waals Correction widget (Adv Setting) (#620)
Browse files Browse the repository at this point in the history
  • Loading branch information
AndresOrtegaGuerrero authored Feb 15, 2024
1 parent 708fed5 commit f64607c
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 0 deletions.
50 changes: 50 additions & 0 deletions src/aiidalab_qe/app/configuration/advanced.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ class AdvancedSettings(Panel):
Tick the box to override the default, smaller is more accurate and costly. </div>"""
)

dftd3_version = {
"dft-d3": 3,
"dft-d3bj": 4,
"dft-d3m": 5,
"dft-d3mbj": 6,
}
# protocol interface
protocol = tl.Unicode(allow_none=True)
input_structure = tl.Instance(orm.StructureData, allow_none=True)
Expand Down Expand Up @@ -121,6 +127,28 @@ def __init__(self, default_protocol=None, **kwargs):
)
self.total_charge.observe(self._callback_value_set, "value")

# Van der Waals setting widget
self.van_der_waals = ipw.Dropdown(
options=[
("None", "none"),
("Grimme-D3", "dft-d3"),
("Grimme-D3BJ", "dft-d3bj"),
("Grimme-D3M", "dft-d3m"),
("Grimme-D3MBJ", "dft-d3mbj"),
("Tkatchenko-Scheffler", "ts-vdw"),
],
description="Van der Waals correction:",
value="none",
disabled=False,
style={"description_width": "initial"},
)

ipw.dlink(
(self.override, "value"),
(self.van_der_waals, "disabled"),
lambda override: not override,
)

self.magnetization = MagnetizationSettings()
ipw.dlink(
(self.override, "value"),
Expand All @@ -146,6 +174,8 @@ def __init__(self, default_protocol=None, **kwargs):
),
# total charge setting widget
self.total_charge,
# van der waals setting widget
self.van_der_waals,
# magnetization setting widget
self.magnetization,
# smearing setting widget
Expand Down Expand Up @@ -245,6 +275,17 @@ def get_panel_value(self):
] = self.pseudo_setter.ecutrho
# if override is not ticked, use the default value
parameters["pw"]["parameters"]["SYSTEM"]["tot_charge"] = self.total_charge.value

if self.van_der_waals.value in ["none", "ts-vdw"]:
parameters["pw"]["parameters"]["SYSTEM"][
"vdw_corr"
] = self.van_der_waals.value
else:
parameters["pw"]["parameters"]["SYSTEM"]["vdw_corr"] = "dft-d3"
parameters["pw"]["parameters"]["SYSTEM"][
"dftd3_version"
] = self.dftd3_version[self.van_der_waals.value]

# there are two choose, use link or parent
if self.spin_type == "collinear":
parameters[
Expand Down Expand Up @@ -290,6 +331,12 @@ def set_panel_value(self, parameters):
self.total_charge.value = parameters["pw"]["parameters"]["SYSTEM"].get(
"tot_charge", 0
)
# van der waals correction
self.van_der_waals.value = self.dftd3_version.get(
system.get("dftd3_version"),
parameters["pw"]["parameters"]["SYSTEM"].get("vdw_corr", "none"),
)

if parameters.get("initial_magnetic_moments"):
self.magnetization._set_magnetization_values(
parameters.get("initial_magnetic_moments")
Expand All @@ -308,6 +355,9 @@ def reset(self):
# reset total charge
self.total_charge.value = DEFAULT_PARAMETERS["advanced"]["tot_charge"]

# reset the van der waals correction
self.van_der_waals.value = DEFAULT_PARAMETERS["advanced"]["vdw_corr"]

# reset the override checkbox
self.override.value = False
self.smearing.reset()
Expand Down
1 change: 1 addition & 0 deletions src/aiidalab_qe/app/parameters/qeapp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ advanced:
functional: PBEsol
accuracy: efficiency
tot_charge: 0
vdw_corr: none

## Codes
codes:
Expand Down
13 changes: 13 additions & 0 deletions src/aiidalab_qe/app/result/summary_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@
(True, False, False): "x",
}

VDW_CORRECTION_VERSION = {
3: "Grimme-D3",
4: "Grimme-D3BJ",
5: "Grimme-D3M",
6: "Grimme-D3MBJ",
"ts-vdw": "Tkatchenko-Scheffler",
"none": "None",
}


def generate_report_parameters(qeapp_wc):
"""Generate the report parameters from the ui parameters and workchain's input.
Expand Down Expand Up @@ -107,6 +116,10 @@ def generate_report_parameters(qeapp_wc):
report["degauss"] = pw_parameters["SYSTEM"]["degauss"]
report["smearing"] = pw_parameters["SYSTEM"]["smearing"]
report["tot_charge"] = pw_parameters["SYSTEM"].get("tot_charge", 0.0)
report["vdw_corr"] = VDW_CORRECTION_VERSION.get(
pw_parameters["SYSTEM"].get("dftd3_version"),
pw_parameters["SYSTEM"].get("vdw_corr", "none"),
)
report["periodicity"] = PERIODICITY_MAPPING.get(
qeapp_wc.inputs.structure.pbc, "xyz"
)
Expand Down
4 changes: 4 additions & 0 deletions src/aiidalab_qe/app/static/workflow_summary.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@
<td>Total Charge</td>
<td>{{ tot_charge }}</td>
</tr>
<tr>
<td>Van der Waals Correction</td>
<td>{{ vdw_corr }}</td>
</tr>
<tr>
<td>Initial Magnetic Moments</td>
<td>{{ initial_magnetic_moments }}</td>
Expand Down
2 changes: 2 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ def _submit_app_generator(
smearing="methfessel-paxton",
degauss=0.015,
tot_charge=0.0,
vdw_corr="none",
initial_magnetic_moments=0.0,
):
configure_step = app.configure_step
Expand All @@ -354,6 +355,7 @@ def _submit_app_generator(
# Advanced settings
configure_step.advanced_settings.override.value = True
configure_step.advanced_settings.total_charge.value = tot_charge
configure_step.advanced_settings.van_der_waals.value = vdw_corr
configure_step.advanced_settings.kpoints_distance.value = kpoints_distance
configure_step.advanced_settings.magnetization._set_magnetization_values(
initial_magnetic_moments
Expand Down
1 change: 1 addition & 0 deletions tests/test_result/test_summary_report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ relaxed: positions_cell
scf_kpoints_distance: 0.5
smearing: cold
tot_charge: 0.0
vdw_corr: none
3 changes: 3 additions & 0 deletions tests/test_submit_qe_workchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def test_create_builder_advanced_settings(
electronic_type="metal",
spin_type="collinear",
tot_charge=1.0,
vdw_corr="dft-d3bj",
initial_magnetic_moments=0.1,
properties=["bands", "pdos"],
)
Expand All @@ -80,6 +81,8 @@ def test_create_builder_advanced_settings(
got["pdos"]["nscf"],
]:
assert parameters["pw"]["parameters"]["SYSTEM"]["tot_charge"] == 1.0
assert parameters["pw"]["parameters"]["SYSTEM"]["vdw_corr"] == "dft-d3"
assert parameters["pw"]["parameters"]["SYSTEM"]["dftd3_version"] == 4

# test initial_magnetic_moments set 'starting_magnetization' in pw.in
assert (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ bands:
occupations: smearing
smearing: cold
tot_charge: 0.0
vdw_corr: none
pseudos:
Si: Si.upf
bands_kpoints_distance: 0.025
Expand Down Expand Up @@ -55,6 +56,7 @@ bands:
occupations: smearing
smearing: methfessel-paxton
tot_charge: 0.0
vdw_corr: none
pseudos:
Si: Si.upf
clean_workdir: false
Expand Down Expand Up @@ -87,6 +89,7 @@ pdos:
nosym: true
occupations: tetrahedra
tot_charge: 0.0
vdw_corr: none
pseudos:
Si: Si.upf
projwfc:
Expand Down Expand Up @@ -123,6 +126,7 @@ pdos:
occupations: smearing
smearing: methfessel-paxton
tot_charge: 0.0
vdw_corr: none
pseudos:
Si: Si.upf
properties:
Expand Down Expand Up @@ -158,6 +162,7 @@ relax:
occupations: smearing
smearing: methfessel-paxton
tot_charge: 0.0
vdw_corr: none
pseudos:
Si: Si.upf
base_final_scf:
Expand Down

0 comments on commit f64607c

Please sign in to comment.