Trajectory classes

BaseTrajectory

An interface that defines the method that can be used to initialise and manage trajectories.

FullTrajectory

A trajectory that builds and loads in memory all the frames at once.

LazyTrajectory

A trajectory that does not load up all the frames in memory at once but parses them one after the other.

class baggianalysis.core.BaseTrajectory(self: baggianalysis.core.BaseTrajectory, arg0: baggianalysis.core.BaseParser)None

Bases: pybind11_builtins.pybind11_object

An interface that defines the method that can be used to initialise and manage trajectories.

Child classes should at least implement initialise_from_filelist(), initialise_from_trajectory_file(), next_frame() and reset().

The constructor takes a parser as its only parameter.

add_filter(self: baggianalysis.core.BaseTrajectory, filter: baggianalysis.core.BaseFilter)None

Add a filter to the list of filters that will be applied to each frame (system) that compose the trajectory.

The order according to which filters are added to the trajectory is important, since they are applied to systems in a “first-in first-out” fashion.

Parameters

filter (BaseFilter) – The new filter.

initialise_from_filelist(self: baggianalysis.core.BaseTrajectory, filelist: List[str])None

Initialise the trajectory out of a list of filenames.

Parameters

filelist (List(str)) – The list of filenames that will be used to initialise the trajectory.

initialise_from_folder(self: baggianalysis.core.BaseTrajectory, folder: str, pattern: str, natural_sorting: bool = True)None

Initialise the trajectory by loading up frames stored in files contained in a folder according to a pattern.

Parameters
  • folder (str) – The folder containing the files to be parsed

  • pattern (str) – A glob pattern used to select the files to be loaded. Examples are confs* or conf?0000.dat.

  • natural_sorting (bool) – Sort the files alphabetically while, at the same time, attempting to handle multi-digit numbers.

initialise_from_trajectory_file(self: baggianalysis.core.BaseTrajectory, trajectory_file: str)None

Initialise the trajectory from a single file, which should contain all the frames, one after the other.

Parameters

trajectory_file (str) – The name of the file containing the trajectory.

next_frame(self: baggianalysis.core.BaseTrajectory)baggianalysis.core.System

Return the next frame (system), or None if we reached the end of the trajectory.

Returns

Either the next system or None if there are no more available frames.

Return type

System

reset(self: baggianalysis.core.BaseTrajectory)None

Reset the trajectory so that a call to next_frame() will return the first frame of the trajectory.

set_include_system(self: baggianalysis.core.BaseTrajectory, system_includer: Callable[[baggianalysis.core.System], bool])None

Set an optional function that will be used to test whether a system should be included in the trajectory or not. The argument should be a callable that takes a System as its only parameter and returns True if the system should be included, False otherwise.

Here is an example that will include only those systems having timesteps larger than 1e4:

def include_system(system):
    return system.time > 1e4

trajectory.set_include_system(include_system)

The same result can be obtained with a lambda function:

trajectory.set_include_system(lambda syst: syst.time > 1e4)
Parameters

system_includer (callable) – A callable that takes the System to be checked a returns a boolean that specifies whether the system should be included in the trajectory or not.

class baggianalysis.core.FullTrajectory(self: baggianalysis.core.FullTrajectory, arg0: baggianalysis.core.BaseParser)None

Bases: baggianalysis.core.BaseTrajectory

A trajectory that builds and loads in memory all the frames at once.

This trajectory is probably the one you should be using unless the memory footprint of the files that should be parsed becomes too large, in which case you should use a LazyTrajectory.

The constructor takes a parser as its only parameter.

property frames

The read-only list of System objects making up the trajectory.

class baggianalysis.core.LazyTrajectory(self: baggianalysis.core.LazyTrajectory, arg0: baggianalysis.core.BaseParser)None

Bases: baggianalysis.core.BaseTrajectory

A trajectory that does not load up all the frames in memory at once but parses them one after the other.

Use it if you need to analyse large trajectories that could fill up all the available memory. Be careful though: the file(s) on the disk will be read every time you loop over the trajectory. If you need to do it more than once it may be worth using a FullTrajectory.

The constructor takes a parser as its only parameter.