mofbuilder.io.XyzWriter#
- class mofbuilder.io.XyzWriter(comm=None, ostream=None, filepath=None, debug=False)[source]#
Bases:
objectWriter for XYZ coordinate files.
Provides functionality to write molecular structure data to XYZ files, optionally with MPI parallel awareness and flexible stream/file handling.
- Parameters:
comm (Any | None)
ostream (veloxchem.outputstream.OutputStream | None)
filepath (str | None)
debug (bool)
- comm#
MPI communicator used for parallel operations.
- Type:
Any
- rank#
MPI rank of the current process.
- Type:
int
- nodes#
Total number of MPI nodes.
- Type:
int
- ostream#
Output stream for logging/info.
- Type:
OutputStream
- filepath#
Default path to write the XYZ file if not provided per call.
- Type:
Optional[str]
- _debug#
If True, debug information is printed.
- Type:
bool
- file_dir#
Directory of the current file to write (only set when writing).
- Type:
Optional[Path]
- write(filepath, header, lines)[source]#
Write the atom coordinates to an XYZ file.
- Parameters:
filepath (str | None)
header (str)
lines (Sequence[Sequence[Any]])
- Return type:
None
- get_xyzlines(header, lines)[source]#
Return formatted XYZ lines as a list of strings.
- Parameters:
header (str)
lines (Sequence[Sequence[Any]])
- Return type:
List[str]
- write(filepath=None, header='', lines=[])[source]#
Write atom coordinate lines to an XYZ file.
- Parameters:
filepath (Optional[str]) – Output XYZ file path. Uses instance default if not specified.
header (str) – Optional header/comment line (is line #2 in XYZ format).
lines (Sequence[Sequence[Any]]) –
Each entry must have fields for atom_type, atom_label, atom_number, residue_name, residue_number, x, y, z, spin, charge, note.
Only atom_label, x, y, z are directly written to the XYZ file.
- Raises:
AssertionError – If filepath is not specified or invalid.
- Return type:
None
Note
XYZ file will be written only by the master MPI rank. If the file extension is not ‘.xyz’, it is automatically added.
- get_xyzlines(header='', lines=[])[source]#
Return formatted XYZ contents as a list of strings.
- Args:
header (str): Optional header/comment line for XYZ content. lines (Sequence[Sequence[Any]]): List of per-atom info, each entry
having the fields: atom_type, atom_label, atom_number, residue_name, residue_number, x, y, z, spin, charge, note. Only atom_label, x, y, z are written.
- Returns:
List[str]: Formatted XYZ contents as a list of strings.
- Example:
xyz_lines = writer.get_xyzlines(header=”Example molecule”, lines=my_atomlist) # ‘
‘.join(xyz_lines) is a complete XYZ file or block.
- Parameters:
header (str)
lines (Sequence[Sequence[Any]])
- Return type:
List[str]