How-to — corpus I/O by language#

Note

Diátaxis how-to (task-oriented). Learning path: Tutorial — first corpus. Full tables: Rust API, C and C++ API, Python API, Fortran API.

Same job in every language: open a corpus, ingest a .con, select, read a hash.

Rust#

use readcon_db::{ConCorpus, Select};

let db = ConCorpus::open("/tmp/corpus")?;
db.append_trajectory_path(1, "run.con")?;
let keys = db.select(
    &Select::new()
        .trajectory(1)
        .require_symbol("Cu")
        .natoms_range(1, 10_000)
        .limit(100),
)?;
let h = db.frame_hash(keys[0])?;
let frame = db.get_frame(keys[0])?;

Exact match: Select::new().exact_hash(h.to_bytes()).

Python#

import readcon_db

db = readcon_db.ConCorpus.open("/tmp/corpus")
db.append_trajectory_path(1, "run.con")
sel = readcon_db.Select().require_symbol("Cu")
keys = db.select(sel)
h = db.frame_hash(keys[0])
text = db.get_frame_text(keys[0])

maturin develop --features python from a checkout. Module name is readcon_db.

C / C++#

#include "readcon-db.h"

RkrdbCorpus *db = rkrdb_open("/tmp/corpus");
rkrdb_append_trajectory_path(db, 1, "run.con");
/* Select via rkrdb_select_* / rkrdb_select_meta; see api_c */
rkrdb_close(db);

C++ RAII: readcon_db::Corpus. MPI pack/bcast takes the caller communicator (readcon-db-mpi.h). The library does not call MPI_Init. Details: C and C++ API.

Fortran#

fortran/ReadConDb is bind(C) over the same rkrdb_* ABI. Build with pkg-config --cflags --libs readcon-db after a prefix install, or the clib tarball. Details: Fortran API.

Many writers#

Do not open one LMDB env from two writers. Partition with Campaign ops runbook (shard-init, shard-ingest, drain, join-drained).

Units and H5MD#

Stamp incoming units on append; collect_h5md / export_h5md emit one [T][N][3] trajectory. CON text stays authoritative. Workflows.