mirror of
https://github.com/rdkit/rdkit.git
synced 2026-06-03 21:44:30 +08:00
* Fixes #8508 * suggestion from review * Update inchi.cpp
This commit is contained in:
3
External/INCHI-API/Wrap/pyInchi.cpp
vendored
3
External/INCHI-API/Wrap/pyInchi.cpp
vendored
@@ -147,4 +147,7 @@ BOOST_PYTHON_MODULE(rdinchi) {
|
||||
"MolToInchiKey", RDKit::MolToInchiKey,
|
||||
(boost::python::arg("mol"), boost::python::arg("options") = ""),
|
||||
docString.c_str());
|
||||
|
||||
boost::python::def("GetInchiVersion", RDKit::getInchiVersion,
|
||||
"returns the version of the InChI software being used");
|
||||
}
|
||||
|
||||
9
External/INCHI-API/inchi.cpp
vendored
9
External/INCHI-API/inchi.cpp
vendored
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// Copyright (c) 2011-2022 Novartis Institutes for BioMedical Research Inc. and
|
||||
// Copyright (c) 2011-2025 Novartis Institutes for BioMedical Research Inc. and
|
||||
// other RDkit contributors
|
||||
// All rights reserved.
|
||||
//
|
||||
@@ -62,6 +62,7 @@
|
||||
#include <GraphMol/Substruct/SubstructMatch.h>
|
||||
#include <GraphMol/SmilesParse/SmilesParse.h>
|
||||
#include <inchi_api.h>
|
||||
#include <bcf_s.h>
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
#include <stack>
|
||||
@@ -2145,9 +2146,7 @@ std::string InchiToInchiKey(const std::string &inchi) {
|
||||
char inchiKey[29];
|
||||
char xtra1[65], xtra2[65];
|
||||
int ret = 0;
|
||||
{
|
||||
ret = GetINCHIKeyFromINCHI(inchi.c_str(), 0, 0, inchiKey, xtra1, xtra2);
|
||||
}
|
||||
ret = GetINCHIKeyFromINCHI(inchi.c_str(), 0, 0, inchiKey, xtra1, xtra2);
|
||||
std::string error;
|
||||
switch (ret) {
|
||||
case INCHIKEY_OK:
|
||||
@@ -2174,4 +2173,6 @@ std::string InchiToInchiKey(const std::string &inchi) {
|
||||
BOOST_LOG(rdErrorLog) << error << " in generating InChI Key" << std::endl;
|
||||
return std::string();
|
||||
}
|
||||
|
||||
std::string getInchiVersion() { return CURRENT_VER; }
|
||||
} // namespace RDKit
|
||||
|
||||
6
External/INCHI-API/inchi.h
vendored
6
External/INCHI-API/inchi.h
vendored
@@ -1,5 +1,6 @@
|
||||
//
|
||||
// Copyright (c) 2011-2014, Novartis Institutes for BioMedical Research Inc.
|
||||
// Copyright (c) 2011-2025, Novartis Institutes for BioMedical Research Inc.
|
||||
// and other RDkit contributors
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
@@ -34,6 +35,7 @@
|
||||
#ifndef RDKIT_INCHI_30JUNE2011
|
||||
#define RDKIT_INCHI_30JUNE2011
|
||||
#include <GraphMol/RDKitBase.h>
|
||||
|
||||
#include <string>
|
||||
namespace RDKit {
|
||||
struct RDKIT_RDINCHILIB_EXPORT ExtraInchiReturnValues {
|
||||
@@ -107,5 +109,7 @@ inline std::string MolToInchiKey(const ROMol &mol, const char *options = NULL) {
|
||||
return InchiToInchiKey(MolToInchi(mol, rv, options));
|
||||
};
|
||||
|
||||
RDKIT_RDINCHILIB_EXPORT std::string getInchiVersion();
|
||||
|
||||
} // namespace RDKit
|
||||
#endif
|
||||
|
||||
5
External/INCHI-API/python/inchi.py
vendored
5
External/INCHI-API/python/inchi.py
vendored
@@ -233,7 +233,10 @@ def MolToInchiKey(mol, options=""):
|
||||
return rdinchi.MolToInchiKey(mol, options)
|
||||
|
||||
|
||||
GetInchiVersion = rdinchi.GetInchiVersion
|
||||
|
||||
__all__ = [
|
||||
'MolToInchiAndAuxInfo', 'MolToInchi', 'MolBlockToInchiAndAuxInfo', 'MolBlockToInchi',
|
||||
'MolFromInchi', 'InchiReadWriteError', 'InchiToInchiKey', 'MolToInchiKey', 'INCHI_AVAILABLE'
|
||||
'MolFromInchi', 'InchiReadWriteError', 'InchiToInchiKey', 'MolToInchiKey', 'GetInchiVersion',
|
||||
'INCHI_AVAILABLE'
|
||||
]
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#
|
||||
# Copyright (c) 2011, Novartis Institutes for BioMedical Research Inc.
|
||||
# Copyright (c) 2011-2025, Novartis Institutes for BioMedical Research Inc.
|
||||
# and other RDKit contributors
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
@@ -42,7 +43,7 @@ from rdkit.Chem import (INCHI_AVAILABLE, ForwardSDMolSupplier, MolFromMolBlock,
|
||||
|
||||
if INCHI_AVAILABLE:
|
||||
from rdkit.Chem import (InchiReadWriteError, InchiToInchiKey, MolBlockToInchi, MolFromInchi,
|
||||
MolToInchi, MolToInchiKey)
|
||||
MolToInchi, MolToInchiKey, GetInchiVersion)
|
||||
|
||||
COLOR_RED = '\033[31m'
|
||||
COLOR_GREEN = '\033[32m'
|
||||
@@ -204,11 +205,11 @@ class TestCase(unittest.TestCase):
|
||||
# InChI messed up the radical?
|
||||
unsanitizedInchiMol = MolFromInchi(x, sanitize=False)
|
||||
if sum([
|
||||
a.GetNumRadicalElectrons() * a.GetAtomicNum()
|
||||
for a in m.GetAtoms() if a.GetNumRadicalElectrons() != 0
|
||||
a.GetNumRadicalElectrons() * a.GetAtomicNum() for a in m.GetAtoms()
|
||||
if a.GetNumRadicalElectrons() != 0
|
||||
]) != sum([
|
||||
a.GetNumRadicalElectrons() * a.GetAtomicNum()
|
||||
for a in unsanitizedInchiMol.GetAtoms() if a.GetNumRadicalElectrons() != 0
|
||||
a.GetNumRadicalElectrons() * a.GetAtomicNum() for a in unsanitizedInchiMol.GetAtoms()
|
||||
if a.GetNumRadicalElectrons() != 0
|
||||
]):
|
||||
reasonable += 1
|
||||
continue
|
||||
@@ -324,6 +325,11 @@ M END"""
|
||||
inchi2 = MolBlockToInchi(mb2, options="/FixedH")
|
||||
self.assertEqual(inchi2, "InChI=1/C8H8N2/c1-6-7-4-2-3-5-8(7)10-9-6/h2-5H,1H3,(H,9,10)/f/h10H")
|
||||
|
||||
def test6GetInchiVersion(self):
|
||||
version = GetInchiVersion()
|
||||
self.assertIsInstance(version, str)
|
||||
self.assertGreaterEqual(version, "1.07.2")
|
||||
|
||||
|
||||
if __name__ == '__main__': # pragma: nocover
|
||||
# only run the test if InChI is available
|
||||
|
||||
Reference in New Issue
Block a user