Correlation 4.10.0
An Analysis Tool for Liquids and for Amorphous Solids
Loading...
Searching...
No Matches
correlation::core::Trajectory Class Reference

This class stores a series of snapshots of a system. More...

#include <Trajectory.hpp>

Collaboration diagram for correlation::core::Trajectory:

Classes

struct  MappedFrameSlice

Public Member Functions

Accessors
std::vector< Cell > & getFrames ()
 Gets a mutable reference to the frames.
const std::vector< Cell > & getFrames () const
 Gets a constant reference to the frames.
std::span< Cell > frameSpan ()
 Gets a mutable span view over the trajectory frames.
std::span< const Cell > frameSpan () const
 Gets an immutable span view over the trajectory frames.
size_t getFrameCount () const noexcept
 Gets the total number of frames in the trajectory.
const Cell & firstFrame () const
 Gets a constant reference to the first frame of the trajectory.
Cell getFrame (size_t index) const
 Gets a copy of a frame at a specific index.
std::array< real_t, 6 > getLatticeParameters (size_t index) const
 Gets the lattice parameters [a, b, c, alpha, beta, gamma] for a specific frame.
real_t getVolume (size_t index) const
 Gets the simulation cell volume for a specific frame.
const std::vector< std::array< real_t, 6 > > & getFrameLatticeParameters () const
 Gets the tracked lattice parameters [a, b, c, alpha, beta, gamma] for all frames.
const std::vector< real_t > & getFrameVolumes () const
 Gets the tracked cell volumes for all frames.
real_t getTimeStep () const noexcept
 Gets the time step between frames.
void setTimeStep (real_t step) noexcept
 Sets the simulation time step.
const correlation::analysis::BondCutoffRange & getBondCutoffRange (size_t type1, size_t type2) const
 Gets the bond cutoff range for two given element types.
real_t getBondCutoffSQ (size_t type1, size_t type2) const
 Gets a squared bond cutoff distance for two given element types.
real_t getMinBondCutoffSQ (size_t type1, size_t type2) const
 Gets a squared minimum bond cutoff distance for two given element types.
real_t getBondCutoff (size_t type1, size_t type2) const
 Gets the maximum bond cutoff distance for two given element types.
real_t getMinBondCutoff (size_t type1, size_t type2) const
 Gets the minimum bond cutoff distance for two given element types.
void setBondCutoffs (const correlation::analysis::BondCutoffMatrix &cutoffs)
 Sets the bond cutoff matrix for neighbor searching.
void removeDuplicatedFrames (real_t tolerance=static_cast< real_t >(1e-5))
 Removes consecutive duplicated frames from the trajectory. Frames are considered duplicates if all atom positions are identical (within a small tolerance).
void precomputeBondCutoffs () const
 Pre-calculates the squared bond cutoff distances for every pair of element types using the elements from the first frame.
void calculateVelocities ()
 Calculates velocities for all atoms in the trajectory using finite differences, accounting for periodic boundary conditions. Assumes constant time step. Populates the internal velocities_ vector.
const correlation::analysis::BondCutoffMatrix & getBondCutoffs () const noexcept
 Gets the matrix of bond cutoff ranges for element pairs.
const correlation::analysis::BondCutoffMatrix & getBondCutoffsSQ () const noexcept
 Backward-compatible alias returning the bond cutoff matrix.
size_t getRemovedFrameCount () const noexcept
 Returns the number of frames removed during deduplication.
bool renameElement (std::string_view old_symbol, std::string_view new_symbol)
 Renames an element species across all frames (both materialized and lazy-mapped) and recomputes bond cutoffs.

Private Member Functions

void validateFrame (const Cell &new_frame) const
 Internal helper to validate that a new frame matches the trajectory topology.
void ensureMaterialized () const
void syncCellMetricsUnlocked () const
void applyElementRemap (Cell &cell) const
bool renameElementMaterialized (std::string_view old_symbol, std::string_view new_symbol)
bool renameElementMapped (std::string_view old_symbol, std::string_view new_symbol)

Private Attributes

std::unique_ptr< std::mutex > init_mutex_ {std::make_unique<std::mutex>()}
std::vector< Cell > frames_
 Collection of simulation snapshots.
std::optional< Cell > first_frame_
std::vector< std::array< real_t, 6 > > frame_lattice_parameters_
 Tracked lattice parameters per cell.
std::vector< real_t > frame_volumes_
 Tracked volume per cell.
correlation::analysis::BondCutoffMatrix bond_cutoffs_
 Cached bond cutoff ranges.
real_t time_step_
 Time between snapshots.
size_t removed_frames_count_ {0}
 Counter for deduplicated frames.
