Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
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, u.atoms, u.atoms] + 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
- 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