Loading...
Searching...
No Matches
ConFileIO.h
Go to the documentation of this file.
1/*
2** This file is part of eOn.
3**
4** SPDX-License-Identifier: BSD-3-Clause
5**
6** Copyright (c) 2010--present, eOn Development Team
7** All rights reserved.
8**
9** Repo:
10** https://github.com/TheochemUI/eOn
11*/
12#pragma once
13#include <array>
14#include <cstdint>
15#include <memory>
16#include <optional>
17#include <readcon-core.hpp>
18#include <string>
19#include <utility>
20#include <vector>
21
22namespace eonc {
23class Matter;
24
25namespace io {
26
29enum class IoStatus : std::uint8_t {
30 Ok = 0,
36};
37
38[[nodiscard]] constexpr bool io_ok(IoStatus s) noexcept {
39 return s == IoStatus::Ok;
40}
41
43[[nodiscard]] constexpr const char *io_status_name(IoStatus s) noexcept {
44 switch (s) {
45 case IoStatus::Ok:
46 return "ok";
48 return "read_error";
50 return "write_error";
52 return "append_error";
54 return "open_error";
56 return "invalid_argument";
57 }
58 return "unknown";
59}
60
62 std::string key;
63 double value;
64};
65
67 std::string key;
68 std::string value;
69};
70
72 std::optional<uint64_t> frame_index;
73 std::optional<double> energy;
74 std::optional<double> time;
75 std::optional<double> timestep;
76 std::optional<uint64_t> neb_bead;
77 std::optional<uint64_t> neb_band;
78 std::optional<std::string> potential_type;
79 std::vector<ConMetadataValue> scalars;
80 std::vector<ConMetadataText> strings;
81 std::optional<std::string> raw_json;
85 std::vector<double> displacements;
90 std::vector<double> spreads;
93 std::optional<bool> write_con_forces;
94};
95
97ConFrameMetadata metadata_from_frame(const readcon::ConFrame &frame);
98
110void set_write_con_forces(bool enabled) noexcept;
111[[nodiscard]] bool write_con_forces() noexcept;
112
113// Reading
114[[nodiscard]] IoStatus con2matter(Matter &m, std::string filename);
115[[nodiscard]] IoStatus con2matter(Matter &m, const readcon::ConFrame &frame,
116 ConFrameMetadata *out_metadata = nullptr);
117[[nodiscard]] IoStatus convel2matter(Matter &m, std::string filename);
118
119// Writing
120
136[[nodiscard]] IoStatus matter2con(Matter &m, std::string filename,
137 bool append = false,
138 const ConFrameMetadata *metadata = nullptr);
139
149[[nodiscard]] IoStatus matter2convel(Matter &m, std::string filename);
150
162[[nodiscard]] IoStatus matter2xyz(Matter &m, std::string filename,
163 bool append = false);
164
166[[nodiscard]] IoStatus writeTibble(Matter &m, std::string filename);
167
172[[nodiscard]] readcon::ConFrame
173matterToConFrame(Matter &m, const ConFrameMetadata *metadata = nullptr);
174
181[[nodiscard]] std::vector<readcon::ConFrame>
182buildNebPathFrames(const std::vector<std::shared_ptr<Matter>> &path,
183 const std::vector<ConFrameMetadata> &metadata_per_image);
184
188[[nodiscard]] IoStatus
189writeConFrames(std::string filename,
190 const std::vector<readcon::ConFrame> &frames);
191
204[[nodiscard]] IoStatus
205writeNebPath(std::string filename,
206 const std::vector<std::shared_ptr<Matter>> &path,
207 const std::vector<ConFrameMetadata> &metadata_per_image);
208
209// Cell lengths and CON header-line-4 angles (alpha, beta, gamma) in degrees.
210std::pair<std::array<double, 3>, std::array<double, 3>>
212
213} // namespace io
214} // namespace eonc
STL class.
IoStatus writeConFrames(std::string filename, const std::vector< readcon::ConFrame > &frames)
Write already-built ConFrames to a multi-frame .con (temp or durable).
IoStatus convel2matter(Matter &m, std::string filename)
IoStatus matter2convel(Matter &m, std::string filename)
void resetConAppendState()
Drop the per-path bookkeeping that lets append-mode writes skip re-parsing frames this process wrote.
std::pair< std::array< double, 3 >, std::array< double, 3 > > cell_to_lengths_angles(const Matter &m)
ConFrameMetadata metadata_from_frame(const readcon::ConFrame &frame)
Extract known frame-level fields from a parsed readcon frame.
bool write_con_forces() noexcept
IoStatus matter2con(Matter &m, std::string filename, bool append, const ConFrameMetadata *metadata)
Append a frame to a .con, or truncate and write one frame.
IoStatus con2matter(Matter &m, std::string filename)
std::vector< readcon::ConFrame > buildNebPathFrames(const std::vector< std::shared_ptr< Matter > > &path, const std::vector< ConFrameMetadata > &metadata_per_image)
Build NEB band ConFrames without writing (clone builder path of writeNebPath).
IoStatus matter2xyz(Matter &m, std::string filename, bool append)
Write one extended-XYZ frame: Lattice= cell and 17-digit coordinates.
IoStatus
Structured I/O result for the client surface (nanobind-friendly).
Definition ConFileIO.h:29
constexpr const char * io_status_name(IoStatus s) noexcept
Human-readable label for logging / bindings.
Definition ConFileIO.h:43
void set_write_con_forces(bool enabled) noexcept
Whether written .con frames carry "Forces of Component" sections.
readcon::ConFrame matterToConFrame(Matter &m, const ConFrameMetadata *metadata)
Build a single stamped ConFrame from Matter (same builder as matter2con).
constexpr bool io_ok(IoStatus s) noexcept
Definition ConFileIO.h:38
IoStatus writeTibble(Matter &m, std::string fname)
Debug table (positions, optional cached forces). Not a structure format.
IoStatus writeNebPath(std::string filename, const std::vector< std::shared_ptr< Matter > > &path, const std::vector< ConFrameMetadata > &metadata_per_image)
Write a full NEB path as one multi-frame .con using ConFrameBuilder::clone().
RAII resource manager for the ARTn C library with global synchronization.
std::optional< uint64_t > frame_index
Definition ConFileIO.h:72
std::vector< double > spreads
Per-atom root-mean-square spread of the position distribution about the written coordinates,...
Definition ConFileIO.h:90
std::optional< uint64_t > neb_band
Definition ConFileIO.h:77
std::vector< ConMetadataValue > scalars
Definition ConFileIO.h:79
std::optional< double > energy
Definition ConFileIO.h:73
std::optional< double > timestep
Definition ConFileIO.h:75
std::vector< ConMetadataText > strings
Definition ConFileIO.h:80
std::optional< double > time
Definition ConFileIO.h:74
std::optional< std::string > raw_json
Definition ConFileIO.h:81
std::optional< std::string > potential_type
Definition ConFileIO.h:78
std::vector< double > displacements
Per-atom displacement, row-major N x 3 in Angstrom (a normal mode, a dimer direction).
Definition ConFileIO.h:85
std::optional< uint64_t > neb_bead
Definition ConFileIO.h:76
std::optional< bool > write_con_forces
When set, this write includes or omits force sections regardless of Parameters.main_options()....
Definition ConFileIO.h:93