schrodinger.structutils.color module

An interface to the Maestro color palette and color schemes.

Color schemes are read from maestro-v<version>/data/res/scheme.res.

Copyright Schrodinger, LLC. All rights reserved.

schrodinger.structutils.color.get_rgb_from_color_index(index)

A convenience function for getting the rgb value for a color index.

Parameters:index – an integer specifying the color index
Return r,g,b:a tuple of 3 integer values for the red, green, blue values. Range from 0 to 255.
class schrodinger.structutils.color.Color(color)

Bases: object

Represent a color as either an integer (colormap index), string (color name or hex “RRGGBB” value), or an RGB value (tuple/list of 3 ints, values 0-255).

Provides the following properties and methods:
  • Color.index = int(Color) - mmcolor index of the closest color
  • Color.name = str(Color) - mmcolor name of the closest color
  • Color.rgb - (tuple of 0-255 ints)
  • equal = (col1 == col2)

When object is initialized from the RGB value, the Color.index and Color.name attributes are set to the closest color in the mmcolor palette.

__init__(color)

Initialize self. See help(type(self)) for accurate signature.

__str__()

Return str(self).

__repr__()

Return repr(self).

__int__()
__eq__(other)

Return self==value.

__ne__(other)

Return self!=value.

rgb_float

Returns a tuple of (R, G, B) for this color, each ranging from 0.0 to 1.0.

hex_string

Returns the color as string of hex RGB values (RRGGBB). For example, pure red will be returned as “FF0000”.

__class__

alias of builtins.type

__delattr__

Implement delattr(self, name).

__dict__ = mappingproxy({'__module__': 'schrodinger.structutils.color', '__doc__': '\n Represent a color as either an integer (colormap index), string\n (color name or hex "RRGGBB" value), or an RGB value\n (tuple/list of 3 ints, values 0-255).\n\n Provides the following properties and methods:\n - Color.index = int(Color) - mmcolor index of the closest color\n - Color.name = str(Color) - mmcolor name of the closest color\n - Color.rgb - (tuple of 0-255 ints)\n - equal = (col1 == col2)\n\n When object is initialized from the RGB value, the Color.index and\n Color.name attributes are set to the closest color in the mmcolor palette.\n\n ', '__init__': <function Color.__init__>, '__str__': <function Color.__str__>, '__repr__': <function Color.__repr__>, '__int__': <function Color.__int__>, '__eq__': <function Color.__eq__>, '__ne__': <function Color.__ne__>, 'rgb_float': <property object>, 'hex_string': <property object>, '__dict__': <attribute '__dict__' of 'Color' objects>, '__weakref__': <attribute '__weakref__' of 'Color' objects>, '__hash__': None})
__dir__() → list

default dir() implementation

__format__()

default object formatter

__ge__

Return self>=value.

__getattribute__

Return getattr(self, name).

__gt__

Return self>value.

__hash__ = None
__init_subclass__()

This method is called when a class is subclassed.

The default implementation does nothing. It may be overridden to extend subclasses.

__le__

Return self<=value.

__lt__

Return self<value.

__module__ = 'schrodinger.structutils.color'
__new__()

Create and return a new object. See help(type) for accurate signature.

__reduce__()

helper for pickle

__reduce_ex__()

helper for pickle

__setattr__

Implement setattr(self, name, value).

__sizeof__() → int

size of object in memory, in bytes

__subclasshook__()

Abstract classes can override this to customize issubclass().

This is invoked early on by abc.ABCMeta.__subclasscheck__(). It should return True, False or NotImplemented. If it returns NotImplemented, the normal algorithm is used. Otherwise, it overrides the normal algorithm (and the outcome is cached).

__weakref__

list of weak references to the object (if defined)

class schrodinger.structutils.color.ColorScheme(name='element', color_asl_list=[])

Bases: schrodinger.utils.colorscheme.MM_CScheme

Define a Maestro color scheme.

This class provides the following functionality:

