shnitsel.core.postprocess

Attributes

Astates

AtXYZ

DimName

Frames

PerState

InterState

_var_delta_t_msg

convert_energy

convert_forces

convert_dipoles

convert_length

Classes

Converter

Functions

norm(da[, dim, keep_attrs])

Calculate the 2-norm of a DataArray, reducing the dimension with dame dim

subtract_combinations(da, dim[, labels])

Calculate all possible pairwise differences over a given dimension

pairwise_dists_pca(atXYZ, **kwargs)

PCA-reduced pairwise interatomic distances

sudi(da)

Take successive differences along the 'frame' dimension

hop_indices(astates)

Find in which frames the active state changes

pca_and_hops(frames)

Get PCA points and info on which of them represent hops

relativize(da, **sel)

setup_frames(ds, *[, to_time, convert_to_eV, ...])

Performs several frequent setup tasks.

validate(frames)

ts_to_time(data[, delta_t, old])

keep_norming(da[, exclude])

_get_fosc(energy, dip_trans)

get_fosc(energy, dip_trans)

assign_fosc(ds)

broaden_gauss(E, fosc[, agg_dim, width, nsamples, xmax])

ds_broaden_gauss(ds[, width, nsamples, xmax])

get_per_state(frames)

get_inter_state(frames)

calc_pops(frames)

Fast way to calculate populations

calc_ci(a[, confidence])

ci_agg_last_dim(a[, confidence])

xr_calc_ci(a, dim[, confidence])

time_grouped_ci(x[, confidence])

to_xyz(da[, comment])

traj_to_xyz(traj_atXYZ)

dnorm(a)

dcross(a, b)

ddot(a, b)

angle_(a, b)

normal(a, b, c)

dihedral_(a, b, c, d)

full_dihedral_(a, b, c, d)

dihedral(atXYZ, i, j, k, l, *[, deg, full])

Calculate all dihedral angles between the atoms specified.

angle(atXYZ, i, j, k, *[, deg])

distance(atXYZ, i, j)

trajs_with_hops(astates)

Example usage: trajs_with_hops(frames['astate'])

get_hop_types(astates)

Example usage:

pick_statecombs(da, statecombs, frames[, framedim])

find_traj_hops(traj)

find_hops(frames)

set_atom_props(mol, **kws)

to_mol(atXYZ_frame[, charge, covFactor, to2D, ...])

mol_to_numbered_smiles(mol)

numbered_smiles_to_mol(smiles)

default_mol(obj)

Module Contents

type Astates = xr.DataArray
type AtXYZ = xr.DataArray
type DimName = Hashable
type Frames = xr.Dataset
type PerState = xr.Dataset
type InterState = xr.Dataset
_var_delta_t_msg = '`delta_t` varies between the trajectories. Please separate the trajectories into groups'
norm(da, dim='direction', keep_attrs=None)

Calculate the 2-norm of a DataArray, reducing the dimension with dame dim

Parameters:
  • da (xarray.DataArray) – Array to calculate the norm of

  • dim (DimName) – Dimension to calculate norm along (and therby reduce), by default ‘direction’

  • optional – Dimension to calculate norm along (and therby reduce), by default ‘direction’

  • keep_attrs (bool | str | None) – How to deal with attributes; passed to xr.apply_ufunc, by default None

  • optional – How to deal with attributes; passed to xr.apply_ufunc, by default None

Return type:

A DataArray with dimension dim reduced

subtract_combinations(da, dim, labels=False)

Calculate all possible pairwise differences over a given dimension

Parameters:
  • da (xarray.DataArray) – Input DataArray; must contain dimension dim

  • dim (DimName) – Dimension (of size $n$) to take pairwise differences over

  • labels (bool) – If True, label the pairwise differences based on the index of dim, by default False

  • optional – If True, label the pairwise differences based on the index of dim, by default False

Return type:

A DataArray with the dimension dim replaced by a dimension ‘`dim`comb’ of size $n(n-1)/2$

pairwise_dists_pca(atXYZ, **kwargs)

PCA-reduced pairwise interatomic distances

Parameters:

atXYZ (AtXYZ) – A DataArray containing the atomic positions; must have a dimension called ‘atom’

