Skip to main content

Module ffi

Module ffi 

Source

Modules§

rkr_dl_device_type
DLPack DLDeviceType values (same numerics as dlpack.h). CPU = 1.
rkr_dl_type_code
DLPack DLDataTypeCode values (same numerics as dlpack.h / dlpk).

Structs§

CAtom
Transparent atom record extracted via rkr_frame_to_c_frame.
CConFrameIterator
CFrame
A transparent, “lossy” C-struct containing only the core atomic data. This can be extracted from an RKRConFrame handle for direct data access. The caller is responsible for freeing the atoms array using free_c_frame.
RKRConFrame
An opaque handle to a full, lossless Rust ConFrame object. The C/C++ side needs to treat this as a void pointer
RKRConFrameBuilder
An opaque handle to a Rust ConFrameBuilder object.
RKRConFrameWriter
An opaque handle to a Rust ConFrameWriter object. The C/C++ side needs to treat this as a void pointer
RKRDLDataType
Element type request — layout-identical to DLPack DLDataType (uint8_t code, uint8_t bits, uint16_t lanes). Interchangeable with DLDataType from <dlpack/dlpack.h> when that header is included.
RKRDLDevice
Device request — layout-identical to DLPack DLDevice (DLDeviceType device_type, int32_t device_id).
RKRDLManagedTensorVersioned
Re-export of dlpk’s DLManagedTensorVersioned for the C ABI surface. Defined here so cbindgen emits a forward declaration without pulling in the full dlpk header; consumers include <dlpack/dlpack.h> (or equivalent) and cast through the standard DLPack ABI. A versioned and managed C Tensor object, manage memory of DLTensor.
RKRDlpackExportOptions
Options for DLPack export: requested DLPack DLDataType + DLDevice.
RKRSelectionResult
Opaque handle for a cached selection evaluation result.
mts_block_t
Lean-build stubs: always export metatensor C symbols so Fortran/C can link without #ifdef. Real implementations live under feature = "metatensor".

Enums§

RKRStatus
Error codes for RKR functions.

Constants§

RKR_CON_SPEC_VERSION
CON/convel format spec version. Use #if RKR_CON_SPEC_VERSION >= 2 in C/C++ to gate code that depends on atom_index semantics.

Functions§

