Skip to content

Commit

Permalink
Add volume inforamtion in the cell tab
Browse files Browse the repository at this point in the history
  • Loading branch information
superstar54 committed Dec 23, 2024
1 parent 0542daa commit ee13a80
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
19 changes: 19 additions & 0 deletions aiidalab_widgets_base/viewers.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import traitlets as tl
import vapory
from aiida import cmdline, orm, tools
from aiida.orm.nodes.data.structure import _get_dimensionality
from ase.data import colors
from IPython.display import clear_output, display
from matplotlib.colors import to_rgb
Expand Down Expand Up @@ -710,6 +711,21 @@ def _observe_cell(self, _=None):
self.periodicity.value = (
f"Periodicity: {periodicity_map[tuple(self.structure.pbc)]}"
)
# Calculate the volume of the cell using the function from orm.StructureData
dimension_data = _get_dimensionality(self.structure.pbc, self.cell)
# Determine the label and unit based on dimensionality
cell_labels = {
1: ["length", "Å"],
2: ["area", "Ų"],
3: ["volume", "ų"],
}
cell_label = cell_labels.get(dimension_data["dim"])
if cell_label:
self.cell_volume.value = f"Cell {cell_label[0]}: {dimension_data['value']:.4f} ({cell_label[1]})"
else:
self.cell_volume.value = f"Cell volume: -"


else:
self.cell_a.value = "<i><b>a</b></i>:"
self.cell_b.value = "<i><b>b</b></i>:"
Expand Down Expand Up @@ -744,6 +760,8 @@ def _cell_tab(self):
self.cell_hall = ipw.HTML()
self.periodicity = ipw.HTML()

self.cell_volume = ipw.HTML()

self._observe_cell()

return ipw.VBox(
Expand Down Expand Up @@ -791,6 +809,7 @@ def _cell_tab(self):
),
]
),
self.cell_volume,
]
)

Expand Down
1 change: 1 addition & 0 deletions tests/test_viewers.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def test_pbc_structure_data_viewer(structure_data_object):
viewer = viewers.StructureDataViewer()
viewer.structure = ase_input
assert viewer.periodicity.value == "Periodicity: xy"
assert viewer.cell_volume.value == "Cell area: 12.2500 (Ų)"


@pytest.mark.usefixtures("aiida_profile_clean")
Expand Down

0 comments on commit ee13a80

Please sign in to comment.