Source code for schrodinger.application.livedesign.pose_name_panel
from schrodinger.models import mappers
from schrodinger.ui.qt import basewidgets
from schrodinger.ui.qt import propertyselector
from . import export_models
from . import pose_name_panel_ui
[docs]class PoseNameEditPanel(mappers.MapperMixin, basewidgets.BaseWidget):
"""
Small panel for setting custom pose names.
"""
SHOW_AS_WINDOW = True
model_class = export_models.PoseNameEditModel
ui_module = pose_name_panel_ui
[docs] def initSetOptions(self):
super().initSetOptions()
self.setWindowTitle('Pose Name Specification')
self.std_btn_specs = {
self.StdBtn.Ok: self._onOKClicked,
self.StdBtn.Cancel: None
}
[docs] def initSetUp(self):
super().initSetUp()
self.ui.property_btn.clicked.connect(self._selectProperty)
[docs] def initFinalize(self):
super().initFinalize()
self.ok_btn.setDefault(True)
[docs] def setModel(self, model):
super().setModel(model)
self._onIncludePropertyChanged()
[docs] def defineMappings(self):
M = self.model_class
ui = self.ui
return super().defineMappings() + [
(ui.custom_text_le, M.custom_text),
(ui.property_user_name_lbl, M.property_user_name),
(ui.example_value_lbl, M.example_name),
(ui.property_cb, M.include_property)
] # yapf: disable
[docs] def getSignalsAndSlots(self, model):
return super().getSignalsAndSlots(model) + [
(model.include_propertyChanged, self._onIncludePropertyChanged),
(model.custom_textChanged, self._updateExampleName),
(model.property_nameChanged, self._onPropertyChanged),
] # yapf: disable
def _selectProperty(self):
"""
Launch a dialog prompting the user to select a structure property to
use as part of the pose name.
"""
prop_sel_dialog = propertyselector.PropertySelectorDialog(
parent=self,
title='Select Property',
accept_text='OK',
show_alpha_toggle=True,
show_filter_field=True)
properties = prop_sel_dialog.chooseFromList(self._getProperties())
if properties:
selected_prop = properties[0]
self.model.property_name = selected_prop
def _onIncludePropertyChanged(self):
"""
Respond when the "include property" checkbox changes.
"""
include = self.model.include_property
if not include:
self.model.property_name = None
self.ui.property_btn.setEnabled(include)
self.ui.property_user_name_lbl.setEnabled(include)
def _onPropertyChanged(self):
"""
Respond when the pose name structure property changes.
"""
# Update the example pose name label
propname = self.model.property_name
if propname is None:
self.model.reset(self.model_class.property_user_name)
else:
self.model.property_user_name = propname.userName()
prop_value = None
data_name = propname.dataName() if propname else None
if data_name and self.model.entry_data:
for st in self.model.entry_data.getRLMap().ligands:
prop_value = st.property.get(data_name)
if prop_value is not None:
break
if prop_value is None:
self.model.example_prop_string = None
else:
self.model.example_prop_string = str(prop_value)
self._updateExampleName()
def _updateExampleName(self):
"""
Update the "example pose name" text based on user input.
"""
example_name = self.model.custom_text
if self.model.example_prop_string is not None:
example_name += self.model.example_prop_string
self.model.example_name = example_name
def _getProperties(self):
"""
:return: a set of structure property names for all ligands/complexes in
the current system
:rtype: set[str]
"""
data_names = set()
if self.model.entry_data:
for ligand in self.model.entry_data.getRLMap().ligands:
data_names = data_names.union(set(ligand.property.keys()))
return data_names
def _onOKClicked(self):
"""
If the user accepts the panel, update the "permanent" parameters used
by the main panel.
"""
model = self.model
model.custom_text_final = model.custom_text
model.property_name_final = model.property_name
[docs] def showEvent(self, event):
"""
Update the "view" parameters using the "permanent" parameters when the
panel is shown.
"""
super().showEvent(event)
model = self.model
model.custom_text = model.custom_text_final
model.property_name = model.property_name_final
model.include_property = bool(model.property_name_final)