aiida_vasp.utils.extended_dicts#

Extensions of dictionaries.

Extensions of Pythons standard dict as well as Aiida’s AttributeDict.

Module Contents#

Classes#

DictWithAttributes

Extension of the AttributeDict from Aiida.common.

Functions#

delete_keys_from_dict

Delete a key from a nested dictionary.

delete_nested_key

Delete the dictionary entry corresponding to a nested hierarchy of keys.

update_nested_dict

Updated a nested dictionary, where dict1 is updated with values in dict2.

update_nested_dict_node

Utility to update a Dict node in a nested way

API#

class aiida_vasp.utils.extended_dicts.DictWithAttributes(dictionary: collections.abc.Mapping[str, Any] | None = None)[source]#

Bases: aiida.common.extendeddicts.AttributeDict

Extension of the AttributeDict from Aiida.common.

This class internally stores values in a dictionary, but exposes the keys also as attributes, i.e. asking for attrdict.key will return the value of attrdict[‘key’] and so on.

If the key is not in the dict a default value will be returned.

Initialization

Recursively turn the dict and all its nested dictionaries into AttributeDict instance.

__getattr__(attr: str) Any[source]#

Read a key as an attribute. Return a Default value on missing key.

__setattr__(attr: str, value: Any) None[source]#

Set a key as an attribute.

aiida_vasp.utils.extended_dicts.delete_keys_from_dict(dictionary: dict[str, Any], keys: str | list[str]) None[source]#

Delete a key from a nested dictionary.

Extended to support somekey.someotherkey in case we need some restrictions on the nesting.

aiida_vasp.utils.extended_dicts.delete_nested_key(dictionary: dict[str, Any], keys: list[str]) None[source]#

Delete the dictionary entry corresponding to a nested hierarchy of keys.

aiida_vasp.utils.extended_dicts.update_nested_dict(dict1: dict[str, Any], dict2: dict[str, Any], extend_list: bool = False) dict[str, Any][source]#

Updated a nested dictionary, where dict1 is updated with values in dict2.

aiida_vasp.utils.extended_dicts.update_nested_dict_node(dict_node: aiida.orm.Dict, update_dict: dict[str, Any], extend_list: bool = False) aiida.orm.Dict[source]#

Utility to update a Dict node in a nested way