com
- mdtools.structure.com(ag, pbc=False, compound='group', make_whole=False, debug=False)[source]
Calculate the center of mass of (compounds of) an MDAnalysis
AtomGroup
.- Parameters:
ag (
MDAnalysis.core.groups.AtomGroup
) – The MDAnalysisAtomGroup
for which to calculate the center of mass.pbc (
bool
, optional) – Seemdtools.structure.center()
.compound (
{'group', 'segments', 'residues', 'molecules', 'fragments', 'atoms'}
, optional) – Seemdtools.structure.center()
.make_whole (
bool
, optional) – Seemdtools.structure.center()
.debug (
bool
, optional) – IfTrue
, run in debug mode.
- Returns:
center (
numpy.ndarray
) – Center of mass position of each compound in ag. If compound was set to'group'
, the output will be a single position vector of shape(3,)
. Else, the output will be a 2d array of shape(n, 3)
wheren
is the number of compounds in ag.- Raises:
RuntimeWarning : – If debug is
True
and the center of mass of any compound isnan
.
See also
MDAnalysis.core.groups.AtomGroup.center()
Weighted center of (compounds of) the group
MDAnalysis.core.groups.AtomGroup.center_of_geometry()
Center of geometry of (compounds of) the group
MDAnalysis.core.groups.AtomGroup.center_of_mass()
Center of mass of (compounds of) the group
mdtools.structure.center()
Different types of centers of (compounds of) an MDAnalysis
AtomGroup
mdtools.structure.wcenter()
Weighted center of (compounds of) an MDAnalysis
AtomGroup
mdtools.structure.wcenter_pos()
Calculate the weighted center of a position array
mdtools.structure.coc()
Center of charge of (compounds of) an MDAnalysis
AtomGroup
mdtools.structure.cog()
Center of geometry of (compounds of) an MDAnalysis
AtomGroup
Notes
This function uses the
center_of_mass()
method of the inputAtomGroup
to calculate the center of mass.Important
MDAnalysis always guesses atom masses! If MDAnalysis cannot guess the mass from the atom type, it will assign this atom a zero mass. If the mass of a compound sum up to zero, the coordinates of that compound’s center of mass will be
nan
! If debug is set toTrue
, a warning will be raised if any compound’s weighted center isnan
. Also in the case ifdebug is false
, a ValueError will be raised, if the mass of any atom in ag is less than or equal to zero.Todo
Check if it is really necessary to wrap all
Atoms
back into the primary unit cell before callingcenter_of_mass()
with unwrap set toTrue
. The currently done back-wrapping is a serious problem, because it implies an inplace change of theAtom
coordinates.