#108 convert str to int in util.py func cbc()



To color selection by chains, one can use util.cbc in command line. Apart from the
selection, it also accepts parameters "first_color", which presumably
defines the first color. But this parameter has no effect at all if one does
not specify the "legacy" parameter to a non-zero value. Yet, if legacy value
is specified, the util.cbc command will fail with error:

Traceback (most recent call last):
File "/.../pymol-v1.4/pymol/modules/pymol/parser.py", line 254, in parse
File "/.../pymol-v1.4/pymol/modules/pymol/util.py", line 509, in cbc
cmd.color("%d"%c,"(chain %s and (%s))"%(a,selection),quiet=quiet)
TypeError: %d format: a number is required, not str

It seems it is because the value of first_color passed from command line is a string in function
cbc() in util.py. It is not converted to a integer. This issue seems to be in the current version
of util.py. How about changing

cmd.color("%d"%c,"(chain %s and (%s))"%(a,selection),quiet=quiet)


cmd.color(str(c),"(chain %s and (%s))"%(a,selection),quiet=quiet)

cheers, hongbo


  • Jason Vertrees

    Jason Vertrees - 2011-08-15
    • status: open --> open-invalid
  • Jason Vertrees

    Jason Vertrees - 2011-08-15

    In PyMOL you can color in at least four ways: color name ("marine"), color triplet ([0.5, 0.5, 0.5]), color ID (4), and hex (#ffcc00). The util.cbc command is old and expects the user to define the color using the color id. You can find a list of color ids in pymol/modules/util.py and layer1/Color.c.

    The following command worked for me:

    # color marine

    util.cbc(first_color=17, legacy=1)

    While unfriendly, I don't think this is a bug. Please verify before I close this out.

  • macro

    macro - 2011-08-15

    try using it in command line:

    import util
    util.cbc myselection, 1, 1

  • Jason Vertrees

    Jason Vertrees - 2011-08-15
    • status: open-invalid --> closed-fixed
  • Jason Vertrees

    Jason Vertrees - 2011-08-15

    Thanks for pointing that out. It's fixed in the latest SVN code.


Log in to post a comment.