Core I/O Macros

These macros handle the fundamental input and output operations for molecular data files.

Read File

OpenBabel.@read_fileMacro
@read_file(file_path, file_format)

Read molecules from an input file.

Arguments

  • file_path: Path to the input file
  • file_format: File format code (e.g., "smi", "mol", "sdf")

Examples

@read_file("molecules.smi", "smi")
@read_file("database.sdf", "sdf")
source

Usage Examples

Basic file reading with format specification:

@chain begin
    @read_file("molecules.smi", "smi")
    @output_as("molecules.mol", "mol")
    @execute
end

Output As

OpenBabel.@output_asMacro
@output_as(expr, file_path, file_format)

Specify output file and format for the pipeline.

Arguments

  • expr: Previous command in the chain
  • file_path: Output file path
  • file_format: Output file format code

Examples

@chain begin
    @read_file("input.smi", "smi")
    @output_as("output.mol", "mol")
    @execute
end
source

Usage 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
end

Write Multiple Files

OpenBabel.@write_multiple_filesMacro
@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
end
source

Usage Examples

@chain begin
    @read_file("database.sdf", "sdf")
    @write_multiple_files()
    @output_as("molecule", "mol")  # Creates molecule1.mol, molecule2.mol, etc.
    @execute
end

Execute

OpenBabel.@executeMacro
@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
end
source

Usage 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
end

Supported File Formats

The library supports all Open Babel file formats:

FormatExtensionDescription
SMILES.smiSimplified molecular-input line-entry system
SDF.sdfStructure-data file
MOL.molMDL Molfile
XYZ.xyzXYZ coordinate format
PDB.pdbProtein 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
end

Batch Processing with Multiple Outputs

@chain begin
    @read_file("database.sdf", "sdf")
    @write_multiple_files()
    @output_as("molecule", "mol")
    @execute
end