Openbabel [1] offers a wide range of operations. One of which is file format conversion which is most widely used. In this article, we will describe commands that convert file formats.
Assuming, you have already installed Openbabel on your system, you should be able to run it as obabel/babel in the terminal. Also, you can use the GUI of Openbabel that you will have to compile during its installation.
So, here is the command syntax for file conversion:
$ obabel -i<input_format> <input_filename> -o<output_format> -O <output_filename> -other_arguments
It is optional to provide input and output formats but it is always better to do so.
Let’s convert opensmiles SMILES to canonical SMILES.
$ obabel -ismi input.smi -osmi -O output.smi -ocan
Similarly, you can convert SMILES to InChi as shown below:
$ obabel -ismi input.smi -oinchi -O output.inchi
If you want, you can give some additional arguments such as ignoring isomers, removing duplicates, etc. Sometimes, the openbabel stops processing once it finds any invalid compound/molecule, so for that, you can -e to the command.
$ obabel -ismi input.smi -oinchi -O output.inchi -e --unique
Here, –unique will not convert the duplicate molecules.
If you want to ignore the stereochemistry of the molecules then you can use the following arguments:
$ obabel -ismi input.smi -oinchi -O output.inchi -e /nostereo /nochg /noiso /noEZ /sp3
You can also keep unique molecules based on the arguments given in the above command by writing –unique before the arguments as shown below.
$ obabel -ismi input.smi -oinchi -O output.inchi -e --unique /nostereo /nochg /noiso /noEZ /sp3
For further information on supported file formats, read here.
References
- O’Boyle, NM, Banck, M., James, CA, Morley, C., Vandermeersch, T., & Hutchison, GR (2011). Open Babel: An open chemical toolbox. Journal of cheminformatics, 3 (1), 1-14.