wrap
- mdtools.box.wrap(ag, compound='atoms', center='cog', box=None, inplace=True, debug=False)[source]
Shift compounds of an MDAnalysis
AtomGroup
back into the primary unit cell.Todo
Include a make_whole argument that makes compounds whole after the wrapping, even if this implies that some
Atoms
might lie outside the primary unit cell again.- Parameters:
ag (
MDAnalysis.core.groups.AtomGroup instance
) – The MDAnalysisAtomGroup
whose compounds shall be wrapped back into the primary unit cell.compound (
{'atoms', 'group', 'segments', 'residues', 'molecules', 'fragments'}
, optional) – Which type of compound to keep together during wrapping.Atoms
belonging to the same compound are shifted by the same translation vector such that the center of the compound lies within the box. This might however mean that not allAtoms
of the compound will be inside the unit cell after wrapping. Default is'atoms'
, which means that eachAtom
of ag is shifted by its individual translation vector so that finally allAtoms
of ag will be inside the unit cell. Refer to the MDAnalysis’ user guide for an explanation of these terms. Note that in any case, even if compound is e.g.'residues'
, only theAtoms
belonging to ag are taken into account, even if the compound might comprise additionalAtoms
that are not contained in ag. Also note that broken compounds are note made whole by this function.center (
{'cog', 'com'}
, optional) – How to define the center of a compound. Parse'cog'
for center of geometry or'com'
for center of mass. If compound is'atoms'
, this parameter is meaningless and therefore ignored.box (
array_like
, optional) – The unit cell dimensions of the system, which can be orthogonal or triclinic and must be provided in the same format as returned byMDAnalysis.coordinates.base.Timestep.dimensions
:[lx, ly, lz, alpha, beta, gamma]
. IfNone
, thedimensions
of the currentTimestep
will be used.inplace (
bool
, optional) – IfTrue
, coordinates are modified in place.debug (
bool
, optional) – IfTrue
, run in debug mode.
- Returns:
wrapped_pos (
numpy.ndarray
) – Array of wrappedAtom
coordinates of dtype numpy.float32 and shape(ag.n_atoms, 3)
.
See also
MDAnalysis.core.groups.AtomGroup.wrap()
Shift compounds of the
AtomGroup
back into the primary unit cellMDAnalysis.core.groups.AtomGroup.pack_into_box()
MDAnalysis.lib.distances.apply_PBC()
Shift coordinates stored as
numpy.ndarray
into the primary unit cellmdtools.box.wrap_pos()
Shift all particle positions into the primary unit cell
mdtools.box.make_whole()
Make compounds of a MDAnalysis
AtomGroup
whole
Notes
This function is just a wrapper around the
wrap()
method of the inputAtomGroup
that additionally checks the masses of allAtoms
in ag when center is set to'com'
and compound is not'atoms'
. Seemdtools.check.masses_new()
for further information.When calling this function with compounds set to something different than
'atoms'
, make sure that the respective compounds are whole. Broken compounds will not be made whole by this function. Seemdtools.box.make_whole()
for a possibility to make compounds whole that are split across periodic boundaries.Because
MDAnalysis
will pulltrajectory
data directly from the file it is reading from, changes toAtom
coordinates and boxdimensions
will not persist once theframe
is changed (even if inplace isTrue
). The only way to make these changes permanent is to load thetrajectory
into memory, or to write a newtrajectory
to file for everyframe
. See the MDAnalysis user guide about trajectories (second last paragraph) and in-memory trajectories.