Returns:

  • A DataArray with the same dimensions as atXYZ, except for the ‘atom’

  • dimension, which is replaced by a dimension ‘PC’ containing the principal

  • components (by default 2)

Return type:

xarray.DataArray

sudi(da)

Take successive differences along the ‘frame’ dimension

Parameters:

da (xarray.DataArray) – An xarray.DataArray with a ‘frame’ dimension corresponding to a pandas.MultiIndex of which the innermost level is ‘time’.

Returns:

  • An xarray.DataArray with the same shape, dimension names etc.,

  • but with the data of the (i)th frame replaced by the difference between

  • the original (i+1)th and (i)th frames, with zeros filling in for both the

  • initial frame and any frame for which time = 0, to avoid taking differences

  • between the last and first frames of successive trajectories.

Return type:

xarray.DataArray

hop_indices(astates)

Find in which frames the active state changes

Parameters:

astates (xarray.DataArray) – A DataArray of state indicators

Return type:

A boolean DataArray indicating whether a hop took place

pca_and_hops(frames)

Get PCA points and info on which of them represent hops

Parameters:

frames (xarray.Dataset) – A Dataset containing ‘atXYZ’ and ‘astate’ variables

Returns:

  • pca_res – The PCA-reduced pairwise interatomic distances

  • hops_pca_coordspca_res filtered by hops, to facilitate marking hops when plotting

Return type:

tuple[xarray.DataArray, xarray.DataArray]

relativize(da, **sel)
Parameters:

da (xarray.DataArray)

Return type:

xarray.DataArray

setup_frames(ds, *, to_time=None, convert_to_eV=None, convert_e_kin_to_eV=None, relativize_energy=None, relativize_selector=None)

Performs several frequent setup tasks. Each task can be skipped (by setting the corresponding parameter to False), carried out if appropriate (None), or forced in the sense that an error is thrown if the task is redundant (True).

Parameters:
  • ds (xarray.Dataset) – The frames-like xr.Dataset to setup.

  • to_time (bool | None) – Whether to convert a ‘ts’ (timestep) coordinate to a ‘time’ coordinate, by default None

  • optional – Whether to convert a ‘ts’ (timestep) coordinate to a ‘time’ coordinate, by default None

  • convert_to_eV (bool | None) – Whether to convert the ‘energy’ variable to eV, by default None

  • optional – Whether to convert the ‘energy’ variable to eV, by default None

  • convert_e_kin_to_eV (bool | None) – Whether to convert the ‘e_kin’ (kinetic energy) variable to eV, by default None

  • optional – Whether to convert the ‘e_kin’ (kinetic energy) variable to eV, by default None

  • relativize_energy (bool | None) – Whether to relativize energies, by default None

  • optional – Whether to relativize energies, by default None

  • relativize_selector – This argument is passed to relativize, by default None

  • optional – This argument is passed to relativize, by default None

Return type:

A modified frames-like xr.Dataset

Raises:

ValueError – If a task should be forced (i.e. the corresponding parameter is set to True) but cannot be carried out (e.g. because the dataset was already processed previously)

class Converter(quantity, conversions)
__name__ = 'convert_Uninferable'
quantity
conversions
targets
__call__(da, to)
Parameters:
Return type:

xarray.DataArray

convert_energy
convert_forces
convert_dipoles
convert_length
validate(frames)
Parameters:

frames (Frames)

Return type:

numpy.ndarray

ts_to_time(data, delta_t=None, old='drop')
Parameters:
Return type:

xarray.Dataset | xarray.DataArray

keep_norming(da, exclude=None)
Parameters:
Return type:

xarray.DataArray

_get_fosc(energy, dip_trans)
get_fosc(energy, dip_trans)
assign_fosc(ds)
Parameters:

ds (xarray.Dataset)

Return type:

xarray.Dataset

