From 08b4235b31afabdb8e3b1e1eb4bdff8451356317 Mon Sep 17 00:00:00 2001 From: superstar54 Date: Tue, 8 Oct 2024 11:28:24 +0000 Subject: [PATCH] shift the center of the control in z direction by 1 --- aiidalab_widgets_base/viewers.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/aiidalab_widgets_base/viewers.py b/aiidalab_widgets_base/viewers.py index df715081c..6bbc220b1 100644 --- a/aiidalab_widgets_base/viewers.py +++ b/aiidalab_widgets_base/viewers.py @@ -1247,6 +1247,14 @@ def _observe_displayed_structure(self, change): self._viewer.add_unitcell() self._viewer._add_shape(set(bonds), name="bonds") self._viewer.center() + # In case of a single atom, the `_viewer.center` method will show a black sphere. + if len(self.displayed_structure) == 1: + # get center of mass of the displayed structure + com = self.displayed_structure.get_center_of_mass() + # The default camera should be in the z direction, so we + # shift the center of the control in z direction by 1 + com[2] -= 1 + self._viewer.control.center(com) self.displayed_selection = []