Source code for schrodinger.ui.qt.forcefield.ffcustomoplssettingwidget
from schrodinger.Qt import QtCore
from schrodinger.Qt.QtWidgets import QWidget
from schrodinger.ui import maestro_ui
from schrodinger.ui.qt.widgetmixins.basicmixins import BaseMixinCollection
from . import ffcustomoplssettingwidget_ui
from . import ffglobalpreferencewidget
from . import stylesheet
from .forcefield import PROJECT_OPLS_DIR_CMD_OPTION
from .forcefield import has_valid_custom_OPLS_preference
maestro_hub = maestro_ui.MaestroHub.instance()
[docs]class FFCustomOPLSSettingMixin(BaseMixinCollection):
"""
Abstract class for creating custom OPLS settings widgets.
Enforces consistent widget appearance and behavior.
Must be inherited by a widget class that defines a .ui file that contains a
checkbox called `use_customized_version_cb` and a `FFSettingsButton`
called `ff_settings_btn`.
Emits a custom signal with a bool defining 'use custom force field'
checkbox check state.
:cvar useCustomParameterStateChanged: signal indication that use custom
forcefield checkbox state is changed.
:vartype useCustomParameterStateChanged: QtCore.pyqtSignal
"""
useCustomParameterStateChanged = QtCore.pyqtSignal(bool)
[docs] def initSetUp(self):
super().initSetUp()
self.setStyleSheet(stylesheet.FF_CUSTOM_OPLS_SETTINGS_WIDGET_STYLESHEET)
self._updateUI()
self.ui.use_customized_version_cb.toggled.connect(self._updateUI)
self.ui.use_customized_version_cb.toggled.connect(
self.useCustomParameterStateChanged)
maestro_hub.projectPreferenceChanged.connect(self._onPreferenceChanged)
ff_global_preference_widget = ffglobalpreferencewidget.FFGlobalPreferenceWidget.getInstance(
)
ff_global_preference_widget.useCustomForceFieldToggled.connect(
self.setUseCustomizedVersionCBState)
ff_global_preference_widget.customOPLSPathChanged.connect(
self._updateAndEmitSignal)
def _onPreferenceChanged(self, pref_name):
"""
Updates the widget state whenever Maestro preferences are changed
"""
if PROJECT_OPLS_DIR_CMD_OPTION in pref_name:
self._updateAndEmitSignal()
[docs] def event(self, e):
"""
Handle the window activation.
:param e: the event object
:rtype: QTCore.QEvent
"""
# update the selector based on possible change to the contents of the
# S-OPLS preferences directory
if e.type() == QtCore.QEvent.WindowActivate:
# ensure that the checkbox update happens after the activate event
# is finished so we can display message boxes if necessary
QtCore.QTimer.singleShot(0, self._updateAndEmitSignal)
return super().event(e)
def _updateAndEmitSignal(self):
self._updateUI()
self.useCustomParameterStateChanged.emit(
self.isUseCustomizedVersionChecked())
def _updateUI(self):
"""
Updates UI of widget
"""
self.ui.ff_settings_btn.setUseCustomOPLS(
self.isUseCustomizedVersionChecked())
if (self.isUseCustomizedVersionChecked() and
not has_valid_custom_OPLS_preference()):
cb_stylesheet = "QCheckBox { color: #aa6d09 }"
else:
cb_stylesheet = "QCheckBox { color: #444444 }"
self.ui.use_customized_version_cb.setStyleSheet(cb_stylesheet)
[docs] def isUseCustomizedVersionChecked(self):
"""
Returns True if use customized option is checked, False otherwise.
:rtype: bool
:return: use customized version checked state.
"""
return self.ui.use_customized_version_cb.isChecked()
[docs] def setUseCustomizedVersionCBState(self, cb_state):
"""
Sets 'use customized version' checkbox state to on/off.
:param cb_state: check state of checkbox.
:type cb_state: bool
"""
self.ui.use_customized_version_cb.setChecked(cb_state)