Skip to content

Commit

Permalink
#2739 - Wrong stereochemistry when reading cdxml reaction (#2740)
Browse files Browse the repository at this point in the history
Co-authored-by: Aliakasndr Dziarkach <[email protected]>
  • Loading branch information
jblack-mestre and AliaksandrDziarkach authored Jan 30, 2025
1 parent eb09d37 commit 1110103
Show file tree
Hide file tree
Showing 4 changed files with 463 additions and 0 deletions.
2 changes: 2 additions & 0 deletions core/indigo-core/molecule/molecule_cdxml_loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ namespace indigo
class BaseCDXProperty
{
public:
virtual ~BaseCDXProperty() = default;
virtual bool hasContent() const = 0;
virtual std::unique_ptr<BaseCDXProperty> copy() = 0;
virtual std::unique_ptr<BaseCDXProperty> next() = 0;
Expand Down Expand Up @@ -375,6 +376,7 @@ namespace indigo
class BaseCDXElement
{
public:
virtual ~BaseCDXElement() = default;
virtual bool hasContent() = 0;
virtual std::unique_ptr<BaseCDXElement> copy() = 0;
virtual std::unique_ptr<BaseCDXProperty> firstProperty() = 0;
Expand Down
1 change: 1 addition & 0 deletions core/indigo-core/molecule/src/molecule_stereocenters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ MoleculeStereocenters::MoleculeStereocenters()
void MoleculeStereocenters::clear()
{
_stereocenters.clear();
_atropocenters.clear();
}

void MoleculeStereocenters::buildFromBonds(BaseMolecule& baseMolecule, const StereocentersOptions& options, int* sensible_bonds_out)
Expand Down
34 changes: 34 additions & 0 deletions core/indigo-core/tests/tests/formats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#include <molecule/sdf_loader.h>
#include <molecule/smiles_loader.h>
#include <molecule/smiles_saver.h>
#include <reaction/reaction_cdxml_loader.h>

#include "common.h"

Expand Down Expand Up @@ -559,6 +560,39 @@ TEST_F(IndigoCoreFormatsTest, mol_to_document)
}
}

TEST_F(IndigoCoreFormatsTest, wrong_stereochemistry_2739)
{
FileScanner scanner(dataPath("reactions/basic/wrong_stereochemistry_2739.cdxml").c_str());
Reaction reaction;
ReactionCdxmlLoader loader(scanner);
loader.loadReaction(reaction);

std::vector<std::pair<int, int>> testData = {{1, 1}, {1, 2}, {2, 1}};

std::vector<std::pair<int, int>> bondDirections;
for (int i = reaction.begin(); i != reaction.end(); i = reaction.next(i))
{
const Molecule& mol = reaction.getMolecule(i);
int bondUp = 0;
int bondDown = 0;
for (int j = mol.edgeBegin(); j != mol.edgeEnd(); j = mol.edgeNext(j))
{
int direction = mol.getBondDirection(j);
if (direction == BOND_UP)
{
++bondUp;
}
else if (direction == BOND_DOWN)
{
++bondDown;
}
}
bondDirections.push_back({bondUp, bondDown});
}

ASSERT_EQ(testData, bondDirections);
}

#ifdef _MSC_VER
#pragma warning(pop)
#endif
Loading

0 comments on commit 1110103

Please sign in to comment.