Option

class ase2sprkkr.common.options.Option(definition, container=None, value=None)[source]

Class for one option (a configuration value) of SPRKKR - either to be used as a part of InputParameters or Potential configuration. Usage:

>>> from ase2sprkkr.sprkkr.calculator import SPRKKR
>>> calculator = SPRKKR()
>>> conf = calculator.input_parameters
>>> conf.ENERGY.ImE = 5.0
>>> conf.ENERGY.ImE()
unyt_quantity(5., 'Ry')
>>> conf.ENERGY.ImE.info
'Configuration value ImE'
>>> conf.ENERGY.ImE.help()
Configuration value ImE

ImE : Energy (<Real> [Ry|eV]) ≝ 0.0 Ry (optional)
>>> conf.ENERGY.ImE.set_dangerous("1J")
>>> conf.ENERGY.ImE()
'1J'

Class hierarchy

Inheritance diagram of ase2sprkkr.common.options.Option


Constructor

__init__(definition, container=None, value=None)[source]

” :param definition: The value type of the option and its format (in potential and/or task file) :type definition: ValueDefinition :param container: The container, that owns the object :param value: The value of the option. :type value: mixed

class Change(option)[source]

Original state and finalization of a staged option value.

Parameters:

option (Option)

_MISSING_RESULT = <object object>
commit()[source]
Return type:

Any

rollback()[source]
Return type:

None

class IndexedChange(option, key)[source]

Rollback state for an in-place indexed value change.

Parameters:
rollback()[source]
Return type:

None

_NO_KEY = <object object>
_value_or_default()[source]
is_dangerous()[source]

Return, whether the option is set to a dangerous value, i.e. a value that bypass the validation.

set_dangerous(value, index=None)[source]

Set the option to a dangerous value - i.e. to a value that bypass the type and value checks and enforcing.

However, the type of such value is still checked by the proper mixed type. To completly bypass the check, set the value to an instance of DangerousValue class directly.

_create_dangerous_value(value)[source]
property default_value

Return default value for the option. The function is here, and not in the definition, since the default value can be given by callable, that accepts the Option as argument. This possibility is used in ase2sprkkr, when the default values of some options are generated from the underlined Atoms object

set(value, *, unknown=None, retain_invalid=None, report_invalid=None)[source]

Set a value using independent retention and reporting policies.

retain_invalid accepts "none", "typed" or "all". The latter stores unconvertible values as DangerousValue. report_invalid accepts "raise", "warn" or "ignore". unknown is accepted for the common container/option assignment interface; leaf options do not perform member lookup.

Parameters:
  • value (Any)

  • unknown (Literal['find', 'add', 'ignore', 'fail'] | None)

  • retain_invalid (Literal['none', 'typed', 'all'] | None)

  • report_invalid (Literal['raise', 'warn', 'ignore'] | None)

Return type:

None

stage(transaction, value, *, unknown=None, key=<object object>)[source]

Stage value or indexed key in transaction.

Conversion and validation issues are recorded in the policy owned by transaction. unknown is accepted for compatibility with container staging.

Parameters:
Return type:

bool

_stage_item(transaction, key, value)[source]

Stage converted value at key in transaction.

Parameters:
Return type:

bool

add_hook(hook)[source]
_check_array_access()[source]

Check, whether the option is array type (or repeated) and thus it can be accessed as array using []

_set_indexed_value(key, value)[source]
_getitem(name)[source]

Get a single item from a numbered array. For internal use - so no sanity checks

_unpack_value(value)[source]

Unpack potentionally dangerous values.

_pack_value(value)[source]

Validate the value, if it’s to be.

_pack_proposed_value(value, policy, *, item=False)[source]

Pack value according to the transaction’s policy.

Parameters:
Return type:

Any

get()[source]

Return the value of self

property result

Return the result value.

In some cases, the value of an option have to be translated for the output. E.g. the site can be given as site object, but the integer index is required in the output.

In a such case, this property can be utilized: the value of the option is retained as is and the transformed value is stored in the result.

clear_result()[source]
stage_clear(transaction, *, check_required=True)[source]

Stage clearing in transaction without global validation.

check_required rejects clearing a required option without a default.

Parameters:
Return type:

bool

is_changed()[source]

True, if the value is set and the value differs from the default

Return type:

bool

is_set()[source]

True, if the value is set (even equal to the default value)

Return type:

bool

_written_value(always=False)[source]
Parameters:

always – Skip all condition checking

Returns:

  • write value (Any) – The value to be written

  • write (bool,) – Whether to write the value or not

is_required()[source]

Return requiredness for this option.

Return type:

bool | str

_validate(why)[source]

Validate this option for phase why.

Parameters:

why (str)

Return type:

None

property name
_as_dict(get)[source]
value_and_changed()[source]

Return value and whether the value was changed

Returns:

  • value (mixed) – The value of the options (return all values for ‘numbered array’)

  • changed (bool) – Whether the value is the same as the default value or not

is_it_the_default_value(value)[source]

Return, whether the given value is the default value. For numbered array, only the wildcard value can be set and this value have to be the same as the default.

has_any_value()[source]