amep.evaluate.MSD#

class amep.evaluate.MSD(traj: ParticleTrajectory, ptype: int | None = None, skip: float = 0.0, nav: int | None = None, use_nojump: bool = False, pbc: bool = True)#

Bases: BaseEvaluation

Mean-square displacement.

__init__(traj: ParticleTrajectory, ptype: int | None = None, skip: float = 0.0, nav: int | None = None, use_nojump: bool = False, pbc: bool = True) None#

Calculates the mean-square displacement over time. If periodic boundary conditions are applied, the unwrapped coordinates are used if they are available. If not, nojump coordinates are used. If periodic boundary conditions are not applied, the normal coordinates inside the box are used.

Parameters:
  • traj (amep.trajectory.ParticleTrajectory) – ParticleTrajectory object.

  • ptype (int or None, optional) – Particle type. The default is None.

  • skip (float, optional) – Skip this fraction of frames at the beginning of the trajectory. The default is 0.0.

  • nav (int or None, optional) – Number of time steps at which the mean square displacement should be evaluated. The default is None, i.e., all available time steps are used.

  • use_nojump (bool, optional) – Forces the use of nojump coordinates. The default is False.

  • pbc (bool, optional) – If True, periodic boundary conditions are applied and the unwrapped coordinates are used for the calculation. If those are not available, nojump coordinates will be used instead. The default is False.

Return type:

None.

Examples

>>> import amep
>>> traj = amep.load.traj("../examples/data/lammps.h5amep")
>>> traj.nojump()
>>> msd_normal = amep.evaluate.MSD(traj, pbc=False)
>>> msd_unwrapped = amep.evaluate.MSD(traj, pbc=True)
>>> msd_nojump = amep.evaluate.MSD(traj, use_nojump=True)
>>> fig, axs = amep.plot.new()
>>> axs.plot(
...     msd_normal.times, msd_normal.frames, ls="--",
...     marker="", label="normal coordinates", c="k"
... )
>>> axs.plot(
...     msd_unwrapped.times, msd_unwrapped.frames, ls="-",
...     marker='', label="unwrapped coordinates", c="gray"
... )
>>> axs.plot(
...     msd_nojump.times, msd_nojump.frames, ls=":",
...     marker='', label="nojump coordinates", c="darkorange"
... )
>>> axs.legend()
>>> axs.loglog()
>>> axs.set_xlabel(r"$t$")
>>> axs.set_ylabel(r"MSD$(t)$")
>>> fig.savefig('./figures/evaluate/evaluate-MSD.png')
../_images/evaluate-MSD.png

Methods

__init__(traj[, ptype, skip, nav, ...])

Calculates the mean-square displacement over time.

items()

keys()

The keys to the evaluation object.

save(path[, backup, database, name])

Stores the evaluation result in an HDF5 file.

values()

Attributes

avg

Time-averaged MSD (averaged over the given number of frames).

frames

MSD for each frame.

indices

Indices of all frames for which the MSD has been evaluated.

name

ptype

Particle type(s) for which the MSD has been calculated.

times

Times at which the MSD is evaluated.

property avg#

Time-averaged MSD (averaged over the given number of frames).

Returns:

Time-averaged MSD.

Return type:

float

property frames#

MSD for each frame.

Returns:

MSD for each frame.

Return type:

np.ndarray

property indices#

Indices of all frames for which the MSD has been evaluated.

Returns:

Frame indices.

Return type:

np.ndarray

keys() list[str]#

The keys to the evaluation object.

Used so Evaluation-objects can be used as dictionaries.

property ptype#

Particle type(s) for which the MSD has been calculated.

Returns:

Particle type(s).

Return type:

float or list of floats

save(path: str, backup: bool = True, database: bool = False, name: str | None = None) None#

Stores the evaluation result in an HDF5 file.

Parameters:
  • path (str) – Path of the ‘.h5’ file in which the data should be stored. If only a directory is given, the filename is chosen as self.name. Raises an error if the given directory does not exist or if the file extension is not ‘.h5’.

  • backup (bool, optional) – If True, an already existing file is backed up and not overwritten. This keyword is ignored if database=True. The default is True.

  • database (bool, optional) – If True, the results are appended to the given ‘.h5’ file if it already exists. If False, a new file is created and the old is backed up. If False and the given ‘.h5’ file contains multiple evaluation results, an error is raised. In this case, database has to be set to True. The default is False.

  • name (str or None, optional) – Name under which the data should be stored in the HDF5 file. If None, self.name is used. The default is None.

Return type:

None.

property times#

Times at which the MSD is evaluated.

Returns:

Times at which the MSD is evaluated.

Return type:

np.ndarray