diff --git a/api/wasm/indigo-ketcher/test/test.js b/api/wasm/indigo-ketcher/test/test.js index 70eff7f415..ad457398e3 100644 --- a/api/wasm/indigo-ketcher/test/test.js +++ b/api/wasm/indigo-ketcher/test/test.js @@ -689,6 +689,20 @@ M END }); options.delete(); }); + test("reactionComponents", "complex_1", () => { + let options = new indigo.MapStringString(); + assert.deepStrictEqual(JSON.parse(indigo.reactionComponents("[#6:1][C:2](=[O:3])[OH1:4].[C:5][N:6]>>[#6:1][C:2](=[O:3])[N:6][C:5] |$R1;;;OH;R2;NHR3;R1;;;NR3;R2$|", options)), { + "reactants": ["CC([OH])=O |$R1;;OH;$|", "CN |$R2;NHR3$|"], + "catalysts": [], + "products": ["CC(NC)=O |$R1;;NR3;R2;$|"] + }); + assert.deepStrictEqual(JSON.parse(indigo.reactionComponents("[#6:1][C:2](=[O:3])[OH1:4].[C:5][N:6]>>[#6:1][C:2](=[O:3])[N:6][C:5] |$R1;;;OH;R2;NHR3;R1;;;NR3;R2$|", options)), { + "reactants": ["CC([OH])=O |$R1;;OH;$|", "CN |$R2;NHR3$|"], + "catalysts": [], + "products": ["CC(NC)=O |$R1;;NR3;R2;$|"] + }); + options.delete(); + }); } // Run tests diff --git a/core/indigo-core/molecule/src/smiles_saver.cpp b/core/indigo-core/molecule/src/smiles_saver.cpp index d342e45206..a0c744da48 100644 --- a/core/indigo-core/molecule/src/smiles_saver.cpp +++ b/core/indigo-core/molecule/src/smiles_saver.cpp @@ -1669,9 +1669,9 @@ void SmilesSaver::_writePseudoAtoms() { writeSpecialAtom(_written_atoms[i], _output); } - else if (mol.isAlias(i)) + else if (mol.isAlias(_written_atoms[i])) { - writePseudoAtom(mol.getAlias(i), _output); + writePseudoAtom(mol.getAlias(_written_atoms[i]), _output); } } diff --git a/core/indigo-core/tests/common.cpp b/core/indigo-core/tests/common.cpp index b8cbf5c199..9dafb72df0 100644 --- a/core/indigo-core/tests/common.cpp +++ b/core/indigo-core/tests/common.cpp @@ -163,3 +163,21 @@ std::string IndigoCoreTest::saverReactionJson(BaseReaction& reaction) std::string result(buffer.ptr()); return result; } + +std::string IndigoCoreTest::smiles(Molecule& m) +{ + Array smiles; + ArrayOutput output(smiles); + SmilesSaver saver(output); + saver.saveMolecule(m); + return {smiles.ptr(), static_cast(smiles.size())}; +} + +std::string IndigoCoreTest::smiles(QueryMolecule& m) +{ + Array smiles; + ArrayOutput output(smiles); + SmilesSaver saver(output); + saver.saveQueryMolecule(m); + return {smiles.ptr(), static_cast(smiles.size())}; +} diff --git a/core/indigo-core/tests/common.h.in b/core/indigo-core/tests/common.h.in index ed355a301c..3777046f01 100644 --- a/core/indigo-core/tests/common.h.in +++ b/core/indigo-core/tests/common.h.in @@ -32,5 +32,7 @@ namespace indigo std::string saveReactionCML(Reaction& reaction); std::string saverReactionJson(BaseReaction& reaction); static std::string dataPath(const char* dataPathSuffix); + static std::string smiles(Molecule& m); + static std::string smiles(QueryMolecule& m); }; } diff --git a/core/indigo-core/tests/tests/molecule.cpp b/core/indigo-core/tests/tests/molecule.cpp index fef4925f2e..037d608e7d 100644 --- a/core/indigo-core/tests/tests/molecule.cpp +++ b/core/indigo-core/tests/tests/molecule.cpp @@ -27,7 +27,6 @@ #include #include "common.h" -#include "molecule/elements.h" using namespace std; using namespace indigo; @@ -306,3 +305,17 @@ TEST_F(IndigoCoreMoleculeTest, pKa) EXPECT_NEAR(6.5, Crippen::pKa(molecule), 0.01); } } + +TEST_F(IndigoCoreMoleculeTest, atom_reorder_query) +{ + QueryMolecule molecule; + loadQueryMolecule("[A:1][C:2](=[O:3])[OH1:4] |$R1;;;OH$|", molecule); + EXPECT_STREQ("*C([OH])=O |$R1;;OH;$|", smiles(molecule).c_str()); +} + +TEST_F(IndigoCoreMoleculeTest, atom_reorder_nonquery) +{ + Molecule molecule; + loadMolecule("SC(=N)O |$R1;;;OH$|", molecule); + EXPECT_STREQ("SC(O)=N |$R1;;OH;$|", smiles(molecule).c_str()); +}