def testGetColorIndices(self): r = cmd.get_color_indices() self.assertTrue( set(r).issuperset([('white', 0), ('black', 1), ('blue', 2)])) self.assertFalse(('grey50', 104) in r) r = cmd.get_color_indices(all=1) self.assertTrue(('grey50', 104) in r)
def testShortcutTiming(self): names = pymol.setting.get_name_list() colors = [c[0] for c in cmd.get_color_indices(0)] with self.timing(): sc = cmd.Shortcut(names) sc = cmd.Shortcut(cmd.kw_list) sc = cmd.Shortcut(colors)
def _getColorTuple(self, color): if isinstance(color, tuple): return color if isinstance(color, list): return tuple(color) elif isinstance(color, int): if color in dict((k,v) for (v,k) in cmd.get_color_indices()): return cmd.get_color_tuple(color) else: hexval = color & 0xffffff return tuple(map(lambda x: x/255., [ hexval >> 16, (hexval >> 8) & 0xff, hexval & 0xff ])) elif isinstance(color, str): return cmd.get_color_tuple(color)
def cpk(cpknew, selection): # Get the existing color indices from PyMOL colorIndex = {} for i in cmd.get_color_indices(): k, v = i colorIndex[k] = v # Select the right CPK dictionary if cpknew: cpk = CPKNewDict suffix = 'cpknew' else: cpk = CPKDict suffix = 'cpk' # Iterate through the colors in the selected CPK dictionary for k in cpk: # Create a hopefully unique name for each color by concatenating # its name in the dictionary with a suffix specifying which dictionary # it came from color = '%s%s' % (k, suffix) # If PyMOL doesn't know about any of them, tell it if color not in colorIndex: cmd.set_color(color, cpk[k]) unk = 'not e. ' for k in cpk: if k != 'UNK': # Assuming ampersands mean "and" to PyMOL's selection algebra, # this line tells PyMOL to use each color in the dictionary, # again identified by its concatenated name (the first argument), # to color all atoms in the selection passed to cpk() whose # elemental symbols match the color's key in the dictionary # (the abbreviation 'e.' in PyMOL's selection algebra can mean # one of two things; in this case, it stands for "element symbol") cmd.color('%s%s' % (k, suffix), 'e. %s & (%s)' % (k, selection)) # This builds a string of the format 'not e. A+B+C+D+...', where # A, B, C, and D are element symbols. Presumably, the intent is # to build a selection containing all atoms that don't have a # color defined for them in the dictionary. I don't have any # reason to believe it doesn't work, but I don't know for sure. unk = '%s%s+' % (unk, k) # This strips the trailing plus off of the resulting string and colors all # atoms that both match it and are in the selection passed into cpk() # with the unknown color 'UNK' in the dictonary. cmd.color('UNK%s' % (suffix), '(%s) & (%s)' % (unk[:-1], selection))
def str_to_color(c): color_map = dict(cmd.get_color_indices()) if c in color_map: return cmd.get_color_tuple(color_map[c]) return str_to_vector(c)
def testGetColorIndices(self): r = cmd.get_color_indices() self.assertTrue( set(r).issuperset([('white', 0), ('black', 1), ('blue', 2)]))