Skip to content

Commit

Permalink
1221 An empty structure is returned given incorrect InChi string (#1228)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wadym authored Aug 17, 2023
1 parent 1738e4b commit 35f60e3
Show file tree
Hide file tree
Showing 14 changed files with 668 additions and 10 deletions.
38 changes: 29 additions & 9 deletions api/c/tests/unit/tests/inchi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,33 @@ TEST_F(IndigoApiInchiTest, test_inchi)

TEST_F(IndigoApiInchiTest, basic)
{
const char* inchi = "InChI=1S/C10H20N2O2/c11-7-1-5-2-8(12)10(14)4-6(5)3-9(7)13/h5-10,13-14H,1-4,11-12H2";
const auto m = indigoInchiLoadMolecule(inchi);
ASSERT_EQ(strcmp(indigoCanonicalSmiles(m), "NC1CC2CC(N)C(O)CC2CC1O"), 0);
const char* res_inchi = indigoInchiGetInchi(m);
ASSERT_EQ(strcmp(res_inchi, inchi), 0);
const char* empty_inchi = "InChI=1S//";
const auto empty = indigoInchiLoadMolecule(empty_inchi);
const char* res_empty = indigoInchiGetInchi(empty);
ASSERT_EQ(strcmp(res_empty, empty_inchi), 0);
try
{
const char* inchi = "InChI=1S/C10H20N2O2/c11-7-1-5-2-8(12)10(14)4-6(5)3-9(7)13/h5-10,13-14H,1-4,11-12H2";
const auto m = indigoInchiLoadMolecule(inchi);
ASSERT_EQ(strcmp(indigoCanonicalSmiles(m), "NC1CC2CC(N)C(O)CC2CC1O"), 0);
const char* res_inchi = indigoInchiGetInchi(m);
ASSERT_EQ(strcmp(res_inchi, inchi), 0);
const char* empty_inchi = "InChI=1S//";
const auto empty = indigoInchiLoadMolecule(empty_inchi);
EXPECT_ANY_THROW(indigoInchiGetInchi(empty));
}
catch (const std::exception& e)
{
ASSERT_STREQ("inchi-wrapper: Indigo-InChI: no structural data has been provided: . Code: -1.", e.what());
}
}

TEST_F(IndigoApiInchiTest, incorrect_symbols)
{
try
{
const char* inchi = "InChI=1S/C7H16O/c1-2-3-4-5-6-7-8$h8H,2-7H2,1H3";
const auto m = indigoInchiLoadMolecule(inchi);
EXPECT_ANY_THROW(indigoInchiGetInchi(m));
}
catch (const std::exception& e)
{
ASSERT_STREQ("inchi-wrapper: Indigo-InChI: no structural data has been provided: (null). Code: -1.", e.what());
}
}
502 changes: 502 additions & 0 deletions api/http/env/Scripts/Activate.ps1

Large diffs are not rendered by default.

69 changes: 69 additions & 0 deletions api/http/env/Scripts/activate
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# This file must be used with "source bin/activate" *from bash*
# you cannot run it directly

deactivate () {
# reset old environment variables
if [ -n "${_OLD_VIRTUAL_PATH:-}" ] ; then
PATH="${_OLD_VIRTUAL_PATH:-}"
export PATH
unset _OLD_VIRTUAL_PATH
fi
if [ -n "${_OLD_VIRTUAL_PYTHONHOME:-}" ] ; then
PYTHONHOME="${_OLD_VIRTUAL_PYTHONHOME:-}"
export PYTHONHOME
unset _OLD_VIRTUAL_PYTHONHOME
fi

# This should detect bash and zsh, which have a hash command that must
# be called to get it to forget past commands. Without forgetting
# past commands the $PATH changes we made may not be respected
if [ -n "${BASH:-}" -o -n "${ZSH_VERSION:-}" ] ; then
hash -r 2> /dev/null
fi

if [ -n "${_OLD_VIRTUAL_PS1:-}" ] ; then
PS1="${_OLD_VIRTUAL_PS1:-}"
export PS1
unset _OLD_VIRTUAL_PS1
fi

unset VIRTUAL_ENV
unset VIRTUAL_ENV_PROMPT
if [ ! "${1:-}" = "nondestructive" ] ; then
# Self destruct!
unset -f deactivate
fi
}

# unset irrelevant variables
deactivate nondestructive

VIRTUAL_ENV="E:\projects\indigo\api\http\env"
export VIRTUAL_ENV

_OLD_VIRTUAL_PATH="$PATH"
PATH="$VIRTUAL_ENV/Scripts:$PATH"
export PATH

# unset PYTHONHOME if set
# this will fail if PYTHONHOME is set to the empty string (which is bad anyway)
# could use `if (set -u; : $PYTHONHOME) ;` in bash
if [ -n "${PYTHONHOME:-}" ] ; then
_OLD_VIRTUAL_PYTHONHOME="${PYTHONHOME:-}"
unset PYTHONHOME
fi

if [ -z "${VIRTUAL_ENV_DISABLE_PROMPT:-}" ] ; then
_OLD_VIRTUAL_PS1="${PS1:-}"
PS1="(env) ${PS1:-}"
export PS1
VIRTUAL_ENV_PROMPT="(env) "
export VIRTUAL_ENV_PROMPT
fi

# This should detect bash and zsh, which have a hash command that must
# be called to get it to forget past commands. Without forgetting
# past commands the $PATH changes we made may not be respected
if [ -n "${BASH:-}" -o -n "${ZSH_VERSION:-}" ] ; then
hash -r 2> /dev/null
fi
34 changes: 34 additions & 0 deletions api/http/env/Scripts/activate.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
@echo off

rem This file is UTF-8 encoded, so we need to update the current code page while executing it
for /f "tokens=2 delims=:." %%a in ('"%SystemRoot%\System32\chcp.com"') do (
set _OLD_CODEPAGE=%%a
)
if defined _OLD_CODEPAGE (
"%SystemRoot%\System32\chcp.com" 65001 > nul
)

set VIRTUAL_ENV=E:\projects\indigo\api\http\env

if not defined PROMPT set PROMPT=$P$G

if defined _OLD_VIRTUAL_PROMPT set PROMPT=%_OLD_VIRTUAL_PROMPT%
if defined _OLD_VIRTUAL_PYTHONHOME set PYTHONHOME=%_OLD_VIRTUAL_PYTHONHOME%

set _OLD_VIRTUAL_PROMPT=%PROMPT%
set PROMPT=(env) %PROMPT%

if defined PYTHONHOME set _OLD_VIRTUAL_PYTHONHOME=%PYTHONHOME%
set PYTHONHOME=

if defined _OLD_VIRTUAL_PATH set PATH=%_OLD_VIRTUAL_PATH%
if not defined _OLD_VIRTUAL_PATH set _OLD_VIRTUAL_PATH=%PATH%

set PATH=%VIRTUAL_ENV%\Scripts;%PATH%
set VIRTUAL_ENV_PROMPT=(env)

:END
if defined _OLD_CODEPAGE (
"%SystemRoot%\System32\chcp.com" %_OLD_CODEPAGE% > nul
set _OLD_CODEPAGE=
)
22 changes: 22 additions & 0 deletions api/http/env/Scripts/deactivate.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
@echo off

if defined _OLD_VIRTUAL_PROMPT (
set "PROMPT=%_OLD_VIRTUAL_PROMPT%"
)
set _OLD_VIRTUAL_PROMPT=

if defined _OLD_VIRTUAL_PYTHONHOME (
set "PYTHONHOME=%_OLD_VIRTUAL_PYTHONHOME%"
set _OLD_VIRTUAL_PYTHONHOME=
)

if defined _OLD_VIRTUAL_PATH (
set "PATH=%_OLD_VIRTUAL_PATH%"
)

set _OLD_VIRTUAL_PATH=

set VIRTUAL_ENV=
set VIRTUAL_ENV_PROMPT=

:END
Binary file added api/http/env/Scripts/pip.exe
Binary file not shown.
Binary file added api/http/env/Scripts/pip3.11.exe
Binary file not shown.
Binary file added api/http/env/Scripts/pip3.exe
Binary file not shown.
Binary file added api/http/env/Scripts/py.test.exe
Binary file not shown.
Binary file added api/http/env/Scripts/pytest.exe
Binary file not shown.
Binary file added api/http/env/Scripts/python.exe
Binary file not shown.
Binary file added api/http/env/Scripts/pythonw.exe
Binary file not shown.
5 changes: 5 additions & 0 deletions api/http/env/pyvenv.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
home = C:\Python311
include-system-site-packages = false
version = 3.11.4
executable = C:\Python311\python.exe
command = C:\Python311\python.exe -m venv E:\projects\indigo\api\http\env
8 changes: 7 additions & 1 deletion core/indigo-core/molecule/src/inchi_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,13 @@ void InchiWrapper::loadMoleculeFromInchi(const char* inchi_string, Molecule& mol
if (inchi_output.szLog)
log.readString(inchi_output.szLog, true);

if (retcode != inchi_Ret_OKAY && retcode != inchi_Ret_WARNING && retcode != inchi_Ret_EOF) // empty structure is acceptable
if (retcode == inchi_Ret_EOF) /* no structural data has been provided */
throw Error("Indigo-InChI: no structural data has been provided: %s. Code: %d.", inchi_output.szMessage, retcode);

if (retcode == inchi_Ret_BUSY) /* Previuos call to InChI has not returned yet */
throw Error("Indigo-InChI: Previuos call to InChI has not returned yet: %s. Code: %d.", inchi_output.szMessage, retcode);

if (retcode != inchi_Ret_OKAY && retcode != inchi_Ret_WARNING)
throw Error("Indigo-InChI: InChI loading failed: %s. Code: %d.", inchi_output.szMessage, retcode);

// Check stereo options
Expand Down

0 comments on commit 35f60e3

Please sign in to comment.