Core I/O Macros
These macros handle the fundamental input and output operations for molecular data files.
Read File
OpenBabel.@read_file — Macro@read_file(file_path, file_format)Read molecules from an input file.
Arguments
file_path: Path to the input filefile_format: File format code (e.g., "smi", "mol", "sdf")
Examples
@read_file("molecules.smi", "smi")
@read_file("database.sdf", "sdf")Usage Examples
Basic file reading with format specification:
@chain begin
@read_file("molecules.smi", "smi")
@output_as("molecules.mol", "mol")
@execute
endOutput As
OpenBabel.@output_as — Macro@output_as(expr, file_path, file_format)Specify output file and format for the pipeline.
Arguments
expr: Previous command in the chainfile_path: Output file pathfile_format: Output file format code
Examples
@chain begin
@read_file("input.smi", "smi")
@output_as("output.mol", "mol")
@execute
endUsage Examples
Convert and save to different formats:
# SMILES to SDF conversion
@chain begin
@read_file("compounds.smi", "smi")
@gen_3D_coords("fast")
@output_as("compounds.sdf", "sdf")
@execute
end
# Multiple format outputs
@chain begin
@read_file("molecules.sdf", "sdf")
@output_as("molecules.mol", "mol")
@execute
endWrite Multiple Files
OpenBabel.@write_multiple_files — Macro@write_multiple_files(expr)Write each molecule to a separate output file instead of one combined file.
Arguments
expr: Previous command in the chain
Example
@chain begin
@read_file("molecules.smi", "smi")
@gen_3D_coords("fast")
@write_multiple_files()
@output_as("molecule", "mol") # Creates molecule1.mol, molecule2.mol, etc.
@execute
endUsage Examples
@chain begin
@read_file("database.sdf", "sdf")
@write_multiple_files()
@output_as("molecule", "mol") # Creates molecule1.mol, molecule2.mol, etc.
@execute
endExecute
OpenBabel.@execute — Macro@execute(expr)Execute the constructed OpenBabel pipeline.
Arguments
expr: Complete command chain to execute
Examples
@chain begin
@read_file("input.smi", "smi")
@gen_3D_coords("fast")
@output_as("output.mol", "mol")
@execute
endUsage Examples
Execute the processing pipeline:
@chain begin
@read_file("molecules.smi", "smi")
@add_properties(["MW", "logP"])
@output_as("processed.sdf", "sdf")
@execute # This executes the entire pipeline
endSupported File Formats
The library supports all Open Babel file formats:
| Format | Extension | Description |
|---|---|---|
| SMILES | .smi | Simplified molecular-input line-entry system |
| SDF | .sdf | Structure-data file |
| MOL | .mol | MDL Molfile |
| XYZ | .xyz | XYZ coordinate format |
| PDB | .pdb | Protein Data Bank format |
For a complete list, refer to the Open Babel documentation.
Complete Workflows
Basic File Conversion
@chain begin
@read_file("molecules.smi", "smi")
@output_as("molecules.mol", "mol")
@execute
endBatch Processing with Multiple Outputs
@chain begin
@read_file("database.sdf", "sdf")
@write_multiple_files()
@output_as("molecule", "mol")
@execute
end