irradiapy.io package

Submodules

Module contents

This subpackage provides classes for reading and writing various file formats.

class irradiapy.io.BZIP2LAMMPSReader(file_path, encoding='utf-8')[source]

Bases: object

A class to read data from a bzip2-compressed LAMMPS dump file.

Note

Assumed orthogonal simulation box.

Variables:
  • file_path (Path) – The path to the bzip2-compressed LAMMPS dump file.

  • encoding (str, optional (default="utf-8")) – The file encoding.

Yields:

dict[str, Any] – A dictionary containing the timestep data with keys: ‘time’ (optional), ‘timestep’, ‘boundary’, ‘xlo’, ‘xhi’, ‘ylo’, ‘yhi’, ‘zlo’, ‘zhi’, and ‘atoms’ (as a numpy structured array).

close()[source]

Close the file associated with this reader.

Return type:

None

encoding: str = 'utf-8'
file_path: Path
class irradiapy.io.BZIP2LAMMPSReaderMPI(file_path, encoding='utf-8', comm=<factory>, parallelization=0)[source]

Bases: MPIExceptionHandlerMixin

A class to read data from a LAMMPS dump file compressed with bzip2 in parallel using MPI.

Note

Assumed orthogonal simulation box.

Note

Rank 0 performs indexed, multi-threaded decompression using indexed_bzip2 of each timestep one by one, then scatters strings of atom data to all ranks, which build local numpy structured arrays.

Parameters:
  • file_path (Path) – Path to the .bz2 LAMMPS dump file.

  • encoding (str) – Text encoding used inside the dump (default: ‘utf-8’).

  • comm (Comm) – The MPI communicator (default: MPI.COMM_WORLD).

  • parallelization (int) – indexed_bzip2 parallelization setting. 0 = use all cores (recommended); 1 = serial; N > 1 = use N threads.

Yields:

dict[str, Any] – A dictionary containing the timestep data with keys: ‘time’ (optional), ‘timestep’, ‘boundary’, ‘xlo’, ‘xhi’, ‘ylo’, ‘yhi’, ‘zlo’, ‘zhi’, and ‘atoms’ (as a numpy structured array).

close()[source]

Closes the file associated with this reader.

Return type:

None

comm: Comm
encoding: str = 'utf-8'
file_path: Path
parallelization: int = 0
class irradiapy.io.BZIP2LAMMPSWriter(file_path, mode='wt', encoding=<factory>, newline=<factory>, compresslevel=9, int_format=<factory>, float_format=<factory>, excluded_items=<factory>)[source]

Bases: object

A class to write data like a LAMMPS dump file, but compressed with bzip2.

Note

Assumed orthogonal simulation box.

Variables:
  • file_path (Path) – The path to the bzip2-compressed LAMMPS dump file.

  • mode (str, optional (default="wt")) – The file open mode.

  • encoding (str, optional (default=irradiapy.config.ENCODING)) – The file encoding.

  • newline (str, optional (default=irradiapy.config.NEWLINE)) – The newline character for the file.

  • compresslevel (int, optional (default=9)) – The bzip2 compression level.

  • int_format (str, optional (default=irradiapy.config.INT_FORMAT)) – The format for integers.

  • float_format (str, optional (default=irradiapy.config.FLOAT_FORMAT)) – The format for floats.

  • excluded_items (list[str], optional (default=irradiapy.config.EXCLUDED_ITEMS)) – Atom fields to exclude from output.

close()[source]

Closes the file associated with this writer.

Return type:

None

compresslevel: int = 9
encoding: str
excluded_items: list[str]
file_path: Path
float_format: str
int_format: str
mode: str = 'wt'
newline: str
write(data)[source]

Write the data to the file.

Parameters:

data (dict[str, Any]) – A dictionary containing the data to be written. The keys should include “timestep”, “boundary”, “xlo”, “xhi”, “ylo”, “yhi”, “zlo”, “zhi”, and “atoms”. Optional keys: “time”.

Return type:

None

class irradiapy.io.BZIP2LAMMPSWriterMPI(file_path, mode='wb', encoding=<factory>, comm=<factory>, compresslevel=9, int_format=<factory>, float_format=<factory>, excluded_items=<factory>)[source]

