namespace gpr::io

Overview

namespace io {
 
// structs
 
struct FrameEnergyForces;
struct GpInitializationOverrides;
struct MetatomicConfigFields;
struct NebDriverConfig;
struct TrainedGpState;
 
// classes
 
class ErrorManager;
class FileManager;
class LogManager;
 
// global functions
 
void loadParametersFromCapnp(const std::string& binary_filename, gpr::InputParameters& parameters);
bool readerIsLegacyDimer(capnp::MessageReader& reader);
void overlayLegacyDimerReader(capnp::MessageReader& reader, gpr::schema::InputParameters::Builder unified);
GpInitializationOverrides readGpInitializationOverrides(gpr::schema::InputParameters::Reader params);
void applyDimerConfigFromCapnp(gpr::schema::InputParameters::Reader params, gpr::InputParameters& parameters);
void loadNebConfigFromCapnp(const std::string& binary_filename, gpr::neb::GPNEBConfig& config);
void applyNebConfigFromCapnp(gpr::schema::InputParameters::Reader params, gpr::neb::GPNEBConfig& config, bool validate_rigid_deflation = true);
void applyOciConfigFromCapnp(gpr::schema::InputParameters::Reader params, gpr::neb::OCINEBConfig& config);
void applyMetatomicConfigFromCapnp(gpr::schema::InputParameters::Reader params, MetatomicConfigFields& metatomic);
void applyDriverConfigFromCapnp(gpr::schema::InputParameters::Reader params, NebDriverConfig& driver);
void loadOciMmfConfigFromCapnp(const std::string& filename, gpr::neb::OCINEBConfig& config);
void saveTrainedGpState(const std::string& path, const GaussianProcessRegression& gp, const Observation& observations, const AtomsConfiguration& atoms);
TrainedGpState loadTrainedGpState(const std::string& path);
TrainedGpState observationState(const Observation& observations);
bool applyTrainedGpState(GaussianProcessRegression& gp, const TrainedGpState& state, const AtomsConfiguration& atoms, bool require_identity);
void refuseNonFiniteSeedRows(const Observation& observations, Eigen::Index expected_cols = -1);
void noteLocalKernel(neb::ActiveLearningSession& session, const TrainedGpState& state);
int seedSession(neb::ActiveLearningSession& session, const TrainedGpState& state, bool require_identity, Eigen::Index expected_cols = -1);
std::string resolveGpStatePath(const std::string& spec, bool restart);
std::string outputDirectory(const std::string& output_path);
void loadEnvironmentAtomTypes(std::istream& input, gpr::AtomsConfiguration& atoms_config, const gpr::InputParameters& parameters);
void loadEnvironmentAtomTypes(const std::string& path, gpr::AtomsConfiguration& atoms_config, const gpr::InputParameters& parameters);
void initializeAtomsConfiguration(const gpr::Coord& R_init, const gpr::InputParameters& parameters, const std::unordered_map<std::string, gpr::Index_t>& atomtypes, gpr::AtomsConfiguration& atoms_config);
std::array<double, 9> cellMatrixFromLengthsAndAngles(const std::array<double, 3>& cell, const std::array<double, 3>& angles);
void setCellDimensionsFromLengthsAndAngles(const std::array<double, 3>& cell, const std::array<double, 3>& angles, gpr::InputParameters& parameters);
static void requireUsableFrame(const readcon::CFrame& frame, const char* role);
 
template <class To, class From>
static To checkedNarrow(From value, const char* field);
 
void loadAtomsConfigurationFromFrame(const readcon::CFrame& frame, gpr::AtomsConfiguration& atoms_config, gpr::Coord& R_init, gpr::InputParameters& parameters, const readcon::CFrame* product = nullptr, std::vector<int>* reactive_atoms = nullptr);
 
template <typename Type, typename AtomicNr>
std::vector<Type> elementAtomTypes(const AtomicNr* atomic_nrs, std::size_t n_atoms);
 
double maxAtomicForce(const double* forces, std::size_t n_atoms);
int addAtomWithOptionalForce(readcon::RKRConFrameBuilder* builder, const char* symbol, double x, double y, double z, bool fixed, std::uint64_t atom_id, double mass, const double* force);
FrameEnergyForces frameEnergyForces(const readcon::RKRConFrame* frame, const readcon::CFrame& parsed);
std::string seedKernelAtomsIdentity(const AtomsConfiguration& atoms);
std::string seedKernelIdentity(const GaussianProcessRegression& gp, const AtomsConfiguration& atoms);
bool readSeedKernelAtomTypes(std::istream& input, AtomsConfiguration& atoms, const InputParameters& parameters);
void writeSeedKernel(std::ostream& out, const GaussianProcessRegression& gp, const AtomsConfiguration& atoms);
bool readSeedKernel(std::istream& input, GaussianProcessRegression& gp, const AtomsConfiguration& atoms, bool require_identity, bool preserve_source_noise);
 
} // namespace io