broaden_gauss(E, fosc, agg_dim='frame', *, width=0.5, nsamples=1000, xmax=None)
Parameters:
  • E (xarray.DataArray) – values used for the x-axis, presumably $E_i$

  • fosc (xarray.DataArray) – values used for the y-axis, presumably $f_mathrm{osc}$

  • agg_dim (DimName) – dimension along which to aggregate the many Gaussian distributions, by default ‘frame’

  • optional – dimension along which to aggregate the many Gaussian distributions, by default ‘frame’

  • width (float) – the width (i.e. 2 standard deviations) of the Gaussian distributions used, by default 0.001

  • optional – the width (i.e. 2 standard deviations) of the Gaussian distributions used, by default 0.001

  • nsamples (int) – number of evenly spaced x-values over which to sample the distribution, by default 1000

  • optional – number of evenly spaced x-values over which to sample the distribution, by default 1000

  • xmax (float | None) – the maximum x-value, by default 3 standard deviations beyond the pre-broadened maximum

  • optional – the maximum x-value, by default 3 standard deviations beyond the pre-broadened maximum

Return type:

xarray.DataArray

ds_broaden_gauss(ds, width=0.5, nsamples=1000, xmax=None)
Parameters:
Return type:

xarray.DataArray

get_per_state(frames)
Parameters:

frames (Frames)

Return type:

PerState

get_inter_state(frames)
Parameters:

frames (Frames)

Return type:

InterState

calc_pops(frames)

Fast way to calculate populations Requires states ids to be small integers

Parameters:

frames (Frames)

Return type:

xarray.DataArray

calc_ci(a, confidence=0.95)
Parameters:
  • a (numpy.typing.NDArray)

  • confidence (float)

Return type:

numpy.typing.NDArray

ci_agg_last_dim(a, confidence=0.95)
xr_calc_ci(a, dim, confidence=0.95)
Parameters:
Return type:

xarray.Dataset

time_grouped_ci(x, confidence=0.9)
Parameters:
Return type:

xarray.Dataset

to_xyz(da, comment='#')
Parameters:

da (AtXYZ)

Return type:

str

traj_to_xyz(traj_atXYZ)
Parameters:

traj_atXYZ (AtXYZ)

Return type:

str

dnorm(a)
dcross(a, b)
ddot(a, b)
angle_(a, b)
normal(a, b, c)
dihedral_(a, b, c, d)
full_dihedral_(a, b, c, d)
dihedral(atXYZ, i, j, k, l, *, deg=False, full=False)

Calculate all dihedral angles between the atoms specified. The atoms specified needed be bonded.

Parameters:
  • atXYZ (AtXYZ) – A DataArray of coordinates, with atom and direction dimensions

  • i (int) – The four atom indices

  • j (int) – The four atom indices

  • k (int) – The four atom indices

  • l (int) – The four atom indices

  • deg (bool) – Whether to return angles in degrees (True) or radians (False), by default False

  • full (bool) – Whether to return signed angles between -180° and 180° (True) or unsigned angles between 0 and 180° (False), by default False

Return type:

A DataArray containing dihedral angles

angle(atXYZ, i, j, k, *, deg=False)
Parameters:
Return type:

xarray.DataArray

distance(atXYZ, i, j)
Parameters:
  • atXYZ (AtXYZ)

  • i (int)

  • j (int)

Return type:

xarray.DataArray

trajs_with_hops(astates)

Example usage: trajs_with_hops(frames[‘astate’])

Parameters:

astates (Astates)

Return type:

list[Hashable]

get_hop_types(astates)

Example usage:

Parameters:

astates (Astates)

Return type:

dict[int, tuple[int, int]]

pick_statecombs(da, statecombs, frames, framedim='frame')
Parameters:
Return type:

xarray.DataArray

find_traj_hops(traj)
Parameters:

traj (xarray.Dataset)

Return type:

xarray.Dataset

find_hops(frames)
Parameters:

frames (Frames)

Return type:

Frames

set_atom_props(mol, **kws)
to_mol(atXYZ_frame, charge=None, covFactor=1.2, to2D=True, molAtomMapNumber=None, atomNote=None, atomLabel=None)
Return type:

rdkit.Chem.Mol

mol_to_numbered_smiles(mol)
Parameters:

mol (rdkit.Chem.Mol)

Return type:

str

numbered_smiles_to_mol(smiles)
Parameters:

smiles (str)

Return type:

rdkit.Chem.Mol

default_mol(obj)
Return type:

rdkit.Chem.Mol