CIF input and output
parse-cif reads a crystallographic information file into the JSON structure used by the materials tools; write-cif serialises that JSON back to CIF. The path - reads standard input.
flowchart LR
A[CIF text] --> B[parse-cif]
B --> C[JSON structure]
C --> D[write-cif]
D --> E[CIF text]
C --> F[periodic-molecule / assembly]
Parsed fields
| Field | Meaning |
|---|---|
data_block | name after data_ |
cell | lattice matrix (Å) |
cell_params | a, b, c (Å), alpha, beta, gamma (degrees) |
space_group_hm, space_group_number | optional space-group metadata |
atom_sites | label, type_symbol, atomic_number, fractional coordinates, occupancy |
Fractional coordinates are wrapped into [0, 1). Cartesian (_atom_site_Cartn_*) sites are converted to fractional coordinates. Values such as 5.640(1) are accepted, with the parenthetical uncertainty stripped.
Example
bash
$ printf 'data_test
_cell_length_a 5.0
_cell_length_b 5.0
_cell_length_c 5.0
loop_
_atom_site_label
_atom_site_type_symbol
_atom_site_fract_x
_atom_site_fract_y
_atom_site_fract_z
_atom_site_occupancy
Na1 Na 0.0 0.0 0.0 1.0
' | sci-form parse-cif -
{
"data_block": "test",
"cell_params": {"a": 5.0, "b": 5.0, "c": 5.0, "alpha": 90.0, "beta": 90.0, "gamma": 90.0},
"space_group_hm": null,
"space_group_number": null,
"atom_sites": [
{
"label": "Na1",
"type_symbol": "Na",
"atomic_number": 11,
"frac_x": 0.0,
"frac_y": 0.0,
"frac_z": 0.0,
"occupancy": 1.0
}
]
}parse-cif ... | sci-form write-cif - performs a round trip.
Validation and limits
_cell_length_a/b/care required; angles default to 90°.- Cell lengths must be finite and > 0, angles in (0°, 180°), and the cell volume must be positive.
- The data block name and every atom label must be non-empty and unique; the element symbol must agree with the atomic number.
- At least one atom site is required. Each site needs a known element symbol and a finite fractional/Cartesian coordinate.
- Occupancy must be finite and in
(0, 1]. - Atom rows with fewer fields than the loop declares are rejected instead of being skipped.
- The parser handles a single data block and the common atom-site loop; it is not a full CIF dictionary implementation (no symmetry expansion, disorder groups, anisotropic displacement parameters or multi-block structures).
write-cifvalidates the JSON structure before writing. The Rustwrite_cifhelper is the historical unchecked writer; usewrite_cif_checked(orCifStructure::validate) for untrusted input.
Surfaces
| Surface | Entry point |
|---|---|
| CLI | `parse-cif <path |
| Rust | parse_cif, CifStructure::validate, write_cif, write_cif_checked |
| Python | parse_cif(text), write_cif(structure) |
| WASM | parse_cif(cif_text), write_cif(cif_json) |