chemparseplot.parse.grammar.xyz#

XYZ grammar (parsimonious) for multi-atom frames.

Port of the wailord paper thesis: structured grammar parsing for XYZ rather than ad-hoc line splits. Multi-character element symbols and scientific floats are supported.

Added in version 1.9.9.

Module Contents#

Classes#

XyzAtom

One atom line: element symbol and Cartesian coordinates (Å).

XyzFrame

Parsed single-frame XYZ.

Functions#

xyz_grammar

Compiled XYZ grammar (cached).

_flatten

_make_visitor

parse_xyz_text

Parse a single-frame XYZ string with the grammar visitor.

parse_xyz_file

Read and parse an XYZ file.

write_xyz_text

Serialize a frame back to XYZ text (Å).

Data#

API#

chemparseplot.parse.grammar.xyz._XYZ_GRAMMAR_SRC = <Multiline-String>#
chemparseplot.parse.grammar.xyz._grammar_cache: Any | None#

None

chemparseplot.parse.grammar.xyz.xyz_grammar() Any[source]#

Compiled XYZ grammar (cached).

class chemparseplot.parse.grammar.xyz.XyzAtom[source]#

One atom line: element symbol and Cartesian coordinates (Å).

symbol: str#

None

x: float#

None

y: float#

None

z: float#

None

class chemparseplot.parse.grammar.xyz.XyzFrame[source]#

Parsed single-frame XYZ.

natoms: int#

None

comment: str#

None

atoms: tuple[chemparseplot.parse.grammar.xyz.XyzAtom, ...]#

None

property symbols: list[str]#
property counts: collections.Counter#
property system: str#

Composition slug as ElementCount joined (e.g. H2, C1O2).

coordinates() list[tuple[float, float, float]][source]#
chemparseplot.parse.grammar.xyz._flatten(xs: Any) list[Any][source]#
chemparseplot.parse.grammar.xyz._make_visitor() Any[source]#
chemparseplot.parse.grammar.xyz.parse_xyz_text(text: str) chemparseplot.parse.grammar.xyz.XyzFrame[source]#

Parse a single-frame XYZ string with the grammar visitor.

Parameters

text: Full XYZ content including atom count and comment line.

Returns

XyzFrame Structured frame (natoms, comment, atoms).

chemparseplot.parse.grammar.xyz.parse_xyz_file(path: str | pathlib.Path) chemparseplot.parse.grammar.xyz.XyzFrame[source]#

Read and parse an XYZ file.

chemparseplot.parse.grammar.xyz.write_xyz_text(frame: chemparseplot.parse.grammar.xyz.XyzFrame, *, comment: str | None = None) str[source]#

Serialize a frame back to XYZ text (Å).