Skip to content

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 ​

FieldMeaning
data_blockname after data_
celllattice matrix (Å)
cell_paramsa, b, c (Å), alpha, beta, gamma (degrees)
space_group_hm, space_group_numberoptional space-group metadata
atom_siteslabel, 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/c are 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-cif validates the JSON structure before writing. The Rust write_cif helper is the historical unchecked writer; use write_cif_checked (or CifStructure::validate) for untrusted input.

Surfaces ​

SurfaceEntry point
CLI`parse-cif <path
Rustparse_cif, CifStructure::validate, write_cif, write_cif_checked
Pythonparse_cif(text), write_cif(structure)
WASMparse_cif(cif_text), write_cif(cif_json)

Released under the MIT License.