I couldn't reproduce the exact error message you received, but I will note:

(1) your splitting of lines leaves out the chain, so chain is never defined
(2) line 9 of your python is missing an opening quotation mark before (resi matching the closing quotation mark right before the % sign
(3) line 9 has an error in that chain is the first argument in your tuple, but should be the last argument based on the string format you are substituting into.
(4) line 10 above cmd.distance("d","sele and n. CA, sele and n. CA")
     you need to have the second and third arguments as part of one string. These should be two separate arguments in python:
     cmd.distance("d","sele and n. CA", "sele and n. CA")
(5) cmd.color("sele", red)
     (a) you switched the order of the arguments for some reason from what you showed in your pymol commands
     (b) red needs to be in quotation marks
(6) cmd.save("%s_%s".pse)%(pdbid,chain) ; you need to have .pse inside the quotation marks, it is part of the string. Also, your parentheses matching places the string substitution tuple outside the arguments of the function.
(7) cmd.png("%s_%s")%(pdbid,chain) again, the string substitution tuple is outside the function
     as an example, you want cmd.png( "%s_%s"%(pdbid,chain) )
     so you produce your string inside the parentheses corresponding to the command.
(8) cmd.delete(pdbid.split(',')[0]) ; you probably want to split on the period, not a comma.

The line numbers in the error messages don't match the python you have pasted. It seems the python you pasted is not what actually produced the error message given.

Your off to a good start. Generally, you should look at the last few lines of the error message, this will tell you what line number your error is on and give you a clue what is happening. You can then start reading backwards through the message to see if it gives more information. Since line numbers are so important, you should use something to write your script that has line numbers. There are many text editors that do so. One with syntax highlighting for python would also be useful as it will make many of the issues much more apparent.

-David






On Wed, Sep 4, 2013 at 3:30 AM, Anasuya Dighe <anasuya@mbu.iisc.ernet.in> wrote:
Hi everyone,

How to write PyMol commands in Python script, save a session and then save a
.png file of the same ?
I have an input file which has the protein information i.e name, chain, and a
list of residues.
I want to plot the C-alpha atoms of these residues for each protein & calculate
distances between this set of atoms, save these operations in a .pse file and
also a .png file of the same.
Below, I am writing all the commands which I use in PyMol.

However,  I am having trouble automating this procedure for a large number of
proteins.

***Input file [testpy.txt](Fields: PDB ID, chain, residue1, residue2, residue3***
2YYI.pdb A 13 28 30
2YYG.pdb A 45 42 67
.
.
.
.

***PyMol Commands***
1) load 2YYI.pdb
2) hide everything
3) show cartoon
4) set cartoon_transparency, 0.8
5) set dash_gap, 0
6) set sphere_scale, 0.45
7) set sphere_mode, 4
8) bg_color white
9) select resi 13+28+30 and chain A and n. CA
10) distance d, sele and n. CA , sele and n. CA
11) hide labels, d*
12) show spheres, sele
13) color red, sele
14) save session_2YYI.pse
15) ray 1000,1000
16) png ~/Desktop/temp/2YYI_A.png

In the above set of commands, I am opening each PDB file as mentioned in the 1st
column of the input file, selecting chain as in the 2nd column, and selecting
residues as mentioned in the next 3 columns.
Also when i save the sessions and the png file, I am taking them from the input
file.
How can i automate this procedure such that I have a total of 2 png files and 2
sessions for each of the pdb that I am listing in the input file. I have tried
doing this but, cant get ahead due to errors.
I am not much of a coder in Python. PLease help.
This is how far i have got.

*****
from pymol import cmd

def process_line(x):
 pdbid,res1,res2,res3 = x.split()
 cmd.load(pdbid)
 cmd.bg_color("white")
 cmd.hide("everything")
 cmd.show("cartoon")
 cmd.select((resi %s + resi %s + resi %s and chain %s name
CA)"%(chain,res1,res2,res3))
 cmd.distance("d","sele and n. CA, sele and n. CA")
 cmd.hide("labels","d*")
 cmd.color("sele", red)
 cmd.show("spheres","sele")
 cmd.ray(1000,1000)
 cmd.save("%s_%s".pse)%(pdbid,chain)
 cmd.png("%s_%s")%(pdbid,chain)
 cmd.delete(pdbid.split(',')[0])

def process_all(filename):
 for line in open(filename):
   process_line(line)

process_all("testpy.txt")

*****
What is going wrong? how can this be automated for all the pdbid's listed in
input file ?

errors I get:
File "/usr/lib/pymodules/python2.6/pymol/parser.py", line 338, in parse
    parsing.run_file(path,self.pymol_names,self.pymol_names)
  File "/usr/lib/pymodules/python2.6/pymol/parsing.py", line 455, in run_file
    execfile(file,global_ns,local_ns)
  File "anu.py", line 19, in <module>
    process_all("testpy.txt")
  File "anu.py", line 17, in process_all
    process_line(line)
  File "anu.py", line 10, in process_line
    cmd.save(thisSession.pse)


- Anasuya


--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.


------------------------------------------------------------------------------
Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more!
Discover the easy way to master current and previous Microsoft technologies
and advance your career. Get an incredible 1,500+ hours of step-by-step
tutorial videos with LearnDevNow. Subscribe today and save!
http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk
_______________________________________________
PyMOL-users mailing list (PyMOL-users@lists.sourceforge.net)
Info Page: https://lists.sourceforge.net/lists/listinfo/pymol-users
Archives: http://www.mail-archive.com/pymol-users@lists.sourceforge.net