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.
- schrodinger.structutils.color.rgb_to_hex(rgb)¶
- Parameters
rgb (Tuple(int, int, int)) – 0-255 based RGB tuple
- Returns
Hex value for color
- Return type
str
- 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)¶
- property rgb_float¶
Returns a tuple of (R, G, B) for this color, each ranging from 0.0 to 1.0.
- property hex_string¶
Returns the color as string of hex RGB values (RRGGBB). For example, pure red will be returned as “FF0000”.
- class schrodinger.structutils.color.ColorScheme(name='element', color_asl_list=[])¶
Bases:
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
- __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 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.
- 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
- class schrodinger.structutils.color.RainbowColorRamp(min_value=0, max_value=100)¶
Bases:
schrodinger.structutils.color.ColorRamp
- COLORS = ('red1', 'user10', 'user12', 'user14', 'user15', 'user16', 'user17', 'user18', 'user19', 'user20', 'user21', 'green', 'user53', 'user54', 'user55', 'user56', 'user57', 'user58', 'user59', 'user60', 'user26', 'user28', 'user30', 'user32', 'user61', 'user62', 'purple')¶
- __init__(min_value=0, max_value=100)¶
- Parameters
min_value (int) – The value corresponding to red.
max_value (int) – The value corresponding to purple.
- 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