Source code for schrodinger.application.matsci.clusterstructgui
"""
GUI elements to aid in pulling dimers or clusters of nearest
neighbors from a larger structure.
Copyright Schrodinger, LLC. All rights reserved.
"""
from schrodinger.application.matsci import clusterstruct
from schrodinger.Qt import QtCore
from schrodinger.ui.qt import swidgets
CRITERIA = [
clusterstruct.NO_MOLS, clusterstruct.ONE_ONLY_MOL,
clusterstruct.AT_LEAST_ONE_MOL, clusterstruct.TWO_MOLS
]
[docs]class SpeciesCombo(swidgets.SLabeledComboBox):
"""
Combobox for showing species
"""
[docs] def __init__(self, label=None, **kwargs):
"""
Create a SpeciesCombo instance
:param str label: The label for the combobox
"""
super().__init__(label, **kwargs)
if not label:
self.label.hide()
self._fixTypeComboSizing()
def _fixTypeComboSizing(self):
"""
Make sure the combo expands if necessary when new species are added
"""
self.setSizeAdjustPolicy(self.AdjustToContents)
policy = self.sizePolicy()
policy.setHorizontalPolicy(policy.Minimum)
self.setSizePolicy(policy)
[docs] def setCurrentSpecies(self, species):
"""
Fill the combo with the list of current species
:type species: dict
:param species: Keys are unique SMILES strings, values are SpeciesData
objects for the species with that SMILES string.
"""
self.clear()
itemdict = clusterstruct.get_species_display_names(species.values())
self.addItemsFromDict(itemdict)
[docs] def currentSpecies(self):
"""
Return the currently selected species
:rtype: `schrodinger.application.matsci.clusterstruct.SpeciesData`
:return: The currently selected species
"""
return self.currentData()
[docs] def getSampleMolNumber(self):
"""
Get a sample molecule number for the current species
:rtype: int
:return: a sample molecule number for the current species
"""
return self.currentSpecies().getSampleMolNumber()
[docs]class MonomerSpeciesSelector(swidgets.SCheckBoxWithSubWidget):
"""
Checkbox and combo that allows the user to select a species. The enabled
state of the combobox is controlled by the checkbox.
"""
species_changed = QtCore.pyqtSignal()
[docs] def __init__(self,
label='Limit active molecules to those of type:',
command=None,
find_species_fn=None,
**kwargs):
"""
Create a Monomer SpeciesSelector instance
:type label: str
:param label: The text between the checkbox and combobox
:type command: callable
:param command: The slot to connect to the species_changed signal
:type find_species_fn: function
:param find_species_fn: Function that is used to create species
All other keyword args are passed to the SCheckBoxWithSubWidget class
"""
self.species = {}
self.find_species_fn = (find_species_fn if find_species_fn else
clusterstruct.find_species)
self.subframe = swidgets.SFrame(layout_type=swidgets.HORIZONTAL)
self.createSubWidgets()
swidgets.SCheckBoxWithSubWidget.__init__(self,
label,
self.subframe,
checked=False,
**kwargs)
if command:
self.species_changed.connect(command)
[docs] def currentSpecies(self):
"""
Return the currently selected species
:rtype: `schrodinger.application.matsci.clusterstruct.SpeciesData`
:return: The currently selected species
"""
return self.type_combo.currentSpecies()
[docs] def speciesChanged(self):
"""
React to a new species being selected
"""
self.species_changed.emit()
[docs] def hasSpecies(self):
"""
Check if any species have been loaded
:rtype: bool
:return: True of any species has been loaded, False if not
"""
return bool(self.type_combo.count())
[docs] def clear(self):
"""
Clear out the species combo
"""
self.type_combo.clear()
[docs] def loadSpecies(self, structs):
"""
Find all the species in the given structures and load them into the
species type combobox
:type structs: list of `schrodinger.structure.Structure`
:param structs: The structures to find the species in
:rtype: list of
`schrodinger.application.matsci.clusterstruct.SpeciesData`
:return: Each item of the list is the data for a species found
"""
species = self.find_species_fn(structs)
self.setCurrentSpecies(species)
return species
[docs] def setCurrentSpecies(self, species):
"""
Fill the species combo with the list of current species
:type species: dict
:param species: Keys are unique SMILES strings, values are SpeciesData
objects for the species with that SMILES string.
"""
self.species = species
self.type_combo.setCurrentSpecies(species)
[docs] def reset(self):
"""
Reset the widget, including clearing the species type combo
"""
swidgets.SCheckBoxWithSubWidget.reset(self)
self.clear()
[docs] def getNumberOfType(self):
"""
Get the number of members of the current species
:rtype: int
:return: The number of members of the current species
"""
data = self.type_combo.currentData()
if data:
return len(data.members)
else:
return 0
[docs]class DimerSpeciesSelector(MonomerSpeciesSelector):
"""
Checkbox and combo that allows the user to select a species for the purpose
of selecting dimers with or without the given species. The enabled state of
the combobox is controlled by the checkbox.
"""
criterion_changed = QtCore.pyqtSignal(str)
[docs] def __init__(self,
label='Limit dimers to only those that contain:',
command=None,
**kwargs):
"""
Create a DimerSpeciesSelector instance
:type label: str
:param label: The text between the checkbox and combobox
:type command: callable
:param command: The slot to connect to the species_changed and
criterion_changed signals
See parent class for additional documentation
"""
MonomerSpeciesSelector.__init__(self,
label=label,
command=command,
**kwargs)
if command:
self.criterion_changed.connect(command)
[docs] def currentCriterion(self):
"""
Return the current amount criterion
:rtype: str
:return: The desired amount of the species. Will be one of the items
from the CRITERIA list
"""
return self.crit_combo.currentText()
[docs] def criterionChanged(self):
"""
React to a change in the amount criterion
"""
self.criterion_changed.emit(self.currentCriterion())
[docs] def reset(self):
"""
Reset the widgets
"""
MonomerSpeciesSelector.reset(self)
self.crit_combo.reset()
[docs] def applyToDimers(self, dimers):
"""
Apply the current settings to a list of dimers, marking them as meeting
the criteria or not. If the controlling checkbox is unchecked, all
dimers will be marked as meeting the criteria.
:type dimers: list
:param dimers: A list of Dimer objects. Each dimer will have its
meets_species_criterion property set based on the results of the
Dimer.evaluateSpeciesCriterion method.
"""
if self.isChecked():
crit_species = self.currentSpecies()
crit = self.currentCriterion()
species = self.species
else:
crit_species = crit = species = None
for dimer in dimers:
dimer.evaluateSpeciesCriterion(crit_species, crit, species)