PyMol is a USER-SPONSORED molecular visualization system on an OPEN-SOURCE foundation. And, it’s a darn good one as well. It can be accessed by an intuitive GUI (regular mode) or via Python Scripts (Pymol API). It can also run its own scripts (real time savers). My issue was how to run it from a python script and I roamed the web for about an hour until I got all the answers I needed. Thus, here’s the short version :)
First, we need to have it installed on the system, obviously. I recommend *dearly* a self-compilation as it is as simple as it can be. Then, comes the installation of any additional scripts/tools such as those listed here and here. Finally, programming the python script. I’ll just leave an example that is well commented so it should be self-explanatory.
The first lines may be kind of “WTF is that for?” but they are handy. They are to provide a couple of “flags” to pymol so it doesn’t open any graphical window (-c of command-line) nor outputs all the text it usually does (-q of quiet). Then we have to import pymol, just as we import any other module, and then the method finish_launching() is essential, otherwise it will break again and again with some threading error.
My script essentially reads 2 pdb files, loads then, aligns them using cealign, and produces a file where the mobile structure is in the position of the static one. Well, it is useful for me :) You can always refer to PyMolWiki for a comprehensive aid for all the commands you can possibily need. They have not only the “in-pymol” way to do it, but the API access as well. Most of them are ran by something like pymol.cmd.command(args).
In the end, don’t forget to close with pymol.cmd.quit()
Oh, yes, I know I could have done from pymol import cmd, but it gave me some errors.. temperamental laptop.
#!/usr/bin/python # # Usage: superimposition.py STATIC MOBILE # Utrecht @ 2009 # Joao Rodrigues # import __main__ __main__.pymol_argv = [ 'pymol', '-qc'] # Quiet and no GUI import sys, time, os import pymol pymol.finish_launching() ## # Read User Input staticStructurePath = os.path.abspath(sys.argv) staticStructureName = staticStructurePath.split('/')[-1].split('.') mobileStructurePath = os.path.abspath(sys.argv) mobileStructureName = mobileStructurePath.split('/')[-1].split('.') # Load Structures pymol.cmd.load(mobileStructurePath, mobileStructureName) pymol.cmd.load(staticStructurePath, staticStructureName) # CEAlign STATIC, MOBILE # CEAlign produces same alignment as the complex SUPER below pymol.cmd.do("run /home/joao/Software/cealign-0.9/cealign.py") # Import Module pymol.cmd.do("cealign %s, %s" %(staticStructureName, mobileStructureName)) time.sleep(1) # Dunno why, but if I don't wait, structures do not align properly.. # Save Superimposition # save(file, selection, state (0 default), format) pymol.cmd.save("%s_%s.pdb" %(mobileStructureName, staticStructureName), mobileStructureName, 0, 'pdb') ## SUPER - old #pymol.cmd.super((staticStructureName and (resn ZN around 5 and (resn CYS or resn HIS))), (mobileStructureName and (resn ZN around 5 and (resn CYS or resn HIS)))) #pymol.cmd.save("%s_%s_SUPER.pdb" %(mobileStructureName, staticStructureName), mobileStructureName, 0, 'pdb') # Get out! pymol.cmd.quit()37.430424 -122.120984Advertisements