Transform Behaviors¶
The format_transform method is available on both FileBatchModelDisk and
individual file objects. It converts between chemical file formats while
preserving as much structure-level information as the target format allows.
For parameter defaults, return values, and error policy, see API Contracts.
from molop import AutoParser
batch = AutoParser("results/*.out", n_jobs=1)
rendered = batch.format_transform("xyz", frame=-1, write_to_disk=False)
The result is a mapping from each absolute source path to rendered text (or
a list of texts when embed_in_one_file=False). No output file is created.
from pathlib import Path
from molop import AutoParser
Path("structures").mkdir(parents=True, exist_ok=True)
batch = AutoParser("results/*.out", n_jobs=1)
batch.format_transform(
"xyz",
output_dir="structures",
write_to_disk=True,
)
The batch API requires output_dir to exist. The CLI creates its
--output-dir; both APIs replace only the source file’s final suffix.
Warning
A coordinate writer cannot preserve properties that the target format has no representation for. Use a graph-capable target for bonding data and a QM-aware target when energies or frequencies must remain available.
Key Behaviors¶
- Frame Selection: By default, only the last frame (
frame=-1) is transformed. You can specifyframe="all"or a sequence of frame IDs to transform more frames. - Embedding: If
embed_in_one_file=True(default), multiple frames are combined into a single output file if the format supports it (e.g., SDF or multi-frame XYZ). - File Output: Python callers must pass
write_to_disk=Trueto write rendered content to disk. When writing,file_pathor batchoutput_dirselects the output location; if no path is provided, MolOP writes beside the source file. Output names replace only the final suffix, soname.hash.logbecomesname.hash.xyzwhen converting to XYZ. Whenwrite_to_disk=False,file_pathandoutput_dirare ignored and the transform only returns the rendered string or list of strings. - Structure Level:
- COORDS (Coordinate Level): Formats such as
xyz,gjf, andorcainpprimarily preserve atomic coordinates and elements. - GRAPH (Graph Level): Formats like
sdf,smi, andcmlpreserve bonding information (molecular graph). If the source file only has coordinates (e.g., a.logfile), MolOP will automatically attempt to reconstruct the molecular graph using its built-in algorithms.
- COORDS (Coordinate Level): Formats such as
- Metadata Preservation:
- The
gjfwriter preserves structured Gaussian directives and keywords. Theorcainpreader parses ORCA keywords, blocks, and geometry into frame fields; its registered canonical writer can build a new input from a coordinate-bearing frame plus explicitkeywords, resources, and blocks, but does not promise source-preserving round trips. - Computational properties (energies, frequencies) are generally NOT preserved when transforming to simple coordinate formats like XYZ, although some formats like SDF can store them as properties.
- The