[Chimera-users] accessing atom information
pett at cgl.ucsf.edu
Mon May 17 16:17:48 PDT 2010
On May 15, 2010, at 5:54 AM, Bala subramanian wrote:
> 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
> >>>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
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:
would have shown that 'id' is of class MolResId. Then:
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
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
UCSF Computer Graphics Lab
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Chimera-users