diff --git a/aiidalab_widgets_base/viewers.py b/aiidalab_widgets_base/viewers.py index b089b10e..9f7492fe 100644 --- a/aiidalab_widgets_base/viewers.py +++ b/aiidalab_widgets_base/viewers.py @@ -227,57 +227,6 @@ def __init__( super().__init__(children, **kwargs) - @observe("ase_structure") - def _observe_ase_structure(self, _=None): - if self.ase_structure: - self.cell = self.ase_structure.cell - self.cell_a.value = "a: {:.4f} {:.4f} {:.4f}".format( - *self.cell.array[0] - ) - self.cell_b.value = "b: {:.4f} {:.4f} {:.4f}".format( - *self.cell.array[1] - ) - self.cell_c.value = "c: {:.4f} {:.4f} {:.4f}".format( - *self.cell.array[2] - ) - - self.cell_a_length.value = "|a|: {:.4f}".format( - self.cell.lengths()[0] - ) - self.cell_b_length.value = "|b|: {:.4f}".format( - self.cell.lengths()[1] - ) - self.cell_c_length.value = "|c|: {:.4f}".format( - self.cell.lengths()[2] - ) - - self.cell_alpha.value = f"α: {self.cell.angles()[0]:.4f}" - self.cell_beta.value = f"β: {self.cell.angles()[1]:.4f}" - self.cell_gamma.value = f"γ: {self.cell.angles()[2]:.4f}" - - spglib_structure = ase2spglib(self.ase_structure) - symmetry_dataset = spglib.get_symmetry_dataset( - spglib_structure, symprec=1e-5, angle_tolerance=1.0 - ) - - self.cell_spacegroup.value = f"Spacegroup: {symmetry_dataset['international']} (No.{symmetry_dataset['number']})" - self.cell_hall.value = f"Hall: {symmetry_dataset['hall']} (No.{symmetry_dataset['hall_number']})" - else: - self.cell_a.value = "a:" - self.cell_b.value = "b:" - self.cell_c.value = "c:" - - self.cell_a_length.value = "|a|:" - self.cell_b_length.value = "|b|:" - self.cell_c_length.value = "|c|:" - - self.cell_alpha.value = "α:" - self.cell_beta.value = "β:" - self.cell_gamma.value = "γ:" - - self.cell_spacegroup.value = "Spacegroup: " - self.cell_hall.value = "Hall: " - def _cell_tab(self): self.cell_a = ipw.HTML() self.cell_b = ipw.HTML() @@ -449,6 +398,57 @@ def change_camera(change): [supercell_selector, background_color, camera_type, center_button] ) + @observe("ase_structure") + def _observe_ase_structure(self, _=None): + if self.ase_structure: + self.cell = self.ase_structure.cell + self.cell_a.value = "a: {:.4f} {:.4f} {:.4f}".format( + *self.cell.array[0] + ) + self.cell_b.value = "b: {:.4f} {:.4f} {:.4f}".format( + *self.cell.array[1] + ) + self.cell_c.value = "c: {:.4f} {:.4f} {:.4f}".format( + *self.cell.array[2] + ) + + self.cell_a_length.value = "|a|: {:.4f}".format( + self.cell.lengths()[0] + ) + self.cell_b_length.value = "|b|: {:.4f}".format( + self.cell.lengths()[1] + ) + self.cell_c_length.value = "|c|: {:.4f}".format( + self.cell.lengths()[2] + ) + + self.cell_alpha.value = f"α: {self.cell.angles()[0]:.4f}" + self.cell_beta.value = f"β: {self.cell.angles()[1]:.4f}" + self.cell_gamma.value = f"γ: {self.cell.angles()[2]:.4f}" + + spglib_structure = ase2spglib(self.ase_structure) + symmetry_dataset = spglib.get_symmetry_dataset( + spglib_structure, symprec=1e-5, angle_tolerance=1.0 + ) + + self.cell_spacegroup.value = f"Spacegroup: {symmetry_dataset['international']} (No.{symmetry_dataset['number']})" + self.cell_hall.value = f"Hall: {symmetry_dataset['hall']} (No.{symmetry_dataset['hall_number']})" + else: + self.cell_a.value = "a:" + self.cell_b.value = "b:" + self.cell_c.value = "c:" + + self.cell_a_length.value = "|a|:" + self.cell_b_length.value = "|b|:" + self.cell_c_length.value = "|c|:" + + self.cell_alpha.value = "α:" + self.cell_beta.value = "β:" + self.cell_gamma.value = "γ:" + + self.cell_spacegroup.value = "Spacegroup: " + self.cell_hall.value = "Hall: " + def _download_tab(self): """Defining the download tab."""