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=None, data=None, settings=None, options=None)[source]#

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

The actually read, interpret and write to/from files is handled by parsevasp and this interface ensures that the parsing framework in AiiDA and preparation before submission is successful. The specific content parser interfaces are always childs of this class.

We assume that there are two main paths when parsing of VASP files takes place. One is when a file is present and we want to interpret it and convert its content into one of the usable data structures in AiiDA. The second is when we already have an AiiDA data structure and want to write a file based on its content. In the former case we basically read from a file, while in the latter we write to a file.

The first approach is enabled if we initialize the parser with the argument handler. This should be a file like handler, i.e. from a context manager telling where the content can be located. The respective quantities can then be fetched using the get_quantity function of the instance with the key representing the quantity. The content of the handler is parsed after initialization. The valid keys representing fetchable quantities is defined for each content parser class using the ~`PARSABLE_QUANTITIES~` class parameter.

The second approach is enabled if we initialize with an argument data. This should be a valid AiiDA data structure node. Using the get_quantity('somekey') function of the instance return the same AiiDA data structure node back as was supplied to data.

One can write the parsed content or the content of the StructureData using the function write of the class instance.

handlerobject, optional

A file like object, for instance a file handler representing the file or object containing content to be parsed. Typically used when parsing completed calculations and is also the parameter used during initialization of the content parser, when the parse function of this AiiDA plugin is executed.

dataobject. optional

An AiiDA data structure node. Typically used when one later want to write VASP input files.

settingsdict, optional

Parser settings. Used to set parser settings, e.g. which quantities to compose into nodes etc.

optionsdict, optional

Parser options. Used to set extra options to the content parsers. For instance for the POSCAR/CONTAR parser one set options.positions_dof to supply selective tags to enable proper construction of selective dynamics POSCAR/CONTCAR from a StructureData. The StructureData does not contain this type of possibilities.

Initialization

OPEN_MODE = 'r'#
PARSABLE_QUANTITIES = None#
DEFAULT_SETTINGS = None#
get_all_quantities()[source]#

Fetch all quantities that can be parsed.

property parsable_quantities#

Fetch the quantities that this content parser can provide.

_set_settings(settings)[source]#

Sets the settings to be used for the content parser.

settingsNone or a 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)[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.

quantity_keystr

A string specifying the key of the quantity to be fetched.

resultobject

If we have initialized the content parser with an AiiDA data structure, we return it in its original form. If the quantity_key is not find to be parsable by this content parser None is returned. Finally, if the content parser was initialized with a file like object and the requested quantity_key is found to be parsable we return the quantity.

write(path)[source]#

Writes VASP content to file.

Uses the write method defined in this loaded content parser.

pathstr

A string describing the relative path in the submission folder to write the file.

abstract _init_from_handler(handler)[source]#

Initialize using a file like object.

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

handlerobject

A file like object that provides the necessary content to be parsed.

abstract _init_from_data(data)[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.

dataobject

A valid AiiDA data structure object.

abstract _content_data_to_content_parser()[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.

content_parserobject

An instance of a content parser from parsevasp, e.g. Poscar.

_parse_content()[source]#

Parse the quantities configured and parseable from the content.