Skip to content

Commit

Permalink
Simplify size multipliers and add comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
yakutovicha committed Nov 16, 2023
1 parent 9ee0f99 commit 6e547fc
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions aiidalab_widgets_base/viewers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 = []

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 6e547fc

Please sign in to comment.