Source code for schrodinger.application.livedesign.ld_export_gui

from typing import List

from schrodinger import get_maestro
from schrodinger.models import mappers
from schrodinger.ui.qt import input_selector
from schrodinger.ui.qt.appframework2 import wizards

from . import entry_types as ets
from . import export_setup_ui
from . import ld_export
from . import login
from . import maestro_sync

maestro = get_maestro()
NAME_ENTRY_TYPE_MAP = {entry_type.name: entry_type for entry_type in
    [ets.Ligands, ets.DockedPoses, ets.Complexes,
     ets.CovalentDockingComplexes, ets.OrganometallicCompounds]
} # yapf: disable

PANEL_TITLE = 'Maestro to LiveDesign Export'


[docs]class ExportPanelWizard(wizards.MultiPanelWizard):
[docs] def __init__(self): self.model = ld_export.ExportModel() super().__init__() self.finished.connect(self.onWizardFinish)
[docs] def setup(self): setup_panel = ExportSetupPanel() setup_panel.setModel(self.model) self.addPanel(setup_panel) main_panel = ExportMainPanel() main_panel.setModel(self.model) self.addPanel(main_panel)
[docs] def setDefaultCheckedItems(self, item_strs: List[str]): """ Specify which LD data items will be checked by default when the main panel is opened. :param item_strs: string representations of the desired checked data item. In most cases, this is the structure property name. """ main_panel = [ panel for panel in self.panels if isinstance(panel, ExportMainPanel) ][0] main_panel.setDefaultCheckedItems(item_strs)
[docs] def run(self, *args, **kwargs): self._setUpLDClient() return super().run(*args, **kwargs)
def _setUpLDClient(self): """ Obtain and store necessary LD modules if necessary. """ model = self.model if model.ld_client is None or model.ld_models is None: msg, ld_client, ld_models = login.get_ld_client_and_models() if msg: raise RuntimeError(msg) model.ld_client = ld_client model.ld_models = ld_models
[docs] def onWizardFinish(self): """ Reset the wizard state on user exit. """ self.current_panel_index = 0 self.last_panel_state = None self.quit()
[docs]class ExportSetupPanel(ld_export.LDExportPanelMixin, mappers.MapperMixin, wizards.BaseWizardPanel): model_class = ld_export.ExportModel ui_module = export_setup_ui TITLE_BASE = PANEL_TITLE
[docs] def initSetUp(self): super().initSetUp() self.input_selector = input_selector.InputSelector( self, file=False, included_entries=True, tracking=True) self.input_selector.setMinimumWidth(450) self.input_selector.input_menu_label.hide() self.input_selector.input_changed.connect(self._onInputChanged) self.ui.entry_type_combo.addItems(NAME_ENTRY_TYPE_MAP)
[docs] def initLayOut(self): super().initLayOut() self.ui.input_selector_layout.addWidget(self.input_selector)
[docs] def initSetDefaults(self): """ Override `mappers.MapperMixin` to avoid resetting the entire model. """ self.input_selector.reset()
[docs] def show(self): super().show() self.adjustCombos() # Collect structures to account for any new changes self._onInputChanged()
[docs] def adjustCombos(self): """ Adjusts combo boxes to appear the same length """ entry_type_width = self.ui.entry_type_combo.width() input_selector_width = self.input_selector.input_menu.width() if entry_type_width > input_selector_width: self.input_selector.input_menu.setFixedWidth(entry_type_width) else: self.ui.entry_type_combo.setFixedWidth(input_selector_width)
[docs] def defineMappings(self): M = self.model_class ui = self.ui entry_type_target = mappers.TargetSpec(ui.entry_type_combo, slot=self._onInputChanged) return super().defineMappings() + [ (entry_type_target, M.entry_type), (ui.description_lbl, M.entry_type_description), (ui.summary_lbl, M.input_summary), ] # yapf: disable
[docs] def processNext(self): """ Evaluates whether to proceed to the next panel. Called when "Next" is clicked. See `wizards.BaseWizardPanel` for further documentation. :return: whether to proceed to the next panel as requested :rtype: bool or NoneType """ results = self.model.entry_data.runValidation(silent=True) if not self.reportValidation(results): return False
def _onInputChanged(self): """ When the user changes the input data, respond by updating the description and summary label text. """ model = self.model st_map = { idx: st for idx, st in enumerate(self.input_selector.structures()) } model.entry_data = model.entry_type(st_map) model.entry_type_description = model.entry_data.description model.input_summary = model.entry_data.getSummary() model.entry_type_name = model.entry_data.name
[docs]class ExportMainPanel(ld_export.AbstractExportPanel): TITLE_BASE = PANEL_TITLE
[docs] def initSetOptions(self): super().initSetOptions() self.help_topic = 'MAESTRO_LIVEDESIGN_EXPORT' if maestro: self.mae_sync = maestro_sync.EntrySelectionMaestroSync() self.mae_sync.entrySelectionChanged.connect( self._onEntrySelectionChanged)
def _onEntrySelectionChanged(self): """ If the project entry selection state changes, remind the user that this will not affect the structures being exported to LiveDesign. """ msg = ('Project entry selection has changed. Note that this will not' ' change the structures selected for export. In order to do' ' this, you must return to the setup panel.') self.warning(text=msg, title=f'{PANEL_TITLE}: Entry Selection', save_response_key='ld_export_entry_selection')
[docs] def showEvent(self, event): if maestro: self.mae_sync.updateSelectedEntries() self.mae_sync.setCallbacksActive(True) super().showEvent(event)
[docs] def closeEvent(self, event): if maestro: self.mae_sync.setCallbacksActive(False) super().closeEvent(event)