colorscheme.apply(st, [atoms])
for color, asl in colorscheme:
    <do>
__init__(name='element', color_asl_list=[])

Create ColorScheme object

Parameters:
  • name (str) – Name of ColorScheme
  • color_asl_list (asl patterns) – List of asl patterns in ColorScheme
add(color_str, asl, rule_description='')

Add another set of rules to this color scheme.

Parameters:
  • color – color string
  • asl – what to apply the color to
__iter__()

Iterate over all entries in this scheme.

Returns a tuple of (Color, asl)

__len__()

Return the number of rules in the scheme

copy()

Return a copy of this scheme.

apply(st, atoms=None)

Applies the scheme to the specified Structure <st>.

Parameters:atoms – Optionally specify which atoms to apply the scheme to in format. Can be a list atom atom indices, or a Bitset instance.
writeSchemeFile(filename)

Write the scheme to the specified .sch file.

Parameters:filename (str) – filelocation to save scheme file to
__class__

alias of builtins.type

__delattr__

Implement delattr(self, name).

__dict__ = mappingproxy({'__module__': 'schrodinger.structutils.color', '__doc__': '\n Define a Maestro color scheme.\n\n This class provides the following functionality::\n\n colorscheme.apply(st, [atoms])\n for color, asl in colorscheme:\n <do>\n ', '__init__': <function ColorScheme.__init__>, 'add': <function ColorScheme.add>, '__iter__': <function ColorScheme.__iter__>, '__len__': <function ColorScheme.__len__>, 'copy': <function ColorScheme.copy>, 'apply': <function ColorScheme.apply>, 'writeSchemeFile': <function ColorScheme.writeSchemeFile>})
__dir__() → list

default dir() implementation

__eq__

Return self==value.

__format__()

default object formatter

__ge__

Return self>=value.

__getattribute__

Return getattr(self, name).

__gt__

Return self>value.

__hash__

Return hash(self).

__init_subclass__()

This method is called when a class is subclassed.

The default implementation does nothing. It may be overridden to extend subclasses.

__le__

Return self<=value.

__lt__

Return self<value.

__module__ = 'schrodinger.structutils.color'
__ne__

Return self!=value.

__new__()

Create and return a new object. See help(type) for accurate signature.

__reduce__()

helper for pickle

__reduce_ex__()

helper for pickle

__repr__()
__setattr__

Implement setattr(self, name, value).

__sizeof__() → int

size of object in memory, in bytes

__str__

Return str(self).

__subclasshook__()

Abstract classes can override this to customize issubclass().

This is invoked early on by abc.ABCMeta.__subclasscheck__(). It should return True, False or NotImplemented. If it returns NotImplemented, the normal algorithm is used. Otherwise, it overrides the normal algorithm (and the outcome is cached).

__swig_destroy__()
__weakref__

list of weak references to the object (if defined)

addRule()
applyScheme()
clearRules()
deleteFile()
getDescription()
getFileName()
getLongName()
getOriginalName()
getRules()
getShortName()
readRulesFromFile()
setDescription()
setFileName()
setLongName()
setOriginalName()
setRules()
setShortName()
thisown

The membership flag

writeFile()
class schrodinger.structutils.color.ColorRamp(colors=('white', 'blue'), values=(0, 100))

Bases: object

An object for calculating colors on a customizable color ramp.

Coloring atoms according to a calculated property that ranges from 0 to 10:

color_ramp = ColorRamp(colors=("white", "blue"), values=(0,10))
for atom in st.atom:
    property = calc_property(atom)
    r, g, b  = color_ramp.getRGB(property)
    atom.setColorRGB(r, g, b)

Coloring atoms according to a calculated property that ranges from -10 to 10 using blues for negative values and reds for positive values:

color_ramp = ColorRamp(colors=("blue", "white", "red"),
                       values=(-10, 0, 10))
for atom in st.atom:
    property = calc_property(atom)
    color = color_ramp.getRGB(property)
    atom.setColorRGB(*color)
