Source code for schrodinger.application.livedesign.summary

from typing import List

from schrodinger import structure
from schrodinger.models import mappers
from schrodinger.models import parameters
from schrodinger.ui.qt import basewidgets
from schrodinger.ui.qt.mapperwidgets import plptable
from schrodinger.utils.scollections import IdSet

from . import export_models
from . import summary_ui

TEXT_3D_YES = 'Yes'
TEXT_3D_NO = 'No (properties only)'


[docs]class SummaryTableSpec(plptable.TableSpec): """ Table spec for the "LiveReport Columns" table. """ @plptable.PLPColumn(title='No.') def number(self, all_prop_specs, prop_spec): return all_prop_specs.index(prop_spec) + 1 @plptable.ParamColumn(title='Column Title') def title(self, prop_spec): return f'{prop_spec.ld_model} {prop_spec.ld_endpoint}'
[docs]class LiveDesignExportSummaryPanel(mappers.MapperMixin, basewidgets.BaseWidget): """ Display to the user for final user approval before beginning the LiveDesign export. """ model_class = export_models.SummaryModel ui_module = summary_ui SHOW_AS_WINDOW = True
[docs] def initSetOptions(self): super().initSetOptions() self.std_btn_specs = { self.StdBtn.Ok: (None, 'Export to LiveDesign'), self.StdBtn.Cancel: None }
[docs] def initSetUp(self): super().initSetUp() # TODO: implement setting "ui.publish_data_lbl" label text after publish # data widget is overhauled in main panel (PANEL-11783) self.ui.publish_lbl.hide() self.ui.publish_data_lbl.hide() table = self.ui.export_data_table table.setSpec(SummaryTableSpec()) title_col_idx = 1 hheader = table.view.horizontalHeader() hheader.setSectionResizeMode(title_col_idx, hheader.Stretch)
[docs] def defineMappings(self): M = self.model_class ui = self.ui num_sts_target = mappers.TargetSpec(slot=self._setNumStructuresText) upload_3d_target = mappers.TargetSpec(setter=self._setUpload3DText) return super().defineMappings() + [ (ui.project_data_lbl, M.ld_destination.proj_name), (ui.lr_data_lbl, M.ld_destination.lr_name), (upload_3d_target, M.three_d_export_items), (num_sts_target, M.structures_for_2d_export), (num_sts_target, M.three_d_export_items), (ui.match_data_lbl, M.match_compounds_by), (ui.export_data_table, M.export_specs) ] # yapf: disable
[docs] def getSignalsAndSlots(self, model): return super().getSignalsAndSlots(model) + [ (model.three_d_export_itemsChanged, self._updateSpecTable), (model.property_export_specsChanged, self._updateSpecTable), (model.ffc_export_specsChanged, self._updateSpecTable) ] # yapf: disable
def _setUpload3DText(self, three_d_export_items): """ Set text in the "Upload 3D data" label based on the model state. """ text = TEXT_3D_YES if three_d_export_items else TEXT_3D_NO self.ui.up_3d_data_lbl.setText(text) def _getNumStructures(self): """ Calculate the number of structures to be exported. :return: the number of structures to be exported :rtype: int """ sts = set() key_sts = set() for item in self.model.three_d_export_items: if item.ligand: sts.add(item.ligand) if item.receptor: sts.add(item.receptor) if isinstance(item.key, structure.Structure): key_sts.add(item.key) # Do not add 2D structures that key alternate 3D structures; this would # mean double-counting nonstandard structures, as they both represent a # single conceptual structure for st in self.model.structures_for_2d_export: if st not in key_sts: sts.add(st) return len(sts) def _setNumStructuresText(self): """ Set text in the "Number of structures" label based on the model state. """ text = str(self._getNumStructures()) self.ui.num_sts_data_lbl.setText(text) def _updateSpecTable(self): """ Gather all types of export specifications to keep the spec table up to date. Meant to be called when any spec data (property, 3D, or FFC) changes. """ model = self.model specs_3d = IdSet() # Find unique 3D specs. Note that we cannot use normal `set`s for this, # as concrete parameters are not hashable for item in model.three_d_export_items: specs_3d.update(IdSet(item.three_d_specs)) model.export_specs = (list(specs_3d) + model.property_export_specs + model.ffc_export_specs)