Source code for schrodinger.application.bioluminate.patch_utils.settings

"""
Classes for storing panel settings.
"""

import enum

from schrodinger.structutils import color

COLOR_PATCHES = 'Patches'
COLOR_AGGSCORE = 'AggScore'

GREEN = color.Color('dark green').rgb
BLUE = color.Color('dark blue').rgb
RED = color.Color('red').rgb
WHITE = color.Color('white').rgb

# The color to use for parts of the protein surface that
# don't contain a patch.
NO_PATCH_COLOR = (224, 224, 224)

DEFAULT_HYD_PATCH_SIZE = 50
DEFAULT_HYD_THRESHOLD = 0.000
DEFAULT_NEG_PATCHSIZE = 15
DEFAULT_NEG_THRESHOLD = -0.05
DEFAULT_POS_PATCHSIZE = 15
DEFAULT_POS_THRESHOLD = 0.05


[docs]class PatchTypeSettings(object): """ Settings for a single patch type (i.e. hydrophobic, positive, or negative). """
[docs] def __init__(self, size=10, threshold=None, color=None): """ :param size: The minimum size of a patch in Angstroms squared :type size: float :param threshold: The minimum value for a vertex to be considered part of a patch :type threshold: float :param color: What to color the patch in the workspace and panel tables, given as integer (r, g, b) values. :type color: list or tuple """ self.size = size self.threshold = threshold self.color = color
[docs]class PatchSettings(object): """ Settings for all patch types (i.e. hydrophobic, positive, and negative). :cvar EP: A very small value (i.e. epsilon) used for floating point comparisons in `sameSizeAndThreshold`. :vartype EP: float """ DEFAULT_TRANSPARENCY = 15 EP = 0.0000001
[docs] def __init__(self): self.hydrophobic = PatchTypeSettings(size=DEFAULT_HYD_PATCH_SIZE, threshold=DEFAULT_HYD_THRESHOLD, color=GREEN) self.positive = PatchTypeSettings(size=DEFAULT_POS_PATCHSIZE, threshold=DEFAULT_POS_THRESHOLD, color=BLUE) self.negative = PatchTypeSettings(size=DEFAULT_NEG_PATCHSIZE, threshold=DEFAULT_NEG_THRESHOLD, color=RED) self.aggscore_color = RED self.display_mode = COLOR_PATCHES self.trans_front = self.DEFAULT_TRANSPARENCY self.trans_back = self.DEFAULT_TRANSPARENCY self.hgp_include_maps = {}
[docs] def color(self, patch_type): """ Get the color for the specified patch type. If coloring by AggScore, then the user's color for AggScore is always returned instead. :param patch_type: The patch type to get the color for :type patch_type: `PatchType` :return: The requested color as a tuple of integer (r, g, b) values :rtype: tuple """ if self.display_mode == COLOR_AGGSCORE: return self.aggscore_color elif patch_type is PatchType.positive: return self.positive.color elif patch_type is PatchType.negative: return self.negative.color elif patch_type is PatchType.hydrophobic: return self.hydrophobic.color
[docs] def getPatchColorRamp(self, patch_type): """ Return the ColorRamp object for the given patch type. Used for coloring Workspace patch surface, as well as background column in tables. If coloring by AggScore, then color ramp for AggScore is always used. :param patch_type: The patch type to get the color ramp for :type patch_type: `PatchType` :return: The requeted color ramp :rtype: `color.ColorRamp` """ patch_color = self.color(patch_type) if self.display_mode == COLOR_AGGSCORE: endpoint_values = (0.0, 10.0) elif patch_type is PatchType.hydrophobic: endpoint_values = (0.0, 0.3) else: endpoint_values = (0.0, 0.5) return color.ColorRamp((WHITE, patch_color), endpoint_values)
[docs] def sameSizeAndThreshold(self, other): """ Check to see if this object and `other` have the same patch size and patch threshold settings. Differences in color are ignored. :param other: The object to compare :type other: `PatchSettings` :return: True if these objects have the same size and threshold settings. False otherwise. :rtype: bool """ self_data = (self.positive.size, self.negative.size, self.hydrophobic.size, self.positive.threshold, self.negative.threshold, self.hydrophobic.threshold) other_data = (other.positive.size, other.negative.size, other.hydrophobic.size, other.positive.threshold, other.negative.threshold, other.hydrophobic.threshold) for cur_self, cur_other in zip(self_data, other_data): if abs(cur_self - cur_other) >= self.EP: return False return True
[docs]class PatchType(enum.Enum): positive = ("Positive", "pos", "eV") negative = ("Negative", "neg", "eV") hydrophobic = ("Hydrophobic", "hyd", "sLogP")
[docs] def __init__(self, long_name, short_name, unit): """ :param long_name: The patch name used in the details dialog :type long_name: str :param short_name: The patch name used in the patch table :type short_name: str :param unit: The unit for values of this patch :type unit: str """ self.long_name = long_name self.short_name = short_name self.unit = unit