Hi Leonhard,

Very interesting analysis. I'm wondering if this slowdown actually scales with 
number of objects or rather total number of atoms.

If your color scheme lookup by (object, resi) key is fast in Python (let's say 
you have it all in a dictionary), then you can use cmd.alter() with a single 
pass, which probably will be faster than cmd.color() in multiple passes. 
Example:

colors = {
  'obj1': {
    1: 0xFF0000,
    2: 0x333300,
    3: 0x000066,
  },
  'obj2': {
    1: 0x001234,
    2: 0x121212,
    3: 0x009900,
  },
}

cmd.alter('all', 'color = 0x40000000 | colors[model][resv]', space={'colors': 
colors})
cmd.recolor()

The magic number 040000000 is the cColor_TRGB_Bits mask which tells PyMOL that 
this is not a color index, but an RGB color.

Instead of a dictionary lookup, you may also use a callback function.

Check out these examples for alter with space argument:
https://pymolwiki.org/index.php/Iterate#.22space.22_argument

Cheers,
  Thomas

On 28 Feb 2017, at 09:34, Leonhard Heizinger <leonhard.heizin...@ur.de> wrote:

> Hi,
> coloring a certain residue in an object takes about 4 ms when only one
> object is loaded in PyMol:
> 
>  %time cmd.color("blue", "obj1of1 and resi 1")
>  CPU times: user 3.33 ms, sys: 0 ns, total: 3.33 ms
>  Wall time: 4.13 ms
> 
> Performing the same operation when a lot of other objects (~300) are
> loaded results in a highly increased execution time:
> 
>  %time cmd.color("blue", "obj1of300 and resi 1")
>  CPU times: user 243 ms, sys: 0 ns, total: 243 ms
>  Wall time: 234 ms
> 
> This is 60-fold increment compared to a PyMol Session with only one
> object loaded. All structures in this example have ~240 residues.
> 
> Consequently, coloring each residue of 300 objects in an individual
> color would take more then 4.5 hours on my machine. Of course this use
> case is pretty unlikely.
> 
> In my case I only have limited number of colors (255 colors gradient)
> which each residue could obtain. So I'm thinking about executing
> cmd.color for each color (255 times), which should be faster. However
> I'd still prefer to apply cmd.color per residue, so I don't have to
> define bulky selections per color.
> 
> Is there some way to accomplish this in a reasonable amount of time?
> Thanks!
> 
> Best,
> 
> Leonhard

-- 
Thomas Holder
PyMOL Principal Developer
Schrödinger, Inc.


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
PyMOL-users mailing list (PyMOL-users@lists.sourceforge.net)
Info Page: https://lists.sourceforge.net/lists/listinfo/pymol-users
Archives: http://www.mail-archive.com/pymol-users@lists.sourceforge.net

Reply via email to