|
10 | 10 | from .frame import Frame |
11 | 11 |
|
12 | 12 | from prody.trajectory import openTrajFile |
| 13 | +from prody.measure import wrapAtoms |
| 14 | + |
| 15 | +from prody import LOGGER |
13 | 16 |
|
14 | 17 | __all__ = ['Trajectory'] |
15 | 18 |
|
@@ -311,3 +314,35 @@ def numFixed(self): |
311 | 314 | """Returns a list of fixed atom numbers, one from each file.""" |
312 | 315 |
|
313 | 316 | 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