wrap
- mdtools.box.wrap(ag, compound='atoms', center='cog', box=None, inplace=True, debug=False)[source]
Shift compounds of an MDAnalysis
AtomGroupback into the primary unit cell.Todo
Include a make_whole argument that makes compounds whole after the wrapping, even if this implies that some
Atomsmight lie outside the primary unit cell again.- Parameters:
ag (
MDAnalysis.core.groups.AtomGroup instance) – The MDAnalysisAtomGroupwhose 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.Atomsbelonging 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 allAtomsof the compound will be inside the unit cell after wrapping. Default is'atoms', which means that eachAtomof ag is shifted by its individual translation vector so that finally allAtomsof 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 theAtomsbelonging to ag are taken into account, even if the compound might comprise additionalAtomsthat 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, thedimensionsof the currentTimestepwill 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 wrappedAtomcoordinates of dtype numpy.float32 and shape(ag.n_atoms, 3).
See also
MDAnalysis.core.groups.AtomGroup.wrap()Shift compounds of the
AtomGroupback into the primary unit cellMDAnalysis.core.groups.AtomGroup.pack_into_box()MDAnalysis.lib.distances.apply_PBC()Shift coordinates stored as
numpy.ndarrayinto 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
AtomGroupwhole
Notes
This function is just a wrapper around the
wrap()method of the inputAtomGroupthat additionally checks the masses of allAtomsin 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
MDAnalysiswill pulltrajectorydata directly from the file it is reading from, changes toAtomcoordinates and boxdimensionswill not persist once theframeis changed (even if inplace isTrue). The only way to make these changes permanent is to load thetrajectoryinto memory, or to write a newtrajectoryto file for everyframe. See the MDAnalysis user guide about trajectories (second last paragraph) and in-memory trajectories.