"obabel -o ... -O" - Output Data Format and Destination

This section provides tutorial examples on how to specify output data format and destination for the Open Babel 'obabel' command.

Open Babel "obabel" command arguments are organized into 3 sections as shown in the following syntax to convert chemical data from input to output with specified options.

obabel input_section output_section option_section

You use output_section to specify Output Data Format and Destination for a "obabel" command. The output_section must be the second section of the "obabel" command line.

The output_section contains to two optional parts to specify output data format and output data destination as shown in the following syntax:

babel input_section [-o output_format] [-O output_name] option_section

1. Output Data Format - There are 2 ways to specify output data format:

1.2. Explicit Format Name - A pre-defined format name is specified after the "-o" option flag with or without a space " ".

Here are some examples of specifying input data formats explicitly:

-o sdf
-osdf
-o smiles
-osmiles
-o svg
-osvg
...

1.2 Implicit Format Name - No "-o" option flag is specified. In this case, the "-O output_name" part is required. Open Babel will determine the output data format implicitly from file name extension of output_name.

For example, the following "obabel" command uses "molecule.svg" as the output_name to determine the output data format as "svg". This command writes data to molecule.svg in "svg" format.

herong$ obabel molecule.sdf -O molecule.svg

1 molecule converted

2. Output Data Destination - There are 3 ways to specify output data destination:

2.1. File name of a single output file - In this case, the output data goes to the specified file.

For example, the following "obabel" command uses "molecule.svg" as the output_section, which specifies a single file named "molecule.svg". This command converts the molecule data from molecule.sdf to molecule.svg.

herong$ obabel molecule.sdf -O molecule.svg

1 molecule converted

2.2. File name prefix and extension for multiple output files with the "-m" option. In this case, the output data goes to multiple files, one per molecule.

For example, the following "obabel" command uses "-O multi_.svg" as the output_section. This command converts molecules from multi.sdf to multi_1.svg, multi_2.svg, ..., because of the "-m" option.

herong$ obabel multi.sdf -O multi_.svg -m
  3 molecules converted
  3 files output. The first is multi_1.svg

herong$ ls -l multi_*.*
  -rw-r--r--  1 herong  staff  7665 Apr 1 20:42 multi_1.svg
  -rw-r--r--  1 herong  staff  5439 Apr 1 20:42 multi_2.svg
  -rw-r--r--  1 herong  staff  5189 Apr 1 20:42 multi_3.svg

2.3. "stdout" stream - No output file is specified. In this case, the output data goes to the "stdout" stream, which could be the console screen, or data redirected to a command pipe. With no input file name, "babel" requires the "-o ..." option in the output_section to specify the output data format.

For example, the following "obabel" command uses "-o smiles" as the output_section, which tells Open Babel to write to "stdout" in SMILES format. This command reads chemical data from molecule.sdf and write to the screen in SMILES format.

herong$ obabel molecule.sdf -o smiles

O(C(=O)CCN1CC1)CC  20009
1 molecule converted

Table of Contents

 About This Book

 SMILES (Simplified Molecular-Input Line-Entry System)

 Open Babel: The Open Source Chemistry Toolbox

Using Open Babel Command: "obabel"

 What Is "obabel" Command

 "obabel -i ..." - Input Data Format and Source

"obabel -o ... -O" - Output Data Format and Destination

 "obabel -... --..." - Generic Conversion Options

 "obabel" Command Option Argument Syntax

 "obabel ... --gen2D" - Calculated 2D Coordinates

 "obabel ... -f # -l #" - Split Large Molecule File

 "obabel -h/-d" - Add/Remove Hydrogens in Molecule Data

 "obabel --append ..." - Calculate Molecule Properties

 "obabel -L formats" - List of File Formats Supported

 "obabel -a..." - Extra Options for Input Reading

 "obabel -x..." - Extra Options for Output Writing

 "obabel" vs. "babel" Open Babel Commands

 Generating SVG Pictures with Open Babel

 Substructure Search with Open Babel

 Similarity Search with Open Babel

 Fingerprint Index for Fastsearch with Open Babel

 Stereochemistry with Open Babel

 Command Line Tools Provided by Open Babel

 RDKit: Open-Source Cheminformatics Software

 rdkit.Chem.rdchem - The Core Module

 rdkit.Chem.rdmolfiles - Molecular File Module

 rdkit.Chem.rdDepictor - Compute 2D Coordinates

 rdkit.Chem.Draw - Handle Molecule Images

 Molecule Substructure Search with RDKit

 rdkit.Chem.rdmolops - Molecule Operations

 Daylight Fingerprint Generator in RDKit

 Morgan Fingerprint Generator in RDKit

 RDKit Performance on Substructure Search

 Introduction to Molecular Fingerprints

 OCSR (Optical Chemical Structure Recognition)

 AlphaFold - Protein Structure Prediction

 Resources and Tools

 Cheminformatics Related Terminologies

 References

 Full Version in PDF/EPUB