Detailed Documentation

Global Functions

void loadParametersFromCapnp(const std::string& binary_filename, gpr::InputParameters& parameters)

Loads parameters by reading a memory-mapped Cap’n Proto binary file.

This function replaces the manual text parsing of FileManager::readInputFile. It opens the binary file, maps it to memory, and populates the legacy gpr::InputParameters struct.

Parameters:

binary_filename

The path to the Cap’n Proto binary file (e.g., “capnp_params.bin”).

parameters

The legacy C++ parameters struct to be filled.

bool readerIsLegacyDimer(capnp::MessageReader& reader)

Whether reader is a gprd_params.capnp message rather than a params.capnp message.

Cap’n Proto does not store the schema id, so the size of the root’s data and pointer sections decides. A gprd_params.capnp message has the root of one of that schema’s revisions since its field numbers settled. A params.capnp message has one data word and between the 20 pointers of that schema’s first revision and its current count; no root is both. A root between two gprd_params.capnp revisions is refused, since no writer emitted it. A root at least as large as the current params.capnp root is a newer params.capnp message when its schema version is newer than this build, and the caller checks that version. The same size stamped with a version this build knows matches no revision and throws std::runtime_error naming the version and the size. Any other root throws std::runtime_error naming its size.

void overlayLegacyDimerReader(capnp::MessageReader& reader, gpr::schema::InputParameters::Builder unified)

Copy a gprd_params.capnp reader onto a unified builder.

The builder’s dimer arm must already be initialized. Strings and lists are copied into the builder, so the legacy reader can be destroyed afterwards. Schema defaults of fields the legacy message left unset overwrite the builder, matching loadParametersFromCapnp.

void applyDimerConfigFromCapnp(gpr::schema::InputParameters::Reader params, gpr::InputParameters& parameters)

Project the dimer arm of a unified configuration into the runtime parameter record.

The reader may be backed by either a params.capnp binary or TOML through UnifiedConfigMessage. The message must select InputParameters.method.dimer.

void loadNebConfigFromCapnp(const std::string& binary_filename, gpr::neb::GPNEBConfig& config)

Load the NEB-chain knobs from a unified-schema (params.capnp) Cap’n Proto binary into a gpr::neb::GPNEBConfig.

Reads the InputParameters.method.neb branch (NebParams) plus the shared GP conditioning blocks (HsSvd.principledNugget/kappaMax, optimizer.lengthScalePriors.lengthScalePrior) and maps them onto the GP-OIE config. The 9-way acquisition switch mirrors the DistMetric / ScgCurvatureMode switch pattern in loadParametersFromCapnp. Fields absent from the message keep their GPNEBConfig defaults (capnp supplies schema defaults). This is the gprn (NEB) counterpart to loadParametersFromCapnp, which serves the dimer driver via the legacy gprd_params.capnp schema.

Parameters:

binary_filename

Path to the unified-schema Cap’n Proto binary.

config

The GP-NEB config to populate (NEB knobs only).

std::runtime_error

if the file is missing/empty or carries no NebParams (method union not set to neb).

void applyNebConfigFromCapnp(gpr::schema::InputParameters::Reader params, gpr::neb::GPNEBConfig& config, bool validate_rigid_deflation = true)

Materialize a gpr::neb::GPNEBConfig from an already-open unified-schema message. Reader-based counterpart of loadNebConfigFromCapnp with additional driver, GP and uncertainty controls for a file baseline. The filename-based adapter retains the established binary override subset. Unset scalar fields use the unified schema defaults.

Parameters:

std::runtime_error

if the message carries no NebParams (method union not set to neb).

void applyOciConfigFromCapnp(gpr::schema::InputParameters::Reader params, gpr::neb::OCINEBConfig& config)

Materialize a gpr::neb::OCINEBConfig (the use-mmf / mmf-* family, plus the dimer posterior-variance accept-tau gate carried on Uncertainty) from an already-open unified-schema message.

Parameters:

std::runtime_error

if the message carries no NebParams.

void applyMetatomicConfigFromCapnp(gpr::schema::InputParameters::Reader params, MetatomicConfigFields& metatomic)

Materialize the metatomic oracle knobs (model/device live on the top-level InputParameters; rotations/so3-policy/uncertainty threshold live on InputParameters.metatomic) from an already-open unified-schema message.

void applyDriverConfigFromCapnp(gpr::schema::InputParameters::Reader params, NebDriverConfig& driver)

Materialize the driver-level knobs (endpoint paths, run I/O, image count, seed, endpoint assignment / pruning switches) from an already-open unified-schema message.

