Skip to content

Commit

Permalink
move function for easy review
Browse files Browse the repository at this point in the history
  • Loading branch information
unkcpz committed Aug 9, 2022
1 parent 8ad90b0 commit 8f80b2e
Showing 1 changed file with 51 additions and 51 deletions.
102 changes: 51 additions & 51 deletions aiidalab_widgets_base/viewers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "<i><b>a</b></i>: {:.4f} {:.4f} {:.4f}".format(
*self.cell.array[0]
)
self.cell_b.value = "<i><b>b</b></i>: {:.4f} {:.4f} {:.4f}".format(
*self.cell.array[1]
)
self.cell_c.value = "<i><b>c</b></i>: {:.4f} {:.4f} {:.4f}".format(
*self.cell.array[2]
)

self.cell_a_length.value = "|<i><b>a</b></i>|: {:.4f}".format(
self.cell.lengths()[0]
)
self.cell_b_length.value = "|<i><b>b</b></i>|: {:.4f}".format(
self.cell.lengths()[1]
)
self.cell_c_length.value = "|<i><b>c</b></i>|: {:.4f}".format(
self.cell.lengths()[2]
)

self.cell_alpha.value = f"&alpha;: {self.cell.angles()[0]:.4f}"
self.cell_beta.value = f"&beta;: {self.cell.angles()[1]:.4f}"
self.cell_gamma.value = f"&gamma;: {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 = "<i><b>a</b></i>:"
self.cell_b.value = "<i><b>b</b></i>:"
self.cell_c.value = "<i><b>c</b></i>:"

self.cell_a_length.value = "|<i><b>a</b></i>|:"
self.cell_b_length.value = "|<i><b>b</b></i>|:"
self.cell_c_length.value = "|<i><b>c</b></i>|:"

self.cell_alpha.value = "&alpha;:"
self.cell_beta.value = "&beta;:"
self.cell_gamma.value = "&gamma;:"

self.cell_spacegroup.value = "Spacegroup: "
self.cell_hall.value = "Hall: "

def _cell_tab(self):
self.cell_a = ipw.HTML()
self.cell_b = ipw.HTML()
Expand Down Expand Up @@ -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 = "<i><b>a</b></i>: {:.4f} {:.4f} {:.4f}".format(
*self.cell.array[0]
)
self.cell_b.value = "<i><b>b</b></i>: {:.4f} {:.4f} {:.4f}".format(
*self.cell.array[1]
)
self.cell_c.value = "<i><b>c</b></i>: {:.4f} {:.4f} {:.4f}".format(
*self.cell.array[2]
)

self.cell_a_length.value = "|<i><b>a</b></i>|: {:.4f}".format(
self.cell.lengths()[0]
)
self.cell_b_length.value = "|<i><b>b</b></i>|: {:.4f}".format(
self.cell.lengths()[1]
)
self.cell_c_length.value = "|<i><b>c</b></i>|: {:.4f}".format(
self.cell.lengths()[2]
)

self.cell_alpha.value = f"&alpha;: {self.cell.angles()[0]:.4f}"
self.cell_beta.value = f"&beta;: {self.cell.angles()[1]:.4f}"
self.cell_gamma.value = f"&gamma;: {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 = "<i><b>a</b></i>:"
self.cell_b.value = "<i><b>b</b></i>:"
self.cell_c.value = "<i><b>c</b></i>:"

self.cell_a_length.value = "|<i><b>a</b></i>|:"
self.cell_b_length.value = "|<i><b>b</b></i>|:"
self.cell_c_length.value = "|<i><b>c</b></i>|:"

self.cell_alpha.value = "&alpha;:"
self.cell_beta.value = "&beta;:"
self.cell_gamma.value = "&gamma;:"

self.cell_spacegroup.value = "Spacegroup: "
self.cell_hall.value = "Hall: "

def _download_tab(self):
"""Defining the download tab."""

Expand Down

0 comments on commit 8f80b2e

Please sign in to comment.