BaseParser

class manim_chemistry.utils.parsers.base_parser.BaseParser(filename: str | bytes | PathLike)[source]

Initializes the parser given a file name.

This is a base class that must be extended on child classes.

The purposes of the parser classes are:
  • Read a file with chemical data.

  • Parse the file to extract the atoms and bonds data.

  • Return a dictionary with the atoms and bonds data.

property atoms

Returns atoms data.

property bonds

Returns bonds data.

abstract static data_parser(data: Any) Tuple[Dict, Dict] | List[Tuple[Dict, Dict]][source]

Parses the atoms and bonds data and returns a tuple of dictionaries with each data.

The atom data follows the structure:

{<atom_index>: {“element”: <atom_element>, “position”: [<x_pos>, <y_pos>, <z_pos>]}}

The bond data follows the structure:

{<bond_index>: {“from_atom_index”: <from_atom_index>, “to_atom_index”: <to_atom_index>, “bond_type”: <bond_type>}}

property molecule_data

Returns molecule data: atoms_data and bonds_data.

parse_file_data() Tuple[Dict, Dict] | List[Tuple[Dict, Dict]][source]

Receives the file data as a string and uses the string_parser.

Returns:

Tuple[Dict, Dict] | List[Tuple[Dict, Dict]]: (atom_data, bond_data)

abstract static read_file(filename: str | bytes | PathLike) Any[source]

Reads the file and converts it to a string.

Returns:

str: String with the file data.