Dear Kirk,

On Sat, Oct 18, 2008 at 1:18 AM, Robert DeLisle <[email protected]> wrote:
>
> I notice within the Python API that RDKit has the ability to communicate
> with PyMol.  I have not, however, been able to find an example and haven't
> quite figured it out on my own.  Could you provide an example of opening a
> file in PyMol through RDKit, please?

Sure. There's a lot of functionality there, so I'll pick an arbitrary
example get this started. If anyone has unanswered questions, please
post. Once we have a somewhat refined set of examples, I'll post it to
the wiki.

The first thing you need to do is get PyMol started with the optional
xml-rpc server running. You do this via the -R switch to PyMol. When
PyMol starts, you should see a message about the xml-rpc server
running on port 9123.

>From python (this actually ought to work for you as is if you run it
in $RDBASE/Python/qtGui/Search3D/testData):

import os
import Chem
from Chem import PyMol
# start the viewer:
s = PyMol.MolViewer()
# have pymol display a pdb file, notice that we have to provide the full path:
s.LoadFile(os.path.join(os.getcwd(),'1OIR-nowater.pdb'),'1oir')
s.Zoom('1oir')
s.SetDisplayStyle('1oir','cartoon')
# create an RDKit molecule:
m = Chem.MolFromMolFile('1oir-xtal.mol',removeHs=False)
# have pymol display it:
s.ShowMol(m,name='ligand',showOnly=False)
s.Zoom('ligand')
s.SetDisplayStyle('ligand','sticks')
# select the protein neighborhood around the ligand and add a surface:
s.SelectProteinNeighborhood('ligand','1oir',showSurface=True)
# show h bonds and bumps:
s.DisplayHBonds('hbonds','ligand','1oir')
s.DisplayCollisions('bumps','ligand','1oir')

s is an instance of the PyMol.MolViewer class and we have so far been
using higher level methods of the class. To get more control (and see
more functionality), you can work directly with the underlying xml-rpc
server object, which the MolViewer carries around as a member named
server.

So, for example, we can use a raw pymol command to add a surface to the ligand:
s.server.do('show surface, ligand')

Or we can ask the server for its list of supported commands:
s.server.help()
or get more specific help about a particular command:
print s.server.help('sphere')

An aside: The version of the xml-rpc server that is distributed with
PyMol is somewhat out of date because I kept forgetting to send a new
version to Warren D. I remedied this this morning, so perhaps the next
version of PyMol will have an up-to-date rpc extension. Until then,
you can always copy $RDBASE/External/pymol/modules/pymol/rpc.py to
pymol's modules/pymol directory if you want the newest functionality.

Best Regards,
-greg

Reply via email to