If he didn't have pymol in his PYTHONPATH, wouldn't he get an error?
Hi all, I would like to know is it possible to run Pymol from Pythoin script ? I tried this script (to produce png file from pdb file)
#!/usr/bin/python
import __main__
__main__.pymol_argv = [ 'pymol', '-qc']
import pymol
pymol.finish_launching()
pdb_file ="my.pdb"
pdb_name ="my_pdb"
pymol.cmd.load(pdb_file, pdb_name)
pymol.cmd.disable("all")
pymol.cmd.enable(pdb_name)
pymol.cmd.png("my_pdb.png")
And run it as "python script.py" but no png file is produced and no error !!! Did I got something wrong about Pymol?? any suggestion !!!
3 answers
The script below worked perfectly in my machine. I installed pymol via MacPorts, so it's a completely brand new installation without any modifications or tweaks. The script outputted one line about the ray tracing process and the image, with the protein, is sitting in the directory I ran the script in.
Do you have pymol in our PYTHONPATH? Can you go to a Python shell and import pymol? Also, which version of Pymol do you have and which OS are you using?
import __main__
__main__.pymol_argv = [ 'pymol', '-qc'] # Quiet and no GUI
import sys, time, os
import pymol
pymol.finish_launching()
##
# Read User Input
spath = os.path.abspath(sys.argv[1])
sname = spath.split('/')[-1].split('.')[0]
# Load Structures
pymol.cmd.load(spath, sname)
pymol.cmd.disable("all")
pymol.cmd.enable(sname)
pymol.cmd.png("my_image.png")
# Get out!
pymol.cmd.quit()
Yes, but sometimes package managers install different versions of the software in 'random' places.. it's good to know what exactly is being called.
I guess pymol provided by Linux package manager have some bug or feature missing. Removing old and installed new Pymol from http://sourceforge.net/projects/pymol/ and Now it works. Thanks @João Rodrigues and @Niek De Klein
Besides, the -q option means that the output of Pymol is silenced, thus the reason you might not see any error.
even after adding pymol.cmd.quit() and time.sleep(1) I didn't get png file :( also similar to http://doeidoei.wordpress.com/2009/02/11/pymol-api-simple-example/ I tried pymol.cmd.save("%s.png" %(pdb_name), pdb_name , 0, 'png') but still no png :(
Try Joao's suggestion, remove the q. Maybe it does give errors.
Yes I tried that also still no png. The script in link http://doeidoei.wordpress.com/2009/02/11/pymol-api-simple-example/ is working fine (so my Pymol and Python are working) but I am not getting any png using the command
pymol.cmd.png("my_pdb.png")
or
pymol.cmd.save("%s.png" %(pdb_name), pdb_name , 0, 'png')
:(
I encountered this problem on Ubuntu 12.04 running pymol verson 1.4.1 (the version installed with apt-get) . I removed that version and reinstalled pymol 1.6.0.0 and was able to get it to work.
Log in to answer this question.
The PyMOL Wiki post "Launching From a Script" might be helpful.