Source code for schrodinger.application.matsci.appbase

"""
Module for customizing af2 app features

Copyright Schrodinger, LLC. All rights reserved.
"""

import schrodinger

from schrodinger.ui.qt.appframework2 import af2

maestro = schrodinger.get_maestro()


[docs]class MatSciAppMixin: """ General mixin for MatSci panels """ WAM_LOAD_SELECTED = af2.input_selector.InputSelector.SELECTED_ENTRIES WAM_LOAD_INCLUDED = af2.input_selector.InputSelector.INCLUDED_ENTRY
[docs] def initMixinOptions(self, wam_input_state=None, wam_load_function=None, wam_run_singleton=True, wam_set_panel_input_state=True): """ Initialize the options for the mixin :param str wam_input_state: The input state to use to get the WAM entries :param callable wam_load_function: Function that takes no arguments and loads the entries into the panel. :param bool wam_run_singleton: Whether the panel singleton should be run (i.e. displayed) or not. :param bool wam_set_panel_input_state: Whether to set panel's input_selector state to the corresponding wam_input_state """ assert wam_input_state in (None, self.WAM_LOAD_SELECTED, self.WAM_LOAD_INCLUDED) self._wam_input_state = wam_input_state self._wam_load_function = wam_load_function self._wam_run_singleton = wam_run_singleton self._wam_set_panel_input_state = wam_set_panel_input_state
[docs] @classmethod def panel(cls, *entry_ids): """ Launch a singleton instance of the panel and load entries if applicable. See `af2.App.panel` for more information. :param tuple entry_ids: Entry ids to load into the panel :raise RuntimeError: If the input state is invalid """ if not entry_ids: super().panel() return the_panel = super().panel(run=False) if not hasattr(the_panel, '_wam_run_singleton'): the_panel.error( '"initMixinOptions" has not been called by the panel. Could' ' not open panel for entries.') return if the_panel._wam_run_singleton: the_panel.run() input_state = the_panel._wam_input_state if input_state is None: return if input_state == cls.WAM_LOAD_INCLUDED: command = 'entrywsincludeonly entry ' + str(entry_ids[0]) elif input_state == cls.WAM_LOAD_SELECTED: command = 'entryselectonly entry ' + ' '.join(map(str, entry_ids)) if the_panel._wam_set_panel_input_state: for selector in ('input_selector', '_if'): input_selector = getattr(the_panel, selector, None) if input_selector: the_panel.input_selector.setInputState(input_state) break maestro.command(command) if the_panel._wam_load_function: the_panel._wam_load_function()