Skip to content

Commit

Permalink
Avoid black sphere in structure viewer (#637)
Browse files Browse the repository at this point in the history
In the case of a structure with only one atom, the structure viewer shows a black sphere. This could be because of the overlap between the atoms and the viewer's control. This PR implements a quick solution by shifting the center of the control in the z direction by 1.
  • Loading branch information
superstar54 authored Oct 21, 2024
1 parent 152c2bb commit 1f400bc
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions aiidalab_widgets_base/viewers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 structure with only one atom, the `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 = []

Expand Down

0 comments on commit 1f400bc

Please sign in to comment.