# Converting mol files to InChiKey in large batches

I want to convert mol files to InChiKey. I am using OpenBabel for the conversion but I have over 500 mol files and converting them one by one is too time consuming. Is there some way to convert them all at once?

Edit 1 This is a sample mol file

0187.cdx
Sample

8  8  0  0  0  0  0  0  0  0999 V2000
-0.4125    0.7145    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
-0.8250    0.0000    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
-0.4125   -0.7145    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
0.4125   -0.7145    0.0000 N   0  0  0  0  0  0  0  0  0  0  0  0
0.8250    0.0000    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
0.4125    0.7145    0.0000 N   0  0  0  0  0  0  0  0  0  0  0  0
-1.6500    0.0000    0.0000 Cl  0  0  0  0  0  0  0  0  0  0  0  0
1.6500    0.0000    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
1  2  2  0
2  3  1  0
3  4  2  0
4  5  1  0
5  6  2  0
6  1  1  0
2  7  1  0
5  8  1  0
M  END


Also I want to know is there some other format which can combine mol files into one.I think I had heard of another format like mol which can combine many mol files,but I cannot remember the name of that format

Edit 2- What is SDF format? Can it combine many mol files into one?

• Could you include the current scheme you are using? What operating system are you using? I am pretty sure there is a batch way to do things like that. (A small sample file would also be appreciated.) – Martin - マーチン Jul 9 '15 at 11:35
• I have no knowledge about mol files in general, not much knowledge about InChI other than that I read the FAQ. I cannot help you on this case, but I can try to make it easier for others to answer it for you. You can edit in all of the comments above, since they provide context to the question. – Martin - マーチン Jul 9 '15 at 12:02
• @ToddMinehardt I figured out a way.Thanks anyway – LifeIsGood Jul 9 '15 at 14:37
• Good to hear. Just in case you or others want a handy one-liner: for i in $(ls *.mol); do name=${i%.mol}; babel -imol $i -oinchi$name.inchi; done – Todd Minehardt Jul 9 '15 at 14:51
• @Todd Since the question is not worded as specific to an operating system, I would encourage you to post the one-liner as an answer, with the system you tested it on. If bash, for i in *.mol; do ... should also work ;) – Martin - マーチン Jul 13 '15 at 1:40

This is exactly why I wrote Open Babel.

obabel *.mol -oinchikey -m

As long as you're not exceeding the number of command line arguments, you're done.

• I should point out that since babel / obabel will process all the filenames internally, this is faster than approaches using the shell. If you have too many files in a directory (e.g., me), you want something like find . -name "*.mol" -print0 | xargs -0 -I % obabel % -oinchi -m – Geoff Hutchison Jul 13 '15 at 22:41

On a system where you're working in the bash shell, in your working directory where the .mol files reside, run this on the command line:

for i in $(ls *.mol); do name=${i%.mol}; babel -imol $i -oinchi$name.inchi; done

I have successfully tested this on machines running Ubuntu 12.04 and 14.04.