Skip to content

Commit

Permalink
added trajectory wrap method
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesmkrieger committed Mar 11, 2021
1 parent d1429ae commit e255fd2
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
34 changes: 34 additions & 0 deletions prody/trajectory/trajbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

from prody.ensemble import Ensemble
from prody.utilities import checkCoords, checkWeights
from prody.measure import wrapAtoms
from prody import LOGGER

from .frame import Frame

Expand Down Expand Up @@ -366,3 +368,35 @@ def hasUnitcell(self):
"""Returns **True** if trajectory has unitcell data."""

pass


def wrap(self, unitcell=None, center=np.array([0., 0., 0.])):
"""Wrap atoms into an image of the system simulated under periodic boundary
conditions for all frames and returns a new Trajectory.
.. note::
This function will wrap all atoms into the specified periodic image, so
covalent bonds will be broken.
:arg unitcell: orthorhombic unitcell array with shape (3,)
:type unitcell: :class:`numpy.ndarray`
:arg center: coordinates of the center of the wrapping cell, default is
the origin of the Cartesian coordinate system
:type center: :class:`numpy.ndarray`"""

if unitcell is None:
unitcell = self[0].getUnitcell()[:3]

wrapped = Ensemble(self.getTitle() + '_wrapped')

coordsets = self.getCoordsets()

LOGGER.progress('Wrapping trajectory ...', len(coordsets))
for i, coordset in enumerate(coordsets):
wrapped.addCoordset(wrapAtoms(coordset), unitcell=unitcell, center=center)
LOGGER.update(i)

LOGGER.finish()

return wrapped
1 change: 1 addition & 0 deletions prody/trajectory/trajectory.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,3 +311,4 @@ def numFixed(self):
"""Returns a list of fixed atom numbers, one from each file."""

return [traj.numFixed() for traj in self._trajectories]

0 comments on commit e255fd2

Please sign in to comment.