con_frame_iterator_next
Reads the next frame from the iterator, returning an opaque handle. The caller OWNS the returned handle and must free it with free_rkr_frame.
create_writer_from_path_c
Creates a new frame writer for the specified file. The caller OWNS the returned pointer and MUST call free_rkr_writer.
create_writer_from_path_with_precision_c
Creates a new frame writer with custom floating-point precision. The caller OWNS the returned pointer and MUST call free_rkr_writer.
create_writer_gzip_c
Creates a new gzip-compressed frame writer for the specified file. The caller OWNS the returned pointer and MUST call free_rkr_writer.
create_writer_gzip_with_precision_c
Creates a gzip-compressed frame writer with a custom floating-point precision. The caller OWNS the returned pointer and MUST call free_rkr_writer.
create_writer_zstd_c
create_writer_zstd_with_precision_c
free_c_frame
Frees the memory of a CFrame struct, including its internal atoms array.
free_con_frame_iterator
Frees the memory for a CConFrameIterator.
free_rkr_frame
Frees the memory for an opaque RKRConFrame handle.
free_rkr_frame_array
Frees an array of frame handles returned by rkr_read_all_frames. Each frame is freed individually, then the array itself.
free_rkr_frame_builder
Frees a frame builder without building.
free_rkr_frame_ptr_array
Free only the outer pointer array from rkr_read_all_frames (not the frames).
free_rkr_writer
Frees the memory for an RKRConFrameWriter, closing the associated file.
read_con_buffer_iterator
Iterate frames from a byte buffer (not necessarily null-terminated).
read_con_file_iterator
Creates a new iterator for a .con / .convel path, including transparent gzip (.con.gz) and zstd (.con.zst, requires zstd feature) inputs via crate::compression::read_file_contents.
read_con_string_iterator
Iterate frames from an in-memory CON text buffer (null-terminated C string).
rkr_con_spec_version
Returns the spec version at runtime (for dynamically linked consumers).
rkr_dlpack_delete
Free a DLPack tensor from rkr_frame_builder_*_dlpack (calls deleter). Safe with NULL.
rkr_frame_add_atom
Deprecated: prefer rkr_frame_add_atom_full with NULL velocity and force pointers. Adds an atom (no velocity, no forces) to the builder using a single uniform fixed flag. Returns RKR_STATUS_SUCCESS on success, or an error code.
rkr_frame_add_atom_full
Adds an atom with optional per-axis fixed mask, velocity, and force vectors.
rkr_frame_add_atom_with_fixed_mask
Deprecated: prefer rkr_frame_add_atom_full. Adds an atom (no velocity, no forces) using per-axis fixed flags. Returns RKR_STATUS_SUCCESS on success, or an error code.
rkr_frame_add_atom_with_forces
Deprecated: prefer rkr_frame_add_atom_full. Adds an atom with a force vector and a single uniform fixed flag. Returns RKR_STATUS_SUCCESS on success, or an error code.
rkr_frame_add_atom_with_forces_fixed_mask
Deprecated: prefer rkr_frame_add_atom_full. Adds an atom with a force vector and per-axis fixed flags. Returns RKR_STATUS_SUCCESS on success, or an error code.
rkr_frame_add_atom_with_velocity
Deprecated: prefer rkr_frame_add_atom_full. Adds an atom with a velocity vector and a single uniform fixed flag. Returns RKR_STATUS_SUCCESS on success, or an error code.
rkr_frame_add_atom_with_velocity_and_forces
Deprecated: prefer rkr_frame_add_atom_full. Adds an atom with both velocity and force vectors and a single uniform fixed flag. Returns RKR_STATUS_SUCCESS on success, or an error code.
rkr_frame_add_atom_with_velocity_and_forces_fixed_mask
Deprecated: prefer rkr_frame_add_atom_full. Adds an atom with both velocity and force vectors and per-axis fixed flags. Returns RKR_STATUS_SUCCESS on success, or an error code.
rkr_frame_add_atom_with_velocity_fixed_mask
Deprecated: prefer rkr_frame_add_atom_full. Adds an atom with a velocity vector and per-axis fixed flags. Returns RKR_STATUS_SUCCESS on success, or an error code.
rkr_frame_atom_count
Number of atoms on the frame (atom_data order).
rkr_frame_atom_energies_dlpack
DLPack per-atom energies, or SECTION_ABSENT if missing (f64/CPU default).
rkr_frame_atom_energies_dlpack_ex
rkr_frame_atom_index_by_id
Returns the position of an atom inside the frame’s atom_data array matching the given atom_id. Returns UINT64_MAX if no atom with that id exists or frame_handle is NULL.
rkr_frame_bond_at
Read one bond at index (0-based into the bonds metadata array).
rkr_frame_bond_count
Number of optional frame topology bonds (metadata["bonds"]), or 0 if absent.
rkr_frame_builder_atom_count
Returns the number of atoms currently held in the builder.
rkr_frame_builder_atom_energies_data
Borrow the per-atom energies buffer as a raw (N,) f64 pointer. Returns NULL if the energies section is absent.
rkr_frame_builder_atom_energies_dlpack
Export builder per-atom energies as a DLPack-managed tensor.
rkr_frame_builder_atom_energies_dlpack_ex
rkr_frame_builder_atom_ids_data
Borrow the per-atom atom_ids buffer as a raw (N,) u64 pointer.
rkr_frame_builder_atom_ids_dlpack
Export builder per-atom ids as a DLPack-managed tensor (N,) u64.
rkr_frame_builder_atom_ids_dlpack_ex
rkr_frame_builder_build
Consumes the builder and returns a finalized RKRConFrame handle. The builder handle is invalidated after this call. The caller OWNS the returned frame and MUST call free_rkr_frame. Returns NULL on error.
rkr_frame_builder_clear_atom_energy
Safety
rkr_frame_builder_clear_atom_force
Safety
rkr_frame_builder_clear_atom_velocity
Removes velocity / force / energy data from an existing atom.
rkr_frame_builder_clone
Cheap, copy-on-write clone of a frame builder. Returned handle owns a new ConFrameBuilder whose per-atom buffers share storage with the source via ArcArray; any subsequent mutation triggers a per-buffer copy-on-write so writes do not leak across clones.
rkr_frame_builder_forces_data
Borrow the forces buffer as a raw (N, 3) f64 row-major pointer. Returns NULL if the forces section is absent.
rkr_frame_builder_forces_dlpack
Export builder forces as a DLPack-managed tensor.
rkr_frame_builder_forces_dlpack_ex
rkr_frame_builder_get_atom_energy
Reads the per-atom energy of an atom (if any). *has_value is set to true if the atom carries an energy contribution, else false and *out_value is left untouched.
rkr_frame_builder_get_atom_force
Safety
rkr_frame_builder_get_atom_mass
Reads the mass of an existing atom.
rkr_frame_builder_get_atom_position
Reads the position of an existing atom into 3 contiguous f64 out values.
rkr_frame_builder_get_atom_velocity
Reads the velocity / force vector of an atom (if any) into 3 contiguous f64. *has_value is set to true if the atom carries that vector, false if it does not (in which case out_xyz is left untouched).
rkr_frame_builder_masses_data
Borrow the per-atom masses buffer as a raw (N,) f64 pointer.
rkr_frame_builder_masses_dlpack
Export builder per-atom masses as a DLPack-managed tensor (N,) f64.
rkr_frame_builder_masses_dlpack_ex
rkr_frame_builder_positions_data
Borrow the positions buffer as a raw (N, 3) f64 row-major pointer. Returns NULL on invalid handle. Pointer is valid until the builder is dropped or add_atom reallocates.
rkr_frame_builder_positions_dlpack
Export builder positions as a DLPack-managed tensor.
rkr_frame_builder_positions_dlpack_ex
Like rkr_frame_builder_positions_dlpack with explicit precision/device.
rkr_frame_builder_set_atom_energies_from_flat
Bulk-update per-atom energies (one f64 per atom).
rkr_frame_builder_set_atom_energy
Sets the per-atom energy contribution of an existing atom.
rkr_frame_builder_set_atom_fixed
Updates per-direction fixed flags [fixed_x, fixed_y, fixed_z].
rkr_frame_builder_set_atom_force
Sets the force vector of an existing atom from 3 contiguous f64 values.
rkr_frame_builder_set_atom_id
Updates the atom_id (pre-grouping index from .con column 5) of an existing atom. The underlying Array1<u64> buffer pointer stays stable; callers that hold a raw *const u64 via rkr_frame_builder_atom_ids_data do not need to refresh after this.
rkr_frame_builder_set_atom_mass
Updates the mass of an existing atom.
rkr_frame_builder_set_atom_position
Updates the Cartesian position of an existing atom.
rkr_frame_builder_set_atom_velocity
Sets the velocity vector of an existing atom from 3 contiguous f64 values.
rkr_frame_builder_set_energy
Sets the per-frame total energy metadata on an existing frame builder. Returns RKR_STATUS_SUCCESS on success, or an error code.
rkr_frame_builder_set_forces_from_flat
Bulk-update forces for every atom.
rkr_frame_builder_set_frame_index
Sets the zero-based frame index metadata on an existing frame builder. Returns RKR_STATUS_SUCCESS on success, or an error code.
rkr_frame_builder_set_last_energy
Attaches a per-atom energy to the most recently added atom on a builder. No-op if no atom has been added yet.
rkr_frame_builder_set_last_force
Attaches a force vector to the most recently added atom on a builder. No-op if no atom has been added yet.
rkr_frame_builder_set_last_velocity
Attaches a velocity vector to the most recently added atom on a builder. No-op if no atom has been added yet.
rkr_frame_builder_set_metadata_json
Parses and sets JSON metadata on an existing frame builder. Returns RKR_STATUS_SUCCESS on success, or an error code.
rkr_frame_builder_set_neb_band
Sets the NEB band index metadata on an existing frame builder. Returns RKR_STATUS_SUCCESS on success, or an error code.
rkr_frame_builder_set_neb_bead
Sets the NEB bead index metadata on an existing frame builder. Returns RKR_STATUS_SUCCESS on success, or an error code.
rkr_frame_builder_set_positions_from_flat
Bulk-update positions for every atom from a flat row-major [x0,y0,z0,x1,y1,z1,...] buffer of length 3 * atom_count().
rkr_frame_builder_set_scalar_metadata
Sets a numeric metadata key on an existing frame builder. Returns RKR_STATUS_SUCCESS on success, or an error code.
rkr_frame_builder_set_string_metadata
Sets a string metadata key on an existing frame builder. Returns RKR_STATUS_SUCCESS on success, or an error code.
rkr_frame_builder_set_time
Sets the simulation time metadata on an existing frame builder. Returns RKR_STATUS_SUCCESS on success, or an error code.
rkr_frame_builder_set_timestep
Sets the timestep metadata on an existing frame builder. Returns RKR_STATUS_SUCCESS on success, or an error code.
rkr_frame_builder_velocities_data
Borrow the velocities buffer as a raw (N, 3) f64 row-major pointer. Returns NULL if the velocities section is absent or the handle is invalid.
rkr_frame_builder_velocities_dlpack
Export builder velocities as a DLPack-managed tensor.
rkr_frame_builder_velocities_dlpack_ex
rkr_frame_cell_volume
Cell volume (lattice det or triclinic); NaN if unavailable.
rkr_frame_composition_formula
Canonical multiset formula (Cu:2|H:2) for campaign idx_formula. Free with rkr_free_string.
rkr_frame_copy_atom_energies
rkr_frame_copy_atom_ids
rkr_frame_copy_forces
rkr_frame_copy_masses
rkr_frame_copy_positions
Copy positions as row-major [x0,y0,z0,...] into out (length >= 3*N).
rkr_frame_copy_velocities
rkr_frame_energy
Returns the per-frame energy from metadata, or NaN if absent.
rkr_frame_fmax
Max (|F_i|); NaN if no finite forces.
rkr_frame_forces_dlpack
DLPack forces from a frame, or SECTION_ABSENT if missing (f64/CPU default).
rkr_frame_forces_dlpack_ex
rkr_frame_frame_index
Returns the zero-based frame index from metadata, or UINT64_MAX if absent.
rkr_frame_get_header_line
Copies a header string line into a caller-provided buffer.
rkr_frame_get_header_line_cpp
Gets a header string line as a newly allocated, null-terminated C string.
rkr_frame_index_energy
Campaign finite energy (crate::index_proj::finite_energy): NaN if missing or non-finite. Prefer this over rkr_frame_energy when mirroring readcon-db indexes.
rkr_frame_index_natoms
Atom count used for campaign idx_natoms (same as atom_data.len()).
rkr_frame_index_projection_json
Compact JSON of crate::index_proj::FrameIndexProjection (campaign screening fields). Free with rkr_free_string. NULL on error.
rkr_frame_metadata_json
Returns the JSON metadata line from a parsed frame as a heap-allocated null-terminated C string. The caller MUST free with rkr_free_string. Returns NULL on error.
rkr_frame_metatensor_atom_energies_block
rkr_frame_metatensor_forces_block
rkr_frame_metatensor_positions_block
rkr_frame_metatensor_velocities_block
rkr_frame_neb_band
Returns the NEB band index from metadata, or UINT64_MAX if absent.
rkr_frame_neb_bead
Returns the NEB bead index from metadata, or UINT64_MAX if absent.
rkr_frame_new
Creates a new frame builder with the given cell dimensions, angles, and header lines.
rkr_frame_positions_as_dlpack
Metatensor-style: export positions as they are stored (CPU f64), with explicit device request. Non-CPU → FEATURE_DISABLED. Prefer this over dtype-cast *_dlpack_ex for new code.
rkr_frame_positions_dlpack
DLPack positions from a frame (default float64 / CPU). Prefer rkr_frame_positions_as_dlpack for metatensor-style device negotiation.
rkr_frame_positions_dlpack_ex
Frame positions with RKRDlpackExportOptions (opts NULL → f64/CPU).
rkr_frame_positions_from_dlpack
Ingest positions from a DLManagedTensorVersioned (CPU float32/64, shape (N,3) or length 3N). Metatensor-style write path symmetry.
rkr_frame_potential_type
Returns the potential type string from metadata as a heap-allocated null-terminated C string. The caller MUST free with rkr_free_string. Returns NULL if absent or on error.
rkr_frame_sections_mask
Sections presence bitmask: bit0 forces, bit1 velocities, bit2 energies (see index_proj).
rkr_frame_select
Evaluate a chemfiles selection-language string on an RKRConFrame.
rkr_frame_spec_version
Returns the spec version stored in a parsed frame’s header. Returns 0 on error (null handle).
rkr_frame_time
Returns the simulation time from metadata, or NaN if absent.
rkr_frame_timestep
Returns the integration timestep from metadata, or NaN if absent.
rkr_frame_to_c_frame
Extracts the core atomic data into a transparent CFrame struct. The caller OWNS the returned pointer and MUST call free_c_frame on it.
rkr_frame_total_mass
Total mass from type masses × counts; NaN if not all finite.
rkr_frame_velocities_dlpack
DLPack velocities from a frame, or SECTION_ABSENT if missing (f64/CPU).
rkr_frame_velocities_dlpack_ex
rkr_free_string
Frees a C string that was allocated by Rust (e.g., from rkr_frame_metadata_json, rkr_frame_potential_type, or rkr_frame_get_header_line_cpp). Safe to call with NULL (no-op).
rkr_has_chemfiles_support
Returns 1 when this library build includes chemfiles selection support.
rkr_library_version
Returns a pointer to a static, null-terminated library version string. The returned pointer is valid for the lifetime of the process. Do NOT free it.
rkr_mts_block_free
rkr_read_all_frames
Reads all frames from a .con file using mmap. Returns an array of frame handles and sets num_frames to the count. The caller OWNS both the array and each frame handle. Free frames with free_rkr_frame and the array with free_rkr_frame_array. Returns NULL on error.
rkr_read_chemfiles_first
Read the first frame from a chemfiles-supported path (XYZ, PDB, GRO, …). Returns NULL on error or without the chemfiles feature. Caller: free_rkr_frame.
rkr_read_chemfiles_memory
Read all frames from memory with chemfiles format (e.g. "XYZ"). Sets *num_frames. Free frames with free_rkr_frame and the array with free_rkr_frame_array. NULL on error / without chemfiles.
rkr_read_first_frame
Reads the first frame from a .con file. Uses read_to_string for small files (< 64 KiB) and mmap for larger ones. Stops after the first frame rather than parsing the entire file. The caller OWNS the returned handle and MUST call free_rkr_frame. Returns NULL on error.
rkr_selection_result_context_size
Selection context size (1=atom, 2=pair, 3=angle, 4=dihedral).
rkr_selection_result_free
Free a selection result from rkr_frame_select. Safe with NULL.
rkr_selection_result_match_at
Copy match match_index atom indices into out_atoms (up to 4 slots). Writes actual arity to *out_size when non-null.
rkr_selection_result_match_count
Number of matches in a selection result.
rkr_selection_result_primary_indices
Fill out_indices with primary atom indices for each match (length = match count). Returns RKR_STATUS_BUFFER_TOO_SMALL if capacity is too small.
rkr_status_message
Returns a stable, static message for a status code. The returned pointer is valid for the lifetime of the process. Do NOT free it.
rkr_symbol_to_z
Returns the atomic number for a chemical symbol, or 0 if the symbol is unknown or symbol is NULL. Lookup covers H..U (Z = 1..=92) and is case-sensitive: “Fe” works, “fe” does not.
rkr_writer_extend
Writes multiple frames from an array of handles to the file managed by the writer. Returns RKR_STATUS_SUCCESS on success, or an error code.
rkr_writer_is_canonical
Returns 1 if the writer is in canonical mode, 0 otherwise (or on null handle).
rkr_writer_set_canonical
Enable (canonical != 0) or disable campaign-stable CON serialization on an open writer. Matches Rust ConFrameWriter::canonical(true) (deterministic metadata key order).
rkr_z_to_symbol
Returns a pointer to a static, NUL-terminated chemical symbol for an atomic number, or “X” for unknown values. Coverage is H..U (Z = 1..=92). The returned pointer is valid for the lifetime of the process; do NOT free it.