Correlation 4.10.0
An Analysis Tool for Liquids and for Amorphous Solids
Loading...
Searching...
No Matches
TrajectoryLoader.hpp
Go to the documentation of this file.
1
8
9#pragma once
10
11#include "core/Cell.hpp"
12#include "core/Trajectory.hpp"
13#include "math/Precision.hpp"
14
15#include <expected>
16#include <functional>
17#include <map>
18#include <memory>
19#include <string>
20#include <string_view>
21#include <utility>
22#include <vector>
23
25class IReaderRegistry;
26}
27
28namespace correlation::app {
29
35public:
36 using ProgressCallback = std::function<void(float, const std::string &)>;
37
42
48
49 ~TrajectoryLoader() = default;
50
53 TrajectoryLoader(TrajectoryLoader &&) noexcept = default;
54 TrajectoryLoader &operator=(TrajectoryLoader &&) noexcept = default;
55
62 std::expected<std::string, std::string> loadFile(const std::string &path,
63 const ProgressCallback &progress = nullptr);
64
71 std::expected<std::string, std::string> loadFiles(const std::vector<std::string> &paths,
72 const ProgressCallback &progress = nullptr);
73
78 [[nodiscard]] const correlation::core::Trajectory *trajectory() const noexcept {
79 return trajectory_.get();
80 }
81
86 [[nodiscard]] correlation::core::Trajectory *trajectoryMut() noexcept {
87 return trajectory_.get();
88 }
89
94 [[nodiscard]] std::shared_ptr<const correlation::core::Trajectory>
95 trajectoryShared() const noexcept {
96 return trajectory_;
97 }
98
103 [[nodiscard]] const correlation::core::Cell *cell() const noexcept {
104 if (trajectory_ && trajectory_->getFrameCount() > 0) {
105 return &trajectory_->firstFrame();
106 }
107 return nullptr;
108 }
109
114 [[nodiscard]] std::map<std::string, int> getAtomCounts() const;
115
120 [[nodiscard]] std::vector<std::pair<std::string, int>> getOrderedAtomCounts() const;
121
128 bool renameElement(std::string_view old_symbol, std::string_view new_symbol);
129
133 [[nodiscard]] size_t getFrameCount() const noexcept {
134 return trajectory_ ? trajectory_->getFrameCount() : 0;
135 }
136
140 [[nodiscard]] size_t getTotalAtomCount() const noexcept {
141 if (!trajectory_ || trajectory_->getFrameCount() == 0) {
142 return 0;
143 }
144 return trajectory_->firstFrame().atomCount();
145 }
146
150 [[nodiscard]] size_t getRemovedFrameCount() const noexcept {
151 return trajectory_ ? trajectory_->getRemovedFrameCount() : 0;
152 }
153
157 [[nodiscard]] real_t getTimeStep() const noexcept {
158 return trajectory_ ? trajectory_->getTimeStep() : static_cast<real_t>(1.0);
159 }
160
164 [[nodiscard]] real_t getRecommendedTimeStep() const;
165
170 void setTrajectory(std::shared_ptr<correlation::core::Trajectory> traj) noexcept {
171 trajectory_ = std::move(traj);
172 }
173
177 void clear() noexcept { trajectory_.reset(); }
178
179private:
180 std::shared_ptr<correlation::core::Trajectory> trajectory_;
182};
183
184} // namespace correlation::app
Simulation cell structure with periodic boundary conditions.
Floating point precision type definitions for Correlation.
Trajectory data structure for time-series atomistic simulations.
const correlation::core::Cell * cell() const noexcept
Gets a pointer to the first cell frame.
Definition TrajectoryLoader.hpp:103
real_t getTimeStep() const noexcept
Simulation timestep of the trajectory in femtoseconds.
Definition TrajectoryLoader.hpp:157
TrajectoryLoader(const TrajectoryLoader &)=delete
void clear() noexcept
Clears currently loaded trajectory and resets state.
Definition TrajectoryLoader.hpp:177
std::expected< std::string, std::string > loadFile(const std::string &path, const ProgressCallback &progress=nullptr)
Loads a structure or trajectory file from the given path.
Definition TrajectoryLoader.cpp:70
const correlation::readers::IReaderRegistry * registry_
Definition TrajectoryLoader.hpp:181
correlation::core::Trajectory * trajectoryMut() noexcept
Gets a mutable pointer to the loaded trajectory.
Definition TrajectoryLoader.hpp:86
size_t getTotalAtomCount() const noexcept
Total number of atoms in the primary frame.
Definition TrajectoryLoader.hpp:140
TrajectoryLoader()
Constructs a TrajectoryLoader using the global default ReaderFactory singleton.
Definition TrajectoryLoader.cpp:21
real_t getRecommendedTimeStep() const
Recommended timestep derived from atomic masses in the active cell.
Definition TrajectoryLoader.cpp:66
std::vector< std::pair< std::string, int > > getOrderedAtomCounts() const
Computes atomic species counts in cell element-registration order.
Definition TrajectoryLoader.cpp:35
std::shared_ptr< correlation::core::Trajectory > trajectory_
Definition TrajectoryLoader.hpp:180
TrajectoryLoader(TrajectoryLoader &&) noexcept=default
void setTrajectory(std::shared_ptr< correlation::core::Trajectory > traj) noexcept
Injects an existing trajectory instance.
Definition TrajectoryLoader.hpp:170
std::expected< std::string, std::string > loadFiles(const std::vector< std::string > &paths, const ProgressCallback &progress=nullptr)
Loads a multi-file trajectory from a collection of paths.
Definition TrajectoryLoader.cpp:120
size_t getRemovedFrameCount() const noexcept
Number of skipped/removed frames during parsing.
Definition TrajectoryLoader.hpp:150
std::function< void(float, const std::string &)> ProgressCallback
Definition TrajectoryLoader.hpp:36
std::shared_ptr< const correlation::core::Trajectory > trajectoryShared() const noexcept
Gets a shared pointer to the loaded trajectory.
Definition TrajectoryLoader.hpp:95
size_t getFrameCount() const noexcept
Total number of frames in the loaded trajectory.
Definition TrajectoryLoader.hpp:133
const correlation::core::Trajectory * trajectory() const noexcept
Gets a pointer to the loaded trajectory.
Definition TrajectoryLoader.hpp:78
TrajectoryLoader & operator=(const TrajectoryLoader &)=delete
bool renameElement(std::string_view old_symbol, std::string_view new_symbol)
Renames an element species across the loaded trajectory.
Definition TrajectoryLoader.cpp:59
std::map< std::string, int > getAtomCounts() const
Computes atomic species counts for the active cell.
Definition TrajectoryLoader.cpp:27
Represents the simulation cell (periodic box).
Definition Cell.hpp:30
This class stores a series of snapshots of a system.
Definition Trajectory.hpp:32
Abstract interface defining lookup capabilities for file reader discovery and instantiation.
Definition IReaderRegistry.hpp:32
Definition AppController.hpp:27
Definition ITrajectoryCalculator.hpp:13
Definition TrajectoryLoader.hpp:24
Definition AnalysisTypes.hpp:11
double real_t
Definition Precision.hpp:18