mirror of
https://github.com/rdkit/rdkit.git
synced 2026-06-03 21:44:30 +08:00
Add MolToInchiKey function() (#1784)
This commit is contained in:
committed by
Brian Kelley
parent
3f136946e3
commit
650ad9e4f3
18
External/INCHI-API/Wrap/pyInchi.cpp
vendored
18
External/INCHI-API/Wrap/pyInchi.cpp
vendored
@@ -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()
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
16
External/INCHI-API/inchi.h
vendored
16
External/INCHI-API/inchi.h
vendored
@@ -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
|
||||
|
||||
13
External/INCHI-API/python/inchi.py
vendored
13
External/INCHI-API/python/inchi.py
vendored
@@ -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']
|
||||
|
||||
2
External/INCHI-API/test.cpp
vendored
2
External/INCHI-API/test.cpp
vendored
@@ -40,6 +40,8 @@ void runblock(const std::vector<ROMol *> &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;
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user