box_writer

A module containing the BoxWriter class and its associated methods.

Summary

Classes:

BoxWriter

A class for writing a trajectory to a box file.

Reference

class BoxWriter(
filename: str | None = None,
output_format: str | BoxFileFormat = 'data',
mode: str | FileWritingMode = 'w',
)[source]

Bases: BaseWriter

A class for writing a trajectory to a box file. Inherits from BaseWriter

It can write a trajectory to a box file in either a data file format or a VMD file format. For more information see BoxFileFormat.

Parameters:
  • filename (str, optional) – The name of the file to write to. If None, the output is printed to stdout.

  • output_format (str | BoxFileFormat, optional) – The format of the file. The default is ‘data’ i.e. BoxFileFormat.DATA.

  • mode (str | FileWritingMode, optional) – The mode of the file. Either ‘w’ for write, ‘a’ for append or ‘o’ for overwrite. The default is ‘w’.

Raises:

ValueError – If the given format is not in BoxFileFormat.

__check_pbc__(
traj: Trajectory,
) None[source]

Checks if the cell of the trajectory is not None.

Parameters:

traj (Trajectory) – The trajectory to check.

Raises:

ValueError – If the cell of a frame of the trajectory is None.

write(
traj: Trajectory,
reset_counter: bool = True,
) None[source]

Wrapper to write the given trajectory to the file. Depending on the format, either write_vmd or write_box_file is called.

Parameters:
  • traj (Trajectory) – The trajectory to write.

  • reset_counter (bool, optional) – If True, the function execution counter of write_box_file is reset to 0, otherwise it is not reset.

write_box_file(
traj: Trajectory,
reset_counter: bool = True,
) None[source]

Writes the given trajectory to the file in data file format.

The @count_decorator is used to count the number of frames written to the file. The default way is that the counter is reset to 0 after each call of the function. This can be changed by setting the reset_counter parameter to False.

Parameters:
  • traj (Trajectory) – The trajectory to write.

  • reset_counter (bool, optional) – If True, the counter is reset to 0, otherwise it is not reset.

Raises:

BoxWriterError – If the cell of a frame of the trajectory is None.

write_vmd(
traj: Trajectory,
) None[source]

Writes the given trajectory to the file in VMD format.

Parameters:

traj (Trajectory) – The trajectory to write.

logger = <CustomLogger PQAnalysis.BoxWriter (INFO)>
property output_format: BoxFileFormat

The format of the file.

Type:

BoxFileFormat