
Hi Ryan, The difference is that when you print a list, the residues in the list are shown with repr(). When you print a residue directly, it is shown with str(). Quoting the Python Tutorial, the difference between str() and repr() is: "The str() function is meant to return representations of values which are fairly human-readable, while repr() is meant to generate representations which can be read by the interpreter..." Since there is no representation of a Residue object that can be directly read by the interpreter, you get the output you saw when printing the list. The result of str() when you directly print the residue is controlled by the "Atomspec display style" preference in the General preferences category (Favorites->Preferences). It seems you have that preference set to "command-line specifier". If you change it to "simple" instead you will get output like "LYS 12.A" etc. Alternatively you could use the chimeraLabel function, e.g.: print chimera.misc.chimeraLabel(r, style="simple") Programmer documentation for Chimera is considerably less complete than user documentation. My best advice is to read through some of the Programmer's Examples (http://www.cgl.ucsf.edu/chimera/docs/ProgrammersGuide/Examples/ index.html) and look through the Programmer's FAQ (http://www.cgl.ucsf.edu/chimera/docs/ProgrammersGuide/faq.html). If you know that some Chimera tool does something similar to what you want then browse through its source code. If you don't know Python that well you might want to work through the Python Tutorial if you have time (http://www.python.org/doc/current/tut/tut.html). And feel free to ask questions; we're happy to help. --Eric On Dec 14, 2007, at 4:55 PM, Ryan wrote:
Hi Eric, thanks for your help. I'm getting closer to achieving the results i'd like.
So i've been able to properly select the residues within a specified radius of my ligand, but am a little confused as to how Chimera handles the selection list. If i try:
print chimera.selection.currentResidues()
i get a list like this:
[<_chimera.Residue object at 0x578d2020>, <_chimera.Residue object at 0x578cbfb0>, ... ]
but if i try:
for x in chimera.selection.currentResidues(): print x
i get output that is much closer to what i'm looking for:
#0:499 #0:496 ...
What is the reason for the difference between these two forms of output that seem to be accessing the same list? Also, is there a way i can get more detailed output with residue names and numbers, such as ['#0:TYR499','#0:TRP496',...]?
Sorry if these questions are answered elsewhere, but i could not find the answers online. Is there a document out there that can teach me how to better master the Chimera Python modules for scripting? I'm no Python expert -- i've so far only been learning things as i need them. Thanks again,
ryan