Skip to content

Commit be6141c

Browse files
committed
added trajectory wrap method
1 parent d1429ae commit be6141c

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

prody/trajectory/trajectory.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
from .frame import Frame
1111

1212
from prody.trajectory import openTrajFile
13+
from prody.measure import wrapAtoms
14+
15+
from prody import LOGGER
1316

1417
__all__ = ['Trajectory']
1518

@@ -311,3 +314,35 @@ def numFixed(self):
311314
"""Returns a list of fixed atom numbers, one from each file."""
312315

313316
return [traj.numFixed() for traj in self._trajectories]
317+
318+
def wrap(self, unitcell=None, center=np.array([0., 0., 0.])):
319+
"""Wrap atoms into an image of the system simulated under periodic boundary
320+
conditions for all frames and returns a new Trajectory.
321+
322+
.. note::
323+
This function will wrap all atoms into the specified periodic image, so
324+
covalent bonds will be broken.
325+
326+
:arg unitcell: orthorhombic unitcell array with shape (3,)
327+
:type unitcell: :class:`numpy.ndarray`
328+
329+
:arg center: coordinates of the center of the wrapping cell, default is
330+
the origin of the Cartesian coordinate system
331+
:type center: :class:`numpy.ndarray`"""
332+
333+
if unitcell is None:
334+
unitcell = self[0].getUnitcell()[:3]
335+
336+
wrapped = Trajectory(self.getTitle() + '_wrapped')
337+
338+
coordsets = self.getCoordsets()
339+
340+
LOGGER.progress('Wrapping trajectory ...', len(coordsets))
341+
for i, coordset in enumerate(coordsets):
342+
wrapped.addCoordset(wrapAtoms(coordset), unitcell=unitcell, center=center)
343+
LOGGER.update(i)
344+
345+
LOGGER.finish()
346+
347+
return wrapped
348+

0 commit comments

Comments
 (0)