Getting started¶
Read an extxyz file into native frames, inspect its values, then write it back. This walkthrough creates all its input locally; no dataset download or optional converter is needed.
Install¶
oxyz requires Python 3.12 or newer, and supports free-threaded CPython 3.14
(3.14t) without re-enabling the GIL. The base package depends on NumPy and
PyYAML:
From a cloned checkout:
Follow development setup and use uv run for Python
so Rust edits rebuild the extension.
Optional extras are ase, metatomic, torch-sim and s3. Install only the
integrations you use, for example pip install "oxyz[ase]".
Create and read a trajectory¶
The first line of each frame is its atom count. The comment line declares per-atom columns and frame metadata; the following lines contain the atom rows. This file contains water followed by a hydrogen molecule:
read(path) defaults to every frame. An integer selects one Frame; a slice,
slice string or index sequence selects a list. Numeric columns are NumPy arrays,
while string columns such as species are lists. File names are preserved:
pos does not become positions, and metadata remains separate from columns.
The data model explains normalised convenience views,
lookup and equality.
Short values can be inspected directly:
>>> water.n_atoms
3
>>> water["energy"]
-7.25
>>> np.asarray(water["pos"]).shape
(3, 3)
Inspect the file before choosing a workflow¶
Structural scanning reads frame boundaries and declared counts. Schema inference parses the values and reports the observed fields and their consistency:
index = oxyz.scan(path)
assert index.n_frames == 2
assert index.total_atoms == 5
schema = oxyz.infer_schema(path)
assert schema.n_frames == 2
assert schema.is_consistent
A scan is not validation
A scan is not content validation, and reading a selected prefix does not validate later frames. See storage and streaming for the cost and guarantees of each operation.
Write and check the round trip¶
output = Path("molecules-copy.extxyz")
oxyz.write(output, frames)
restored = oxyz.read(output)
assert restored == frames
assert restored[0].metadata["energy"] == -7.25
np.testing.assert_array_equal(restored[1].columns["pos"], [[0, 0, 0], [0, 0, 0.75]])
Verify before replacing source data
Equality compares represented values, not original file bytes or formatting. This example verifies its own round trip; it is not a guarantee for every possible parsed value. The encoder may change whitespace, quoting and field order, and has string-quoting limitations. The writing guide also covers incremental output, codecs and append/stdout restrictions.
Choose the next step¶
- Read and select for subsets, repeated indices and frame iteration.
- Batch and stream for concatenated arrays, training batches and memory strategies.
- API reference for public objects and their full docstrings.
- Format reference, compatibility and errors for syntax, interpretation and failure rules.