"babel" Command - Input Data Source and Format

Q

How to specify Input Data Source and Format for a "babel" command?

✍: FYIcenter.com

A

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

babel input_section output_section option_section

You use input_section to specify Input Data Source and Format for a "babel" command. The input_section must be the first section of the "babel" command line.

The input_section contains to two optional parts to specify input data format and input data source as shown in the following syntax:

babel [-i input_format] [input_name] output_section option_section

There are 2 ways to specify input data format:

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

Here are some examples of specifying input data formats explicitly:

-i sdf 
-isdf 
-i smiles 
-ismiles 
-i smi 
-ismi
...

Implicit Format Name - No "-i" option flag is specified. In this case, the input_name part is required. Open Babel will determine the input data format implicitly from file name extension of input_name.

For example, the following "babel" command uses "molecule.sdf" as the input_name to determine the input data format as "sdf". This command reads data from molecule.sdf in "sdf" format.

fyicenter$ babel molecule.sdf molecule.svg 

1 molecule converted
29 audit log messages 

There are 3 ways to specify input data source:

File name of a single input file - In this case, the input data comes from the specified file.

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

fyicenter$ babel molecule.sdf molecule.svg 

1 molecule converted
29 audit log messages 

Multiple file names or a file pattern to match a group of input files - In this case, the input data comes from all specified files concatenated sequentially.

For example, the following "babel" command uses "mol-20001.sdf mol-20002.sdf mol-20003.sdf" as the input_section, which specifies 3 input files. This command converts merges molecules from 3 input files and converts them to molecule.svg.

fyicenter$ babel mol-20001.sdf mol-20002.sdf mol-20003.sdf output.svg

3 molecules converted
85 audit log messages 

Note that "babel" command syntax has no delimiter to separate the input_section and the output_section. If a list of file names are provided as shown in the above command, the last file name is considered to be the output_section. Other files are considered as input_section.

Here is another way to specified multiple input files a file name pattern:

fyicenter$ babel mol-*.sdf output.svg

3 molecules converted
85 audit log messages 

Note that when a file pattern is specified, the operating system will convert it into a list of file names. So the following two commands are identical from "babel" command point of view.

fyicenter$ babel mol-*.sdf output.svg

fyicenter$ babel mol-20001.sdf mol-20002.sdf mol-20003.sdf output.svg

"stdin" stream - No input file is specified. In this case, the input data comes from the "stdin" stream, which could be keys typed in from the keyboard, or data redirected from a command pipe. With no input file name, "babel" requires the "-i ..." option in the input_section to specify the input data type.

For example, the following "babel" command uses "-i smiles" as the input_section, which tells Open Babel to read "stdin" as SMILES data. This command reads chemical data from "stdin" in SMILES format and convert to benzene.svg.

fyicenter$ babel -i smiles benzene.svg
c1ccccc1
<Ctrl-D>

1 molecule converted
21 audit log messages 

Note the above command expects you to enter SMILES string from the keyboard. You need to press "<Ctrl-D>" to end the input.

 

"babel" Command - Output Data Destination and Format

What Is "babel" Command

Understanding "babel" Command Line Syntax

⇑⇑ Open Babel Tutorials

2021-07-19, 735🔥, 0💬