irradiapy.utils package
Submodules
irradiapy.utils.io module
Utility functions for I/O operations.
- irradiapy.utils.io.apply_boundary_conditions_to_lammps(path_in, path_out, x, y, z, overwrite=False)[source]
Apply periodic boundary conditions to a LAMMPS dump file.
- Parameters:
path_in (Path) – Path to the input LAMMPS file (bzip2 compressed or not).
path_out (Path) – Path to the output LAMMPS file (bzip2 compressed or not).
x (bool) – Whether to apply periodic boundary conditions in the x direction.
y (bool) – Whether to apply periodic boundary conditions in the y direction.
z (bool) – Whether to apply periodic boundary conditions in the z direction.
overwrite (bool, optional (default=False)) – Whether to overwrite the output file if it exists.
- Return type:
- irradiapy.utils.io.compress_file_bz2(input_path, output_path, compresslevel=9)[source]
Compress a file using bzip2.
- irradiapy.utils.io.decompress_file_bz2(input_path, output_path)[source]
Decompress a bzip2-compressed file.
- irradiapy.utils.io.get_last_lammps_dump(path)[source]
Get the last snaptshot from a LAMMPS dump file.
- Parameters:
path (Path) – Path to the LAMMPS dump file.
- Returns:
The last snapshot from the LAMMPS dump file.
- Return type:
defaultdict
- irradiapy.utils.io.merge_lammps_snapshots(path_in, path_out, overwrite=False)[source]
Merge multiple snapshots in a LAMMPS file into a single snapshot.
- Parameters:
path_in (Path) – Path to the input LAMMPS file (bzip2 compressed or not).
path_out (Path) – Path to the output LAMMPS file (bzip2 compressed or not).
overwrite (bool, optional (default=False)) – Whether to overwrite the output file if it exists.
- Returns:
A dictionary containing the merged snapshot data.
- Return type:
defaultdict
irradiapy.utils.math module
This module contains math utilities for the irradiapy package.
- irradiapy.utils.math.apply_boundary_conditions(data_atoms, x, y, z)[source]
Apply boundary conditions to atoms.
- Parameters:
data_atoms (defaultdict[str, Any]) – Atoms data containing atom positions and boundaries.
x (bool) – Whether to apply periodic boundary conditions in the x direction.
y (bool) – Whether to apply periodic boundary conditions in the y direction.
z (bool) – Whether to apply periodic boundary conditions in the z direction.
- Returns:
Updated atoms data with applied boundary conditions.
- Return type:
defaultdict[str, Any]
- irradiapy.utils.math.fit_gaussian(xs, ys, p0=None, asymmetry=1.0)[source]
Fit data to a Gaussian function.
- Parameters:
xs (npt.NDArray[np.float64]) – X values where the function is evaluated.
ys (npt.NDArray[np.float64]) – Y values at the given xs.
p0 (npt.NDArray[np.float64], optional (default=None)) – Initial guess of fit parameters. If None, a guess is generated.
asymmetry (float, optional (default=1.0)) – Bound for the asymmetry fit parameter. Fit will be done in (-asymmetry, asymmetry).
- Return type:
tuple[ndarray[tuple[Any,...],dtype[float64]],ndarray[tuple[Any,...],dtype[float64]],Callable[[ndarray[tuple[Any,...],dtype[float64]]],ndarray[tuple[Any,...],dtype[float64]]]]- Returns:
popt (npt.NDArray[np.float64]) – Optimal values for the parameters.
pcov (npt.NDArray[np.float64]) – Covariance of popt.
fit_function (Callable[[npt.NDArray[np.float64]], npt.NDArray[np.float64]]) – Function that evaluates the fitted Gaussian.
- irradiapy.utils.math.fit_lorentzian(xs, ys, p0=None, asymmetry=1.0)[source]
Fit data to a Lorentzian function.
- Parameters:
xs (npt.NDArray[np.float64]) – X values where the function is evaluated.
ys (npt.NDArray[np.float64]) – Y values at the given xs.
p0 (npt.NDArray[np.float64], optional (default=None)) – Initial guess of fit parameters. If None, a guess is generated.
asymmetry (float, optional (default=1.0)) – Bound for the asymmetry fit parameter. Fit will be done in (-asymmetry, asymmetry).
- Return type:
tuple[ndarray[tuple[Any,...],dtype[float64]],ndarray[tuple[Any,...],dtype[float64]],Callable[[ndarray[tuple[Any,...],dtype[float64]]],ndarray[tuple[Any,...],dtype[float64]]]]- Returns:
popt (npt.NDArray[np.float64]) – Optimal values for the parameters.
pcov (npt.NDArray[np.float64]) – Covariance of popt.
fit_function (Callable[[npt.NDArray[np.float64]], npt.NDArray[np.float64]]) – Function that evaluates the fitted Lorentzian.
- irradiapy.utils.math.fit_scaling_law(centers, counts)[source]
Fit a scaling law to the given histogram data.
- Parameters:
centers (npt.NDArray[np.float64]) – The centers of the bins.
counts (npt.NDArray[np.float64]) – The values of the histogram.
- Returns:
A tuple containing: the prefactor of the scaling law, the exponent of the scaling law, and the scaling law function.
- Return type:
- irradiapy.utils.math.gaussian(xs, x_peak, linewidth, amplitude, asymmetry)[source]
Evaluate a Gaussian function.
- Parameters:
- Returns:
Evaluated Gaussian function.
- Return type:
float | npt.NDArray[np.float64]
References
- irradiapy.utils.math.lorentzian(xs, x_peak, linewidth, amplitude, asymmetry)[source]
Evaluate a Lorentzian function.
- Parameters:
- Returns:
Evaluated Lorentzian function.
- Return type:
float | npt.NDArray[np.float64]
References
- irradiapy.utils.math.recombine_in_radius(data_defects, radius)[source]
Recombine defects (interstitials and vacancies) within a given radius.
Takes into account periodic boundary conditions.
irradiapy.utils.mpi module
Utilities for MPI-related functionalities.
- class irradiapy.utils.mpi.MPIExceptionHandlerMixin[source]
Bases:
objectProvides a common MPI exception handler method when mpi_safe_method cannot be used.
This is useful for __init__ and __post_init__ methods where decorators cannot be applied because self.comm and self.rank are not yet defined before the function is called. You can use this method after the comm and rank attributes are initialized in a try/except block.
- class irradiapy.utils.mpi.MPITagAllocator[source]
Bases:
objectA class to allocate unique tags for processes.
- irradiapy.utils.mpi.ap_rm_file(original, target, comm)[source]
Append content from original to target and delete original.
- Return type:
- irradiapy.utils.mpi.cp_file(original, target, comm)[source]
Copy a file from original to target, overwriting target if it exists.
- Return type:
- irradiapy.utils.mpi.mpi_safe_method(method)[source]
Decorator that wraps an MPI-using method so any exception prints a traceback with the current rank and then calls MPI.Abort.
The method should be a member of a class that has comm and rank attributes.
- irradiapy.utils.mpi.mpi_subdomains_decomposition(n)[source]
Factor n into three integers nx, ny, nz for MPI decomposition into subdomains.
nx, ny and nz are such that: - nx * ny * nz == n - the maximum of (nx, ny, nz) divided by the minimum is as small as possible.
irradiapy.utils.sqlite module
sqlite3 utilities.
- irradiapy.utils.sqlite.delete_all_arrays(path_db)[source]
Drop the arrays table from the database.
- Parameters:
path_db (Path) – Path to the SQLite database file.
- Return type:
Module contents
Utilities subpackage.