porereax.density

Module for sampling atomic and bond densities.

The module provides:

  1. DensitySampler: A class to sample atomic densities of specified atom structures.

  2. BondDensitySampler: A class to sample bond densities of specified bonds.

  3. ReactionSampler: A class to sample reaction events based on bond formation and breaking.

All samplers support multiple dimensions for density sampling:

  • “Cartesian1D”: Samples the density histogram along a specified Cartesian direction for the whole simulation box.

  • “Cartesian2D”: Samples the density histogram in a specified plane for the whole simulation box.

  • “Time”: Samples the number of atoms (with given bonds) or bonds per frame

  • “Pore1D”: Samples the density histogram along a specified direction in a cylindrical pore.

  • “Pore2D”: Samples the density histogram in a specified plane in a cylindrical pore.

Classes

BondDensitySampler(name_out, bonds, ...[, ...])

Sampler class for bond densities.

DensitySampler(name_out, atoms, dimension, ...)

Sampler class for atomic densities.

ReactionSampler(name_out, reactions, ...)

Sampler class for reaction events based on bond formation and breaking.

type porereax.density.Dimension = Literal['Cartesian1D', 'Cartesian2D', 'Time', 'Pore1D', 'Pore2D']
class porereax.density.DensitySampler(name_out, atoms, dimension, region, process_id, atom_lib, masses, num_frames, box, system_properties, num_bins, direction, conditions=None)[source]

Bases: AtomSampler

Sampler class for atomic densities.

Parameters:
  • name_out (str) – Name of the output file of the sampler data

  • atoms (list) –

    List of atoms to sample, each specified as a dictionary with keys:

    • ”atom”: str, the atom type

    • ”bonds”: list, optional, list of bonded atom types. Each entry may either be a plain atom type string (no constraint on what that neighbour is itself bonded to) or a dictionary with the same “atom”/ “bonds” shape, describing a required bonding environment for that specific neighbour one hop further out. Nesting may repeat to describe arbitrarily deep bonding environments. An entry’s atom type (plain string or the “atom” key of a nested dictionary) may be “X” to match any atom type; a nested “X” entry may still carry its own “bonds” requirement, constraining that wildcard neighbour’s further bonding environment without constraining its own type.

  • dimension (Dimension) – Dimension along which to sample.

  • region (Region) – Region specification for sampling. Can be a string defining a geometric region or a function that takes coordinates and returns a boolean mask.

  • process_id (int) – Process ID for parallel processing.

  • atom_lib (dict) – Dictionary mapping atom type strings to their type IDs.

  • masses (dict) – Dictionary mapping atom type strings to their masses.

  • num_frames (int) – Total number of frames to sample.

  • box (ndarray) – Simulation box dimensions.

  • system_properties (dict | None) – System properties for sampling, if applicable.

  • num_bins (int) – Number of bins for histogram sampling.

  • direction (str) –

    Direction options, depending on the dimension:

    • (“x”, “y”, or “z”) for “Cartesian1D”.

    • (“xy”, “xz”, or “yz”) for “Cartesian2D”.

    • (“r”, “p”, or “d”) for “Pore1D”.

    • (“rp”, “rz”, or “pz”) for “Pore2D”.

  • conditions (dict | None) – Additional conditions for sampling. - “Charge”: tuple (min_charge, max_charge) - “Angle”: tuple (min_angle, max_angle) using angle type all

sample(frame_id, molecule_mask, molecule_bond_atoms, bond_mask, frame, bond_enum, positions_transformed)[source]

Sample data for the current frame.

Parameters:
  • frame_id (int) – Frame index in perspective of the subprocess (starts from 0 for each subprocess).

  • molecule_mask (dict) – Dictionary mapping molecule identifiers to boolean masks indicating which atoms belong to that molecule in the frame.

  • molecule_bond_atoms (dict) – Dictionary mapping molecule identifiers to their bonded atom indices in the frame.

  • bond_mask (dict) – Dictionary mapping bond identifiers to boolean masks indicating which bonds belong to that identifier in the frame.

  • frame (object) – Current frame object from OVITO containing atomic data.

  • bond_enum (object) – OVITO BondsEnumerator object for enumerating bonds in the frame.

  • positions_transformed (ndarray) – Transformed positions of atoms in the current frame.

class porereax.density.BondDensitySampler(name_out, bonds, dimension, region, process_id, atom_lib, masses, num_frames, box, system_properties, num_bins, direction, conditions=None)[source]

Bases: BondSampler

Sampler class for bond densities.