std::vector< std::shared_ptr< MappedFile > > mapped_files_
std::vector< MappedFrameSlice > frame_slices_
FrameParser parser_
std::vector< std::pair< std::string, std::string > > element_remap_

Constructors

using FrameParser = std::function<Cell(const char *data, size_t size)>
 Trajectory ()
 Trajectory (std::vector< Cell > frames, real_t time_step)
 Constructs a trajectory from a vector of frames.
 Trajectory (std::shared_ptr< MappedFile > mapped_file, std::vector< size_t > frame_offsets, FrameParser parser, real_t time_step)
 Constructs a lazy-loading trajectory from a memory-mapped file.
 Trajectory (std::vector< std::shared_ptr< MappedFile > > mapped_files, std::vector< MappedFrameSlice > frame_slices, FrameParser parser, real_t time_step)
 Constructs a lazy-loading trajectory from multiple memory-mapped files.
void addFrame (const Cell &frame)
 Appends a new frame to the trajectory.

Detailed Description

This class stores a series of snapshots of a system.

It ensures that the number of atoms and their identities are consistent across all frames. It provides methods to analyze dynamic properties of the system, such as velocity distributions.

Member Typedef Documentation

◆ FrameParser

using correlation::core::Trajectory::FrameParser = std::function<Cell(const char *data, size_t size)>

Constructor & Destructor Documentation

◆ Trajectory() [1/4]

correlation::core::Trajectory::Trajectory ( )
Here is the caller graph for this function:

◆ Trajectory() [2/4]

correlation::core::Trajectory::Trajectory ( std::vector< Cell > frames,
real_t time_step )

Constructs a trajectory from a vector of frames.

Parameters
framesVector of Cell objects representing simulation snapshots.
time_stepThe time interval between consecutive frames.
Here is the call graph for this function:

◆ Trajectory() [3/4]

correlation::core::Trajectory::Trajectory ( std::shared_ptr< MappedFile > mapped_file,
std::vector< size_t > frame_offsets,
FrameParser parser,
real_t time_step )

Constructs a lazy-loading trajectory from a memory-mapped file.

Parameters
mapped_fileShared pointer to the mapped file.
frame_offsetsByte offsets of the frames in the file.
parserFunction to parse a frame from a slice of memory.
time_stepThe time interval between consecutive frames.
Here is the call graph for this function:

◆ Trajectory() [4/4]

correlation::core::Trajectory::Trajectory ( std::vector< std::shared_ptr< MappedFile > > mapped_files,
std::vector< MappedFrameSlice > frame_slices,
FrameParser parser,
real_t time_step )

Constructs a lazy-loading trajectory from multiple memory-mapped files.

Parameters
mapped_filesVector of shared pointers to mapped files.
frame_slicesSlice descriptors locating each frame across the mapped files.
parserFunction to parse a frame from a slice of memory.
time_stepThe time interval between consecutive frames.
Here is the call graph for this function:

Member Function Documentation

◆ addFrame()

void correlation::core::Trajectory::addFrame ( const Cell & frame)

Appends a new frame to the trajectory.

Parameters
frameThe Cell object to add.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ applyElementRemap()

void correlation::core::Trajectory::applyElementRemap ( Cell & cell) const
private
Here is the call graph for this function:
Here is the caller graph for this function:

◆ calculateVelocities()

void correlation::core::Trajectory::calculateVelocities ( )

Calculates velocities for all atoms in the trajectory using finite differences, accounting for periodic boundary conditions. Assumes constant time step. Populates the internal velocities_ vector.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ensureMaterialized()

void correlation::core::Trajectory::ensureMaterialized ( ) const
private
Here is the call graph for this function:
Here is the caller graph for this function:

◆ firstFrame()

const Cell & correlation::core::Trajectory::firstFrame ( ) const
nodiscard

Gets a constant reference to the first frame of the trajectory.

Returns
A Cell object representing the first frame.
Exceptions
std::runtime_errorif the trajectory is empty.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ frameSpan() [1/2]

std::span< Cell > correlation::core::Trajectory::frameSpan ( )
nodiscard

Gets a mutable span view over the trajectory frames.

Returns
Mutable span of Cell objects.
Here is the call graph for this function:

◆ frameSpan() [2/2]

std::span< const Cell > correlation::core::Trajectory::frameSpan ( ) const
nodiscard

Gets an immutable span view over the trajectory frames.

Returns
Const span of Cell objects.
Here is the call graph for this function:

◆ getBondCutoff()

real_t correlation::core::Trajectory::getBondCutoff ( size_t type1,
size_t type2 ) const
nodiscard

