BaseRealWithUnits

class ase2sprkkr.common.grammar_types.BaseRealWithUnits(prefix=None, postfix=None, format='', default_value=None, condition=None, after_convert=None, description='', min=None, max=None)[source]

The base class for float value, which can have units append. The value is converted automatically to the base units.

Class hierarchy

Inheritance diagram of ase2sprkkr.common.grammar_types.BaseRealWithUnits

Constructor

Parameters
  • prefix (Optional[str]) –

  • postfix (Optional[str]) –

  • format (str) –

  • default_value (Any) –

  • condition (Optional[Callable[[Any], Union[bool, str]]]) –

  • after_convert (Optional[Callable[[Any], Any]]) –

  • min (Optional[int]) –

  • max (Optional[int]) –

__init__(prefix=None, postfix=None, format='', default_value=None, condition=None, after_convert=None, description='', min=None, max=None)
Parameters
  • min (Optional[int]) – Minimal allowed value.

  • max (Optional[int]) – Maximal allowed value.

  • prefix (Optional[str]) –

  • postfix (Optional[str]) –

  • format (str) –

  • default_value (Any) –

  • condition (Optional[Callable[[Any], Union[bool, str]]]) –

  • after_convert (Optional[Callable[[Any], Any]]) –

grammar_cache = {}

A grammar for units is cached

_grammar_units(units)[source]
_grammar(param_name)[source]

Token for matching strings that match a given regular expression. Defined with string specifying the regular expression in a form recognized by the stdlib Python re module. If the given regex contains named groups (defined using (?P<name>...)), these will be preserved as named ParseResults.

If instead of the Python stdlib re module you wish to use a different RE module (such as the regex module), you can do so by building your Regex object with a compiled RE that was compiled using regex.

Example:

realnum = Regex(r"[+-]?\d+\.\d*")
# ref: https://stackoverflow.com/questions/267399/how-do-you-match-only-valid-roman-numerals-with-a-regular-expression
roman = Regex(r"M{0,4}(CM|CD|D?{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})")

# named fields in a regex will be returned as named results
date = Regex(r'(?P<year>\d{4})-(?P<month>\d\d?)-(?P<day>\d\d?)')

# the Regex class will accept re's compiled using the regex module
import regex
parser = pp.Regex(regex.compile(r'[0-9]'))
_validate(value, why='set')[source]

Return error message if the value is not valid.

grammar_name()[source]

Human readable expression of the grammar. By default, this is what is set by grammar.setName, however, sometimes is desirable to set even shorter string

numpy_type

alias of float

datatype_name = 'baserealwithunits'