Supported File Formats and Options

Chemists are a very imaginative group. They keep thinking of new file formats.

Indeed, these are not just simple differences in how chemical data is stored, but often completely different views on molecular representations. For example, some file formats ignore hydrogen atoms as “implicit,” while others do not store bonding information. This is, in fact, a key reason for Open Babel’s existence.

OpenBabel has support for 146 formats in total. It can read 108 formats and can write 107 formats. These formats are identified by a name (for example, ShelX format) and one or more short codes (in this case, ins or res). The titles of each section provide this information (for example, ShelX format (ins, res)).

The short code is used when using obabel or babel to convert files from one format to another:

obabel -iins myfile.ins -ocml

converts from ShelX format to Chemical Markup Language (in this case, no output file is specified and the output will be written to screen [stdout]). In fact, if the filename extension is the same as the file format code, then there is no need to specify the code. In other words, the following command will behave identically:

babel myfile.ins -ocml

As well as the general conversion options described elsewhere (see Options), each format may have its own options for either reading or writing. For example, the ShelX format has two options that affect reading of files, s and b. To set a file format option:

  • For Read Options, precede the option with -a at the command line
  • For Write Options, precede the option with -x

For example, if we wanted to set all bonds to single bonds when reading a ShelX format file, we could specify the s option:

babel -iins myfile.ins -ocml -as

More than one read (or write) option can be specified (e.g. -ax -ay -az). babel (but not obabel) also allows you to specify several options together (e.g. as -axyz).

Developer Note
To set the file formats for an OBConversion object, use SetInAndOutFormat(InCode, OutCode). To set a Read Option s, use SetOptions("s", OBConversion::INOPTIONS).