Question: Running Pymol From Python Script
1
gravatar for Sheila
7.2 years ago by
Sheila250
Germany
Sheila250 wrote:

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 !!!

python pymol structure • 16k views
ADD COMMENTlink modified 5.5 years ago by tyler.weirick120 • written 7.2 years ago by Sheila250

The PyMOL Wiki post "Launching From a Script" might be helpful.

ADD REPLYlink written 6.4 years ago by David0
4
gravatar for João Rodrigues
7.2 years ago by
João Rodrigues2.5k
Stanford University, U
João Rodrigues2.5k wrote:

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()
ADD COMMENTlink written 7.2 years ago by João Rodrigues2.5k
2

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

ADD REPLYlink written 7.2 years ago by Sheila250
1

If he didn't have pymol in his PYTHONPATH, wouldn't he get an error?

ADD REPLYlink written 7.2 years ago by Niek De Klein2.5k

Yes, but sometimes package managers install different versions of the software in 'random' places.. it's good to know what exactly is being called.

ADD REPLYlink written 7.2 years ago by João Rodrigues2.5k
3
gravatar for Niek De Klein
7.2 years ago by
Niek De Klein2.5k
Netherlands
Niek De Klein2.5k wrote:

Read this post:

In the end, don’t forget to close with pymol.cmd.quit()

Adding

pymol.cmd.quit()

to the end of your script should probably work.

ADD COMMENTlink modified 7.2 years ago • written 7.2 years ago by Niek De Klein2.5k
2

Besides, the -q option means that the output of Pymol is silenced, thus the reason you might not see any error.

ADD REPLYlink written 7.2 years ago by João Rodrigues2.5k

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 :(

ADD REPLYlink written 7.2 years ago by Sheila250

Try Joao's suggestion, remove the q. Maybe it does give errors.

ADD REPLYlink written 7.2 years ago by Niek De Klein2.5k

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') ' :(

ADD REPLYlink written 7.2 years ago by Sheila250

This might be a stupid question, but have you checked if the file is not being saved somewhere else? Also, remove the "disable"/"enable" part and see if it works.

ADD REPLYlink written 7.2 years ago by João Rodrigues2.5k

I did both but still no PNG :( if someone have a working script which makes PNG from a PDB please post

ADD REPLYlink written 7.2 years ago by Sheila250
0
gravatar for tyler.weirick
5.5 years ago by
tyler.weirick120
Germany
tyler.weirick120 wrote:

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.

ADD COMMENTlink written 5.5 years ago by tyler.weirick120
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 2149 users visited in the last hour