Source code for schrodinger.application.jaguar.gui.tabs.input_sub_tabs.charge_constraints
import warnings
from collections import Counter
from schrodinger.application.jaguar.input import InvalidCDFTError
from ...ui import input_sub_tabs as sub_tabs_ui
from ...utils import JaguarSettingWarning
from ..sub_tab_widgets import charge_constraints_widgets
from . import base_sub_tab
[docs]class ChargeConstraintsSubTab(base_sub_tab.BaseSubTab):
"""
An Input tab sub-tab for charge constraints.
See parent class for documentation on the class variables
"""
NAME = "Charge Constraints"
TABLE_MODEL_CLASS = charge_constraints_widgets.ChargeConstraintsModel
UI_MODULE = sub_tabs_ui.charge_constraints_ui
[docs] def setup(self):
self._marker_count = Counter()
self.ui.new_btn.clicked.connect(self.addNewConstraint)
self.ui.table_view.addJaguarMarker.connect(self.emitAddMarker)
self.ui.table_view.removeJaguarMarker.connect(self.emitRemoveMarker)
[docs] def addNewConstraint(self):
"""
Add a blank row for a new constraint
"""
model = self._table_model
row_num = model.addRow()
col_num = model.COLUMN.ATOMS
model_index = model.index(row_num, col_num)
proxy_index = self._proxy_model.mapFromSource(model_index)
self.ui.table_view.setCurrentIndex(proxy_index)
self.ui.table_view.edit(proxy_index)
[docs] def saveSettings(self, jag_input, eid):
# See parent class for documentation
rows = self._table_model.rowsForEid(eid)
for cur_row in rows:
weights = cur_row.weightsByNum()
jag_input.appendChargeConstraints(cur_row.charge, weights)
[docs] def loadSettings(self, jag_input, eid, title, struc):
# See parent class for documentation
self._table_model.clearDataForEid(eid)
try:
constraints = jag_input.getChargeConstraints()
except InvalidCDFTError as err:
msg = str(err) + '\nCDFT constraints ignored.'
warnings.warn(JaguarSettingWarning(msg))
return
for charge, wts_by_idx in constraints:
weights = {}
for atom_num, weight in wts_by_idx.items():
# mmjag stores weights by atom index, not name
atom_name = struc.atom[atom_num].atom_name
weights[atom_name] = weight
if weights:
self._table_model.addRow(eid, title, charge, weights)
[docs] def emitAddMarker(self, atoms, settings):
"""
Pass along addJaguarMarker signals received from the table model or
`charge_constraints_widgets.AtomSelectionDelegate`.
Since this sub-tab allows overlapping charge constraint groups, it's
possible to have more than one marker for an atom. Since the panel code
can't handle multiple markers per atom, we use "marker counting" to
ensure that markers are created and deleted appropriately.
See parent class for argument documentation.
"""
atom_hash = self._getAtomHash(atoms[0])
if not self._marker_count[atom_hash]:
super(ChargeConstraintsSubTab, self).emitAddMarker(atoms, settings)
elif settings.get("highlight"):
self.emitSetMarkerHighlighting(atoms, True)
self._marker_count[atom_hash] += 1
[docs] def emitRemoveMarker(self, atoms):
"""
Pass along removeJaguarMarker signals received from the table model or
`charge_constraints_widgets.AtomSelectionDelegate`.
Since this sub-tab allows overlapping charge constraint groups, it's
possible to have more than one marker for an atom. Since the panel code
can't handle multiple markers per atom, we use "marker counting" to
ensure that markers are created and deleted appropriately.
See parent class for argument documentation.
"""
atom_hash = self._getAtomHash(atoms[0])
self._marker_count[atom_hash] -= 1
if not self._marker_count[atom_hash]:
super(ChargeConstraintsSubTab, self).emitRemoveMarker(atoms)
else:
self.emitSetMarkerHighlighting(atoms, False)
def _getAtomHash(self, atom):
"""
Convert the given atom into something hashable that depends on the atom
entry id and index
:param atom: The atom to convert
:type atom: L{schrodinger.structure._StructureAtom
:return: A hashable object. (Specifically, a tuple of entry id and atom
index.)
:rtype: tuple
"""
return (atom.entry_id, atom.index)