-
Notifications
You must be signed in to change notification settings - Fork 652
AtomGroup
outdated (July 2018), see the docs https://www.mdanalysis.org/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.
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.
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
- a.atoms
- list of Atom objects
For a atom group a
:
- a.coordinates()
- numpy array of all coordinates
- a.centerOfGeometry(pbc=False)
- mean position of all atoms
- a.centerOfMass(pbc=False)
- center of mass of the atoms; needs masses to be defined
- a.principalAxes(pbc=False)
- 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.
- a.numberOfAtoms()
- number of atoms
- a.numberOfResidues()
- number of residues that include those atoms
- a.radiusOfGyration()
- radius of gyration
- a.totalCharge()
- sum of all partial charges (only useful when the topology contained charges)
- a.totalMass()
- sum of all masses
One can also make a sub-selection using
- a.selectAtoms(selection-string)
- 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)