From 6e547fc5957793efe8450003be81ffb371e3d7bc Mon Sep 17 00:00:00 2001 From: Aliaksandr Yakutovich Date: Thu, 16 Nov 2023 16:25:43 +0000 Subject: [PATCH] Simplify size multipliers and add comments. --- aiidalab_widgets_base/viewers.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/aiidalab_widgets_base/viewers.py b/aiidalab_widgets_base/viewers.py index 86a46441..55eddedb 100644 --- a/aiidalab_widgets_base/viewers.py +++ b/aiidalab_widgets_base/viewers.py @@ -249,9 +249,9 @@ def nglview_parameters(self, indices): }, } if self.type.value == "ball+stick": - nglview_parameters_dict["params"]["radiusScale"] = self.size.value * 0.1 + nglview_parameters_dict["params"]["radiusScale"] = self.size.value * 0.08 elif self.type.value == "spacefill": - nglview_parameters_dict["params"]["radiusScale"] = self.size.value * 0.3 + nglview_parameters_dict["params"]["radiusScale"] = self.size.value * 0.25 return nglview_parameters_dict @@ -560,8 +560,11 @@ def _compute_bonds(self, structure, radius=1.0, color="element", povray=False): import ase.neighborlist - radius = radius / 5 + # The radius is scaled by 0.04 to have a better visual appearance. + radius = radius * 0.04 + # The value 1.09 is chosen based on our experience. It is a good compromise between showing too many bonds + # and not showing bonds that should be there. cutoff = ase.neighborlist.natural_cutoffs(structure, mult=1.09) bonds = [] @@ -968,10 +971,6 @@ def highlight_atoms( params["params"]["opacity"] = 0.8 params["params"]["color"] = "darkgreen" params["params"]["component_index"] = 0 - if "radiusScale" in params["params"]: - params["params"]["radiusScale"] *= 1.2 - else: - params["params"]["aspectRatio"] *= 1.2 # Use directly the remote call for more flexibility. self._viewer._remote_call( @@ -1213,7 +1212,7 @@ def _observe_displayed_structure(self, change): if representation.type.value == "ball+stick": bonds += self._compute_bonds( self.displayed_structure[indices], - representation.size.value * 0.2, + representation.size.value, representation.color.value, ) self._viewer.set_representations(nglview_params, component=0)