amep.evaluate.TimeCor#

class amep.evaluate.TimeCor(traj, *args, ptype=None, skip=0.0, nav=None)#

Bases: BaseEvaluation

Calculate the autocorrelation function in time of a user-defined quantity.

__init__(traj, *args, ptype=None, skip=0.0, nav=None)#

Calculate the autocorrelation function. Averages over all particles of the given type.

Notes

If only one data key is given, the 1D time correlation function

\[c(t)=\langle x(0)x(t)\rangle\]

is calculated. If more than one data key is given, the data is combined in a vector and the calculated time correlation function reads

\[c(t)=\langle\vec{x}(0)\cdot\vec{x}(t)\rangle.\]
Parameters:
  • traj (amep.base.BaseTrajectory) – Trajectory object.

  • *args (str) – Data keys.

  • ptype (int, 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, optional) – Number of time steps at which the autocorrelation function should be evaluated. The default is None.

Return type:

None.

Examples

>>> import amep
>>> traj = amep.load.traj("../examples/data/lammps.h5amep")
>>> timecor = amep.evaluate.TimeCor(traj, "mux")
>>> timecor.save('./eval/my-time-cor.h5')
>>> fig, axs = amep.plot.new()
>>> axs.plot(timecor.times, timecor.frames)
>>> axs.set_xlabel(r"$t$")
>>> axs.set_ylabel(r"$C_{\mu_x}(t)$")
>>> axs.semilogx()
>>> fig.savefig("./figures/evaluate/evaluate-TimeCor.png")
../_images/evaluate-TimeCor.png

Methods

__init__(traj, *args[, ptype, skip, nav])

Calculate the autocorrelation function.

items()

keys()

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

Stores the evaluation result in an HDF5 file.

values()

Attributes

args

Data keys.

frames

TimeCor for each frame.

indices

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

name

ptype

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

times

Times at which the TimeCor is evaluated.

property args#

Data keys.

Returns:

Data keys.

Return type:

tuple of floats

property frames#

TimeCor for each frame.

Returns:

TimeCor for each frame.

Return type:

np.ndarray

property indices#

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

Returns:

Frame indices.

Return type:

np.ndarray

property ptype#

Particle type(s) for which the TimeCor 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 TimeCor is evaluated.

Returns:

Times at which the TimeCor is evaluated.

Return type:

np.ndarray