Skip to content

Commit

Permalink
Update selection to added/modified atoms (#282).
Browse files Browse the repository at this point in the history
Whenever BasicStructureEditor.add() or BasicStructureEditor.modify() functions
are used, the selection filed will highlight only the newly added atoms.
  • Loading branch information
cpignedoli committed Jan 19, 2022
1 parent b319ebc commit 856d643
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions aiidalab_widgets_base/structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -1142,6 +1142,7 @@ def align(self, _=None):
def mod_element(self, _=None):
"""Modify selected atoms into the given element."""
atoms = self.structure.copy()
last_atom = atoms.get_global_number_of_atoms()
selection = self.selection

if self.ligand.value == 0:
Expand All @@ -1153,6 +1154,7 @@ def mod_element(self, _=None):
atoms[idx].symbol = new.symbol
atoms[idx].tag = new.tag
atoms[idx].charge = new.charge
new_selection = selection
else:
initial_ligand = self.ligand.rotate(
align_to=self.action_vector, remove_anchor=True
Expand All @@ -1162,9 +1164,12 @@ def mod_element(self, _=None):
lgnd = initial_ligand.copy()
lgnd.translate(position)
atoms += lgnd
new_selection = [
i for i in range(last_atom, last_atom + len(selection) * len(lgnd))
]

self.structure = atoms
self.selection = selection
self.selection = new_selection

def copy_sel(self, _=None):
"""Copy selected atoms and shift by 1.0 A along X-axis."""
Expand All @@ -1183,6 +1188,7 @@ def copy_sel(self, _=None):
def add(self, _=None):
"""Add atoms."""
atoms = self.structure.copy()
last_atom = atoms.get_global_number_of_atoms()
selection = self.selection

if self.ligand.value == 0:
Expand All @@ -1209,7 +1215,9 @@ def add(self, _=None):
atoms += lgnd

self.structure = atoms
self.selection = selection
self.selection = [
i for i in range(last_atom, last_atom + len(selection) * len(lgnd))
]

def remove(self, _):
"""Remove selected atoms."""
Expand Down

0 comments on commit 856d643

Please sign in to comment.