nep_writer

A module containing the NEPWriter class to write NEP training and testing files.

Summary

Classes:

NEPWriter

A class to write NEP training and testing files.

Reference

class NEPWriter(
filename: str | None,
mode: FileWritingMode | str = 'w',
)[source]

Bases: BaseWriter

A class to write NEP training and testing files.

Parameters:
  • filename (str) – _description_

  • mode (FileWritingMode | str, optional) – _description_, by default “w”

write_from_atomic_system(
system: AtomicSystem,
file: TextIOWrapper | None,
use_forces: bool = False,
use_stress: bool = False,
use_virial: bool = False,
) None[source]

Writes the NEP trajectory file from the given atomic system.

Parameters:
  • system (AtomicSystem) – The system to be written to the NEP trajectory file.

  • file (_io.TextIOWrapper) – The file to write the NEP trajectory file to. If None, nothing is written

  • use_forces (bool, optional) – Whether to write the forces to the NEP trajectory file, by default False

  • use_stress (bool, optional) – Whether to write the stress tensor to the NEP trajectory file, by default False

  • use_virial (bool, optional) – Whether to write the virial tensor to the NEP trajectory file, by default False

Raises:
  • ValueError – If the system does not have coordinates.

  • ValueError – If the system does not have an energy.

  • ValueError – If the system does not have forces and they were specified to be written to the NEP trajectory file.

  • ValueError – If both the stress and the virial tensor were specified to be written to the NEP trajectory file. Only one of them can be written at a time.

  • ValueError – If the system does not have a stress tensor and it was specified to be written to the NEP trajectory file.

  • ValueError – If the system does not have a virial tensor and it was specified to be written to the NEP trajectory file.

write_from_files(
file_prefixes: list[str] | str,
use_forces: bool = False,
use_stress: bool = False,
use_virial: bool = False,
xyz_file_extension: str | None = None,
energy_file_extension: str | None = None,
info_file_extension: str | None = None,
force_file_extension: str | None = None,
stress_file_extension: str | None = None,
virial_file_extension: str | None = None,
test_ratio: PositiveReal = 0.0,
total_ratios: str | None = None,
) None[source]

Writes the NEP trajectory file from the given files.

Parameters:
  • file_prefixes (List[str] | str) – The prefixes of the files to find. Here with prefix we mean the part of the filename not only the name before the extension, but every matching file that starts with the given prefix.

  • use_forces (bool, optional) – Whether to include forces in the output file, by default False

  • use_stress (bool, optional) – Whether to include the stress tensor in the output file, by default False

  • use_virial (bool, optional) – Whether to include the virial in the output file, by default False

  • xyz_file_extension (str, optional) – The extension of the xyz files, by default None. This means that the respective file extension will be automatically determined from all files with the given file prefixes.

  • energy_file_extension (str, optional) – The extension of the energy files, by default None. This means that the respective file extension will be automatically determined from all files with the given file prefixes.

  • info_file_extension (str, optional) – The extension of the info files, by default None. This means that the respective file extension will be automatically determined from all files with the given file prefixes.

  • force_file_extension (str, optional) – The extension of the force files, by default None. This means that the respective file extension will be automatically determined from all files with the given file prefixes.

  • stress_file_extension (str, optional) – The extension of the stress files, by default None. This means that the respective file extension will be automatically determined from all files with the given file prefixes.

  • virial_file_extension (str, optional) – The extension of the virial files, by default None. This means that the respective file extension will be automatically determined from all files with the given file prefixes.

  • test_ratio (PositiveReal, optional) – The ratio of testing frames to the total number of frames, by default 0.0. If the test_ratio is 0.0 no train and test files are created. If the test_ratio is larger not equal to 0.0, the test_ratio is used to determine the number of training and testing frames. The final ratio will be as close to the test_ratio as possible, but if it is not possible to have the exact ratio, always the higher next higher ratio is chosen. As output filenames the original filename is used with the suffix _train or _test appended and the same FileWritingMode as the original file is used.

  • total_ratios (str, optional) – The total_ratios keyword argument is used to describe frame ratios including validation frames in the format train_ratio:test_ratio:validation_ratio. The validation_ratio is optional and if not given, no validation frames are written. The total sum of the integer values provided do not have to add up to the total number of frames in the input trajectory files. The ratios are used to determine the ratios of the training, testing, and validation frames. The final ratio will be as close to the given ratios as possible, but if it is not possible to have the exact ratio, always the next higher ratio is chosen. As output filenames the original filename is used with the suffix _train, _test, or _validation appended and the same FileWritingMode as the original file is used. The validation frames are written to a file with the suffix _validation and a file with the suffix _validation.ref. The _validation file contains only the coordinates and box information to function as crude testing input and the _validation.ref file contains all information additionally provided in the original files. Pay Attention: This keyword argument is mutually exclusive with the test_ratio keyword argument. If both are given, a ValueError is raised.

Raises:
  • ValueError – If the test_ratio is larger than 1.0.

  • ValueError – If test_ratio and total_ratios are given at the same time.

write_from_trajectory(
trajectory: Trajectory,
use_forces: bool = False,
use_stress: bool = False,
use_virial: bool = False,
) None[source]

Writes the NEP trajectory file from the given trajectory.

Parameters:
  • trajectory (Trajectory) – The trajectory to be written to the NEP trajectory file.

  • use_forces (bool, optional) – Whether to write the forces to the NEP trajectory file, by default False

  • use_stress (bool, optional) – Whether to write the stress tensor to the NEP trajectory file, by default False

  • use_virial (bool, optional) – Whether to write the virial tensor to the NEP trajectory file, by default False

logger = <CustomLogger PQAnalysis.NEPWriter (INFO)>