środa, września 17, 2008

Cute molecules

For me is Pymol the number one tool for molecule visualization. Sure, there's a lot of visualization software out there on the net and some of them are quite impressing, but I haven't found one that is so flexible and extensible like Pymol. Basically almost all chemistry visualizations tools are OpenGL applications that squeeze more or less the last pixel from your GFX-card. It's just a matter of the settings. So hat makes the difference? The answer is Python. The core program is written in C, but above this is a bunch of Python modules and that means the program is hackable without recompiling. All you need is a plain text editor...

Ever heard about QuteMol? It's a very nice program and the images are just astonishing. The reason why I didn't convinced myself to try it is because it's only available for the Windows and Mac platforms and I'm starting to use my Arch Linux more and more. Ok, now you are probably asking yourself what I asked myself - how do I get such images in Pymol? I was not the first who thought about it. Here's a pymolwiki recipe how it can be done. Like I sed earlier - it's just a matter of the settings. You could write a script for it but I've decided to go one step further integrating it into Pymol. After some cups of coffee I've started playing around with the Pymol GUI python modules and found the right ones - menu.py and preset.py. All modifications were done on a linux Pymol version 0.99rc6, but besically it should also work on other Pymol versions.
First I've opened the file preset.py and defined my own representation preset function called qutemollike (add the code below at the end of the file):

preset.py(Toggle Plain Text)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
def qutemollike(selection="(all)",_self=cmd):
    s = tmp_sele
    cmd.set_color("oxygen",[1.0,0.4,0.4])
    cmd.set_color("nitrogen", [0.5,0.5,1.0])
    cmd.remove("solvent")
    cmd.as("spheres")
    util.cbaw()
    cmd.bg_color("white")
    cmd.set("light_count",10)
    cmd.set("spec_count",1)
    cmd.set("shininess",10)
    cmd.set("specular",0.25)
    cmd.set("ambient",0)
    cmd.set("direct",0)
    cmd.set("reflect",1.5)
    cmd.set("ray_shadow_decay_factor",0.1)
    cmd.set("ray_shadow_decay_range", 2)
    cmd.unset("depth_cue")

and then added a callback (line #495) to it in the file menu.py witch describes all the menus used in the viewer window.

menu.py(Toggle Plain Text)

482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
def presets(s):
    return [[ 2, 'Preset:'       ,''                        ],     
              [ 1, 'simple'   ,'preset.simple("'+s+'")'          ],
              [ 1, 'simple (no solvent)'   ,'preset.simple_no_solv("'+s+'")'          ],           
              [ 1, 'ball and stick' , 'preset.ball_and_stick("'+s+'")' ],
              [ 1, 'b factor putty' , 'preset.b_factor_putty("'+s+'")' ],
              [ 1, 'technical'   , 'preset.technical("'+s+'")'          ],
              [ 1, 'ligands'   , 'preset.ligands("'+s+'")'          ],
              [ 1, 'ligand sites'   , preset_ligand_sites(s)         ],
              [ 1, 'pretty ', 'preset.pretty("'+s+'")'          ],
              [ 1, 'pretty (with solvent)'     , 'preset.pretty_solv("'+s+'")'          ],
              [ 1, 'publication '   , 'preset.publication("'+s+'")'          ],
              [ 1, 'publication (with solvent)'   , 'preset.pub_solv("'+s+'")'          ],
              [ 1, 'QuteMol like', 'preset.qutemollike("'+s+'")' ],
              [ 0, ''               ,''                             ],                      
              [ 1, 'default'   ,'preset.default("'+s+'")'          ],           
              ]


Here is a screenshot showing the added "QuteMol like" option in the preset submenu.

As you can see I've loaded a caffeine molecule. I give it the final polish by typing in the console: set ray_trace_mode,1
ray 800,600
And here's how it looks now.

7 komentarzy:

Marius pisze...

Nice post. It works with the latest svn version of Pymol, but I had to change this line
[ 1, 'QuteMol like', 'preset.qutemollike("'+s+'")' ],
to:
[ 1, 'QuteMol like', 'preset.qutemollike("'+sele+'")' ],

Lightnir pisze...

I know. I compiled pymol from svn (1.2pre) a day after I wrote this post. I've been a bit busy lately and haven't found the time to update this post. Thanks for the comment anyway.

Felix pisze...

hi, that's some cool stuff. i like that quteMol look. especially if you do that and take the ball and stick model afterwards.
and now i also know another thing I was wondering about. how i can always have black carbons when i click ball and stick. just added two lines:
cmd.set_color("carbon", [0.4, 0.4, 0.4])
cmd.color("carbon", "e. c")
im my eyes carbons should be black ... and so far i always had to change it manually
if i do that in the QuteMol subroutine it does not work though and i just get the white carbons.

anyway it's pretty fun to be able to change the program so quickly

Lightnir pisze...

Maybe you just need your own preset for this ];) Let me guess - you added:
cmd.color("carbon", "e. c")
before
util.cbaw()
Right? See this for reference.

Try this:

def felix(selection="(all)",_self=cmd):
    s = tmp_sele
    cmd.remove("solvent")
    cmd.select(s,selection)
    _prepare(s)
    cmd.hide("everything",s)
    cmd.set("stick_color","white",s)
    cmd.set("stick_radius","0.14",s)
    cmd.set("sphere_scale","0.25",s)
    cmd.set_color("oxygen",[1.0,0.4,0.4])
    cmd.set_color("nitrogen", [0.5,0.5,1.0])
    cmd.set_color("carbon", [0.4, 0.4, 0.4])
    cmd.show("sticks",s)
    cmd.show("spheres",s)
    cmd.color("carbon", "e. c")
    cmd.bg_color("white")
    cmd.set("light_count",10)
    cmd.set("spec_count",1)
    cmd.set("shininess",10)
    cmd.set("specular",0.25)
    cmd.set("ambient",0)
    cmd.set("direct",0)
    cmd.set("reflect",1.5)
    cmd.set("ray_shadow_decay_factor",0.1)
    cmd.set("ray_shadow_decay_range", 2)
    cmd.unset("depth_cue")


Of course you have to add a callback to this function in menu.py and don't forget to format the code(some space before all lines except "def felix..."). I tested it with pymol 0.99rc6-win32 on a p-aminobenzenesulfonic acid molecule and it looks nice. Of course you have to tweak some settings to fit your needs, and maybe make some modifications to it for some newer pymol versions.
Hope this was useful to you.

Felix pisze...

thanks, that looks very cool ... if you don't undo the depth cue :)
yes i guess my mistake was that i put the coloring and then util.cbaw() recolored it
now that works, too
pymol rocks :)

Anonimowy pisze...

You were visited simply with a brilliant idea

Anonimowy pisze...

Hi I'd love to thank you for such a great quality forum!
Was thinking this would be a perfect way to introduce myself!

Sincerely,
Johnie Maverick
if you're ever bored check out my site!
[url=http://www.partyopedia.com/articles/first-communion-party-supplies.html]first communion Party Supplies[/url].