IO#

Function

Responsibility

atom_array_from_file

Return atoms with bonds and annotations using minimal parsing

prepare_atom_array

Apply configured atom cleanup/completion and bond/annotation assignment to an existing array

parse

Read and prepare a file with metadata and assemblies

atom_array_to_file

Write CIF/BCIF to a path or buffer or return content

Use parse_atom_array when existing atoms need a result dictionary instead of an array. Use atom_array_to_file to save atoms with bonds and annotations. atom_array_from_file wraps parse(config="minimal") and returns just the atoms. It selects the first conformer and uses the parser’s identifier conventions. Use CIF/BCIF for StandardAnnotations.

Pass CIFWriteConfig only when you need custom export settings.

atomworks.io.atom_array_from_file(source: str | PathLike | StringIO | BytesIO, file_type: str | None = None, *, model: int | None = None, squeeze: bool = True) → AtomArray | AtomArrayStack | list[AtomArray][source]#

Read atoms, bonds, and StandardAnnotations using minimal parsing.

Keeps waters and hydrogens; adds no missing atoms or assemblies. Uses the first alternate conformer and normalized identifiers. StandardAnnotations require CIF-family input.

Parameters:
  • source – Path or buffer; paths may be gzip or Zstandard compressed.

  • file_type – CIF, BinaryCIF, mmJSON, PDB, or catcif; inferred when omitted.

  • model – 1-based model selection (negative positions count from the end), or all models.

  • squeeze – Return an array for a single model. Explicit model selection always does so.

Returns:

A Plus array or stack, or a list when the parser returns separate models.

atomworks.io.atom_array_to_file(structure: AtomArray | AtomArrayStack | list[AtomArray], dest: PathLike | str | StringIO | BytesIO | None = None, *, file_type: Literal['cif', 'bcif', 'cif.gz', 'bcif.gz', 'cif.gzip', 'bcif.gzip', 'cif.zst', 'bcif.zst'] | None = None, model_ids: list[int] | None = None, config: CIFWriteConfig | None = None) → str | bytes | PathLike | None[source]#

Write atoms, bonds, and StandardAnnotations as CIF or BinaryCIF.

Parameters:
  • structure – Atoms, or a list of models.

  • dest – Path, writable buffer, or None to return content.

  • file_type – cif or bcif, optionally compressed with gz, gzip, or zst. Inferred from paths; otherwise defaults to cif.

  • model_ids – IDs for list input; defaults to [1, 2, ...].

  • config – Optional CIF export settings, replacing the defaults.

Returns:

Absolute path, None for buffers, or content (text for CIF, bytes for binary/compressed output).