Parameters:
  • name_out (str) – Name of the output file of the sampler data

  • bonds (list) –

    List of bonds to sample, each specified as a dictionary with keys:

    • ”bond”: str, the bond in format “A-B”

    • ”bonds_A”: list, optional, list of bonded atom types for atom A. Each entry may be a plain atom type string or a nested dictionary describing a required bonding environment for that neighbour, see “bonds” in AtomSampler, including “X” as a wildcard atom type.

    • ”bonds_B”: list, optional, list of bonded atom types for atom B, with the same nested-dictionary support as “bonds_A”.

  • dimension (Dimension) – Dimension along which to sample.

  • region (Region) – Region specification for sampling. Can be a string defining a geometric region or a function that takes coordinates and returns a boolean mask.

  • process_id (int) – Process ID for parallel processing.

  • atom_lib (dict) – Dictionary mapping atom type strings to their type IDs.

  • masses (dict) – Dictionary mapping atom type strings to their masses.

  • num_frames (int) – Total number of frames to sample.

  • box (ndarray) – Simulation box dimensions.

  • system_properties (dict | None) – System properties for sampling, if applicable.

  • num_bins (int) – Number of bins for histogram sampling.

  • direction (str) –

    Direction options, depending on the dimension:

    • (“x”, “y”, or “z”) for “Cartesian1D”.

    • (“xy”, “xz”, or “yz”) for “Cartesian2D”.

    • (“r”, “p”, or “d”) for “Pore1D”.

    • (“rp”, “rz”, or “pz”) for “Pore2D”.

  • conditions (dict | None) – Additional conditions for sampling. - “Bond Length”: tuple (min_length, max_length)

sample(frame_id, molecule_mask, molecule_bond_atoms, bond_mask, frame, bond_enum, positions_transformed)[source]

Sample data for the current frame.

Parameters:
  • frame_id (int) – Frame index in perspective of the subprocess (starts from 0 for each subprocess).

  • molecule_mask (dict) – Dictionary mapping molecule identifiers to boolean masks indicating which atoms belong to that molecule in the frame.

  • molecule_bond_atoms (dict) – Dictionary mapping molecule identifiers to their bonded atom indices in the frame.

  • bond_mask (dict) – Dictionary mapping bond identifiers to boolean masks indicating which bonds belong to that identifier in the frame.

  • frame (object) – Current frame object from OVITO containing atomic data.

  • bond_enum (object) – OVITO BondsEnumerator object for enumerating bonds in the frame.

  • positions_transformed (ndarray) – Transformed positions of atoms in the current frame.

class porereax.density.ReactionSampler(name_out, reactions, dimension, region, process_id, atom_lib, masses, num_frames, box, system_properties, num_bins, direction, position)[source]

Bases: AtomSampler

Sampler class for reaction events based on bond formation and breaking.

Parameters:
  • name_out (str) – Name of the output file of the sampler data

  • reactions (list) –

    List of reactions to sample, each specified as a tuple of two dictionaries (reactant_dict, product_dict): Each dictionary should have keys:

    • ”atom”: str, the atom type string.

    • ”bonds”: list, optional, list of bonded atom types.

  • dimension (Dimension) – Dimension along which to sample.

  • region (Region) – Region specification for sampling. Can be a string defining a geometric region or a function that takes coordinates and returns a boolean mask.

  • process_id (int) – Process ID for parallel processing.

  • atom_lib (dict) – Dictionary mapping atom type strings to their type IDs.

  • masses (dict) – Dictionary mapping atom type strings to their masses.

  • num_frames (int) – Total number of frames to sample.

  • box (ndarray) – Simulation box dimensions.

  • system_properties (dict | None) – System properties for sampling, if applicable.

  • num_bins (int) – Number of bins for histogram sampling.

  • direction (str) –

    Direction options, depending on the dimension:

    • (“x”, “y”, or “z”) for “Cartesian1D”.

    • (“xy”, “xz”, or “yz”) for “Cartesian2D”.

    • (“r”, “p”, or “d”) for “Pore1D”.

    • (“rp”, “rz”, or “pz”) for “Pore2D”.

  • position (Literal['center', 'reactant', 'product']) –

    Position to sample for reaction events. Options:

    • ”center”: Sample at the midpoint of the reactant and product positions.

    • ”reactant”: Sample at the position of the reactant.

    • ”product”: Sample at the position of the product.

sample(frame_id, molecule_mask, molecule_bond_atoms, bond_mask, frame, bond_enum, positions_transformed)[source]

Sample data for the current frame.

Parameters:
  • frame_id (int) – Frame index in perspective of the subprocess (starts from 0 for each subprocess).

  • molecule_mask (dict) – Dictionary mapping molecule identifiers to boolean masks indicating which atoms belong to that molecule in the frame.

  • molecule_bond_atoms (dict) – Dictionary mapping molecule identifiers to their bonded atom indices in the frame.

  • bond_mask (dict) – Dictionary mapping bond identifiers to boolean masks indicating which bonds belong to that identifier in the frame.

  • frame (object) – Current frame object from OVITO containing atomic data.

  • bond_enum (object) – OVITO BondsEnumerator object for enumerating bonds in the frame.

  • positions_transformed (ndarray) – Transformed positions of atoms in the current frame.