aiida_vasp.parsers.content_parsers.win#
The .win parser interface.
Contains routines to parse Wannier90 input files. Will in the future utilize the parser in the Wannier90 plugin, but no input parser exists yet.
Module Contents#
Classes#
Common codebase for all parser utilities. |
|
Key and value parser. |
|
Parses wannier90 input files. |
API#
- class aiida_vasp.parsers.content_parsers.win.BaseKeyValueParser[source]#
Common codebase for all parser utilities.
This class provides utility methods for parsing key-value and line-based data.
- empty_line = 'compile(...)'#
- classmethod line(fobj_or_str: str | Any, d_type: type = str) Any[source]#
Grab a line from a file object or string and convert it to
d_type(default:str).
- class aiida_vasp.parsers.content_parsers.win.KeyValueParser[source]#
Bases:
aiida_vasp.parsers.content_parsers.win.BaseKeyValueParserKey and value parser.
This base class provides utility functions for parsing files that are (mostly) in a
key = valueformat.Note
This class does not integrate with the
VaspParserclass currently.Example usage:
import re from aiida_vasp.parsers.file_parsers.parser import KeyValueParser class 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 retval(*args: Any, **kwargs: Any) dict[str, Any][source]#
Normalize return values from value conversion functions.
- Returns:
Dictionary with the value and any additional keyword arguments.
- Return type:
- classmethod flatten(lst: list[list[Any]]) list[Any][source]#
Flatten a list of lists into a single list.
- classmethod find_kv(line: str) list[tuple[str, str]][source]#
Find key-value pairs in a line using the assignment regex.
- classmethod float(string_: str) dict[str, Any][source]#
Parse a string into a float value followed by a comment.
- classmethod float_unit(string_: str) dict[str, Any][source]#
Parse string into a float number with attached unit.
- classmethod int(string_: str) dict[str, Any][source]#
Parse a string into an integer value followed by a comment.
- classmethod int_unit(string_: str) dict[str, Any][source]#
Convert a string into a python value, associated unit and optional comment.
- classmethod string(string_: str) dict[str, Any][source]#
Parse a string into value and comment, assuming only the first word is the value.
- classmethod bool(string_: str) dict[str, Any][source]#
Parse string into a boolean value.
- Parameters:
string (str) – String to parse.
- Returns:
Dictionary with value and comment.
- Return type:
- Raises:
ValueError – If the string does not match a boolean pattern.
- classmethod kv_list(filename: str) list[Any][source]#
Read a file and return a list of key-value pairs for each line.
- classmethod kv_dict(kv_list: list[Any]) dict[str, Any][source]#
Convert a list of key-value pairs into a dictionary.
- classmethod clean_value(str_value: str) dict[str, Any][source]#
Get the converted python value from a string.
- classmethod get_converter_iter() Any[source]#
Get an iterator over the value converter functions in order.
- Returns:
Iterator over converter functions.
- class aiida_vasp.parsers.content_parsers.win.WinParser(path: str)[source]#
Bases:
aiida_vasp.parsers.content_parsers.win.KeyValueParserParses wannier90 input files.
This parser extracts keywords, blocks, and comments from a Wannier90
.wininput file.Initialization
Initialize the parser and parse the Wannier90 input file.
- Parameters:
path (str) – Path to the Wannier90 .win file.
- block = 'compile(...)'#
- comment = 'compile(...)'#