.. index:: pair: namespace; gpr::io .. _doxid-namespacegpr_1_1io: namespace gpr::io ================= .. toctree:: :hidden: struct_gpr_io_FrameEnergyForces.rst struct_gpr_io_GpInitializationOverrides.rst struct_gpr_io_MetatomicConfigFields.rst struct_gpr_io_NebDriverConfig.rst struct_gpr_io_TrainedGpState.rst class_gpr_io_ErrorManager.rst class_gpr_io_FileManager.rst class_gpr_io_LogManager.rst Overview ~~~~~~~~ .. ref-code-block:: cpp :class: doxyrest-overview-code-block namespace io { // structs struct :ref:`FrameEnergyForces`; struct :ref:`GpInitializationOverrides`; struct :ref:`MetatomicConfigFields`; struct :ref:`NebDriverConfig`; struct :ref:`TrainedGpState`; // classes class :ref:`ErrorManager`; class :ref:`FileManager`; class :ref:`LogManager`; // global functions void :ref:`loadParametersFromCapnp`(const std::string& binary_filename, :ref:`gpr::InputParameters`& parameters); bool :ref:`readerIsLegacyDimer`(capnp::MessageReader& reader); void :ref:`overlayLegacyDimerReader`(capnp::MessageReader& reader, gpr::schema::InputParameters::Builder unified); :ref:`GpInitializationOverrides` :target:`readGpInitializationOverrides`(gpr::schema::InputParameters::Reader params); void :ref:`applyDimerConfigFromCapnp`(gpr::schema::InputParameters::Reader params, :ref:`gpr::InputParameters`& parameters); void :ref:`loadNebConfigFromCapnp`(const std::string& binary_filename, :ref:`gpr::neb::GPNEBConfig`& config); void :ref:`applyNebConfigFromCapnp`(gpr::schema::InputParameters::Reader params, :ref:`gpr::neb::GPNEBConfig`& config, bool validate_rigid_deflation = true); void :ref:`applyOciConfigFromCapnp`(gpr::schema::InputParameters::Reader params, :ref:`gpr::neb::OCINEBConfig`& config); void :ref:`applyMetatomicConfigFromCapnp`(gpr::schema::InputParameters::Reader params, :ref:`MetatomicConfigFields`& metatomic); void :ref:`applyDriverConfigFromCapnp`(gpr::schema::InputParameters::Reader params, :ref:`NebDriverConfig`& driver); void :ref:`loadOciMmfConfigFromCapnp`(const std::string& filename, :ref:`gpr::neb::OCINEBConfig`& config); void :ref:`saveTrainedGpState`(const std::string& path, const :ref:`GaussianProcessRegression`& gp, const :ref:`Observation`& observations, const :ref:`AtomsConfiguration`& atoms); :ref:`TrainedGpState` :target:`loadTrainedGpState`(const std::string& path); :ref:`TrainedGpState` :ref:`observationState`(const :ref:`Observation`& observations); bool :ref:`applyTrainedGpState`(:ref:`GaussianProcessRegression`& gp, const :ref:`TrainedGpState`& state, const :ref:`AtomsConfiguration`& atoms, bool require_identity); void :ref:`refuseNonFiniteSeedRows`(const :ref:`Observation`& observations, Eigen::Index expected_cols = -1); void :target:`noteLocalKernel`(:ref:`neb::ActiveLearningSession`& session, const :ref:`TrainedGpState`& state); int :ref:`seedSession`(:ref:`neb::ActiveLearningSession`& session, const :ref:`TrainedGpState`& state, bool require_identity, Eigen::Index expected_cols = -1); std::string :ref:`resolveGpStatePath`(const std::string& spec, bool restart); std::string :ref:`outputDirectory`(const std::string& output_path); void :ref:`loadEnvironmentAtomTypes`(std::istream& input, :ref:`gpr::AtomsConfiguration`& atoms_config, const :ref:`gpr::InputParameters`& parameters); void :target:`loadEnvironmentAtomTypes`(const std::string& path, :ref:`gpr::AtomsConfiguration`& atoms_config, const :ref:`gpr::InputParameters`& parameters); void :target:`initializeAtomsConfiguration`(const :ref:`gpr::Coord`& R_init, const :ref:`gpr::InputParameters`& parameters, const std::unordered_map`>& atomtypes, :ref:`gpr::AtomsConfiguration`& atoms_config); std::array :ref:`cellMatrixFromLengthsAndAngles`(const std::array& cell, const std::array& angles); void :target:`setCellDimensionsFromLengthsAndAngles`(const std::array& cell, const std::array& angles, :ref:`gpr::InputParameters`& parameters); static void :target:`requireUsableFrame`(const readcon::CFrame& frame, const char* role); template static To :target:`checkedNarrow`(From value, const char* field); void :ref:`loadAtomsConfigurationFromFrame`(const readcon::CFrame& frame, :ref:`gpr::AtomsConfiguration`& atoms_config, :ref:`gpr::Coord`& R_init, :ref:`gpr::InputParameters`& parameters, const readcon::CFrame* product = nullptr, std::vector* reactive_atoms = nullptr); template std::vector :ref:`elementAtomTypes`(const AtomicNr* atomic_nrs, std::size_t n_atoms); double :ref:`maxAtomicForce`(const double* forces, std::size_t n_atoms); int :ref:`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); :ref:`FrameEnergyForces` :target:`frameEnergyForces`(const readcon::RKRConFrame* frame, const readcon::CFrame& parsed); std::string :ref:`seedKernelAtomsIdentity`(const :ref:`AtomsConfiguration`& atoms); std::string :target:`seedKernelIdentity`(const :ref:`GaussianProcessRegression`& gp, const :ref:`AtomsConfiguration`& atoms); bool :ref:`readSeedKernelAtomTypes`(std::istream& input, :ref:`AtomsConfiguration`& atoms, const :ref:`InputParameters`& parameters); void :ref:`writeSeedKernel`(std::ostream& out, const :ref:`GaussianProcessRegression`& gp, const :ref:`AtomsConfiguration`& atoms); bool :ref:`readSeedKernel`(std::istream& input, :ref:`GaussianProcessRegression`& gp, const :ref:`AtomsConfiguration`& atoms, bool require_identity, bool preserve_source_noise); } // namespace io .. _details-namespacegpr_1_1io: Detailed Documentation ~~~~~~~~~~~~~~~~~~~~~~ Global Functions ---------------- .. index:: pair: function; loadParametersFromCapnp .. _doxid-namespacegpr_1_1io_1a9abc210281e17821cec7fdfe4e65fa57: .. ref-code-block:: cpp :class: doxyrest-title-code-block void loadParametersFromCapnp(const std::string& binary_filename, :ref:`gpr::InputParameters`& parameters) Loads parameters by reading a memory-mapped Cap'n Proto binary file. This function replaces the manual text parsing of :ref:`FileManager::readInputFile `. It opens the binary file, maps it to memory, and populates the legacy :ref:`gpr::InputParameters ` struct. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - 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. .. index:: pair: function; readerIsLegacyDimer .. _doxid-namespacegpr_1_1io_1afabab52bcd1d5383f3502e0fd1dcd759: .. ref-code-block:: cpp :class: doxyrest-title-code-block 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. .. index:: pair: function; overlayLegacyDimerReader .. _doxid-namespacegpr_1_1io_1a8b8e52d208488ed3de5fb4b04f4cee46: .. ref-code-block:: cpp :class: doxyrest-title-code-block 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. .. index:: pair: function; applyDimerConfigFromCapnp .. _doxid-namespacegpr_1_1io_1a5e00915a44431f716c3247b4c199d031: .. ref-code-block:: cpp :class: doxyrest-title-code-block void applyDimerConfigFromCapnp(gpr::schema::InputParameters::Reader params, :ref:`gpr::InputParameters`& parameters) :ref:`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. .. index:: pair: function; loadNebConfigFromCapnp .. _doxid-namespacegpr_1_1io_1a6a90e07d4317f4452c0efd4438bd2181: .. ref-code-block:: cpp :class: doxyrest-title-code-block void loadNebConfigFromCapnp(const std::string& binary_filename, :ref:`gpr::neb::GPNEBConfig`& config) Load the NEB-chain knobs from a unified-schema (params.capnp) Cap'n Proto binary into a :ref:`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 / :ref:`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. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - 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). .. index:: pair: function; applyNebConfigFromCapnp .. _doxid-namespacegpr_1_1io_1a2a35cd9ef9be98e50a1434eeaaf80a44: .. ref-code-block:: cpp :class: doxyrest-title-code-block void applyNebConfigFromCapnp(gpr::schema::InputParameters::Reader params, :ref:`gpr::neb::GPNEBConfig`& config, bool validate_rigid_deflation = true) Materialize a :ref:`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. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - std::runtime_error - if the message carries no NebParams (method union not set to neb). .. index:: pair: function; applyOciConfigFromCapnp .. _doxid-namespacegpr_1_1io_1a9b72e1a45ebd8c71afa569bf439746bd: .. ref-code-block:: cpp :class: doxyrest-title-code-block void applyOciConfigFromCapnp(gpr::schema::InputParameters::Reader params, :ref:`gpr::neb::OCINEBConfig`& config) Materialize a :ref:`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. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - std::runtime_error - if the message carries no NebParams. .. index:: pair: function; applyMetatomicConfigFromCapnp .. _doxid-namespacegpr_1_1io_1a237aeb39e88330a020c6142524a813c8: .. ref-code-block:: cpp :class: doxyrest-title-code-block void applyMetatomicConfigFromCapnp(gpr::schema::InputParameters::Reader params, :ref:`MetatomicConfigFields`& metatomic) Materialize the metatomic oracle knobs (model/device live on the top-level :ref:`InputParameters `; rotations/so3-policy/uncertainty threshold live on InputParameters.metatomic) from an already-open unified-schema message. .. index:: pair: function; applyDriverConfigFromCapnp .. _doxid-namespacegpr_1_1io_1ac4d02a193ede5c7646d1fa92e9198821: .. ref-code-block:: cpp :class: doxyrest-title-code-block void applyDriverConfigFromCapnp(gpr::schema::InputParameters::Reader params, :ref:`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. .. index:: pair: function; loadOciMmfConfigFromCapnp .. _doxid-namespacegpr_1_1io_1a10fc71f437fe8ff24d71eaab38a31566: .. ref-code-block:: cpp :class: doxyrest-title-code-block void loadOciMmfConfigFromCapnp(const std::string& filename, :ref:`gpr::neb::OCINEBConfig`& config) Load the binary MMF override subset, preserving uncertainty controls. .. index:: pair: function; saveTrainedGpState .. _doxid-namespacegpr_1_1io_1adf62159cb41a2c82583dd3e47aa71816: .. ref-code-block:: cpp :class: doxyrest-title-code-block void saveTrainedGpState(const std::string& path, const :ref:`GaussianProcessRegression`& gp, const :ref:`Observation`& observations, const :ref:`AtomsConfiguration`& atoms) Write ``gp-state.npz``. A second save of the same state is the same bytes. .. index:: pair: function; observationState .. _doxid-namespacegpr_1_1io_1a9db1f6a31b1290ce939c63069a4e773c: .. ref-code-block:: cpp :class: doxyrest-title-code-block :ref:`TrainedGpState` observationState(const :ref:`Observation`& observations) A state that carries observations and no pair kernel. .. index:: pair: function; applyTrainedGpState .. _doxid-namespacegpr_1_1io_1a26b96a7e6ca39c76337774ead6906092: .. ref-code-block:: cpp :class: doxyrest-title-code-block bool applyTrainedGpState(:ref:`GaussianProcessRegression`& gp, const :ref:`TrainedGpState`& state, const :ref:`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. .. index:: pair: function; refuseNonFiniteSeedRows .. _doxid-namespacegpr_1_1io_1a55b190a605f9283a1777635d008ec2cd: .. ref-code-block:: cpp :class: doxyrest-title-code-block void refuseNonFiniteSeedRows(const :ref:`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. .. index:: pair: function; seedSession .. _doxid-namespacegpr_1_1io_1aed9090ef5c462d3e13f538451009e2e7: .. ref-code-block:: cpp :class: doxyrest-title-code-block int seedSession(:ref:`neb::ActiveLearningSession`& session, const :ref:`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. .. index:: pair: function; resolveGpStatePath .. _doxid-namespacegpr_1_1io_1a2a608a47435c902203a5cd05bafa7408: .. ref-code-block:: cpp :class: doxyrest-title-code-block 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. .. index:: pair: function; outputDirectory .. _doxid-namespacegpr_1_1io_1ae4fd3bbb0cdc8c92bfa010fab8b4ce44: .. ref-code-block:: cpp :class: doxyrest-title-code-block std::string outputDirectory(const std::string& output_path) Directory of an output path, or ``.`` when the path has no directory. .. index:: pair: function; loadEnvironmentAtomTypes .. _doxid-namespacegpr_1_1io_1a09c93257d497dccd19a9726b32eb2cd7: .. ref-code-block:: cpp :class: doxyrest-title-code-block void loadEnvironmentAtomTypes(std::istream& input, :ref:`gpr::AtomsConfiguration`& atoms_config, const :ref:`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. .. index:: pair: function; cellMatrixFromLengthsAndAngles .. _doxid-namespacegpr_1_1io_1a981bc8f57f290651c31ae54d7de39556: .. ref-code-block:: cpp :class: doxyrest-title-code-block std::array cellMatrixFromLengthsAndAngles(const std::array& cell, const std::array& 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. .. index:: pair: function; loadAtomsConfigurationFromFrame .. _doxid-namespacegpr_1_1io_1a118b6301cb1e3a721d5b5ea6d9bea9e3: .. ref-code-block:: cpp :class: doxyrest-title-code-block void loadAtomsConfigurationFromFrame(const readcon::CFrame& frame, :ref:`gpr::AtomsConfiguration`& atoms_config, :ref:`gpr::Coord`& R_init, :ref:`gpr::InputParameters`& parameters, const readcon::CFrame* product = nullptr, std::vector* 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 (:ref:`gpr::geometry::assignReactiveAtomTypes `) before the pair types are built, so the reactive pairs get their own kernel length scales; ``reactive_atoms`` receives their indices. .. index:: pair: function; elementAtomTypes .. _doxid-namespacegpr_1_1io_1ae36662fa929700ddfe4e3afdbf7e4b5d: .. ref-code-block:: cpp :class: doxyrest-title-code-block template std::vector 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. .. index:: pair: function; maxAtomicForce .. _doxid-namespacegpr_1_1io_1a9ec53605f725f40b85ac6a8787484316: .. ref-code-block:: cpp :class: doxyrest-title-code-block double maxAtomicForce(const double* forces, std::size_t n_atoms) Largest atomic force norm. NaN when any component is non-finite. .. index:: pair: function; addAtomWithOptionalForce .. _doxid-namespacegpr_1_1io_1a6d443fc4fcfb2d48894a41204cdd43a6: .. ref-code-block:: cpp :class: doxyrest-title-code-block 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. .. index:: pair: function; seedKernelAtomsIdentity .. _doxid-namespacegpr_1_1io_1af795b6d091dd1d5b576c79fce77a0393: .. ref-code-block:: cpp :class: doxyrest-title-code-block std::string seedKernelAtomsIdentity(const :ref:`AtomsConfiguration`& atoms) Atomic descriptor identity; moving positions belong to the observations. .. index:: pair: function; readSeedKernelAtomTypes .. _doxid-namespacegpr_1_1io_1a2cff46329b2da880d783ef53333cd9f3: .. ref-code-block:: cpp :class: doxyrest-title-code-block bool readSeedKernelAtomTypes(std::istream& input, :ref:`AtomsConfiguration`& atoms, const :ref:`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. .. index:: pair: function; writeSeedKernel .. _doxid-namespacegpr_1_1io_1a0f02d037d7f90512bc098727953fe4ce: .. ref-code-block:: cpp :class: doxyrest-title-code-block void writeSeedKernel(std::ostream& out, const :ref:`GaussianProcessRegression`& gp, const :ref:`AtomsConfiguration`& atoms) Write fitted covariance parameters, output units, and descriptor identity. .. index:: pair: function; readSeedKernel .. _doxid-namespacegpr_1_1io_1a0034396101c53a989536c84c6da7f3cc: .. ref-code-block:: cpp :class: doxyrest-title-code-block bool readSeedKernel(std::istream& input, :ref:`GaussianProcessRegression`& gp, const :ref:`AtomsConfiguration`& atoms, bool require_identity, bool preserve_source_noise) Validate the complete seed before changing any model parameter.