rdkit / homebrew-rdkit

Homebrew formula for rdkit
44 stars 19 forks source link

inchi not working #21

Closed supern8ent closed 9 years ago

supern8ent commented 9 years ago

inchi doesn't seem to be working, even though I did brew install --with-inchi rdkit. I pulled ethanol examples from wikipedia's inchi page, and generating the mol doesn't work. All of these,

> mol = Chem.MolFromInchi(u'InChI=1/C2H6O/c1-2-3/h3H,2H2,1H3')
> mol = Chem.MolFromInchi(u'InChI=1/C2H6O/c1-2-3/h3H,2H2,1H3/m0/s1')
> mol = Chem.MolFromInchi(u'InChI=1S/C2H6O/c1-2-3/h3H,2H2,1H3')
> mol = Chem.MolFromInchi(u'InChI=1S/C2H6O/c1-2-3/h3H,2H2,1H3/m0/s1')
> mol = Chem.MolFromInchi(u'1/C2H6O/c1-2-3/h3H,2H2,1H3')
> mol = Chem.MolFromInchi(u'1/C2H6O/c1-2-3/h3H,2H2,1H3/m0/s1')
> mol = Chem.MolFromInchi(u'1S/C2H6O/c1-2-3/h3H,2H2,1H3')
> mol = Chem.MolFromInchi(u'1S/C2H6O/c1-2-3/h3H,2H2,1H3/m0/s1')

raise the same ArgumentError:

---------------------------------------------------------------------------
ArgumentError                             Traceback (most recent call last)
<ipython-input-30-32b267697aff> in <module>()
----> 1 mol = Chem.MolFromInchi(u'InChI=1/C2H6O/c1-2-3/h3H,2H2,1H3')

/Users/nathan/.virtualenvs/A0/lib/python2.7/site-packages/rdkit/Chem/inchi.pyc in MolFromInchi(inchi, sanitize, removeHs, logLevel, treatWarningAsError)
     69     """
     70     try:
---> 71         mol, retcode, message, log = rdinchi.InchiToMol(inchi, sanitize, removeHs)
     72     except ValueError as e :
     73         logger.error(str(e))

ArgumentError: Python argument types in
    rdkit.Chem.rdinchi.InchiToMol(unicode, bool, bool)
did not match C++ signature:
    InchiToMol(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > inchi, bool sanitize=True, bool removeHs=True)

Other observations: If I don't pass a unicode string (i.e. drop the "u"), it returns NoneType. MolFromSmiles works. I tried adding True, True as arguments and that got the same error.

greglandrum commented 9 years ago

I would expect the first four InChIs above to work as long as you don't provide them as unicode (this is a known limitation in the code at the moment).

The last four are not valid InChIs (they don't start with "InChI="), so I would not expect them to work at all.

Do the first four work if you provide them as standard strings and not unicode?

supern8ent commented 9 years ago

Gosh, I'm sorry. In all my attempts I never tried both dropping the u (for unicode) and leaving in "InChi=" at the same time. At some point I misinterpreted the exception which includes "rdkit.Chem.rdinchi.InchiToMol(unicode, bool, bool)" to mean that unicode was expected.

Thank you very much for straightening that out.