3
$\begingroup$

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?

$\endgroup$
17
  • $\begingroup$ 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.) $\endgroup$ Commented Jul 9, 2015 at 11:35
  • 1
    $\begingroup$ 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. $\endgroup$ Commented Jul 9, 2015 at 12:02
  • 1
    $\begingroup$ @ToddMinehardt I figured out a way.Thanks anyway $\endgroup$
    – LifeIsGood
    Commented Jul 9, 2015 at 14:37
  • 2
    $\begingroup$ 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 $\endgroup$ Commented Jul 9, 2015 at 14:51
  • 1
    $\begingroup$ @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 ;) $\endgroup$ Commented Jul 13, 2015 at 1:40

2 Answers 2

3
$\begingroup$

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.

$\endgroup$
1
  • $\begingroup$ 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 $\endgroup$ Commented Jul 13, 2015 at 22:41
1
$\begingroup$

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.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.