BaseRealWithUnits
- class ase2sprkkr.common.grammar_types.basic.BaseRealWithUnits(prefix=None, postfix=None, format='', after_format=None, default_value=None, condition=None, after_convert=None, description='', min=None, max=None, nan=None)[source]
The base class for float value, which can have units append. The value is converted automatically to the base units.
Class hierarchy

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)
min (int | None)
max (int | None)
- __init__(prefix=None, postfix=None, format='', after_format=None, default_value=None, condition=None, after_convert=None, description='', min=None, max=None, nan=None)
- Parameters:
min (int | None) – Minimal allowed value.
max (int | None) – Maximal allowed value.
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)
- grammar_cache = {}
The grammar for units is cached
- _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 namedParseResults.If instead of the Python stdlib
remodule you wish to use a different RE module (such as theregexmodule), you can do so by building yourRegexobject with a compiled RE that was compiled usingregex.The parameters
patternandflagsare passed to there.compile()function as-is. See the Python re module module for an explanation of the acceptable patterns and flags.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 regular expressions compiled using the # re module import re parser = pp.Regex(re.compile(r'[0-9]'))
- _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.
- grammar_name()[source]
Human readable expression of the grammar. By default, this is what is set by grammar.set_name, however, sometimes is desirable to set even shorter string
- numpy_type
alias of
float