Hierarchical Views

This module defines HierView class that builds a hierarchical views of atom groups.

class HierView(atoms, **kwargs)[source]

Hierarchical views can be generated for AtomGroup, Selection, and Chain instances. Indexing a HierView instance returns a Chain instance.

Some object methods are customized as follows:

  • len() returns the number of atoms, i.e. numChains()
  • iter() yields Chain instances
  • indexing by:
    • segment name (str()), e.g. "PROT", returns a Segment
    • chain identifier (str()), e.g. "A", returns a Chain
    • [segment name,] chain identifier, residue number[, insertion code] (tuple()), e.g. "A", 10 or "A", 10, "B" or "PROT", "A", 10, "B", returns a Residue

Note that when an AtomGroup instance have distinct segments, they will be considered when building the hierarchical view. A Segment instance will be generated for each distinct segment name. Then, for each segment chains and residues will be evaluated. Having segments in the structure will not change most behaviors of this class, except indexing. For example, when indexing a hierarchical view for chain P in segment PROT needs to be indexed as hv['PROT', 'P'].


Returns atoms for which the hierarchical view was built.

getChain(chid, segname=None)

Returns chain with identifier chid, if it is present.

getResidue(chid, resnum, icode=None, segname=None)

Returns residue with number resnum and insertion code icode from the chain with identifier chid in segment with name segname.


Returns segment with name segname, if it is present.


Yield chains.


Yield residues.


Yield segments.


Returns number of chains.


Returns number of residues.


Returns number of chains.


Update (or build) hierarchical view of atoms. This method is called at instantiation, but can be used to rebuild the hierarchical view when attributes of atoms change.