Oliver Beckstein edited this page Jul 13, 2018 · 6 revisions

outdated (July 2018), see the docs

The AtomGroup class is the most important object in MDAnalysis. It contains a list of Atoms and is described in under Fundamental building blocks in the online documentation.

Creating an AtomGroup

The atoms in a Universe are a AtomGroup

>>> import MDAnalysis
>>> from MDAnalysis.tests.datafiles import *
>>> u = MDAnalysis.Universe(PSF,DCD)
>>> type(u.atoms)
<class 'MDAnalysis.core.AtomGroup.AtomGroup'>

Any selection produces a AtomGroup

>>> calphas = u.selectAtoms("name CA")
>>> type(calphas)
<class 'MDAnalysis.core.AtomGroup.AtomGroup'>

Multiple AtomGroup instances can be joined using addition:

>>> arginines = u.selectAtoms('resname ARG')
>>> lysines = u.selectAtoms('resname LYS')
>>> basics = arginines + lysines

(Of course, this example is contrived and one could have simply used basics = u.selectAtoms('resname ARG or resname LYS').)

A AtomGroup can be manually created by supplying a list of Atom instances to the class constructor

>>> manual_atom_selection = [u.atoms[5], u.atoms[111], u.atoms[1000]] + u.atoms[-10:]
>>> manual_atomgroup = MDAnalysis.core.AtomGroup.AtomGroup(manual_atom_selection)
>>> print manual_atomgroup
<AtomGroup with 13 atoms>

but this is rarely necessary; typically one simply uses a selection.

Using an AtomGroup

The AtomGroup instance has a number of methods that compute properties over all atoms in the group. The values that these methods return can change when one steps through the trajectory on which the selection is based.

The list of Atom instances can be accessed as

list of Atom objects

Partial list of useful AtomGroup methods

For a atom group a:

numpy array of all coordinates
mean position of all atoms
center of mass of the atoms; needs masses to be defined
the three principal axes of the collection of atoms; needs the masses in order to calculate the moments of inertia. The eigenvectors are sorted by eigenvalue, with the first one corresponding to the highest eigenvalue.
number of atoms
number of residues that include those atoms
radius of gyration
sum of all partial charges (only useful when the topology contained charges)
sum of all masses

One can also make a sub-selection using

standard selection with the limitation that one can only access atoms that are part of the atom group (see Issue 10 and Issue 42).

For more information the documentation string that can be obtained with

>>> help(MDAnalysis.core.AtomGroup.AtomGroup)

Project Information

GNU GPL v2 code license
Labels: python, molecular dynamics, analysis, DCD, CHARMM, LAMMPS, NAMD, Gromacs, computer simulation, atoms, coordinates, trajectory, XTC, Library, object-oriented
Core Developers


Release Notes
Guide for Developers
Google Summer of Code

Code of Conduct


@mdanalysis on Twitter
Downloads (PyPi)
Mailing Lists:
User discussion group
Developer mailing list

Clone this wiki locally
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.