Bases: MPIExceptionHandlerMixin

A class to write data like a LAMMPS dump bzip2 compressed file in parallel using MPI.

Note

Assumed orthogonal simulation box.

Note

All ranks compute their local subdomain of atoms, then rank 0 collects and writes the data.

Parameters:
  • file_path (Path) – Output .bz2 path.

  • mode (str) – File mode for the container file opened on rank 0 (default: ‘wb’).

  • encoding (str) – The file encoding.

  • comm (Comm) – The MPI communicator.

  • compresslevel (int) – Compression level for bzip2.

  • int_format (str) – The format for integers.

  • float_format (str) – The format for floats.

  • excluded_items (list[str]) – Atom fields to exclude from output.

close()[source]

Closes the file associated with this writer.

Return type:

None

comm: Comm
compresslevel: int = 9
encoding: str
excluded_items: list[str]
file_path: Path
float_format: str
int_format: str
mode: str = 'wb'
write(data)[source]

Write the data to the file.

Parameters:

data (dict[str, Any]) – A dictionary containing the data to be written. The keys should include “timestep”, “boundary”, “xlo”, “xhi”, “ylo”, “yhi”, “zlo”, “zhi”, and “atoms”. Optional keys: “time”.

Return type:

None

class irradiapy.io.LAMMPSLogReader(log_path)[source]

Bases: object

Class to read LAMMPS log files.

Parameters:

log_path (Path) – The path to the LAMMPS log file.

Yields:

Generator[dict[str, Any], None, None] – A dictionary containing the thermo data.

Note

This generator yields a dictionary with a single key for the thermo data, this ensures compatibility if this reader is extended to read more data in the future.

data: dict
get_pka_data()[source]

Extract PKA data if exists.

Return type:

defaultdict

log_path: Path
thermo: NDArray[float64]
class irradiapy.io.LAMMPSReader(file_path, encoding='utf-8')[source]

Bases: object

A class to read data from a LAMMPS dump file.

Note

Assumed orthogonal simulation box.

Variables:
  • file_path (Path) – The path to the LAMMPS dump file.

  • encoding (str, optional (default="utf-8")) – The file encoding.

Yields:

dict[str, Any] – A dictionary containing the timestep data with keys: ‘time’ (optional), ‘timestep’, ‘boundary’, ‘xlo’, ‘xhi’, ‘ylo’, ‘yhi’, ‘zlo’, ‘zhi’, and ‘atoms’ (as a numpy structured array).

close()[source]

Close the file associated with this reader.

Return type:

None

encoding: str = 'utf-8'
file_path: Path
class irradiapy.io.LAMMPSReaderMPI(file_path, encoding='utf-8', comm=<factory>)[source]

Bases: MPIExceptionHandlerMixin

A class to read data from a LAMMPS dump file in parallel using MPI.

Note

Assumed orthogonal simulation box.

Note

Rank 0 reads each timestep one by one, then scatters strings of atom data to all ranks, which build local numpy structured arrays.

Variables:
  • file_path (Path) – The path to the LAMMPS dump file.

  • encoding (str, optional (default="utf-8")) – The file encoding.

  • comm (MPI.Comm, optional (default=mpi4py.MPI.COMM_WORLD)) – The MPI communicator.

Yields:

dict[str, Any] – A dictionary containing the timestep data with keys: ‘time’ (optional), ‘timestep’, ‘boundary’, ‘xlo’, ‘xhi’, ‘ylo’, ‘yhi’, ‘zlo’, ‘zhi’, and ‘atoms’ (as a numpy structured array).

close()[source]

Closes the file associated with this reader.

Return type:

None

comm: Comm
encoding: str = 'utf-8'
file_path: Path
class irradiapy.io.LAMMPSWriter(file_path, mode='w', encoding=<factory>, newline=<factory>, int_format=<factory>, float_format=<factory>, excluded_items=<factory>)[source]

Bases: object

A class to write data like a LAMMPS dump file.

Note

Assumed orthogonal simulation box.

