NumpyArray

class ase2sprkkr.common.grammar_types.data.NumpyArray(prefix=None, postfix=None, format='', after_format=None, default_value=None, condition=None, after_convert=None, description='', *, delimiter=None, shape=None, written_shape=None, lines=None, item_format='% .18e', indented=False, line_length=None, dtype=None, ends_with=None)[source]

Match anything up to the end of the file, as numpy array

Class hierarchy

Inheritance diagram of ase2sprkkr.common.grammar_types.data.NumpyArray

Constructor

Parameters:
  • prefix (str | None) –

  • postfix (str | None) –

  • format (str) –

  • after_format (str | None) –

  • default_value (Any) –

  • condition (Callable[[Any], bool | str] | None) –

  • after_convert (Callable[[Any], Any] | None) –

__init__(prefix=None, postfix=None, format='', after_format=None, default_value=None, condition=None, after_convert=None, description='', *, delimiter=None, shape=None, written_shape=None, lines=None, item_format='% .18e', indented=False, line_length=None, dtype=None, ends_with=None)[source]
Parameters:
  • delimiter – None - default behavior. int - the number will take given fixed number of chars

  • shape – Resize to given shape after read

  • written_shape – Resize to given shape before writing

  • lines – Number of lines to read. Can be given as string - then the value of the given option determines the number of lines.

  • item_format – Output format of the array (just for writing).

  • indented

    If there are <n> spaces before data, pass n to this arg.

    If the file has the following structure:

    .......................................
         ....rest of the splitted line.....
         ....rest of the splitted line.
    ....... The second line................
         ..... the rest of the ............
         ............ second line ...
    ............
    

    Pass a tuple with two integers into this argument. The first number of tuple is the max. number of characters on a line, longer lines will be splitted. The second number is the number of spaces placed on the begining of the new lines created by splitting the old.

  • line_length – Wrap the lines longer than a given number

  • dtype – Type of the resulting data. Pass 'line' to get array of whole lines

  • ends_with – The data ends with a given string. The string is parsed and ignored/writen to the output, too.

  • **kwargs – Any other arguments are passed to the GrammarType constructor

  • prefix (str | None) –

  • postfix (str | None) –

  • format (str) –

  • after_format (str | None) –

  • default_value (Any) –

  • condition (Callable[[Any], bool | str] | None) –

  • after_convert (Callable[[Any], Any] | None) –

array_access = True

The value of this type can be accessed as array

_validate(value, why='set')[source]

Return error message if the value is not valid.

convert(value)[source]

Convert a value from user to the “cannonical form”

_string(value)[source]

Convert the value to the ouput.

The string() apply format and do some additional transformation (add prefix, postfix etc.), so the actual way how to convert the value for the output should be here.

static is_the_same_value(a, b)

The numpy arrays cannot be compared by =, that’s why this method. However, the method is still far from to be perfect, it can not compare nested numpy arrays.

_n_lines_grammar(lines)[source]

return a grammar for n lines of text

_parse_numpy_array_grammar(grammar)[source]

Change a parse action of given grammar such that it returns numpy array

_grammar(param_name=False)[source]
copy_value(value)[source]
added_to_container(container)[source]