pyiron.base.pyio package

Submodules

pyiron.base.pyio.parser module

class pyiron.base.pyio.parser.LogTag(tag_dict, h5_dict=None, key_dict=None)[source]

Bases: object

LogTag object to parse for a specific pattern in the output file

Parameters:
  • tag_dict (dict) – Dictionary with tags/patterns as key and an additional dictionary to describe the data structure. The data structure dictionary can contain the following keys: - “arg”: position of the argument - or dimension (“:”, “:,:”) - “type”: Python data type - “h5”: HDF5 key to store the information - “rows”: number of rows from the line where the tag was found - “splitTag”: split the tag - [True/False] - “splitArg”: split the argument - [True/False] - “lineSkip”: skip a line - “func”: function to convert the data
  • h5_dict (dict) – Translation dictionary of output tags as keys to the tags used on the HDF5 file as values.
  • key_dict (dict) – Translation dictionary of python internal tags as keys to the output tags as values.
apply_func(val)[source]

Apply the function on a given value

Parameters:val (dict, list, float, int) – value to apply the function on
Returns:result of applying the function
Return type:dict, list, float, int
arg()[source]

Get tag argument

Returns:tag arguments
Return type:str
current

Get the current tag

Returns:current tag
Return type:dict
dyn_tags

Get dynamic tags

Returns:dynamic tags
Return type:dict
get_item(item, default)[source]

If item is part of the current dictionary keys the corresponding value is returned otherwise the default is returned.

Parameters:
  • item (str) – dictionary key
  • default (list, dict, int, float) – Default value
Returns:

The values connected to the key item in the current dictionary and if item is not a

key in the current dictionary return the default value.

Return type:

list, dict, int, float

h5()[source]

Translate current tag to HDF5 tag using the tag dictionary

Returns:hdf5 key name
Return type:str
h5_dict

Get translation dictionary of output tags as keys to the tags used on the HDF5 file as values.

Returns:h5 dictionary
Return type:dict
is_func()[source]

Check if a function is defined to convert the data - if “func” is included in the tag_dict dictionary

Returns:[True/ False]
Return type:bool
is_item(item_line, start=0)[source]

Check if the current line - item_line - matches one of the provided tags, if that is the case set the tag to be the current tag and update the val_list with the corresponding values.

Parameters:
  • item_line (str) – Line of the output file
  • start (int) – Character to start with when parsing the item_line - default=0
Returns:

[True/False]

Return type:

bool

key_dict

Get translation dictionary of python internal tags as keys to the output tags as values.

Returns:key dictionary
Return type:dict
line_skip()[source]

Check how many lines should be skipped.

Returns:[True/ False]
Return type:bool
resolve_dynamic_variable(val)[source]

Resolve dynamic variable using the key_dict dictionary

Parameters:val – values to resolve
rows()[source]

Number of rows to parse

Returns:number of rows
Return type:int, str
set_item(tag_vals, log_file)[source]

Set LogTag item

Parameters:
  • tag_vals (dict) – tag value dictionary
  • log_file (Logstatus) – Logstatus object
Returns:

tag name, tag values, rows, line skip [True/False]

Return type:

list

tag_dict

Get tag dictionary with tags/patterns as key and an additional dictionary to describe the data structure. The data structure dictionary can contain the following keys: - “arg”: position of the argument - or dimension (“:”, “:,:”) - “type”: Python data type - “h5”: HDF5 key to store the information - “rows”: number of rows from the line where the tag was found - “splitTag”: split the tag - [True/False] - “splitArg”: split the argument - [True/False] - “lineSkip”: skip a line - “func”: function to convert the data

Returns:tag dictionary
Return type:dict
tag_first_word

Get first word of the tag

Returns:first word
Return type:str
tag_name

Get tag name

Returns:tag name
Return type:str
test_split()[source]

Check if the argument or the tag should be split - if “splitArg” or “splitTag” is included in the tag_dict dictionary.

Returns:[True/ False]
Return type:bool
translate(item)[source]

Translate current tag to HDF5 tag using the h5_dict dictionary

Parameters:item (str) – Python tag
Returns:HDF5 tag
Return type:str
class pyiron.base.pyio.parser.Logstatus(h5=None, iter_levels=1)[source]

Bases: object

Generic Parser for parsing output files by searching for a specific pattern structure and extracting the data that follows the pattern into the status_dict dictionary.

Parameters:iter_levels (int) – Levels of iteration - default = 1
append(title, data_to_append, vec=False)[source]

