Skip to content

Commit

Permalink
core: molecule: fix saving aliases order in SMILES saver
Browse files Browse the repository at this point in the history
  • Loading branch information
mkviatkovskii committed Aug 26, 2023
1 parent 964da3f commit 03717cc
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 3 deletions.
14 changes: 14 additions & 0 deletions api/wasm/indigo-ketcher/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions core/indigo-core/molecule/src/smiles_saver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
18 changes: 18 additions & 0 deletions core/indigo-core/tests/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,21 @@ std::string IndigoCoreTest::saverReactionJson(BaseReaction& reaction)
std::string result(buffer.ptr());
return result;
}

std::string IndigoCoreTest::smiles(Molecule& m)
{
Array<char> smiles;
ArrayOutput output(smiles);
SmilesSaver saver(output);
saver.saveMolecule(m);
return {smiles.ptr(), static_cast<std::size_t>(smiles.size())};
}

std::string IndigoCoreTest::smiles(QueryMolecule& m)
{
Array<char> smiles;
ArrayOutput output(smiles);
SmilesSaver saver(output);
saver.saveQueryMolecule(m);
return {smiles.ptr(), static_cast<std::size_t>(smiles.size())};
}
2 changes: 2 additions & 0 deletions core/indigo-core/tests/common.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
}
15 changes: 14 additions & 1 deletion core/indigo-core/tests/tests/molecule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#include <molecule/tpsa.h>

#include "common.h"
#include "molecule/elements.h"

using namespace std;
using namespace indigo;
Expand Down Expand Up @@ -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());
}

0 comments on commit 03717cc

Please sign in to comment.