Correlation 4.10.0
An Analysis Tool for Liquids and for Amorphous Solids
Loading...
Searching...
No Matches
Trajectory.hpp
Go to the documentation of this file.
1
8
9#pragma once
10
12#include "core/Cell.hpp"
13
14#include <functional>
15#include <memory>
16#include <mutex>
17#include <optional>
18#include <span>
19#include <vector>
20
21namespace correlation::core {
22
23class MappedFile;
24
33
34public:
37 Trajectory();
38
44 Trajectory(std::vector<Cell> frames, real_t time_step);
45
47 uint32_t file_index{0};
48 size_t offset{0};
49 size_t size{0};
50 };
51
52 using FrameParser = std::function<Cell(const char *data, size_t size)>;
53
61 Trajectory(std::shared_ptr<MappedFile> mapped_file, std::vector<size_t> frame_offsets,
62 FrameParser parser, real_t time_step);
63
71 Trajectory(std::vector<std::shared_ptr<MappedFile>> mapped_files,
72 std::vector<MappedFrameSlice> frame_slices, FrameParser parser, real_t time_step);
73
78 void addFrame(const Cell &frame);
79
81
84
88 [[nodiscard]] std::vector<Cell> &getFrames();
89
94 [[nodiscard]] const std::vector<Cell> &getFrames() const;
95
100 [[nodiscard]] std::span<Cell> frameSpan();
101
106 [[nodiscard]] std::span<const Cell> frameSpan() const;
107
112 [[nodiscard]] size_t getFrameCount() const noexcept;
113
119 [[nodiscard]] const Cell &firstFrame() const;
120
127 [[nodiscard]] Cell getFrame(size_t index) const;
128
135 [[nodiscard]] std::array<real_t, 6> getLatticeParameters(size_t index) const;
136
143 [[nodiscard]] real_t getVolume(size_t index) const;
144
149 [[nodiscard]] const std::vector<std::array<real_t, 6>> &getFrameLatticeParameters() const;
150
155 [[nodiscard]] const std::vector<real_t> &getFrameVolumes() const;
156
161 [[nodiscard]] real_t getTimeStep() const noexcept { return time_step_; }
162
167 void setTimeStep(real_t step) noexcept { time_step_ = step; }
168
175 [[nodiscard]] const correlation::analysis::BondCutoffRange &
176 getBondCutoffRange(size_t type1, size_t type2) const;
177
184 [[nodiscard]] real_t getBondCutoffSQ(size_t type1, size_t type2) const;
185
192 [[nodiscard]] real_t getMinBondCutoffSQ(size_t type1, size_t type2) const;
193
200 [[nodiscard]] real_t getBondCutoff(size_t type1, size_t type2) const;
201
208 [[nodiscard]] real_t getMinBondCutoff(size_t type1, size_t type2) const;
209
216
223 void removeDuplicatedFrames(real_t tolerance = static_cast<real_t>(1e-5));
224
229 void precomputeBondCutoffs() const;
230
237 void calculateVelocities();
238
243 [[nodiscard]] const correlation::analysis::BondCutoffMatrix &getBondCutoffs() const noexcept {
244 return bond_cutoffs_;
245 }
246
251 [[nodiscard]] const correlation::analysis::BondCutoffMatrix &getBondCutoffsSQ() const noexcept {
252 return bond_cutoffs_;
253 }
254
259 [[nodiscard]] size_t getRemovedFrameCount() const noexcept { return removed_frames_count_; }
260
268 bool renameElement(std::string_view old_symbol, std::string_view new_symbol);
269
271
272private:
279 void validateFrame(const Cell &new_frame) const;
280 void ensureMaterialized() const;
281 void syncCellMetricsUnlocked() const;
282 void applyElementRemap(Cell &cell) const;
283 bool renameElementMaterialized(std::string_view old_symbol, std::string_view new_symbol);
284 bool renameElementMapped(std::string_view old_symbol, std::string_view new_symbol);
285
286 mutable std::unique_ptr<std::mutex> init_mutex_{std::make_unique<std::mutex>()};
287
288 mutable std::vector<Cell> frames_;
289 mutable std::optional<Cell> first_frame_;
290 mutable std::vector<std::array<real_t, 6>>
292 mutable std::vector<real_t> frame_volumes_;
296
297 std::vector<std::shared_ptr<MappedFile>> mapped_files_;
298 std::vector<MappedFrameSlice> frame_slices_;
300 std::vector<std::pair<std::string, std::string>> element_remap_;
301};
302
303} // namespace correlation::core
Simulation cell structure with periodic boundary conditions.
Contiguous 2D matrix of element-pair bond cutoff ranges.
Definition AnalysisTypes.hpp:48
Represents the simulation cell (periodic box).
Definition Cell.hpp:30
RAII memory-mapped read-only file view.
Definition MappedFile.hpp:54
std::span< Cell > frameSpan()
Gets a mutable span view over the trajectory frames.
Definition Trajectory.cpp:76
bool renameElementMapped(std::string_view old_symbol, std::string_view new_symbol)
Definition Trajectory.cpp:227
std::function< Cell(const char *data, size_t size)> FrameParser
Definition Trajectory.hpp:52
std::optional< Cell > first_frame_
Definition Trajectory.hpp:289
std::vector< Cell > frames_
Collection of simulation snapshots.
Definition Trajectory.hpp:288
bool renameElementMaterialized(std::string_view old_symbol, std::string_view new_symbol)
Definition Trajectory.cpp:213
FrameParser parser_
Definition Trajectory.hpp:299
real_t getBondCutoff(size_t type1, size_t type2) const
Gets the maximum bond cutoff distance for two given element types.
Definition Trajectory.cpp:299
real_t getMinBondCutoffSQ(size_t type1, size_t type2) const
Gets a squared minimum bond cutoff distance for two given element types.
Definition Trajectory.cpp:295
void ensureMaterialized() const
Definition Trajectory.cpp:186
size_t removed_frames_count_
Counter for deduplicated frames.
Definition Trajectory.hpp:295
std::array< real_t, 6 > getLatticeParameters(size_t index) const
Gets the lattice parameters [a, b, c, alpha, beta, gamma] for a specific frame.
Definition Trajectory.cpp:112
const std::vector< real_t > & getFrameVolumes() const
Gets the tracked cell volumes for all frames.
Definition Trajectory.cpp:144
void setTimeStep(real_t step) noexcept
Sets the simulation time step.
Definition Trajectory.hpp:167
real_t getVolume(size_t index) const
Gets the simulation cell volume for a specific frame.
Definition Trajectory.cpp:125
void addFrame(const Cell &frame)
Appends a new frame to the trajectory.
Definition Trajectory.cpp:312
const correlation::analysis::BondCutoffMatrix & getBondCutoffsSQ() const noexcept
Backward-compatible alias returning the bond cutoff matrix.
Definition Trajectory.hpp:251
const correlation::analysis::BondCutoffRange & getBondCutoffRange(size_t type1, size_t type2) const
Gets the bond cutoff range for two given element types.
Definition Trajectory.cpp:283
const std::vector< std::array< real_t, 6 > > & getFrameLatticeParameters() const
Gets the tracked lattice parameters [a, b, c, alpha, beta, gamma] for all frames.
Definition Trajectory.cpp:138
std::vector< Cell > & getFrames()
Gets a mutable reference to the frames.
Definition Trajectory.cpp:66
size_t getFrameCount() const noexcept
Gets the total number of frames in the trajectory.
Definition Trajectory.cpp:86
real_t getMinBondCutoff(size_t type1, size_t type2) const
Gets the minimum bond cutoff distance for two given element types.
Definition Trajectory.cpp:303
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 ...
Definition Trajectory.cpp:264
correlation::analysis::BondCutoffMatrix bond_cutoffs_
Cached bond cutoff ranges.
Definition Trajectory.hpp:293
real_t getTimeStep() const noexcept
Gets the time step between frames.
Definition Trajectory.hpp:161
void applyElementRemap(Cell &cell) const
Definition Trajectory.cpp:207
Trajectory()
Definition Trajectory.cpp:23
const correlation::analysis::BondCutoffMatrix & getBondCutoffs() const noexcept
Gets the matrix of bond cutoff ranges for element pairs.
Definition Trajectory.hpp:243
std::vector< std::pair< std::string, std::string > > element_remap_
Definition Trajectory.hpp:300
void setBondCutoffs(const correlation::analysis::BondCutoffMatrix &cutoffs)
Sets the bond cutoff matrix for neighbor searching.
Definition Trajectory.cpp:307
std::unique_ptr< std::mutex > init_mutex_
Definition Trajectory.hpp:286
std::vector< real_t > frame_volumes_
Tracked volume per cell.
Definition Trajectory.hpp:292
std::vector< std::shared_ptr< MappedFile > > mapped_files_
Definition Trajectory.hpp:297
std::vector< std::array< real_t, 6 > > frame_lattice_parameters_
Tracked lattice parameters per cell.
Definition Trajectory.hpp:291
void syncCellMetricsUnlocked() const
Definition Trajectory.cpp:150
std::vector< MappedFrameSlice > frame_slices_
Definition Trajectory.hpp:298
real_t time_step_
Time between snapshots.
Definition Trajectory.hpp:294
void removeDuplicatedFrames(real_t tolerance=static_cast< real_t >(1e-5))
Removes consecutive duplicated frames from the trajectory. Frames are considered duplicates if all at...
Definition Trajectory.cpp:340
const Cell & firstFrame() const
Gets a constant reference to the first frame of the trajectory.
Definition Trajectory.cpp:169
Cell getFrame(size_t index) const
Gets a copy of a frame at a specific index.
Definition Trajectory.cpp:93
void calculateVelocities()
Calculates velocities for all atoms in the trajectory using finite differences, accounting for period...
Definition Trajectory.cpp:359
real_t getBondCutoffSQ(size_t type1, size_t type2) const
Gets a squared bond cutoff distance for two given element types.
Definition Trajectory.cpp:291
void validateFrame(const Cell &new_frame) const
Internal helper to validate that a new frame matches the trajectory topology.
Definition Trajectory.cpp:368
void precomputeBondCutoffs() const
Pre-calculates the squared bond cutoff distances for every pair of element types using the elements f...
Definition Trajectory.cpp:329
size_t getRemovedFrameCount() const noexcept
Returns the number of frames removed during deduplication.
Definition Trajectory.hpp:259
Definition ITrajectoryCalculator.hpp:13
double real_t
Definition Precision.hpp:18
Represents the squared minimum and maximum bond distance bounds for an element pair.
Definition AnalysisTypes.hpp:29
size_t size
Definition Trajectory.hpp:49
uint32_t file_index
Definition Trajectory.hpp:47
size_t offset
Definition Trajectory.hpp:48