Append data to the LogStatus object status_dict dictionary

Parameters:
  • title (str) – Title of the data to append
  • data_to_append (list,dict) – the data can be of various types
  • vec (bool) – [True/False] if the data is a single vector instead of a matrix or a tensor
combine_mat(x_key, xy_key, xz_key, y_key, yz_key, z_key, combined_key)[source]

Combine three lists representing the x,y,z coordinates, by accessing them from the status_dict dictionary, combining them, store them under the combined_key and remove the other three keys.

Parameters:
  • x_key (str) – key of the x coordinates
  • y_key (str) – key of the y coordinates
  • z_key (str) – key of the z coordinates
  • combined_key (str) – name of the combined coordinates
combine_xyz(x_key, y_key, z_key, combined_key, as_vector=False)[source]

Combine three lists representing the x,y,z coordinates, by accessing them from the status_dict dictionary, combining them, store them under the combined_key and remove the other three keys.

Parameters:
  • x_key (str) – key of the x coordinates
  • y_key (str) – key of the y coordinates
  • z_key (str) – key of the z coordinates
  • combined_key (str) – name of the combined coordinates
convert_unit(key, factor)[source]
extract_file(file_name, tag_dict, h5_dict=None, key_dict=None)[source]

Main function of the LogStatus class to extract data from an output file by searching for the tag dictionary

Parameters:
  • file_name (str) – absolute path to the output file
  • tag_dict (dict) – Dictionary with tags/patterns as key and an additional dictionary to describe the data structure. The data structure dictionary can contain the following keys: - “arg”: position of the argument - or dimension (“:”, “:,:”) - “type”: Python data type - “h5”: HDF5 key to store the information - “rows”: number of rows from the line where the tag was found - “splitTag”: split the tag - [True/False] - “splitArg”: split the argument - [True/False] - “lineSkip”: skip a line - “func”: function to convert the data
  • h5_dict (dict) – Translation dictionary of output tags as keys to the tags used on the HDF5 file as values.
  • key_dict (dict) – Translation dictionary of python internal tags as keys to the output tags as values.
extract_from_list(list_of_lines, tag_dict, h5_dict=None, key_dict=None)[source]

Main function of the LogStatus class to extract data from an output file by searching for the tag dictionary

Parameters:
  • file_name (str) – absolute path to the output file
  • tag_dict (dict) – Dictionary with tags/patterns as key and an additional dictionary to describe the data structure. The data structure dictionary can contain the following keys: - “arg”: position of the argument - or dimension (“:”, “:,:”) - “type”: Python data type - “h5”: HDF5 key to store the information - “rows”: number of rows from the line where the tag was found - “splitTag”: split the tag - [True/False] - “splitArg”: split the argument - [True/False] - “lineSkip”: skip a line - “func”: function to convert the data
  • h5_dict (dict) – Translation dictionary of output tags as keys to the tags used on the HDF5 file as values.
  • key_dict (dict) – Translation dictionary of python internal tags as keys to the output tags as values.
static extract_item(l_item)[source]

Method to extract information from a single line - currently very specific for the Lammps output

Parameters:l_item (str) – line to extract information from
Returns:the tag_string as string and the arguments as list
Return type:str, list
raise_iter(dim=0)[source]

Increase the iteration level

Parameters:dim (int) – position - default = 0
reset_iter(dim=0)[source]

Reset iteration level

Parameters:dim (int) – reset value - default = 0
to_hdf(hdf)[source]

Store the LogStatus object status_dict dictionary in an HDF5 file

Parameters:hdf (ProjectHDFio) – HDF5 object to store the dictionary in.
pyiron.base.pyio.parser.extract_data_from_file(file_name, tag, num_args=1)[source]

General purpose routine to extract any static from a log (text) file

Parameters:
  • file_name (str) – file name or path to the file, can either be absolute or relative
  • tag (str) – string at the beginning of the line
  • num_args (int) – number of arguments separated by ‘ ‘ or ‘,’ to extract after the tag
Returns:

List of arguments extracted as strings

Return type:

list

pyiron.base.pyio.parser.extract_data_from_str_lst(str_lst, tag, num_args=1)[source]

General purpose routine to extract any static from a log (text) file

Parameters:
  • file_name (str) – file name or path to the file, can either be absolute or relative
  • tag (str) – string at the beginning of the line
  • num_args (int) – number of arguments separated by ‘ ‘ or ‘,’ to extract after the tag
Returns:

List of arguments extracted as strings

Return type:

list

Module contents