Gets the maximum bond cutoff distance for two given element types.

Parameters
type1ID of the first element type.
type2ID of the second element type.
Returns
The bond cutoff distance.
Here is the call graph for this function:

◆ getBondCutoffRange()

const correlation::analysis::BondCutoffRange & correlation::core::Trajectory::getBondCutoffRange ( size_t type1,
size_t type2 ) const
nodiscard

Gets the bond cutoff range for two given element types.

Parameters
type1ID of the first element type.
type2ID of the second element type.
Returns
Const reference to the BondCutoffRange.
Here is the call graph for this function:

◆ getBondCutoffs()

const correlation::analysis::BondCutoffMatrix & correlation::core::Trajectory::getBondCutoffs ( ) const
inlinenodiscardnoexcept

Gets the matrix of bond cutoff ranges for element pairs.

Returns
The bond cutoff matrix.
Here is the caller graph for this function:

◆ getBondCutoffSQ()

real_t correlation::core::Trajectory::getBondCutoffSQ ( size_t type1,
size_t type2 ) const
nodiscard

Gets a squared bond cutoff distance for two given element types.

Parameters
type1ID of the first element type.
type2ID of the second element type.
Returns
The squared bond cutoff distance.
Here is the call graph for this function:

◆ getBondCutoffsSQ()

const correlation::analysis::BondCutoffMatrix & correlation::core::Trajectory::getBondCutoffsSQ ( ) const
inlinenodiscardnoexcept

Backward-compatible alias returning the bond cutoff matrix.

Returns
The bond cutoff matrix.
Here is the caller graph for this function:

◆ getFrame()

Cell correlation::core::Trajectory::getFrame ( size_t index) const
nodiscard

Gets a copy of a frame at a specific index.

Parameters
indexThe index of the frame to retrieve.
Returns
A Cell object representing the frame.
Exceptions
std::out_of_rangeif the index is invalid.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getFrameCount()

size_t correlation::core::Trajectory::getFrameCount ( ) const
nodiscardnoexcept

Gets the total number of frames in the trajectory.

Returns
The number of frames.
Here is the caller graph for this function:

◆ getFrameLatticeParameters()

const std::vector< std::array< real_t, 6 > > & correlation::core::Trajectory::getFrameLatticeParameters ( ) const
nodiscard

Gets the tracked lattice parameters [a, b, c, alpha, beta, gamma] for all frames.

Returns
Const reference to the per-cell lattice parameters vector.
Here is the call graph for this function:

◆ getFrames() [1/2]

std::vector< Cell > & correlation::core::Trajectory::getFrames ( )
nodiscard

Gets a mutable reference to the frames.

Returns
A vector of Cell objects representing the frames.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getFrames() [2/2]

const std::vector< Cell > & correlation::core::Trajectory::getFrames ( ) const
nodiscard

Gets a constant reference to the frames.

Returns
A vector of Cell objects representing the frames.
Here is the call graph for this function:

◆ getFrameVolumes()

const std::vector< real_t > & correlation::core::Trajectory::getFrameVolumes ( ) const
nodiscard

Gets the tracked cell volumes for all frames.

Returns
Const reference to the per-cell volumes vector.
Here is the call graph for this function:

◆ getLatticeParameters()

std::array< real_t, 6 > correlation::core::Trajectory::getLatticeParameters ( size_t index) const
nodiscard

Gets the lattice parameters [a, b, c, alpha, beta, gamma] for a specific frame.

Parameters
indexThe index of the frame to query.
Returns
Array of 6 lattice parameters (lengths in Angstroms, angles in degrees).
Exceptions
std::out_of_rangeif the index is invalid.
Here is the call graph for this function:

◆ getMinBondCutoff()

real_t correlation::core::Trajectory::getMinBondCutoff ( size_t type1,
size_t type2 ) const
nodiscard

Gets the minimum bond cutoff distance for two given element types.

Parameters
type1ID of the first element type.
type2ID of the second element type.
Returns
The minimum bond cutoff distance.
Here is the call graph for this function:

◆ getMinBondCutoffSQ()

real_t correlation::core::Trajectory::getMinBondCutoffSQ ( size_t type1,
size_t type2 ) const
nodiscard

Gets a squared minimum bond cutoff distance for two given element types.

Parameters
type1ID of the first element type.
type2ID of the second element type.
Returns
The squared minimum bond cutoff distance.
Here is the call graph for this function:

◆ getRemovedFrameCount()

size_t correlation::core::Trajectory::getRemovedFrameCount ( ) const
inlinenodiscardnoexcept

Returns the number of frames removed during deduplication.

