pyiron_atomistics.atomistics.structure.neighbors.NeighborsTrajectory#
- class pyiron_atomistics.atomistics.structure.neighbors.NeighborsTrajectory(*args, **kwargs)[source]#
Bases:
DataContainerThis class generates the neighbors for a given atomistic trajectory. The resulting indices, distances, and vectors are stored as numpy arrays.
- __init__(init=None, has_structure=None, num_neighbors=12, table_name='neighbors_traj', store=None, **kwargs)[source]#
- Parameters:
has_structure (
HasStructure) – object containing the structures to compute the neighbors onnum_neighbors (int) – The cutoff for the number of neighbors
table_name (str) – Table name for the base DataContainer (stores this object as a group in a HDF5 file with this name)
store (FlattenedStorage) – internal storage that should be used to store the neighborhood information, creates a new one if not provided; if provided and not empty it must be compatible with the lengths of the structures in has_structure, but this is not checked
**kwargs (dict) – Additional arguments to be passed to the get_neighbors() routine (eg. cutoff_radius, norm_order , etc.)
Methods
__init__([init, has_structure, ...])- param has_structure:
object containing the structures to compute the neighbors on
append(val)Add new value to the container without a key.
clear()Remove all items from DataContainerBase.
Compute the neighbors across the trajectory
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.
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
Neighbour distances (excluding itself) of each atom computed using the get_neighbors_traj() method
has_structureNeighbour indices (excluding itself) of each atom computed using the get_neighbors_traj() method
The maximum number of neighbors to be computed
False if the object can currently be written to
Neighbor shell indices (excluding itself) of each atom computed using the get_neighbors_traj() method.
Neighbour vectors (excluding itself) of each atom computed using the get_neighbors_traj() method
- 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) []
- property distances#
Neighbour distances (excluding itself) of each atom computed using the get_neighbors_traj() method
If the structures have different number of atoms, the array will have NaN on indices that are invalid.
- Returns:
A float array of dimension N_steps / stride x N_atoms x N_neighbors
- Return type:
numpy.ndarray
- 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
- property indices#
Neighbour indices (excluding itself) of each atom computed using the get_neighbors_traj() method
If the structures have different number of atoms, the array will have -1 on indices that are invalid.
- Returns:
An int array of dimension N_steps / stride x N_atoms x N_neighbors
- Return type:
numpy.ndarray
- 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
- property num_neighbors#
The maximum number of neighbors to be computed
- Returns:
The max number of neighbors
- Return type:
int
- 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#
- property shells#
Neighbor shell indices (excluding itself) of each atom computed using the get_neighbors_traj() method.
For trajectories with non constant amount of particles this array may contain -1 for invalid values, i.e.
- Returns:
An int array of dimension N_steps / stride x N_atoms x N_neighbors x 3
- Return type:
ndarray
- 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#
- property vecs#
Neighbour vectors (excluding itself) of each atom computed using the get_neighbors_traj() method
If the structures have different number of atoms, the array will have NaN on indices that are invalid.
- Returns:
A float array of dimension N_steps / stride x N_atoms x N_neighbors x 3
- Return type:
numpy.ndarray
- 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.