[docs]defsetup_ase():"""Add uncertainty keys to ASE all properties."""fromase.calculators.calculatorimportall_propertiesforvalin["forces_uncertainty","energy_uncertainty","stress_uncertainty","energy_ensemble","forces_ensemble","node_energy",]:ifvalnotinall_properties:all_properties.append(val)
[docs]@tyex.deprecated("It is recommended to pass the attribute directly, instead of giving a 'zntrack.Node'"" instance.")defget_deps_if_node(obj,attribute:str):"""Apply getdeps if obj is subclass/instance of a Node. Parameters ---------- obj: any Any object that is either a Node or not. attribute: str Name of the attribute to get. Returns ------- Either the requested attribute if obj is a Node. Otherwise, it will return the obj itself. """ifisinstance(obj,(list,tuple)):return[get_deps_if_node(x,attribute)forxinobj]withcontextlib.suppress(TypeError):ifissubclass(obj,Node):returnobj@attribute# TODO attribute access should also work, right?ifisinstance(obj,znflow.Connection):ifobj.attributeisNone:ifobj.itemisnotNone:raiseValueError("Cannot get attribute of item.")returnznflow.Connection(obj.instance,attribute)returnobj@attributeifisinstance(obj,Node)elseobj
[docs]defcheck_duplicate_keys(dict_a:dict,dict_b:dict,log:Logger)->None:"""Check if a key of dict_a is present in dict_b and then log a warning."""forkeyindict_a:ifkeyindict_b:log.warning(f"Found <{key}> in given config file. Please be aware that <{key}>"" will be overwritten by MLSuite!")