|
70 | 70 | |
71 | 71 | In MDAnalysis you can use the |
72 | 72 | :class:`~MDAnalysis.transformations.nojump.NoJump` |
73 | | - transformation. |
| 73 | + transformation to unwrap coordinates on-the-fly. |
| 74 | + |
| 75 | + A minimal example: |
| 76 | +
|
| 77 | + .. code-block:: python |
| 78 | + |
| 79 | + import MDAnalysis as mda |
| 80 | + from MDAnalysis.transformations import NoJump |
| 81 | + |
| 82 | + u = mda.Universe(TOP, TRAJ) |
| 83 | + |
| 84 | + # Apply NoJump transformation to unwrap coordinates |
| 85 | + u.trajectory.add_transformations(NoJump(u)) |
| 86 | + |
| 87 | + # Now the trajectory is unwrapped and MSD can be computed normally: |
| 88 | + from MDAnalysis.analysis.msd import EinsteinMSD |
| 89 | + MSD = EinsteinMSD(u, select="all", msd_type="xyz") |
| 90 | + MSD.run() |
| 91 | +
|
| 92 | + This example assumes that the trajectory contains periodic box |
| 93 | + dimensions. If no periodic boundary information is present, box |
| 94 | + dimensions must be defined before applying ``NoJump``, which can |
| 95 | + be accomplished by applying the |
| 96 | + :class:`~MDAnalysis.transformations.boxdimensions.set_dimensions` |
| 97 | + transformation *before* the |
| 98 | + :class:`~MDAnalysis.transformations.nojump.NoJump` transformation. |
| 99 | + |
| 100 | + This replaces the need to preprocess trajectories externally. |
74 | 101 | |
75 | 102 | In GROMACS, for example, this can be done using `gmx trjconv`_ with the |
76 | 103 | ``-pbc nojump`` flag. |
@@ -382,14 +409,11 @@ def _parse_msd_type(self): |
382 | 409 | "xyz": [0, 1, 2], |
383 | 410 | } |
384 | 411 |
|
385 | | - self.msd_type = self.msd_type.lower() |
386 | | - |
387 | 412 | try: |
388 | | - self._dim = keys[self.msd_type] |
389 | | - except KeyError: |
| 413 | + self._dim = keys[self.msd_type.lower()] |
| 414 | + except (AttributeError, KeyError): |
390 | 415 | raise ValueError( |
391 | | - "invalid msd_type: {} specified, please specify one of xyz, " |
392 | | - "xy, xz, yz, x, y, z".format(self.msd_type) |
| 416 | + f"Invalid msd_type {self.msd_type}, must be a string and one of: xyz, xy, xz, yz, x, y, z" |
393 | 417 | ) |
394 | 418 |
|
395 | 419 | self.dim_fac = len(self._dim) |
|
0 commit comments