Skip to content

Commit

Permalink
Added also the symprec in the estimation of the supercells to be comp…
Browse files Browse the repository at this point in the history
…uted

- adding a reset for symprec
- adding upper and lower bound 1 and 1e-7 (if out of this range, automatically reset to max or min)
- added tests for all the new widgets/logics
  • Loading branch information
mikibonacci committed Sep 23, 2024
1 parent cb42238 commit 96ad9be
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 6 deletions.
40 changes: 34 additions & 6 deletions src/aiidalab_qe_vibroscopy/app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import sys
import os

from aiida.plugins import CalculationFactory, DataFactory, WorkflowFactory
from aiida.plugins import DataFactory

HubbardStructureData = DataFactory("quantumespresso.hubbard_structure")

Expand Down Expand Up @@ -179,15 +179,15 @@ def change_supercell(_=None):
self.supercell_hint_button = ipw.Button(
description="Size hint",
disabled=False,
width="500px",
width="100px",
button_style="info",
)
# supercell hint (15A lattice params)
self.supercell_hint_button.on_click(self._suggest_supercell)

# reset supercell
self.supercell_reset_button = ipw.Button(
description="Reset",
description="Reset hint",
disabled=False,
layout=ipw.Layout(width="100px"),
button_style="warning",
Expand All @@ -211,8 +211,8 @@ def change_supercell(_=None):
[
self.supercell_selector,
self.supercell_hint_button,
self.supercell_number_estimator,
self.supercell_reset_button,
self.supercell_number_estimator,
],
),
]
Expand All @@ -222,10 +222,26 @@ def change_supercell(_=None):

self.symmetry_symprec = ipw.FloatText(
value=1e-5,
max=1,
min=1e-7, # Ensure the value is always positive
step=1e-4, # Step value of 1e-4
description="Symmetry tolerance (symprec):",
style={"description_width": "initial"},
layout={"width": "300px"},
)
self.symmetry_symprec.observe(self._estimate_supercells, "value")

# reset supercell
self.symmetry_symprec_reset_button = ipw.Button(
description="Reset symprec",
disabled=False,
layout=ipw.Layout(width="150px"),
button_style="warning",
)
# supercell reset reaction
self.symmetry_symprec_reset_button.on_click(
lambda _: setattr(self.symmetry_symprec, "value", 1e-5)
)

self.children = [
ipw.VBox(
Expand All @@ -251,7 +267,12 @@ def change_supercell(_=None):
],
),
self.supercell_widget,
self.symmetry_symprec,
ipw.HBox(
[
self.symmetry_symprec,
self.symmetry_symprec_reset_button,
],
),
]

super().__init__(**kwargs)
Expand Down Expand Up @@ -308,6 +329,13 @@ def _estimate_supercells(self, _=None):
if self.block:
return

if self.symmetry_symprec.value > 1:
self.symmetry_symprec.value = 1
elif self.symmetry_symprec.value < 1e-5:
self.symmetry_symprec.value = 1e-5

symprec = self.symmetry_symprec.value

self.supercell_number_estimator.value = spinner_html

from aiida_phonopy.data.preprocess import PreProcessData
Expand All @@ -320,7 +348,7 @@ def _estimate_supercells(self, _=None):
[0, self._sc_y.value, 0],
[0, 0, self._sc_z.value],
],
symprec=1e-5,
symprec=symprec,
distinguish_kinds=False,
is_symmetry=True,
)
Expand Down
48 changes: 48 additions & 0 deletions tests/test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,51 @@ def test_x_settings(generate_structure_data):
configure_step.workchain_settings.properties["vibronic"].run.value = True
parameters = configure_step.settings["vibronic"].get_panel_value()
assert parameters["supercell_selector"] == [2, 1, 1]


@pytest.mark.usefixtures("sssp")
def test_supercell_number_estimator(generate_structure_data):
"""Test the settings of the vibroscopy app."""

from aiidalab_qe.app.configuration import ConfigureQeAppWorkChainStep

configure_step = ConfigureQeAppWorkChainStep()
structure = generate_structure_data("silicon")
configure_step.input_structure = structure
configure_step.workchain_settings.properties["vibronic"].run.value = True
parameters = configure_step.settings["vibronic"].get_panel_value()
assert parameters["supercell_selector"] == [2, 2, 2]
assert configure_step.settings["vibronic"].supercell_number_estimator.value == "1"
configure_step.settings["vibronic"]._suggest_supercell()
parameters = configure_step.settings["vibronic"].get_panel_value()
assert parameters["supercell_selector"] == [4, 4, 4]
assert configure_step.settings["vibronic"].supercell_number_estimator.value == "1"
configure_step.settings["vibronic"]._sc_x.value = 3
configure_step.settings["vibronic"]._sc_y.value = 2
configure_step.settings["vibronic"]._sc_z.value = 2
assert configure_step.settings["vibronic"].supercell_number_estimator.value == "4"
configure_step.settings["vibronic"]._reset_supercell()
configure_step.settings["vibronic"]._sc_x.value = 2
configure_step.settings["vibronic"]._sc_y.value = 2
configure_step.settings["vibronic"]._sc_z.value = 2
assert configure_step.settings["vibronic"].supercell_number_estimator.value == "1"


@pytest.mark.usefixtures("sssp")
def test_symprec(generate_structure_data):
"""Test the settings of the vibroscopy app."""

from aiidalab_qe.app.configuration import ConfigureQeAppWorkChainStep

configure_step = ConfigureQeAppWorkChainStep()
structure = generate_structure_data("silicon")
configure_step.input_structure = structure
configure_step.workchain_settings.properties["vibronic"].run.value = True
parameters = configure_step.settings["vibronic"].get_panel_value()
assert parameters["symmetry_symprec"] == 1e-5
configure_step.settings["vibronic"].symmetry_symprec.value = 1
parameters = configure_step.settings["vibronic"].get_panel_value()
assert parameters["symmetry_symprec"] == 1
configure_step.settings["vibronic"].reset()
parameters = configure_step.settings["vibronic"].get_panel_value()
assert parameters["symmetry_symprec"] == 1e-5

0 comments on commit 96ad9be

Please sign in to comment.