Thanks Thomas and Tsjerk for pointing me back to the path...from my quicksand and brambles where I knew I was off! Brilliant. Seems to be an unfortunate habit I have in scripting where it's like "Why use a simple, elegant one-liner when a mess of impenetrable hack-arounds would do?" I had forgotten about those get_<goodstuff> commands.

Much appreciated!

On Sun, Jan 23, 2011 at 5:58 AM, Thomas Holder <> wrote:
Hi Seth,

I think this one-liner will do the job for you:

print cmd.get_chains('polymer')


Seth Harris wrote, On 01/23/11 10:04:

Hi All,

I am script-plowing through PDB files and extracting unique chain identifiers only for "polymers" using PyMOL's polymer selection. Right now my code is a kind of brute force thing like this:

 cmd.create ("justpolys","polymer")


 for a in cmd.index("justpolys"):
   q_sel = "%s`%d"%a
   #print q_sel+":",
   cmd.iterate(q_sel, "stored.qry_info = (chain,resn,resi,name)")
   #cmd.iterate_state(1,q_sel, "stored.qry_xyz = (x,y,z)")
   #print stored.qry_info[0],stored.qry_info[1],stored.qry_info[2],stored.qry_info[3]
   # Track any unique chains by adding to polymer_chains list if not already there
   # first reformat to get rid of flanking ' marks
   if thischain not in polymer_chains:

This works, but is quite slow as it iterates over every atom in every pdb just to get out the chain so it is quite redundant.
Is there any way to iterate in a 'chain by chain' fashion? This q_sel stuff is recycled from something Warren suggested for a different purpose years ago, and I only have a loose idea of how that is interacting with the cmd.index part. Maybe there's a way to get just the chain from the get-go instead of all the individual atoms? Any reminders on that one or better method suggestions?