aiida_vasp.parsers.content_parsers.base#

Base classes for the VASP content parsers.


Contains the base classes for the VASP content parsers.

Module Contents#

Classes#

BaseFileParser

Base class for all the content parsers which parse (read and write) VASP files.

API#

class aiida_vasp.parsers.content_parsers.base.BaseFileParser(*, handler: TextIO | BinaryIO | None = None, data: aiida.orm.Data | None = None, settings: dict[str, Any] | None = None, options: dict[str, Any] | None = None, raise_errors: bool = False)[source]#

Base class for all the content parsers which parse (read and write) VASP files.

This class provides the interface for parsing and writing VASP files using parsevasp. It ensures integration with the AiiDA parsing framework and preparation before submission. Specific content parser interfaces should inherit from this class.

There are two main usage patterns:

  1. Parsing from file: Initialize with handler (a file-like object), then fetch quantities using get_quantity() with the appropriate key. The valid keys are defined in the PARSABLE_QUANTITIES class parameter of each subclass.

  2. Writing from data: Initialize with data (an AiiDA data node), then use get_quantity() to retrieve the same node, or use write() to write the content to a file.

Parameters:
  • handler (file-like object, optional) – File-like object containing content to be parsed. Used when parsing completed calculations.

  • data (object, optional) – AiiDA data node. Used when writing VASP input files.

  • settings (dict, optional) – Parser settings, e.g. which quantities to compose into nodes.

  • options (dict, optional) – Parser options, e.g. extra options for content parsers such as selective dynamics for POSCAR.

Initialization

OPEN_MODE: str = 'r'#
PARSABLE_QUANTITIES: dict[str, Any] = None#
DEFAULT_SETTINGS: dict[str, Any] = None#
get_all_quantities() tuple[dict[str, Any], dict[str, Any]][source]#

Fetch all quantities that can be parsed.

Returns:

Tuple of (parsed, errored) dictionaries.

Return type:

tuple

property parsable_quantities: list[str]#

Fetch the quantities that this content parser can provide.

Returns:

List of parsable quantity keys.

Return type:

list

_set_settings(settings: dict[str, Any] | None) None[source]#

Set the settings to be used for the content parser.

Parameters:

settings (None or dict) – The settings to be used for the content parser. Can be None if no settings is supplied to init. Defaults are then set.

get_quantity(quantity_key: str) Any[source]#

Fetch the required quantity from the content parser.

Either fetch it from an existing AiiDA data structure, a parsed content dictionary if that exists, otherwise parse this specific quantity using the loaded instance, which is now a specific content parser.

Parameters:

quantity_key (str) – Key of the quantity to be fetched.

Returns:

The requested quantity, or None if not parsable.

Return type:

object or None

write(path: str) None[source]#

Write VASP content to file using the loaded content parser.

Parameters:

path (str) – Path to write the file to.

abstract _init_from_handler(handler: TextIO | BinaryIO) None[source]#

Initialize using a file-like object.

Should be overridden in specific content parsers under content_parsers if it will accept parsable content.

Parameters:

handler (object) – File-like object that provides the necessary content to be parsed.

abstract _init_from_data(data: aiida.orm.Data) None[source]#

Initialize using an AiiDA data structure.

Should be overridden in specific content parsers under content_parsers if it will accept an AiiDA data structure. It should also check that the right structure is supplied.

Parameters:

data (object) – A valid AiiDA data structure object.

abstract _content_data_to_content_parser() Any[source]#

Convert an AiiDA data structure to a content parser instance relevant for that data structure. E.g. Poscar from parsevasp for an AiiDA StructureData.

Should be overridden in specific content parsers under content_parsers if it will accept an AiiDA data structure. It should also check that the right structure is supplied.

Returns:

Instance of a content parser from parsevasp, e.g. Poscar.

Return type:

object

_parse_content() dict[str, Any][source]#

Parse the quantities configured and parseable from the content.

Returns:

Dictionary of parsed quantities.

Return type:

dict