Groups of atoms¶
MDAnalysis has a hierarchy of
Atom containers that are used throughout the code.
First and foremost is the
AtomGroup is the primary
Atom container; virtually everything can be accessed through it, as detailed in AtomGroup. This includes chemically meaningful groups of
Atoms such as a
Residue or a
Residues and Segments¶
In : import MDAnalysis as mda In : from MDAnalysis.tests.datafiles import TPR2019B3 In : u = mda.Universe(TPR2019B3) In : ag = u.atoms.select_atoms('resname ARG and name CA') In : ag Out: <AtomGroup with 11 atoms>
Each of these container groups can be accessed through another. The behaviour of this differs by level. For example, the residues of the
ag are the residues that the atoms of
ag belong to.
In : ag.residues Out: <ResidueGroup with 11 residues>
Accessing the atoms of those residues, however, returns all the atoms in the residues, not just those originally in
In : ag.residues.atoms Out: <AtomGroup with 264 atoms>
The same applies to segments.
In : ag[:3].segments.atoms Out: <AtomGroup with 1960 atoms>
In : a = u.atoms In : a.residue Out: <Residue LYSH, 0> In : a.residue.segment Out: <Segment seg_0_Protein_A> In : a.residue.segment.residues Out: <ResidueGroup with 129 residues>
For information on adding custom Residues or Segments, have a look at Adding a Residue or Segment to a Universe.
Certain analysis methods in MDAnalysis also make use of additional ways to group atoms. A key concept is a fragment. A fragment is what is typically considered a molecule: an AtomGroup where any atom is reachable from any other atom in the AtomGroup by traversing bonds, and none of its atoms is bonded to any atoms outside the AtomGroup. (A ‘molecule’ in MDAnalysis methods refers to a GROMACS-specific concept). The fragments of a Universe are determined by MDAnalysis as a derived quantity. They can only be determined if bond information is available.
The fragments of an
AtomGroup are accessible via the
fragments property. Below is a Universe from a GROMACS TPR file of lysozyme (PDB ID: 2LYZ) with 101 water molecules. While it has 230 residues, there are only 102 fragments: 1 protein and 101 water fragments.
In : len(u.residues) Out: 230 In : len(u.atoms.fragments) Out: 102
See Topology objects for more on bonds and which file formats give MDAnalysis bond information.
You can also look at which fragment a particular
Atom belongs to:
In : u.atoms.fragment # first atom of lysozyme Out: <AtomGroup with 1960 atoms>
and see which fragments are associated with atoms in a smaller
In : u.atoms[1959:1961].fragments Out: (<AtomGroup with 1960 atoms>, <AtomGroup with 3 atoms>)