Skip to content

Commit

Permalink
atom selection 3d picker initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ChiCheng45 committed May 2, 2024
1 parent df7c1ad commit a47455b
Show file tree
Hide file tree
Showing 5 changed files with 364 additions and 282 deletions.
21 changes: 20 additions & 1 deletion MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/AtomSelectionWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
)
from MDANSE.Framework.AtomSelector import Selector
from MDANSE_GUI.InputWidgets.WidgetBase import WidgetBase
from MDANSE_GUI.Tabs.Visualisers.View3D import View3D
from MDANSE_GUI.MolecularViewer.MolecularViewer import MolecularViewerWithPicking
from MDANSE.Framework.InputData.HDFTrajectoryInputData import HDFTrajectoryInputData


class CheckableComboBox(QComboBox):
Expand Down Expand Up @@ -212,6 +215,7 @@ def __init__(self, selector: Selector, field: QLineEdit, parent, *args, **kwargs
self.selection_textbox = QTextEdit()
self.selection_textbox.setReadOnly(True)

self.view_3d = View3D(MolecularViewerWithPicking())
layouts = self.create_layouts()

bottom = QHBoxLayout()
Expand All @@ -227,6 +231,13 @@ def __init__(self, selector: Selector, field: QLineEdit, parent, *args, **kwargs
self.setLayout(helper_layout)
self.update_selection_textbox()

def closeEvent(self, a0):
"""Hide the window instead of closing. Some issues occur in the
3D viewer when it is closed and then reopened.
"""
a0.ignore()
self.hide()

def create_buttons(self) -> list[QPushButton]:
"""
Returns
Expand All @@ -248,14 +259,16 @@ def create_layouts(self) -> list[QVBoxLayout]:
list[QVBoxLayout]
List of QVBoxLayout to add to the helper layout.
"""
layout_3d = QVBoxLayout()
layout_3d.addWidget(self.view_3d)
left = QVBoxLayout()
for widget in self.left_widgets():
left.addWidget(widget)

right = QVBoxLayout()
right.addWidget(self.selection_textbox)

return [left, right]
return [layout_3d, left, right]

def left_widgets(self) -> list[QWidget]:
"""
Expand Down Expand Up @@ -367,7 +380,13 @@ def __init__(self, *args, **kwargs):
self._field.setPlaceholderText(self._default_value)
self._field.setMaxLength(2147483647) # set to the largest possible
self._field.textChanged.connect(self.updateValue)
traj_config = self._configurator._configurable[
self._configurator._dependencies["trajectory"]
]
traj_filename = traj_config["filename"]
hdf_traj = HDFTrajectoryInputData(traj_config["filename"])
self.helper = self.create_helper()
self.helper.view_3d.update_panel((traj_filename, hdf_traj))
helper_button = QPushButton(self._push_button_text, self._base)
helper_button.clicked.connect(self.helper_dialog)
self._layout.addWidget(self._field)
Expand Down
8 changes: 6 additions & 2 deletions MDANSE_GUI/Src/MDANSE_GUI/MolecularViewer/AtomProperties.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ def __init__(self, *args, init_colours: list = None, **kwargs):
self.itemChanged.connect(self.onNewValues)
self._groups = []
self._total_length = 0
self.colours = np.array([], dtype=int)
self.radii = np.array([], dtype=float)

def clear_table(self):
"""This was meant to be used for cleaning up,
Expand Down Expand Up @@ -186,6 +188,7 @@ def reinitialise_from_database(

@Slot()
def onNewValues(self):
self.rebuild_colours()
colours = np.empty(self._total_length, dtype=int)
radii = np.empty(self._total_length, dtype=float)
numbers = np.arange(self._total_length)
Expand All @@ -197,5 +200,6 @@ def onNewValues(self):
indices = entry.indices()
radii[indices] = radius
colours[indices] = vtk_colour
scalars = ndarray_to_vtkarray(colours, radii, numbers)
self.new_atom_properties.emit(scalars)
self.radii = radii
self.colours = colours
self.new_atom_properties.emit((colours, radii, numbers))
Loading

0 comments on commit a47455b

Please sign in to comment.