diff --git a/src/aiidalab_qe_vibroscopy/app/settings.py b/src/aiidalab_qe_vibroscopy/app/settings.py index 316a2cf..f2e1665 100644 --- a/src/aiidalab_qe_vibroscopy/app/settings.py +++ b/src/aiidalab_qe_vibroscopy/app/settings.py @@ -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") @@ -179,7 +179,7 @@ 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) @@ -187,7 +187,7 @@ def change_supercell(_=None): # reset supercell self.supercell_reset_button = ipw.Button( - description="Reset", + description="Reset hint", disabled=False, layout=ipw.Layout(width="100px"), button_style="warning", @@ -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, ], ), ] @@ -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( @@ -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) @@ -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 @@ -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, ) diff --git a/tests/test_settings.py b/tests/test_settings.py index 88d7db6..d071fbe 100644 --- a/tests/test_settings.py +++ b/tests/test_settings.py @@ -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