shnitsel.data.shnitsel_db

Submodules

Attributes

_datatree_level_attribute_key

Classes

CompoundGroup

DataTree node to keep track of all data associated with a common compound within the datatree

CompoundInfo

Class to hold identifying and auxiliary info of a compound type in ShnitselDB

TrajectoryData

DataTree node to keep track of a single trajectory entry

TrajectoryGroup

DataTree node to keep track of a group of trajectories where properties defining the group can be set

GroupInfo

Class to hold auxiliaryt info of a group of Trajectories in ShnitselDB

Package Contents

_datatree_level_attribute_key = 'DataTree_Level'
class CompoundGroup(compound_info=None, children=None)

Bases: xarray.DataTree

DataTree node to keep track of all data associated with a common compound within the datatree

Parameters:
is_level(target_level)

Check whether we are at a certain level

Parameters:

target_level (str) – Desired level to check for

Returns:

True if this level satisfies the requirements

Return type:

bool

get_compound_info()

Get the store compound info of this Compound group.

Returns:

_description_

Return type:

CompoundInfo

collect_trajectories()

Function to retrieve all trajectories in this subtree

Returns:

List of all nodes with TrajectoryData type

Return type:

List[TrajectoryData]

merge_with(other)

Function to merge two compound groups into one.

Called when merging two database states. Will fail if compound_info differs between compounds to avoid loss of information.

Parameters:

other (CompoundGroup) – The other CompoundGroup to be merged

Raises:

ValueError – Raised if the compound_info differs.

Returns:

A CompoundGroup object holding the entire merged subtree

Return type:

CompoundGroup

filter_trajectories(filter_func=None, est_level=None, basis_set=None, **kwargs)

Function to filter trajectories based on their attributes.

Parameters:
  • filter_func (Callable[[xr.Dataset], bool] | None, optional) – A function to evaluate whether a trajectory should be retained. Should return True if the trajectory should stay in the filtered set. Defaults to None.

  • est_level (str | List[str] | None, optional) – Option to filter for a certain level of electronic structure theory/calculation method. Can be a single key value or a set of values to retain. Defaults to None.

  • basis_set (str | List[str] | None, optional) – Option to filter for a certain basis set. Can be a single key value or a set of values to retain. Defaults to None.

  • **kwargs – Key-value pairs, where the key denotes an attribute

Returns:

Either returns the CompoundGroup with the remaining set of trajectories or None if the group would be empty.

Return type:

Compoundgroup|None

add_trajectory_group(group_name, filter_func_trajectories=None, flatten_trajectories=False, **kwargs)

Function to add trajectories within this compound subtree to a TrajectoryGroup of trajectories.

The group_name will be set as the name of the group in the tree. If flatten_trajectories=True all existing groups will be dissolved before filtering and the children will be turned into an ungrouped list of trajectories. The filter_func_trajectories will either be applied to only the current groups and trajectories immediately beneath this compound or to the flattened list of all child directories.

Parameters:
  • group_name (str) – The name to be set for the TrajectoryGroup object

  • filter_func_Trajectories (Callable[[Trajectory|GroupInfo], bool] | None, optional) – A function to return true for Groups and individual trajectories that should be added to the new group. Defaults to None.

  • flatten_trajectories (bool, optional) – A flag whether all descendant groups should be dissolved and flattened into a list of trajectories first before applying a group. Defaults to False.

  • filter_func_trajectories (Callable[[shnitsel.data.trajectory_format.Trajectory | shnitsel.data.shnitsel_db.db_trajectory_group.GroupInfo], bool] | None)

Returns:

The restructured Compound with a new added group if at least one trajectory has satisfied the filter condition.

Return type:

CompoundGroup

map_over_trajectories(map_func, result_as_dict=False, result_var_name='result')

Method to apply a function to all trajectories in this subtree.

Parameters:
  • map_func (Callable[[Trajectory], T]) – Function to be applied to each individual trajectory in this database structure.

  • result_as_dict (bool, optional) – Whether to return the result as a dict or as a CompoundGroup structure. Defaults to False which yields a CompoundGroup.

  • result_var_name (str,optional) – The name of the result variable to be assigned in either the result dataset or in the result dict.

Returns:

The result, either again as a CompoundGroup structure or as a layered dict structure.

Return type:

CompoundGroup|dict

class CompoundInfo

Class to hold identifying and auxiliary info of a compound type in ShnitselDB

compound_name: str = 'unknown'
class TrajectoryData(dataset=None, name=None)

Bases: xarray.DataTree

DataTree node to keep track of a single trajectory entry

Parameters:
  • dataset (xarray.Dataset | shnitsel.data.trajectory_format.Trajectory | None)

  • name (str | None)

is_level(target_level)

Check whether we are at a certain level

Parameters:

target_level (str) – Desired level to check for

Returns:

True if this level satisfies the requirements

Return type:

bool

collect_trajectories()

Function to retrieve all trajectories in this subtree

Returns:

List of all nodes with TrajectoryData type

Return type:

List[TrajectoryData]

map_over_trajectories(map_func, result_as_dict=False, result_var_name='result')

Method to apply a function to all trajectories in this subtree.

Parameters:
  • map_func (Callable[[Trajectory], T]) – Function to be applied to each individual trajectory in this database structure.

  • result_as_dict (bool, optional) – Whether to return the result as a dict or as a TrajectoryData structure. Defaults to False which yields a CompoundGroup.

  • result_var_name (str,optional) – The name of the result variable to be assigned in either the result dataset or in the result dict.

Returns:

The result, either again as a TrajectoryData structure or as a layered dict structure.

Return type:

TrajectoryData|dict

class TrajectoryGroup(group_info=None, children=None)

Bases: xarray.DataTree

DataTree node to keep track of a group of trajectories where properties defining the group can be set

Parameters:
is_level(target_level)

Check whether we are at a certain level

Parameters:

target_level (str) – Desired level to check for

Returns:

True if this level satisfies the requirements

Return type:

bool

get_group_info()

Reconstruct the Group info object from settings stored in this node’s attributes

Returns:

The group information

Return type:

GroupInfo

collect_trajectories()

Function to retrieve all trajectories in this subtree

Returns:

List of all nodes with TrajectoryData type

Return type:

List[TrajectoryData]

map_over_trajectories(map_func, result_as_dict=False, result_var_name='result')

Method to apply a function to all trajectories in this subtree.

Parameters:
  • map_func (Callable[[Trajectory], T]) – Function to be applied to each individual trajectory in this database structure.

  • result_as_dict (bool, optional) – Whether to return the result as a dict or as a TrajectoryGroup structure. Defaults to False which yields a CompoundGroup.

  • result_var_name (str,optional) – The name of the result variable to be assigned in either the result dataset or in the result dict.

Returns:

The result, either again as a TrajectoryGroup structure or as a layered dict structure.

Return type:

TrajectoryGroup|dict

merge_with(other)

Function to merge two TrajectoryGroups into one.

Called when merging two database states. Will fail if group_info differs between compounds to avoid loss of information.

Parameters:

other (CompoundGroup) – The other CompoundGroup to be merged

Raises:

ValueError – Raised if the compound_info differs.

Returns:

A CompoundGroup object holding the entire merged subtree

Return type:

CompoundGroup

class GroupInfo

Class to hold auxiliaryt info of a group of Trajectories in ShnitselDB

group_name: str
group_attributes: Dict[str, Any] | None = None