<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Hi Roger,<div><span class="Apple-tab-span" style="white-space: pre; "> </span>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:</div><div><br></div><div><a href="http://www.cgl.ucsf.edu/chimera/docs/ProgrammersGuide/basicPrimer.html">http://www.cgl.ucsf.edu/chimera/docs/ProgrammersGuide/basicPrimer.html</a></div><div><br></div><div>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:</div><div><br></div><div><div># gather the names of .pdb files in the folder</div><div>file_names = [fn for fn in os.listdir(".") if fn.endswith(".pdb")]</div><div><br></div><div># loop through the files, opening, processing, and closing each in turn</div><div>for fn in file_names:</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>replyobj.status("Processing " + fn) # show what file we're working on</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>rc("open " + fn)</div></div><div><br></div><div>with something like:</div><div><div><div><br></div><div># open file of PDB IDs</div><div>f = open("pdb-list", "r")</div><div><br></div><div># loop through the IDs, opening, processing, and closing each in turn</div><div>for line in f:</div><div><span class="Apple-tab-span" style="white-space: pre; "> </span>pdbID = line.strip()</div><div><span class="Apple-tab-span" style="white-space: pre; "> </span>replyobj.status("Processing " + pdbID) # show what PDB we're working on</div><div><span class="Apple-tab-span" style="white-space: pre; "> </span>rc("open " + pdbID)</div><div><br></div><div><br></div><div>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:</div><div><br></div><div><span class="Apple-tab-span" style="white-space: pre; "> </span>from chimera import selection</div><div><span class="Apple-tab-span" style="white-space: pre; "> </span>residues = selection.currentResidues()</div><div><br></div><div>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:</div></div></div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>for r in residues:</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>print>>outf, r, r.areaSES</div><div><br></div><div>you could similarly print out the sum of the areas:</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>print>>outf, sum([r.areaSES for r in residues])</div><div><br></div><div>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.</div><div><br></div><div>--Eric</div><div><br></div><div><div><span class="Apple-style-span" style="font-size: 16px; "> Eric Pettersen</span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font-size: 16px; "><font face="Helvetica" size="5" style="font: normal normal normal 16px/normal Helvetica; "> UCSF Computer Graphics Lab</font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font-size: 16px; "><font face="Helvetica" size="5" style="font: normal normal normal 16px/normal Helvetica; "> <a href="http://www.cgl.ucsf.edu">http://www.cgl.ucsf.edu</a></font></div><div><br></div><div> On Feb 26, 2012, at 7:50 PM, Roger L. Chang wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div>Hi,<br><br>1) I need to get residue.areaSES for two separate selections (all polar<br>amino acids and all nonpolar amino acids). I have successfully generated<br>a list of residue.areaSES using the GUI simply by selecting the residues<br>of interest and then using the attribute calculator typing<br>"residue.areaSES" in the formula box of the Attribute Calculator, which<br>outputs the list to the Reply Log. This is the data that I need, but I<br>need to get it for >2000 PDB structures and would like to automate this<br>analysis through a Python script. I am somewhat new to Python and Chimera<br>and don't yet know all the ins and outs yet. I dug through the code and<br>found a method "getResidueAttr" in the "ResidueDataWrapper" class from<br>"CalcAttr". This seems to be what I need, but I don't know the proper<br>syntax to call it from my Python script. Could someone please provide an<br>example?<br><br>2) I would like to sum the residue.areaSES values once I have them. I<br>tried "sum(residue.areaSES)" in the formula box of the Attribute<br>Calculator in the GUI, but this returns the error "Formula evaluation<br>error: expecting vector argument in function". I'm not sure again on the<br>proper syntax to use "sum()" in the Attribute Calculator. If I knew how<br>to generate/save the residue.areaSES data from the command line, I could<br>just parse the saved file and sum the values in Python. How can Attribute<br>Calculator formulas be used from the command line, and if they can't, how<br>can I save the residue.areaSES data to file from a Python script?<br><br>Thanks in advance,<br>Roger<br><br><br>-- <br>Roger L. Chang<br>Graduate Student<br>Bioinformatics and Systems Biology Graduate Program<br>University of California, San Diego<br>_______________________________________________<br>Chimera-users mailing list<br><a href="mailto:Chimera-users@cgl.ucsf.edu">Chimera-users@cgl.ucsf.edu</a><br>http://plato.cgl.ucsf.edu/mailman/listinfo/chimera-users<br></div></blockquote></div><div apple-content-edited="true"><span class="Apple-style-span" style="border-collapse: separate; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; -webkit-text-decorations-in-effect: none; text-indent: 0px; -webkit-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br class="Apple-interchange-newline"></div></span> </div><br></body></html>