Function parse_single_frame

Source
pub fn parse_single_frame<'a>(
    lines: &mut impl Iterator<Item = &'a str>,
) -> Result<ConFrame, ParseError>
Expand description

Parses a complete frame from a .con file, including its header and atomic data.

This function first parses the complete frame header and then uses the information within it (specifically the number of atom types and atoms per type) to parse the subsequent atom coordinate blocks.

§Arguments

  • lines - A mutable reference to an iterator that yields string slices for the frame.

§Errors

  • ParseError::IncompleteFrame if the iterator ends before all expected atomic data has been read.
  • Propagates any errors from the underlying calls to parse_frame_header and parse_line_of_n.

§Example

use readcon_core::parser::parse_single_frame;

let frame_text = r#"
PREBOX LINE 1
PREBOX LINE 2
10.0 10.0 10.0
90.0 90.0 90.0
POSTBOX LINE 1
POSTBOX LINE 2
2
1 1
12.011 1.008
C
Coordinates of Component 1
1.0 1.0 1.0 0.0 1
H
Coordinates of Component 2
2.0 2.0 2.0 0.0 2
"#;

let mut lines = frame_text.trim().lines();
let con_frame = parse_single_frame(&mut lines).unwrap();

assert_eq!(con_frame.header.natm_types, 2);
assert_eq!(con_frame.atom_data.len(), 2);
assert_eq!(&*con_frame.atom_data[0].symbol, "C");
assert_eq!(con_frame.atom_data[1].atom_id, 2);