__init__(colors=('white', 'blue'), values=(0, 100))

Initialize a ColorRamp object where the specified values correspond to the given colors

Parameters:
  • colors (list or tuple) – The list of colors. Any color description that is recognized by Color may be used (a color name or colormap index).
  • values (list or tuple) – The list of numerical values. This list must be the same length as colors, all values must be unique, and the list must be sorted in either ascending or descending order.
__class__

alias of builtins.type

__delattr__

Implement delattr(self, name).

__dict__ = mappingproxy({'__module__': 'schrodinger.structutils.color', '__doc__': '\n An object for calculating colors on a customizable color ramp.\n\n Coloring atoms according to a calculated property that ranges from 0 to 10::\n\n color_ramp = ColorRamp(colors=("white", "blue"), values=(0,10))\n for atom in st.atom:\n property = calc_property(atom)\n r, g, b = color_ramp.getRGB(property)\n atom.setColorRGB(r, g, b)\n\n Coloring atoms according to a calculated property that ranges from -10\n to 10 using blues for negative values and reds for positive values::\n\n color_ramp = ColorRamp(colors=("blue", "white", "red"),\n values=(-10, 0, 10))\n for atom in st.atom:\n property = calc_property(atom)\n color = color_ramp.getRGB(property)\n atom.setColorRGB(*color)\n ', '__init__': <function ColorRamp.__init__>, 'getRGB': <function ColorRamp.getRGB>, '_getRGBFloat': <function ColorRamp._getRGBFloat>, '__dict__': <attribute '__dict__' of 'ColorRamp' objects>, '__weakref__': <attribute '__weakref__' of 'ColorRamp' objects>})
__dir__() → list

default dir() implementation

__eq__

Return self==value.

__format__()

default object formatter

__ge__

Return self>=value.

__getattribute__

Return getattr(self, name).

__gt__

Return self>value.

__hash__

Return hash(self).

__init_subclass__()

This method is called when a class is subclassed.

The default implementation does nothing. It may be overridden to extend subclasses.

__le__

Return self<=value.

__lt__

Return self<value.

__module__ = 'schrodinger.structutils.color'
__ne__

Return self!=value.

__new__()

Create and return a new object. See help(type) for accurate signature.

__reduce__()

helper for pickle

__reduce_ex__()

helper for pickle

__repr__

Return repr(self).

__setattr__

Implement setattr(self, name, value).

__sizeof__() → int

size of object in memory, in bytes

__str__

Return str(self).

__subclasshook__()

Abstract classes can override this to customize issubclass().

This is invoked early on by abc.ABCMeta.__subclasscheck__(). It should return True, False or NotImplemented. If it returns NotImplemented, the normal algorithm is used. Otherwise, it overrides the normal algorithm (and the outcome is cached).

__weakref__

list of weak references to the object (if defined)

getRGB(value)

Determine the color that corresponds to the specified value

Parameters:value (int or float) – The value to calculate the color for
Returns:The color corresponding to the specified value, where the color is a represented by a list of (red, green, blue) integers in the 0-255 range.
Return type:list
schrodinger.structutils.color.available_color_schemes()

Return a list of available color schemes (list of names). Raises RuntimeError if Maestro installation is not available. Raises IOError if scheme.res file could not be found

schrodinger.structutils.color.get_color_scheme(name)

Return a ColorScheme object for scheme <name>. Raises ValueError if such scheme does not exist. Raises RuntimeError if Maestro installation is not available. Raises IOError if scheme.res file could not be found

schrodinger.structutils.color.apply_color_scheme(st, scheme, atom_list=None)

Applies the scheme to the specified Structure <st>. Optionally a list of atom indecies may be specified.

scheme
One of the names returned by available_color_schemes() or a ColorScheme object returned by get_color_scheme().
atom_list
A list of atom indices to apply color scheme to (default all atoms).

Raises ValueError if such scheme does not exist. Raises RuntimeError if Maestro installation is not available. Raises IOError if scheme.res file could not be found