Running Pymol From Python Script
3
3
Entering edit mode
12.6 years ago
Sheila ▴ 280

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 • 32k views
ADD COMMENT
0
Entering edit mode

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

ADD REPLY
6
Entering edit mode
12.6 years ago
João Rodrigues ★ 2.5k

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 COMMENT
2
Entering edit mode

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 REPLY
1
Entering edit mode

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

ADD REPLY
0
Entering edit mode

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 REPLY
3
Entering edit mode
12.6 years ago
Niek De Klein ★ 2.6k

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 COMMENT
2
Entering edit mode

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

ADD REPLY
0
Entering edit mode

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 REPLY
0
Entering edit mode

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

ADD REPLY
0
Entering edit mode

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 REPLY
0
Entering edit mode

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 REPLY
0
Entering edit mode

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

ADD REPLY
0
Entering edit mode
11.0 years ago
tyler.weirick ▴ 120

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 COMMENT

Login before adding your answer.

Traffic: 2509 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6