porereax.utils

Module providing utility functions for the PoreReax package.

This module includes functions for saving and loading Python objects using pickle, loading YAML configuration files, and common mathematical operations such as the minimum-image convention.

Functions

save_object(obj, filename)

Save a Python object to a file using pickle.

load_object(file_path)

Load a Python object from a file using pickle.

load_yaml(→ dict)

Load a YAML file and return its contents as a dictionary.

min_image_convention(→ numpy.ndarray)

Apply the minimal image convention to a vector given the simulation box dimensions.

min_image_midpoint(→ numpy.ndarray)

Calculate the midpoint between two vectors considering the minimal image convention.

get_identifiers(→ list)

Retrieve the list of identifiers from a data file.

get_data(→ dict)

Retrieve the data for a specific identifier from a data file.

read_pore_yml(→ dict)

Read a YAML file containing pore system properties and extract relevant depending on the pore shape.

Module Contents

porereax.utils.save_object(obj, filename)[source]

Save a Python object to a file using pickle.

Parameters:
  • obj (any) – The Python object to be saved.

  • filename (str) – The path to the file where the object will be saved.

porereax.utils.load_object(file_path)[source]

Load a Python object from a file using pickle.

Parameters:

file_path (str) – The path to the file from which the object will be loaded.

Returns:

The loaded Python object.

Return type:

any

porereax.utils.load_yaml(file_path: str) dict[source]

Load a YAML file and return its contents as a dictionary.

Parameters:

file_path (str) – The path to the YAML file.

Returns:

The contents of the YAML file as a dictionary.

Return type:

dict

porereax.utils.min_image_convention(vec: numpy.ndarray, box: numpy.ndarray) numpy.ndarray[source]

Apply the minimal image convention to a vector given the simulation box dimensions.

Parameters:
  • vec (np.ndarray) – The input vector (shape: (N, 3)).

  • box (np.ndarray) – The simulation box dimensions (shape: (3,)).

Returns:

The vector adjusted by the minimal image convention (shape: (N, 3)).

Return type:

np.ndarray

porereax.utils.min_image_midpoint(vec1: numpy.ndarray, vec2: numpy.ndarray, box: numpy.ndarray) numpy.ndarray[source]

Calculate the midpoint between two vectors considering the minimal image convention.

Parameters:
  • vec1 (np.ndarray) – The first vector (shape: (N, 3)).

  • vec2 (np.ndarray) – The second vector (shape: (N, 3)).

  • box (np.ndarray) – The simulation box dimensions (shape: (3,)).

Returns:

The midpoint vector adjusted by the minimal image convention (shape: (N, 3)).

Return type:

np.ndarray

porereax.utils.get_identifiers(link_data: str) list[source]

Retrieve the list of identifiers from a data file.

Parameters:

link_data (str) – Path to the data file created by a sampler instance.

Returns:

List of identifiers present in the data file.

Return type:

list

porereax.utils.get_data(link_data: str, identifier: str) dict[source]

Retrieve the data for a specific identifier from a data file.

Parameters:
  • link_data (str) – Path to the data file created by a sampler instance.

  • identifier (str) – The identifier for which to retrieve the data.

Returns:

The data corresponding to the specified identifier.

Return type:

dict

porereax.utils.read_pore_yml(file_path: str) dict[source]

Read a YAML file containing pore system properties and extract relevant depending on the pore shape.

Parameters:

file_path (str) – Path to the YAML file containing pore system properties.

Returns:

A dictionary containing the extracted pore properties.

Return type:

dict