void loadOciMmfConfigFromCapnp(const std::string& filename, gpr::neb::OCINEBConfig& config)

Load the binary MMF override subset, preserving uncertainty controls.

void saveTrainedGpState(const std::string& path, const GaussianProcessRegression& gp, const Observation& observations, const AtomsConfiguration& atoms)

Write gp-state.npz. A second save of the same state is the same bytes.

TrainedGpState observationState(const Observation& observations)

A state that carries observations and no pair kernel.

bool applyTrainedGpState(GaussianProcessRegression& gp, const TrainedGpState& state, const AtomsConfiguration& atoms, bool require_identity)

Install the saved hyperparameters. Raw float64 values overwrite the text kernel, so a load/apply round trip keeps the bits. Returns false when the kernel does not match this model.

void refuseNonFiniteSeedRows(const Observation& observations, Eigen::Index expected_cols = -1)

Refuse a seed whose rows are non-finite, the wrong length, or a different width from this search. expected_cols < 0 skips the width check. The message names how many rows would have been kept.

int seedSession(neb::ActiveLearningSession& session, const TrainedGpState& state, bool require_identity, Eigen::Index expected_cols = -1)

Copy seed rows into the session. They are prior data: append does not count an oracle call. The hook installs hyperparameters once the session builds its GP. expected_cols < 0 skips the width check; a seed with rows of any other width is refused before a column is stored.

std::string resolveGpStatePath(const std::string& spec, bool restart)

--gp-init names the npz file. --restart names a directory or a previous output file; the npz is that directory’s gp-state.npz, or the sibling of the output file.

std::string outputDirectory(const std::string& output_path)

Directory of an output path, or . when the path has no directory.

void loadEnvironmentAtomTypes(std::istream& input, gpr::AtomsConfiguration& atoms_config, const gpr::InputParameters& parameters)

Load fixed environment classes from rows: atom index, atomic number, type, and optionally the base type (element and reaction role) the class refines, which fills pair_type_parent for tied length scales. Validate every row before replacing types and rebuilding moving/frozen pairs.

std::array<double, 9> cellMatrixFromLengthsAndAngles(const std::array<double, 3>& cell, const std::array<double, 3>& angles)

Full 3x3 cell matrix (row-major; rows are the lattice vectors a, b, c) from .con lengths + angles (degrees, order alpha, beta, gamma). Lower-triangular convention: a along x, b in the xy plane.

void loadAtomsConfigurationFromFrame(const readcon::CFrame& frame, gpr::AtomsConfiguration& atoms_config, gpr::Coord& R_init, gpr::InputParameters& parameters, const readcon::CFrame* product = nullptr, std::vector<int>* reactive_atoms = nullptr)

Fill the configuration from a readcon frame: positions, frozen flags, ids, atomic numbers, one atom type per element, the cell, then the moving/frozen split and pair types. With a product frame of the same atoms, every atom whose covalent bond set differs between the two frames is moved to its element’s reactive type (gpr::geometry::assignReactiveAtomTypes) before the pair types are built, so the reactive pairs get their own kernel length scales; reactive_atoms receives their indices.

template <typename Type, typename AtomicNr>
std::vector<Type> elementAtomTypes(const AtomicNr* atomic_nrs, std::size_t n_atoms)

Dense atom types for n_atoms atomic numbers: one type per element, numbered in order of first appearance.

double maxAtomicForce(const double* forces, std::size_t n_atoms)

Largest atomic force norm. NaN when any component is non-finite.

int addAtomWithOptionalForce(readcon::RKRConFrameBuilder* builder, const char* symbol, double x, double y, double z, bool fixed, std::uint64_t atom_id, double mass, const double* force)

Add one atom. force is three doubles, or null when the atom has none.

std::string seedKernelAtomsIdentity(const AtomsConfiguration& atoms)

Atomic descriptor identity; moving positions belong to the observations.

bool readSeedKernelAtomTypes(std::istream& input, AtomsConfiguration& atoms, const InputParameters& parameters)

Restore the archived type map after checking physical atom identity.

Restore a saved type map before GP initialization. Physical composition, frozen geometry, cell, and the rebuilt pair ordering must match exactly. Kernel parameters and model-profile compatibility are checked separately by readSeedKernel after the destination GP is initialized.

void writeSeedKernel(std::ostream& out, const GaussianProcessRegression& gp, const AtomsConfiguration& atoms)

Write fitted covariance parameters, output units, and descriptor identity.

bool readSeedKernel(std::istream& input, GaussianProcessRegression& gp, const AtomsConfiguration& atoms, bool require_identity, bool preserve_source_noise)

Validate the complete seed before changing any model parameter.