mofbuilder.io.GroWriter#
- class mofbuilder.io.GroWriter(comm=None, ostream=None, filepath=None, debug=False)[source]#
Bases:
objectWrite atomic structure data to GROMACS .gro coordinate files.
Handles formatting, unit conversion, residue management, and MPI-based output stream selection. Supports both orthorhombic and triclinic box specification.
- Parameters:
comm (Any | None)
ostream (veloxchem.outputstream.OutputStream | None)
filepath (str | None)
debug (bool)
- comm#
MPI communicator.
- Type:
MPI.Comm
- rank#
MPI process rank.
- Type:
int
- nodes#
Number of MPI processes.
- Type:
int
- ostream#
Output stream for printing/logging.
- Type:
OutputStream
- filepath#
Path to the target .gro file (default None, set by user).
- Type:
Optional[str]
- _debug#
Toggle debug printouts.
- Type:
bool
- file_dir#
Directory containing the output file (set during write).
- Type:
Optional[Path]
- write()[source]#
Write data to a .gro file. Handles formatting and box conversion.
- Parameters:
filepath (str | None)
header (str)
lines (Sequence[Sequence[Any]])
box (Sequence[float] | None)
triclinic (bool)
- Return type:
None
- write(filepath=None, header='Generated by MofBuilder\n', lines=[], box=None, triclinic=False)[source]#
Write atomic coordinates and box information to a .gro coordinate file.
The input ‘lines’ should be a list of lists/arrays, one per atom, following this order: [atom_type, atom_label, atom_number, residue_name, residue_number, x, y, z, spin, charge, note]
- Parameters:
filepath (Optional[str]) – Output .gro file path (overrides instance attribute, required if not set).
header (str) – Header string to write at the top of the .gro file. Defaults to “Generated by MofBuilder”.
lines (Sequence[Sequence[Any]]) – List of atom data lines.
box (Optional[Sequence[float]]) – Box vector or box+extra terms for triclinic (see Note). Units: angstroms.
triclinic (bool) – If True, expects box to have 6 elements.
- Raises:
AssertionError – If filepath is not provided.
AssertionError – If triclinic=True and box does not have 6 elements.
- Return type:
None
Note
Positions (x, y, z) are converted from angstroms to nanometers. Box lengths are also written in nanometers. Triclinic box format: [lx, ly, lz, xy, xz, yz].
Example
>>> writer = GroWriter() >>> writer.write("output.gro", lines=atom_list, box=[30.0, 30.0, 30.0])