pyiron_atomistics.sphinx.input_writer.Group#
- class pyiron_atomistics.sphinx.input_writer.Group(*args, **kwargs)[source]#
Bases:
DataContainerDictionary-like object to store SPHInX inputs.
Attributes (sub-groups, parameters, & flags) can be set and accessed via dot notation, or as standard dictionary key/values.
to_{job_type} converts the Group to the format expected by the given DFT code in its input files.
- __init__(init=None, table_name=None, lazy=False, wrap_blacklist=(), lock_method='warning')#
Create new container.
- Parameters:
init (Sequence, Mapping) – initial data for the container, nested occurances of Sequence and Mapping are translated to nested containers
table_name (str) – default name of the data container in HDF5
lazy (bool) – if True, use
HDFStubto load values lazily from HDF5wrap_blacklist (tuple of types) – any values in init that are instances of the given types are not wrapped in
DataContainerBase
Methods
__init__([init, table_name, lazy, ...])Create new container.
append(val)Add new value to the container without a key.
clear()Remove all items from DataContainerBase.
copy()Returns deep copy of it self.
create_group(name)Add a new empty subcontainer under the given key.
extend(vals)Append vals to the end of this DataContainerBase.
from_dict(obj_dict[, version])Populate the object from the serialized object.
from_hdf(hdf[, group_name])Read object to HDF.
from_hdf_args(hdf)Read arguments for instance creation from HDF5 file.
get(key[, default, create])If
keyexists, behave as generic, if not call create_group.groups()Iterate over keys to nested containers.
has_keys()Check if the container has keys set or not.
insert(index, val[, key])Add a new element to the container at the specified position, with an optional key.
instantiate(obj_dict[, version])Create a blank instance of this class.
items()keys()list_all()Returns dictionary of :method:`.list_groups()` and :method:`.list_nodes()`.
Return a list of names of all nested groups.
Return a list of names of all nested nodes.
lock([method])Set
read_only.mark(index, key)Add a key to an existing item at index.
nodes()Iterator over keys to terminal nodes.
pop(k[,d])If key is not found, d is returned if given, otherwise KeyError is raised.
popitem()as a 2-tuple; but raise KeyError if D is empty.
read(file_name[, wrap])Parse file as dictionary and add its keys to this container.
rewrite_hdf(hdf[, group_name])Update the HDF representation.
search(key[, stop_on_first_hit])Search for
keyin the Container hierarchy.setdefault(k[,d])to_builtin([stringify])Convert the container back to builtin dict's and list's recursively.
to_dict()Reduce the object to a dictionary.
to_hdf(hdf[, group_name])Write object to HDF.
to_sphinx([content, indent])unlocked()Unlock the object temporarily.
update(init[, wrap, blacklist])Add all elements or key-value pairs from init to this container.
values()write(file_name)Writes the DataContainerBase to a text file.
Attributes
False if the object can currently be written to
- append(val)#
Add new value to the container without a key.
- Parameters:
val – new element
- clear()#
Remove all items from DataContainerBase.
- copy()#
Returns deep copy of it self. A shallow copy can be obtained via the copy module.
- Returns:
deep copy of itself
- Return type:
DataContainer
>>> pl = DataContainer([[1,2,3]]) >>> pl.copy() == pl True >>> pl.copy() is pl False >>> all(a is not b for a, b in zip(pl.copy().values(), pl.values())) True
- create_group(name)#
Add a new empty subcontainer under the given key.
- Parameters:
name (str) – key under which to store the new subcontainer in this container
- Returns:
the newly created subcontainer
- Return type:
DataContainerBase
- Raises:
ValueError – name already exists in container and is not a sub container
>>> pl = DataContainerBase({}) >>> pl.create_group("group_name") DataContainerBase([]) >>> list(pl.group_name) []
- extend(vals)#
Append vals to the end of this DataContainerBase.
- Parameters:
vals (Sequence) – any python sequence to draw new elements from
- from_dict(obj_dict: dict, version: str = None)#
Populate the object from the serialized object.
- Parameters:
obj_dict (dict) – data previously returned from
to_dict()version (str) – version tag written together with the data
- from_hdf(hdf: ProjectHDFio, group_name: str = None)#
Read object to HDF.
If group_name is given descend into subgroup in hdf first.
- Parameters:
hdf (
ProjectHDFio) – HDF group to read fromgroup_name (str, optional) – name of subgroup
- classmethod from_hdf_args(hdf: ProjectHDFio) dict#
Read arguments for instance creation from HDF5 file.
- Parameters:
hdf (ProjectHDFio) – HDF5 group object
- Returns:
arguments that can be **kwarg-passed to cls().
- Return type:
dict
- get(key, default=None, create=False)#
If
keyexists, behave as generic, if not call create_group.- Parameters:
key (str) – key to search
default (optional) – return this instead if nothing found
create (bool, optional) – create empty container at key if nothing found
- Raises:
IndexError – if key is not in the container and neither
defaultnotcreate` are give –
- Returns:
element at
keyor new empty subcontainer- Return type:
object
- groups()#
Iterate over keys to nested containers.
- Returns:
list of all keys to elements of
DataContainerBase.- Return type:
list
- has_keys()#
Check if the container has keys set or not.
- Returns:
True if there is at least one key set
- Return type:
bool
- insert(index, val, key=None)#
Add a new element to the container at the specified position, with an optional key. If the key is already in the container it will be updated to point to the new element at the new index. If index is larger than container, append instead.
- Parameters:
index (int) – place val after this element
val – new element to add
key (str, optional) – optional key to mark the new element
- classmethod instantiate(obj_dict: dict, version: str = None) Self#
Create a blank instance of this class.
This can be used when some values are already necessary for the objects __init__.
- Parameters:
obj_dict (dict) – data previously returned from
to_dict()version (str) – version tag written together with the data
- Returns:
a blank instance of the object that is sufficiently initialized to call
_from_dict()on it- Return type:
object
- items() a set-like object providing a view on D's items#
- keys() a set-like object providing a view on D's keys#
- list_all()#
Returns dictionary of :method:`.list_groups()` and :method:`.list_nodes()`.
- Returns:
- results of :method:`.list_groups() under the key "groups"; results of :method:`.list_nodes()` und the
key “nodes”
- Return type:
dict
- list_groups()#
Return a list of names of all nested groups.
- Returns:
group names
- Return type:
list of str
- list_nodes()#
Return a list of names of all nested nodes.
- Returns:
node names
- Return type:
list of str
- lock(method: Literal['error', 'warning'] | None = None)#
Set
read_only.Objects may be safely locked multiple times without further effect.
- Parameters:
method (str, either "error" or "warning") – if “error” raise an
Lockedexception if modification is attempted; if “warning” raise aLockedWarningwarning; default is “error” or the value passed to the constructor.- Raises:
ValueError – if method is not an allowed value
- mark(index, key)#
Add a key to an existing item at index. If key already exists, it is overwritten.
- Parameters:
index (int) – index of the existing element to mark
key (str) – key for the existing element
- Raises:
IndexError – if index > len(self)
>>> pl = DataContainerBase([42]) >>> pl.mark(0, "head") >>> pl.head == 42 True
- nodes()#
Iterator over keys to terminal nodes.
- Returns:
list of keys to normal values.
- Return type:
list
- pop(k[, d]) v, remove specified key and return the corresponding value.#
If key is not found, d is returned if given, otherwise KeyError is raised.
- popitem() (k, v), remove and return some (key, value) pair#
as a 2-tuple; but raise KeyError if D is empty.
- read(file_name, wrap=True)#
Parse file as dictionary and add its keys to this container.
For supported file types, see
fileio.read().Errors during reading of the files generate a warning, but leave the container unchanged.
- Parameters:
file_name (str) – path to the input file
wrap (bool)
- Raises:
ValueError – if file extension doesn’t match one of the supported ones
- property read_only: bool#
False if the object can currently be written to
Setting this value will trigger
_on_lock()and_on_unlock()if it changes.- Type:
bool
- rewrite_hdf(hdf: ProjectHDFio, group_name: str = None)#
Update the HDF representation.
If an object is read from an older layout, this will remove the old data and rewrite it in the newest layout.
- Parameters:
hdf (
ProjectHDFio) – HDF group to read/writegroup_name (str, optional) – name of subgroup
- search(key, stop_on_first_hit=True)#
Search for
keyin the Container hierarchy.This should be used if there is only one such item in the hierarchy.
If stop_on_first_hit is True the first item found is taken. Otherwise, a ValueError is raised if the key appears multiple times.
- Parameters:
key (str) – the key to look for
stop_on_first_hit (bool) – whether to stop on the first hit
- Raises:
TypeError – if key is not str
KeyError – if key is not found
ValueError – if stop_on_first_hit is False and key is found twice
- Returns:
element at
key- Return type:
object
- setdefault(k[, d]) D.get(k,d), also set D[k]=d if k not in D#
- to_builtin(stringify=False)#
Convert the container back to builtin dict’s and list’s recursively.
- Parameters:
stringify (bool, optional) – convert all non-recursive elements to str
- to_dict() dict#
Reduce the object to a dictionary.
- Returns:
serialized state of this object
- Return type:
dict
- to_hdf(hdf: ProjectHDFio, group_name: str = None)#
Write object to HDF.
If group_name is given create a subgroup in hdf first.
- Parameters:
hdf (
ProjectHDFio) – HDF group to write togroup_name (str, optional) – name of subgroup
- unlocked() _UnlockContext#
Unlock the object temporarily.
Context manager returns this object again and relocks it after the with statement finished.
Note
lock() vs. unlocked()
There is a small asymmetry between these two methods.
lock()can only be done once (meaningfully), whileunlocked()is a context manager and can be called multiple times.
- update(init, wrap=False, blacklist=(), **kwargs)#
Add all elements or key-value pairs from init to this container. If wrap is not given, behaves as the generic method.
- Parameters:
init (Sequence, Set, Mapping) – container to draw new elements from
wrap (bool) – if True wrap all encountered Sequences and Mappings in
DataContainerBaserecursivelyblacklist (list of types) – when wrap is True, don’t wrap these types even if they’re instances of Sequence or Mapping
**kwargs – update from this mapping as well
- values() an object providing a view on D's values#
- write(file_name)#
Writes the DataContainerBase to a text file.
For supported file types, see
fileio.write().- Parameters:
file_name (str) – the name of the file to be writen to.