Variables:
  • file_path (Path) – The path to the LAMMPS dump file.

  • mode (str, optional (default="w")) – The file open mode.

  • encoding (str, optional (default=irradiapy.config.ENCODING)) – The file encoding.

  • newline (str, optional (default=irradiapy.config.NEWLINE)) – The newline character for the file.

  • int_format (str, optional (default=irradiapy.config.INT_FORMAT)) – The format for integers.

  • float_format (str, optional (default=irradiapy.config.FLOAT_FORMAT)) – The format for floats.

  • excluded_items (list[str], optional (default=irradiapy.config.EXCLUDED_ITEMS)) – Atom fields to exclude from output.

close()[source]

Closes the file associated with this writer.

Return type:

None

encoding: str
excluded_items: list[str]
file_path: Path
float_format: str
int_format: str
mode: str = 'w'
newline: str
write(data)[source]

Write the data to the file.

Parameters:

data (dict[str, Any]) – A dictionary containing the data to be written. The keys should include “timestep”, “boundary”, “xlo”, “xhi”, “ylo”, “yhi”, “zlo”, “zhi”, and “atoms”. Optional keys: “time”.

Return type:

None

class irradiapy.io.LAMMPSWriterMPI(file_path, mode='w', encoding=<factory>, newline=<factory>, comm=<factory>, int_format=<factory>, float_format=<factory>, excluded_items=<factory>)[source]

Bases: MPIExceptionHandlerMixin

A class to write data like a LAMMPS dump file in parallel using MPI.

Note

Assumes orthogonal simulation box.

Variables:
  • file_path (Path) – The path to the LAMMPS dump file.

  • mode (str, optional (default="w")) – The file open mode.

  • encoding (str, optional (default=irradiapy.config.ENCODING)) – The file encoding.

  • newline (str, optional (default=irradiapy.config.NEWLINE)) – The newline character for the file.

  • comm (MPI.Comm, optional (default=mpi4py.MPI.COMM_WORLD)) – The MPI communicator.

  • int_format (str, optional (default=irradiapy.config.INT_FORMAT)) – The format for integers.

  • float_format (str, optional (default=irradiapy.config.FLOAT_FORMAT)) – The format for floats.

  • excluded_items (list[str], optional (default=irradiapy.config.EXCLUDED_ITEMS)) – Atom fields to exclude from output.

close()[source]

Closes the file associated with this writer.

Return type:

None

comm: Comm
encoding: str
excluded_items: list[str]
file_path: Path
float_format: str
int_format: str
mode: str = 'w'
newline: str
write(data)[source]

Write the data to the file.

Parameters:

data (dict[str, Any]) – A dictionary containing the data to be written. The keys should include “timestep”, “boundary”, “xlo”, “xhi”, “ylo”, “yhi”, “zlo”, “zhi”, and “atoms”. Optional keys: “time”.

Return type:

None

class irradiapy.io.XYZReader(file_path, encoding='utf-8')[source]

Bases: object

A class to read data from an extended XYZ file.

Variables:
  • file_path (Path) – The path to the XYZ file.

  • dtype (npt.DTypeLike) – The data type of the properties in the file. By default, it is set to None and will be determined from the file.

dtype: DTypeLike = None
encoding: str = 'utf-8'
file: TextIO = None
file_path: Path
class irradiapy.io.XYZWriter(file_path, mode='w', encoding=<factory>, int_format=<factory>, float_format=<factory>)[source]

Bases: object

Class for writing structured data to an XYZ file format.

Parameters:
  • file_path (Path) – Path to the file where data will be written.

  • mode (str) – File open mode.

  • encoding (str) – The file encoding.

  • int_format (str) – Format for integers.

  • float_format (str) – Format for floats.

close()[source]

Close the file associated with this writer.

Return type:

None

encoding: str
file: TextIO = None
file_path: Path
float_format: str
int_format: str
mode: str = 'w'
write(datas, extra_comment='')[source]

Writes the given data into the file.

Parameters:
  • datas (NDArray) – Data to write.

  • extra_comment (str) – Additional info to add at the end of the comment. Must follow xyz guidelines. For example: ‘Info=”Fe irradiated in Fe, Ion 1”’

Return type:

None