aiida_vasp.parsers.content_parsers.win#

The .win parser interface.

Module Contents#

Classes#

BaseKeyValueParser

Common codebase for all parser utilities.

KeyValueParser

WinParser

Parses wannier90 input.

API#

class aiida_vasp.parsers.content_parsers.win.BaseKeyValueParser[source]#

Common codebase for all parser utilities.

empty_line = 'compile(...)'#
classmethod line(fobj_or_str, d_type=str)[source]#

Grab a line from a file object or string and convert it to d_type (default: str).

classmethod splitlines(fobj_or_str, d_type=float)[source]#

Split a chunk of text into a list of lines and convert each line to d_type (default: float).

class aiida_vasp.parsers.content_parsers.win.KeyValueParser[source]#

Bases: aiida_vasp.parsers.content_parsers.win.BaseKeyValueParser

This baseclass has some utility functions for parsing files that are (mostly) in a key = value format. This class does not integrate with the VaspParser class currently. A simple example, which tries to convert values to python objects on a best effort basis. Usage:

import re
from aiida_vasp.parsers.file_parsers.parser import KeyValueParser
ParamParser(KeyValueParser):
    def __init__(self, file_path):
        self._file_path = py.path.local(file_path)
        super().__init__()
        self.result = {}
    def convert_or_not(self, value):
        for converter in self.get_converter_iter():
            converted = self.try_convert(value, converter)
            if converted and 'value' in converted:
                return converted['value']
        return value
    def parse_file(self):
        assignments = re.findall(self.assignment, self._file_path.read())
        return {key: self.convert_or_not(value)}
Parses files like::

StrParam = value_1 FloatParam = 1.0 BoolParam = True

assignment = 'compile(...)'#
bool_true = 'compile(...)'#
bool_false = 'compile(...)'#
comment = True#
classmethod get_lines(filename)[source]#
classmethod retval(*args, **kwargs)[source]#

Normalize return values from value conversion functions.

classmethod flatten(lst)[source]#
classmethod find_kv(line)[source]#
classmethod float(string_)[source]#

Parse a string into an float value followed by a comment.

classmethod float_unit(string_)[source]#

Parse string into a float number with attached unit.

classmethod int(string_)[source]#

Parse a string into an integer value followed by a comment.

classmethod int_unit(string_)[source]#

Convert a string into a python value, associated unit and optional comment.

classmethod string(string_)[source]#

Parse a string into value and comment, assuming only the first word is the value.

classmethod bool(string_)[source]#

Parse string into a boolean value.

classmethod kv_list(filename)[source]#
classmethod kv_dict(kv_list)[source]#
classmethod clean_value(str_value)[source]#

Get the converted python value from a string.

classmethod get_converter_iter()[source]#
classmethod try_convert(input_value, converter)[source]#

Try to convert the input string into a python value given a conversion function.

class aiida_vasp.parsers.content_parsers.win.WinParser(path)[source]#

Bases: aiida_vasp.parsers.content_parsers.win.KeyValueParser

Parses wannier90 input.

Initialization

block = 'compile(...)'#
comment = 'compile(...)'#
classmethod parse_win(fobj_or_str)[source]#

Parse a wannier90 input.