Skip to content

Commit

Permalink
Can now draw interaction bonds between atom and bond
Browse files Browse the repository at this point in the history
  • Loading branch information
YHordijk committed Nov 6, 2024
1 parent 72bd379 commit 8ef29b9
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/tcviewer/mol_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,8 @@ def eventFilter(self, widget, event):

bond_selected = len(self.parent().selected_actors) == 1 and self.parent().selected_actors[0].type == 'bond'
atoms2_selected = len(self.parent().selected_actors) == 2 and self.parent().selected_actors[0].type == 'atom' and self.parent().selected_actors[1].type == 'atom'
atom_and_bond_selected = len(self.parent().selected_actors) == 2 and any(actor.type == 'bond' for actor in self.parent().selected_actors) and any(actor.type == 'atom' for actor in self.parent().selected_actors)
print(bond_selected, atoms2_selected, atom_and_bond_selected)
if atoms2_selected:
actor1, actor2 = self.parent().selected_actors
if event.key() == QtCore.Qt.Key_1:
Expand All @@ -785,6 +787,16 @@ def eventFilter(self, widget, event):
self.parent().remove_highlight(actor)
self.parent().Render()


if atom_and_bond_selected:
if event.key() == QtCore.Qt.Key_I:
actor1, actor2 = self.parent().selected_actors
if actor1.type != 'bond':
actor1, actor2 = actor2, actor1
p1, p2 = actor1.atoms
scene.draw_interaction_bond((np.array(p1) + np.array(p2))/2, actor2.atom.coords)
self.parent().Render()

if event.key() == QtCore.Qt.Key_A and event.modifiers() == QtCore.Qt.ControlModifier:
atoms = [actor.atom for actor in self.parent().selected_actors if actor.type == 'atom']
bonds = [actor.atoms for actor in self.parent().selected_actors if actor.type == 'bond']
Expand All @@ -807,7 +819,6 @@ def eventFilter(self, widget, event):
scene.reset_camera()
scene.post_draw()


# if the user selected a single bond we align it to the x-axis
if len(bonds) == 2:
a1, a2, a3, a4 = [*bonds[0], *bonds[1]]
Expand Down

0 comments on commit 8ef29b9

Please sign in to comment.