Returns
Count of duplicate frames found and removed.

◆ getTimeStep()

real_t correlation::core::Trajectory::getTimeStep ( ) const
inlinenodiscardnoexcept

Gets the time step between frames.

Returns
The time step in simulation units.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getVolume()

real_t correlation::core::Trajectory::getVolume ( size_t index) const
nodiscard

Gets the simulation cell volume for a specific frame.

Parameters
indexThe index of the frame to query.
Returns
Volume of the cell in cubic Angstroms.
Exceptions
std::out_of_rangeif the index is invalid.
Here is the call graph for this function:

◆ precomputeBondCutoffs()

void correlation::core::Trajectory::precomputeBondCutoffs ( ) const

Pre-calculates the squared bond cutoff distances for every pair of element types using the elements from the first frame.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ removeDuplicatedFrames()

void correlation::core::Trajectory::removeDuplicatedFrames ( real_t tolerance = static_cast<real_t>(1e-5))

Removes consecutive duplicated frames from the trajectory. Frames are considered duplicates if all atom positions are identical (within a small tolerance).

Parameters
toleranceEuclidean distance threshold in Angstroms for position equivalence.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ renameElement()

bool correlation::core::Trajectory::renameElement ( std::string_view old_symbol,
std::string_view new_symbol )

Renames an element species across all frames (both materialized and lazy-mapped) and recomputes bond cutoffs.

Parameters
old_symbolExisting element symbol (e.g., "1").
new_symbolReplacement element symbol (e.g., "Cu").
Returns
True if the element was renamed, false otherwise.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ renameElementMapped()

bool correlation::core::Trajectory::renameElementMapped ( std::string_view old_symbol,
std::string_view new_symbol )
private
Here is the call graph for this function:
Here is the caller graph for this function:

◆ renameElementMaterialized()

bool correlation::core::Trajectory::renameElementMaterialized ( std::string_view old_symbol,
std::string_view new_symbol )
private
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setBondCutoffs()

void correlation::core::Trajectory::setBondCutoffs ( const correlation::analysis::BondCutoffMatrix & cutoffs)

Sets the bond cutoff matrix for neighbor searching.

Parameters
cutoffsMatrix of bond cutoff ranges [type1][type2].
Exceptions
std::invalid_argumentIf any cutoff bound is negative or min_sq > max_sq.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setTimeStep()

void correlation::core::Trajectory::setTimeStep ( real_t step)
inlinenoexcept

Sets the simulation time step.

Parameters
stepTime step in femtoseconds.

◆ syncCellMetricsUnlocked()

void correlation::core::Trajectory::syncCellMetricsUnlocked ( ) const
private
Here is the call graph for this function:
Here is the caller graph for this function:

◆ validateFrame()

void correlation::core::Trajectory::validateFrame ( const Cell & new_frame) const
private

Internal helper to validate that a new frame matches the trajectory topology.

Parameters
new_frameThe frame to check.
Exceptions
std::invalid_argumentif frame is inconsistent.
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ bond_cutoffs_

correlation::analysis::BondCutoffMatrix correlation::core::Trajectory::bond_cutoffs_
mutableprivate

Cached bond cutoff ranges.

◆ element_remap_

std::vector<std::pair<std::string, std::string> > correlation::core::Trajectory::element_remap_
private

◆ first_frame_

std::optional<Cell> correlation::core::Trajectory::first_frame_
mutableprivate

◆ frame_lattice_parameters_

std::vector<std::array<real_t, 6> > correlation::core::Trajectory::frame_lattice_parameters_
mutableprivate

Tracked lattice parameters per cell.

◆ frame_slices_

std::vector<MappedFrameSlice> correlation::core::Trajectory::frame_slices_
private

◆ frame_volumes_

std::vector<real_t> correlation::core::Trajectory::frame_volumes_
mutableprivate

Tracked volume per cell.

◆ frames_

std::vector<Cell> correlation::core::Trajectory::frames_
mutableprivate

Collection of simulation snapshots.

◆ init_mutex_

std::unique_ptr<std::mutex> correlation::core::Trajectory::init_mutex_ {std::make_unique<std::mutex>()}
mutableprivate

◆ mapped_files_

std::vector<std::shared_ptr<MappedFile> > correlation::core::Trajectory::mapped_files_
private

◆ parser_

FrameParser correlation::core::Trajectory::parser_
private

◆ removed_frames_count_

size_t correlation::core::Trajectory::removed_frames_count_ {0}
private

Counter for deduplicated frames.

◆ time_step_

real_t correlation::core::Trajectory::time_step_
private

Time between snapshots.


The documentation for this class was generated from the following files: