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

get_data(link_data, identifier)

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

get_identifiers(link_data)

Retrieve the list of identifiers from a data file.

load_object(file_path)

Load a Python object from a file using pickle.

load_yaml(file_path)

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

min_image_convention(vec, box)

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

min_image_midpoint(vec1, vec2, box)

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

read_pore_yml(file_path)

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

save_object(obj, filename)

Save a Python object to a file using pickle.

Classes

Substitution(**kwargs)

Decorator that fills %(name)s placeholders in a docstring.

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)[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, box)[source]

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

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

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

Returns:

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

Return type:

ndarray

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

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

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

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

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

Returns:

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

Return type:

ndarray

porereax.utils.get_identifiers(link_data)[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, identifier)[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)[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

class porereax.utils.Substitution(**kwargs)[source]

Bases: object

Decorator that fills %(name)s placeholders in a docstring.

Use this to inject a shared block (e.g. a common Parameters section) into multiple docstrings without retyping it. Unlike plain %-formatting, only whole-line %(name)s placeholders are replaced, so an unrelated bare ‘%’ elsewhere in the docstring is left untouched. Each line of the replacement text is reindented to match the placeholder’s own indentation, so it splices cleanly into an indented class docstring.