Color cbcobj

From PyMOLWiki
Jump to navigation Jump to search
Type Python Script
Download
Author(s) Oscar Conchillo-Solé
License

Overview

color_cbcobj

Color all chains in different objects with a different color

color_cbcobj(selection='(all)', first_color=0, quiet=0, _self=cmd):

uses colors and order as in _color_cycle defined here: https://github.com/schrodinger/pymol-open-source/blob/master/modules/pymol/util.py

quiet=0 means verbose (not quiet)

Usage

color_cbcobj selection, [first_color=0..n, [quiet=0/1 ]]

where:

  • selection can be any existing or newly-defined selection
  • first_color first color tu use from "_color_cycle" (first is 0)
  • quiet (default 0) print colored chains and models quiet=0 means verbose (not quiet)

Examples

PyMOL>color_cbcobj all and elem C,2,1

colors all chains in all objects differently, only carbon atoms, starting by color 154 (lightmagenta), does not show what has been colored

PyMOL>color_cbcobj all and elem C,2
 util.cbcobj: color 154 and model 6Y6C_BC', (chain B)
 Executive: Colored 670 atoms.
 util.cbcobj: color 6 and model 6Y6C_BC', (chain C)
 Executive: Colored 1131 atoms.
 util.cbcobj: color 9 and model 6Y6C_AD', (chain A)
 Executive: Colored 664 atoms.
 util.cbcobj: color 29 and model 6Y6C_AD', (chain D)
 Executive: Colored 1135 atoms.

Code

Copy the following text and save it as color_cbcobj.py

from pymol import cmd, CmdException

_color_cycle = [
    26   , # /* carbon */
    5    , # /* cyan */
    154  , # /* lightmagenta */
    6    , # /* yellow */
    9    , # /* salmon */
    29   , # /* hydrogen */
    11   , # /* slate */
    13   , # /* orange */
    10   , # /* lime */
    5262 , # /* deepteal */
    12   , # /* hotpink */
    36   , # /* yelloworange */
    5271 , # /* violetpurple */
    124  , # /* grey70 */
    17   , # /* marine */
    18   , # /* olive */
    5270 , # /* smudge */
    20   , # /* teal */
    5272 , # /* dirtyviolet */
    52   , # /* wheat */
    5258 , # /* deepsalmon */
    5274 , # /* lightpink */
    5257 , # /* aquamarine */
    5256 , # /* paleyellow */
    15   , # /* limegreen */
    5277 , # /* skyblue */
    5279 , # /* warmpink */
    5276 , # /* limon */
    53   , # /* violet */
    5278 , # /* bluewhite */
    5275 , # /* greencyan */
    5269 , # /* sand */
    22   , # /* forest */
    5266 , # /* lightteal */
    5280 , # /* darksalmon */
    5267 , # /* splitpea */
    5268 , # /* raspberry */
    104  , # /* grey50 */
    23   , # /* deepblue */
    51   , # /* brown */
    ]

_color_cycle_len = len(_color_cycle)

def color_cbcobj(selection='(all)', first_color=0, quiet=0, _self=cmd):
    '''
DESCRIPTION

    Color all chains in different objects a different color

SEE ALSO

    util.cbc, https://github.com/schrodinger/pymol-open-source/blob/master/modules/pymol/util.py
    split_chains.py, https://pymolwiki.org/index.php/Split_chains
    '''
    quiet = int(quiet)
    count = int(first_color)
    models = cmd.get_object_list('(' + selection + ')')
    for model in models:
        for chain in cmd.get_chains('(%s) and model %s' % (selection, model)):
            if len(chain.split()) != 1:
                chain = '"' + chain + '"'
            color = _color_cycle[count % _color_cycle_len]
            if not quiet:
                print(" util.cbcobj: color %s and model %s', (chain %s)" % (color, model, chain))
            #_self.color(color, "(chain %s and (%s))" % (chain, model), quiet=quiet)
            _self.color(color, "(chain %s and (%s) and (%s))" % (chain, model, selection), quiet)
            count+=1

cmd.extend('color_cbcobj', color_cbcobj)

#color_cbcobj all and elem C,1