Hi Roger,
I think the first thing you should do is look at the simple example for looping through data files and running Chimera commands on them, since it is very similar to what you want to do:

http://www.cgl.ucsf.edu/chimera/docs/ProgrammersGuide/basicPrimer.html

Since you want to loop through PDB IDs (presumably listed in a file) instead of a set of files, you would replace this part of the example:

# gather the names of .pdb files in the folder
file_names = [fn for fn in os.listdir(".") if fn.endswith(".pdb")]

# loop through the files, opening, processing, and closing each in turn
for fn in file_names:
replyobj.status("Processing " + fn) # show what file we're working on
rc("open " + fn)

with something like:

# open file of PDB IDs
f = open("pdb-list", "r")

# loop through the IDs, opening, processing, and closing each in turn
for line in f:
pdbID = line.strip()
replyobj.status("Processing " + pdbID) # show what PDB we're working on
rc("open " + pdbID)


Since you can use the 'rc' (shorthand for 'runCommand') function to execute Chimera commands from Python, you would then just insert whatever commands you use to select polar/non-polar residues. You can then get a list of the selected residues with:

from chimera import selection
residues = selection.currentResidues()

Assuming you've already used 'surface' to add a surface, those residues will each have a 'areaSES' attribute which you could print into an output file (presumably opened with something like 'outf = open(pdbID, "w")') with:

for r in residues:
print>>outf, r, r.areaSES

you could similarly print out the sum of the areas:

print>>outf, sum([r.areaSES for r in residues])

Don't forget to close each output file before opening the next (outf.close()) since with 2000 output files the Chimera process would likely run out of allowed open files before your script finished.  Let me know if you need more help with this.

--Eric

                       Eric Pettersen
                        UCSF Computer Graphics Lab
                        http://www.cgl.ucsf.edu

On Feb 26, 2012, at 7:50 PM, Roger L. Chang wrote:

Hi,

1) I need to get residue.areaSES for two separate selections (all polar
amino acids and all nonpolar amino acids).  I have successfully generated
a list of residue.areaSES using the GUI simply by selecting the residues
of interest and then using the attribute calculator typing
"residue.areaSES" in the formula box of the Attribute Calculator, which
outputs the list to the Reply Log.  This is the data that I need, but I
need to get it for >2000 PDB structures and would like to automate this
analysis through a Python script.  I am somewhat new to Python and Chimera
and don't yet know all the ins and outs yet.  I dug through the code and
found a method "getResidueAttr" in the "ResidueDataWrapper" class from
"CalcAttr".  This seems to be what I need, but I don't know the proper
syntax to call it from my Python script.  Could someone please provide an
example?

2) I would like to sum the residue.areaSES values once I have them.  I
tried "sum(residue.areaSES)" in the formula box of the Attribute
Calculator in the GUI, but this returns the error "Formula evaluation
error: expecting vector argument in function".  I'm not sure again on the
proper syntax to use "sum()" in the Attribute Calculator.  If I knew how
to generate/save the residue.areaSES data from the command line, I could
just parse the saved file and sum the values in Python.  How can Attribute
Calculator formulas be used from the command line, and if they can't, how
can I save the residue.areaSES data to file from a Python script?

Thanks in advance,
Roger


--
Roger L. Chang
Graduate Student
Bioinformatics and Systems Biology Graduate Program
University of California, San Diego
_______________________________________________
Chimera-users mailing list
Chimera-users@cgl.ucsf.edu
http://plato.cgl.ucsf.edu/mailman/listinfo/chimera-users