import warnings
from collections import OrderedDict
from schrodinger.infra import mm
from schrodinger.Qt import QtGui
from .. import ui
from ..utils import JaguarSettingError
from ..utils import JaguarSettingWarning
from .molecule_tab import MoleculeTabNoInputSelector
from .multi_structure_tab import MultiStructureTab
[docs]class IrcTab(MultiStructureTab):
NAME = "IRC"
HELP_TOPIC = "JAGUAR_TOPIC_IRC_FOLDER"
UI_MODULES = (ui.irc_top_ui, ui.multi_structures_ui, ui.irc_bottom_ui,
(MoleculeTabNoInputSelector, "molecule_sub_tab"))
DIRECTIONS = OrderedDict(
(("Forward/Reverse", mm.MMJAG_IRCMODE_BOTH),
("Forward", mm.MMJAG_IRCMODE_FWD), ("Reverse", mm.MMJAG_IRCMODE_REV),
("Downhill", mm.MMJAG_IRCMODE_DOWN)))
[docs] def setup(self):
super(IrcTab, self).setup()
self.ui.direction_combo.addItemsFromDict(self.DIRECTIONS)
self.ui.direction_combo.currentIndexChanged.connect(
self.directionChanged)
self.directionChanged()
step_size_validator = QtGui.QDoubleValidator(self)
step_size_validator.setBottom(0.0)
self.ui.step_size_le.setValidator(step_size_validator)
[docs] def directionChanged(self):
"""
Respond to the direction combo box selection changing
"""
direction = self.ui.direction_combo.currentData()
if direction == mm.MMJAG_IRCMODE_DOWN:
self.setStructureSelectorsEnabled(True, False, False)
else:
self.setStructureSelectorsEnabled(True, True, True)
[docs] def getDefaultKeywords(self):
new_keywords = {mm.MMJAG_IKEY_IRC: mm.MMJAG_IRC_ON}
keywords = super(IrcTab, self).getDefaultKeywords()
keywords.update(new_keywords)
return keywords
[docs] def getMmJagKeywords(self):
keywords = super(IrcTab, self).getMmJagKeywords()
keywords[mm.MMJAG_SKEY_IRCMODE] = self.ui.direction_combo.currentData()
keywords[mm.MMJAG_IKEY_IRCMAX] = self.ui.num_points_sb.value()
keywords[mm.MMJAG_IKEY_IRCMXCYC] = self.ui.max_opt_sb.value()
step_size = str(self.ui.step_size_le.text())
if self.ui.step_size_le.hasAcceptableInput():
keywords[mm.MMJAG_RKEY_IRCSTEP] = float(step_size)
else:
msg = "Unacceptable value for IRC step size: %s" % step_size
raise JaguarSettingError(msg)
if self.ui.use_weighted_cb.isChecked():
irc = mm.MMJAG_IRC_MW
else:
irc = mm.MMJAG_IRC_ON
keywords[mm.MMJAG_IKEY_IRC] = irc
return keywords
[docs] def loadSettings(self, jag_input):
super(IrcTab, self).loadSettings(jag_input)
self.ui.direction_combo.setCurrentMmJagData(jag_input,
mm.MMJAG_SKEY_IRCMODE,
"direction")
self._loadIntoSbIfPositive(self.ui.num_points_sb, jag_input,
mm.MMJAG_IKEY_IRCMAX, "number of IRC points")
self._loadIntoSbIfPositive(self.ui.max_opt_sb, jag_input,
mm.MMJAG_IKEY_IRCMXCYC,
"maximum optimization steps")
self._loadIntoLeIfPositive(self.ui.step_size_le, jag_input,
mm.MMJAG_RKEY_IRCSTEP, "IRC step size")
use_weighted = (jag_input[mm.MMJAG_IKEY_IRC] == mm.MMJAG_IRC_MW)
self.ui.use_weighted_cb.setChecked(use_weighted)
if jag_input[mm.MMJAG_IKEY_IRC] == mm.MMJAG_IRC_OFF:
msg = ("%s may not be %s for a Reaction Coordinate job. Assuming "
"%s=%i." % (mm.MMJAG_IKEY_IRC, mm.MMJAG_IRC_OFF,
mm.MMJAG_IKEY_IRC, mm.MMJAG_IRC_ON))
warnings.warn(JaguarSettingWarning(msg))
elif jag_input[mm.MMJAG_IKEY_IRC] not in (mm.MMJAG_IRC_ON,
mm.MMJAG_IRC_MW):
msg = ("Unrecognized %s value (%i). Assuming %s=%i." %
(mm.MMJAG_IKEY_IRC, jag_input[mm.MMJAG_IKEY_IRC],
mm.MMJAG_IKEY_IRC, mm.MMJAG_IRC_ON))
warnings.warn(JaguarSettingWarning(msg))
def _loadIntoSbIfPositive(self, spinbox, jag_input, keyword, setting_name):
"""
Load the specified value into the given spinbox if the value is
positive. Issue a warning otherwise.
:param spinbox: The spinbox to load the value into
:type spinbox: `PyQt5.QtWidgets.QSpinBox`
:param jag_input: The JaguarInput containing the value to load
:type jag_input: `schrodinger.application.jaguar.input.JaguarInput`
:param keyword: The keyword to load the value for
:type keyword: str
:param setting_name: The name of the setting. This name will only be
used when issueing warnings.
:type setting_name: str
"""
load_func = spinbox.setValue
self._loadIntoWidgetIfPositive(load_func, jag_input, keyword,
setting_name)
def _loadIntoLeIfPositive(self, line_edit, jag_input, keyword,
setting_name):
"""
Load the specified value into the given line edit if the value is
positive. Issue a warning otherwise.
:param line_edit: The line edit to load the value into
:type line_edit: `PyQt5.QtWidgets.QSpinBox`
:param jag_input: The JaguarInput containing the value to load
:type jag_input: `schrodinger.application.jaguar.input.JaguarInput`
:param keyword: The keyword to load the value for
:type keyword: str
:param setting_name: The name of the setting. This name will only be
used when issueing warnings.
:type setting_name: str
"""
load_func = lambda x: line_edit.setText(str(x))
self._loadIntoWidgetIfPositive(load_func, jag_input, keyword,
setting_name)
def _loadIntoWidgetIfPositive(self, load_func, jag_input, keyword,
setting_name):
"""
Load the specified value into the given widget if the value is
positive. Issue a warning otherwise.
:param load_func: The function to use for loading the value into the
widget
:type load_func: function
:param jag_input: The JaguarInput containing the value to load
:type jag_input: `schrodinger.application.jaguar.input.JaguarInput`
:param keyword: The keyword to load the value for
:type keyword: str
:param setting_name: The name of the setting. This name will only be
used when issuing warnings.
:type setting_name: str
"""
value = jag_input[keyword]
if value > 0:
load_func(value)
else:
if value == 0:
neg_or_zero = "Zero"
else:
neg_or_zero = "Negative"
msg = ("%s values are not allowed for %s (%s=%s)." %
(neg_or_zero, setting_name, keyword, value))
warnings.warn(JaguarSettingWarning(msg))