shnitsel.io.helpers

Attributes

KindType

PathOptionsType

__atnum2symbol__

__symbol2atnum__

Classes

LoadingParameters

ConsistentValue

Class to keep track of a value that may only be assigned once and not overwritten afterwards.

Functions

make_uniform_path(path)

Unify the path options to alyways yield a pathlib.Path object

get_atom_number_from_symbol(symbol)

get_symbol_from_atom_number(number)

get_triangular(original_array)

get_triangular - get the upper triangle of a (nstat1 x nstat2 x natoms x 3) matrix

dip_sep(dipoles)

Separates a complete matrix of dipoles into permanent

default_state_type_assigner(dataset)

Function to assign default state types to states.

default_state_name_assigner(dataset)

Function to assign default state names to states.

random_trajid_assigner(path)

Function to generate a random id for a path.

Module Contents

KindType
PathOptionsType
class LoadingParameters
input_units: Dict[str, str] | None = None
error_reporting: Literal['log', 'raise'] = 'log'
trajectory_id: Dict[str, int] | Callable[[pathlib.Path], int] | None = None
state_types: List[int] | Callable[[xarray.Dataset], xarray.Dataset] | None = None
state_names: List[str] | Callable[[xarray.Dataset], xarray.Dataset] | None = None
make_uniform_path(path)

Unify the path options to alyways yield a pathlib.Path object

Parameters:

path (str | os.PathLike | pathlib.Path | None) – path input of arbitrary type

Returns:

The converted path or None

Return type:

pathlib.Path|None

class ConsistentValue(name='ConsistentValue', weak=False, ignore_none=False)

Class to keep track of a value that may only be assigned once and not overwritten afterwards.

Can be used to check consistency of a value across multiple datasets. The value is written to and read from the property v of the object.

Raises:
  • AttributeError – Will be raised if the value is read before first assignment if the object has not been created with weak=true.

  • ValueError – _description_

name: str = 'ConsistentValue'
defined: bool = False
_weak: bool = False
_val: T | None = None
_ignore_none: bool = False
property v: T | None
Return type:

T | None

__atnum2symbol__
__symbol2atnum__
get_atom_number_from_symbol(symbol)
Parameters:

symbol (str)

Return type:

int

get_symbol_from_atom_number(number)
Parameters:

number (int)

Return type:

str

get_triangular(original_array)

get_triangular - get the upper triangle of a (nstat1 x nstat2 x natoms x 3) matrix

This function takes in a 4-dimensional numpy array (original_array) and returns a 3-dimensional numpy array (upper_tril) which is the upper triangle of the input matrix, obtained by excluding the diagonal elements. The number of steps (k) to move the diagonal above the leading diagonal is 1. The returned matrix has shape (len(cols), natoms, 3)

Parameters:

original_array – 4D numpy array of shape (nstat1, nstat2, natoms, 3) representing the input matrix

Returns:

3D numpy array of shape (len(cols), natoms, 3) representing the upper triangle of the input matrix

Return type:

upper_tril

dip_sep(dipoles)

Separates a complete matrix of dipoles into permanent and transitional dipoles, removing redundancy in the process.

Parameters:

dipoles (numpy.ndarray) – 3D numpy array of shape (nstates, nstates, 3) where the first axis represents state before transition, the second axis represents state after transition and the third axis contains x, y and z coordinates.

Returns:

  • dip_perm – 2D numpy array of shape (nstates, 3)

  • dip_trans – 2D numpy array of shape (math.comb(nstates, 2), 3) in the order e.g. (for nstates = 4) 0->1, 0->2, 0->3, 1->2, 1->3, 2->3 where 0->1 is the transitional dipole between state 0 and state 1.

Return type:

Tuple[numpy.ndarray, numpy.ndarray]

default_state_type_assigner(dataset)

Function to assign default state types to states.

Parameters:

dataset (xr.Dataset) – The dataset to assign the states to

Returns:

The dataset after the assignment

Return type:

xr.Dataset

default_state_name_assigner(dataset)

Function to assign default state names to states.

Parameters:

dataset (xr.Dataset) – The dataset to assign the states to

Returns:

The dataset after the assignment

Return type:

xr.Dataset

random_trajid_assigner(path)

Function to generate a random id for a path.

Parameters:

path (pathlib.Path) – Unused: the path we are generating for

Returns:

the chosen trajectory id

Return type:

int