
Friends, I have just begun to explore the chimera-python linkage. I loaded a pdb file using chimera.openModels function. Then i tried to loop through the residues and display atom information based on a condition.
for r in mymodel.residues: *#this works for me* if r.type=='ARG': print r.atoms
for r in mymodel.residues: *#this dose not work. I know there is a ARG residue with id 151.* if r.id=='151': print r.atoms
I dnt understand how atom attributes are packaged within a residue. Kindly write me few examples of accessing atom information from a residue. Thanks, Bala

On May 15, 2010, at 5:54 AM, Bala subramanian wrote:
Friends,
I have just begun to explore the chimera-python linkage. I loaded a pdb file using chimera.openModels function. Then i tried to loop through the residues and display atom information based on a condition.
for r in mymodel.residues: #this works for me if r.type=='ARG': print r.atoms
for r in mymodel.residues: #this dose not work. I know there is a ARG residue with id 151. if r.id=='151': print r.atoms
Hi Bala, A residue's 'id' attribute encodes the chain ID, number, and insertion code. In the above code you would want "if r.id.position == 151". This assumes that no other residues in other chains (or waters, etc.) have the same number. In IDLE, the help() function can get you information about an object's or class's methods and attributes. So: help(chimera.Residue.id) would have shown that 'id' is of class MolResId. Then: help(chimera.MolResId) would have shown that MolResIds have 'chainId', 'insertionCode', and 'position' attributes and the the first two are strings and the latter is an integer.
I dnt understand how atom attributes are packaged within a residue. Kindly write me few examples of accessing atom information from a residue.
From your code it looks like you know that r.atoms is a list of atoms, though putting it directly in a print statement like that won't be very informative since the 'repr' of each atom gets printed, which is something like: <_chimera.Atom object at 0x...> You would want to force the 'str' of the atom to get printed, e.g.: print [str(a) for a in r.atoms] The only other atom attribute in a residue I can think of is r.atomsMap, which is a dictionary keyed on atom name whose values are lists of atoms with those names. It's a list since sometimes atoms are not given unique names in a residue (most frequently with small molecules). --Eric Eric Pettersen UCSF Computer Graphics Lab http://www.cgl.ucsf.edu
participants (2)
-
Bala subramanian
-
Eric Pettersen