shnitsel.io.ase.parse#

Attributes#

Functions#

complete_shapes_guesses_from_variables(tmp_vars, ...)

Helper function to guess the format from variable shapes if no metadata could be found.

shapes_from_metadata(db_meta[, db_format])

Function to assign shapes based on the chosen db_format and potential information in the metadata of a database.

apply_dataset_meta_from_db_metadata(dataset, db_meta, ...)

Apply attributes from db metadata and perform some validation checks on the result.

read_ase(db_path[, db_format, loading_parameters])

Reads an ASE DB containing data in the SPaiNN or SchNet format

Module Contents#

dummy_leading_dim: str = 'leading_dim_unknown'#
multi_level_prefix: str = '_MultiIndex_levels_for_'#
SUPPORTED_COORD_KEYS#
complete_shapes_guesses_from_variables(tmp_vars, meta_shape_vars, meta_shape_coords, db_format_meta, leading_dim_name, leading_dim_target_guess=None)#

Helper function to guess the format from variable shapes if no metadata could be found.

_extended_summary_

Parameters:
  • tmp_vars (dict[str, np.ndarray]) – The temporary arrays of the variables read for this dataset

  • meta_shape_vars (dict[str, list[str]]) – The shapes per frame of the variable arrays read for this dataset

  • meta_shape_coords (dict[str, list[str]],) – The variable shape s

  • db_format_meta (Literal['spainn', 'schnet'] | None,)

  • leading_dim_name (Literal['frame', 'time'] | str,)

  • leading_dim_target_guess (Literal['frame', 'time'] | str | None = None,)

Returns:

_description_

Return type:

_type_

Raises:
shapes_from_metadata(db_meta, db_format=None)#

Function to assign shapes based on the chosen db_format and potential information in the metadata of a database.

If conflicting information on the db_format is provided and present in the database, en error will be raised.

Parameters:
  • db_meta (dict) – The metadata dict of an ASE database.

  • db_format (Literal['spainn', 'schnet'] | None, optional) – The requested format of the database. Defaults to None.

Returns:

  • dict[str, list[str]] – Dict of data_var shapes

  • dict[str, list[str]] – Dict of coordinate shapes

  • str – The name of the leading dimension. Should be frame or time, but can be leading_dim_unknown if unknown

Raises:

ValueError – If a db_format of database was requested that conflicts with the format of the database.

Return type:

tuple[dict[str, list[str]], dict[str, list[str]], Literal[‘frame’, ‘time’] | str, Literal[‘spainn’, ‘schnet’] | None]

apply_dataset_meta_from_db_metadata(dataset, db_meta, default_attrs)#

Apply attributes from db metadata and perform some validation checks on the result.

Loads remaining missing coordinate variables from db metadata if available. Checks size of resulting dimensions if specified in db metadata. Further initializes the multi indices if specified in the metadata.

Parameters:
  • dataset (xr.Dataset) – Trajectory/Frames dataset parsed from ASE db

  • db_meta (dict) – Metadata from the trajectory db file

  • default_attrs (dict) – Attributes to apply to variables by default

Returns:

Dataset with attributes set from from db metadata and dimension sizes asserted

Return type:

xr.Dataset

read_ase(db_path, db_format=None, loading_parameters=None)#

Reads an ASE DB containing data in the SPaiNN or SchNet format

Parameters:
  • db_path (pathlib.Path) – Path to the database

  • db_format (Literal['spainn', 'schnet'] | None, optional) – Must be one of ‘spainn’ or ‘schnet’ or None; determines interpretation of array shapes If None is provided, no shape will be assumed

  • loading_parameters (LoadingParameters) – Potentially configured parameters to overwrite loading behavior

Returns:

An xr.Dataset of frames. Potentially with a time coordinate.

Return type:

xr.Dataset

Raises:
  • ValueError – If db_format is not one of ‘spainn’ or ‘schnet’

  • FileNotFoundError – If db_path is not a file

  • ValueError – If db_path does not contain data corresponding to the format db_format