From 08d5650784c82d100dfacee3a5dbb35a2827303f Mon Sep 17 00:00:00 2001 From: Aliaksandr Dziarkach <18146690+AliaksandrDziarkach@users.noreply.github.com> Date: Thu, 19 Oct 2023 17:07:59 +0300 Subject: [PATCH] #1331 Ring bond count 'As drawn' saved wrong (#1352) --- .../ref/formats/custom_query.py.out | 2 + .../integration/tests/formats/custom_query.py | 19 +++++ .../formats/ref/ket_with_rb_as_drawn.ket | 70 +++++++++++++++++++ .../molecule/src/query_molecule.cpp | 2 +- 4 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 api/tests/integration/tests/formats/ref/ket_with_rb_as_drawn.ket diff --git a/api/tests/integration/ref/formats/custom_query.py.out b/api/tests/integration/ref/formats/custom_query.py.out index a511ef77e8..b74cda7718 100644 --- a/api/tests/integration/ref/formats/custom_query.py.out +++ b/api/tests/integration/ref/formats/custom_query.py.out @@ -1,2 +1,4 @@ **** #1310 error at opening SMARTS with comma **** [#6]1-[#6]=[#6]-[#6]=[#6]-[b;r;3;s&2,X3]=1 OK. Expected string found. +**** #1331 wrong smarts for ring bond count as drawn **** +ket_with_rb_as_drawn.ket OK. Smarts equals expected string '[#6](-[#6])(-[#6;x0])-[#6]' diff --git a/api/tests/integration/tests/formats/custom_query.py b/api/tests/integration/tests/formats/custom_query.py index 1bab694f60..7ce4565849 100644 --- a/api/tests/integration/tests/formats/custom_query.py +++ b/api/tests/integration/tests/formats/custom_query.py @@ -11,6 +11,8 @@ indigo = Indigo() +ref_path = joinPathPy("ref/", __file__) + def test_smarts_to_ket(smarts_in, expected_str): mol = indigo.loadSmarts(smarts_in) @@ -21,8 +23,25 @@ def test_smarts_to_ket(smarts_in, expected_str): print("%s FAILED. Expected string not found." % smarts_in) +def test_ket_to_smarts(filename, expected_str): + mol = indigo.loadQueryMoleculeFromFile(os.path.join(ref_path, filename)) + smarts = mol.smarts() + if smarts == expected_str: + print( + "%s OK. Smarts equals expected string '%s'" + % (filename, expected_str) + ) + else: + print( + "%s FAILED. Expected '%s', generated smarts '%s'" + % (filename, expected_str, smarts) + ) + + print("**** #1310 error at opening SMARTS with comma ****") test_smarts_to_ket( "[#6]1-[#6]=[#6]-[#6]=[#6]-[b;r;3;s&2,X3]=1", '"queryProperties":{"customQuery":"b;r;3;s&2,X3"}', ) +print("**** #1331 wrong smarts for ring bond count as drawn ****") +test_ket_to_smarts("ket_with_rb_as_drawn.ket", "[#6](-[#6])(-[#6;x0])-[#6]") diff --git a/api/tests/integration/tests/formats/ref/ket_with_rb_as_drawn.ket b/api/tests/integration/tests/formats/ref/ket_with_rb_as_drawn.ket new file mode 100644 index 0000000000..735fcd395e --- /dev/null +++ b/api/tests/integration/tests/formats/ref/ket_with_rb_as_drawn.ket @@ -0,0 +1,70 @@ +{ + "root": { + "nodes": [ + { + "$ref": "mol0" + } + ] + }, + "mol0": { + "type": "molecule", + "atoms": [ + { + "label": "C", + "location": [ + 10.366987298107782, + -9.325000000000001, + 0 + ] + }, + { + "label": "C", + "location": [ + 11.23301270189222, + -8.825000000000001, + 0 + ] + }, + { + "label": "C", + "location": [ + 9.500961894323343, + -8.825000000000001, + 0 + ], + "ringBondCount": -2 + }, + { + "label": "C", + "location": [ + 10.366987298107782, + -10.325000000000001, + 0 + ] + } + ], + "bonds": [ + { + "type": 1, + "atoms": [ + 0, + 1 + ] + }, + { + "type": 1, + "atoms": [ + 0, + 2 + ] + }, + { + "type": 1, + "atoms": [ + 0, + 3 + ] + } + ] + } +} diff --git a/core/indigo-core/molecule/src/query_molecule.cpp b/core/indigo-core/molecule/src/query_molecule.cpp index 2fc432c4a0..3551f2fed1 100644 --- a/core/indigo-core/molecule/src/query_molecule.cpp +++ b/core/indigo-core/molecule/src/query_molecule.cpp @@ -579,7 +579,7 @@ void QueryMolecule::writeSmartsAtom(Output& output, Atom* atom, int aam, int chi } case ATOM_RING_BONDS_AS_DRAWN: { - output.printf("x:%d", atom->value_min); + output.printf("x0"); // exact value should be writed in extended part break; }