diff --git a/External/INCHI-API/Wrap/pyInchi.cpp b/External/INCHI-API/Wrap/pyInchi.cpp index cd8ae37ba..4481e49da 100644 --- a/External/INCHI-API/Wrap/pyInchi.cpp +++ b/External/INCHI-API/Wrap/pyInchi.cpp @@ -100,5 +100,21 @@ BOOST_PYTHON_MODULE(rdinchi) { (boost::python::arg("inchi")), docString.c_str() ); -} + docString = "return the InChI key for a ROMol molecule.\n\ +\n\ + Arguments:\n\ + - mol: the molecule to use.\n\ + - options: the InChI generation options.\n\ + Options should be prefixed with either a - or a /\n\ + Available options are explained in the InChI technical FAQ:\n\ + http://www.inchi-trust.org/fileadmin/user_upload/html/inchifaq/inchi-faq.html#15.14\n\ + and the User Guide:\n\ + http://www.inchi-trust.org/fileadmin/user_upload/software/inchi-v1.04/InChI_UserGuide.pdf\n\ + Returns: the InChI key\n"; + boost::python::def("MolToInchiKey", RDKit::MolToInchiKey, + (boost::python::arg("mol"), + boost::python::arg("options")=""), + docString.c_str() + ); +} diff --git a/External/INCHI-API/inchi.h b/External/INCHI-API/inchi.h index 6a94479e6..e8933a781 100644 --- a/External/INCHI-API/inchi.h +++ b/External/INCHI-API/inchi.h @@ -70,5 +70,21 @@ namespace RDKit { * \param inchi The input InChI string, which can be standard or not. */ std::string InchiToInchiKey(const std::string &inchi); + + /*! Get the InChI key for a given molecule directly + * \param mol The input molecule + * \param options An null-terminated character string of space-deliminated + * InChI options that is passed to InChI API as is (except that / is naively + * converted to - to non-Windows platforms and - is converted to / on Windows) + * Available options are explained in the InChI technical FAQ: + * http://www.inchi-trust.org/fileadmin/user_upload/html/inchifaq/inchi-faq.html#15.14 + * and the User Guide: + * http://www.inchi-trust.org/fileadmin/user_upload/software/inchi-v1.04/InChI_UserGuide.pdf + */ + inline std::string MolToInchiKey(const ROMol& mol, const char *options=NULL){ + ExtraInchiReturnValues rv; + return InchiToInchiKey(MolToInchi(mol,rv,options)); + }; + } #endif diff --git a/External/INCHI-API/python/inchi.py b/External/INCHI-API/python/inchi.py index 754f563ef..49d72ea25 100644 --- a/External/INCHI-API/python/inchi.py +++ b/External/INCHI-API/python/inchi.py @@ -161,6 +161,17 @@ def InchiToInchiKey(inchi): else: return None +def MolToInchiKey(mol, options=""): + """Returns the standard InChI key for a molecule + + Returns: + the standard InChI key returned by InChI API for the input molecule + """ + return rdinchi.MolToInchiKey(mol,options) + + + + __all__ = ['MolToInchiAndAuxInfo', 'MolToInchi', 'MolFromInchi', 'InchiReadWriteError', - 'InchiToInchiKey', 'INCHI_AVAILABLE'] + 'InchiToInchiKey', 'MolToInchiKey', 'INCHI_AVAILABLE'] diff --git a/External/INCHI-API/test.cpp b/External/INCHI-API/test.cpp index 5fd3e1104..4db0e5768 100644 --- a/External/INCHI-API/test.cpp +++ b/External/INCHI-API/test.cpp @@ -40,6 +40,8 @@ void runblock(const std::vector &mols, unsigned int count, TEST_ASSERT(inchi == inchis[i]); std::string key = InchiToInchiKey(inchi); TEST_ASSERT(key == keys[i]); + std::string key2 = MolToInchiKey(*mol); + TEST_ASSERT(key2 == keys[i]); ROMol *mol2 = InchiToMol(inchi, tmp); TEST_ASSERT(mol2); ExtraInchiReturnValues tmp2; diff --git a/rdkit/Chem/UnitTestInchi.py b/rdkit/Chem/UnitTestInchi.py index 0e1a65eee..503921222 100755 --- a/rdkit/Chem/UnitTestInchi.py +++ b/rdkit/Chem/UnitTestInchi.py @@ -46,7 +46,7 @@ from rdkit.Chem import MolFromMolBlock, MolToMolBlock from rdkit.Chem import INCHI_AVAILABLE if INCHI_AVAILABLE: from rdkit.Chem import InchiReadWriteError - from rdkit.Chem import MolToInchi, MolFromInchi, InchiToInchiKey + from rdkit.Chem import MolToInchi, MolFromInchi, InchiToInchiKey, MolToInchiKey COLOR_RED = '\033[31m' COLOR_GREEN = '\033[32m' @@ -262,6 +262,13 @@ class TestCase(unittest.TestCase): inchi = 'InChI=1S/C9H12/c1-2-6-9-7-4-3-5-8-9/h3-5,7-8H,2,6H2,1H3' self.assertEqual(InchiToInchiKey(inchi), 'ODLMAHJVESYWTB-UHFFFAOYSA-N') + def test4MolToInchiKey(self): + m = MolFromSmiles("CC=C(N)C") + inchi = MolToInchi(m) + k1 = InchiToInchiKey(inchi) + k2 = MolToInchiKey(m) + self.assertEqual(k1,k2) + if __name__ == '__main__': # pragma: nocover # only run the test if InChI is available