Source code for schrodinger.application.livedesign.summary

from schrodinger import structure
from schrodinger.models import mappers
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)'
PUBLISH_DATA_YES = 'Yes'
PUBLISH_DATA_NO = 'No'


[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() 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 upload_3d_target = mappers.TargetSpec(setter=self._setUpload3DText) publish_data_target = mappers.TargetSpec( ui.publish_data_lbl, setter=self._setPublishDataLabel, datatype=bool) match_data_target = mappers.TargetSpec( ui.match_data_lbl, setter=self._setMatchDataLabel, datatype=export_models.MatchCompoundsBy) 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), (ui.num_sts_data_lbl, M.input_summary), (match_data_target, M.match_compounds_by), (ui.export_data_table, M.export_specs), (publish_data_target, M.publish_data), ] # 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 _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) def _setPublishDataLabel(self, publish_data: bool): is_published_text = PUBLISH_DATA_YES if publish_data else PUBLISH_DATA_NO self.ui.publish_data_lbl.setText(is_published_text) def _setMatchDataLabel(self, match_compound_enum: export_models.MatchCompoundsBy): if match_compound_enum is export_models.MatchCompoundsBy.structure: text = 'Structure' else: text = str(match_compound_enum) self.ui.match_data_lbl.setText(text)