Skip to content

Commit

Permalink
#1254 SMARTS with component-level grouping saved without '()'
Browse files Browse the repository at this point in the history
Fix UTs
  • Loading branch information
AliaksandrDziarkach committed Sep 13, 2023
1 parent 51c0167 commit b95b6ab
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 15 deletions.
5 changes: 1 addition & 4 deletions core/indigo-core/molecule/query_molecule.h
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ namespace indigo
// must belong to different connected components of the target molecule
Array<int> components;

std::list<std::unordered_set<int>>& getComponentNeighbors();
void getComponentNeighbors(std::list<std::unordered_set<int>> &componentNeighbors);

void invalidateAtom(int index, int mask) override;

Expand All @@ -399,9 +399,6 @@ namespace indigo

PtrArray<Atom> _atoms;
PtrArray<Bond> _bonds;

std::list<std::unordered_set<int>> _component_neighbors;
void _calculateComponentNeighbors();
};

} // namespace indigo
Expand Down
11 changes: 3 additions & 8 deletions core/indigo-core/molecule/src/query_molecule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2141,7 +2141,7 @@ void QueryMolecule::getQueryAtomLabel(int qa, Array<char>& result)
result.readString(it->second.c_str(), true);
}

void QueryMolecule::_calculateComponentNeighbors()
void QueryMolecule::getComponentNeighbors(std::list<std::unordered_set<int>> &componentNeighbors)
{
std::unordered_map<int, std::unordered_set<int>> componentAtoms;
for (int i = 0; i < components.size(); ++i)
Expand All @@ -2152,16 +2152,11 @@ void QueryMolecule::_calculateComponentNeighbors()
componentAtoms[componentId].insert(i);
}
}
componentNeighbors.clear();
for (auto elem : componentAtoms)
{
auto atoms = elem.second;
if (atoms.size() > 1)
_component_neighbors.emplace_back(atoms);
componentNeighbors.emplace_back(atoms);
}
}

std::list<std::unordered_set<int>>& QueryMolecule::getComponentNeighbors()
{
_calculateComponentNeighbors();
return _component_neighbors;
}
6 changes: 3 additions & 3 deletions core/indigo-core/reaction/src/rsmiles_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ void RSmilesLoader::_loadReaction()
{
rcnt = std::make_unique<QueryMolecule>();
r_loader.loadQueryMolecule(static_cast<QueryMolecule&>(*rcnt));
rcnt_extNeibs = static_cast<QueryMolecule&>(*rcnt).getComponentNeighbors();
static_cast<QueryMolecule&>(*rcnt).getComponentNeighbors(rcnt_extNeibs);
}
rcnt_aam.copy(rcnt->reaction_atom_mapping);

Expand Down Expand Up @@ -162,7 +162,7 @@ void RSmilesLoader::_loadReaction()
{
ctlt = std::make_unique<QueryMolecule>();
c_loader.loadQueryMolecule(static_cast<QueryMolecule&>(*ctlt));
ctlt_extNeibs = static_cast<QueryMolecule&>(*ctlt).getComponentNeighbors();
static_cast<QueryMolecule&>(*ctlt).getComponentNeighbors(ctlt_extNeibs);
}
ctlt_aam.copy(ctlt->reaction_atom_mapping);

Expand Down Expand Up @@ -202,7 +202,7 @@ void RSmilesLoader::_loadReaction()
{
prod = std::make_unique<QueryMolecule>();
p_loader.loadQueryMolecule(static_cast<QueryMolecule&>(*prod));
prod_extNeibs = static_cast<QueryMolecule&>(*prod).getComponentNeighbors();
static_cast<QueryMolecule&>(*prod).getComponentNeighbors(prod_extNeibs);
}
prod_aam.copy(prod->reaction_atom_mapping);

Expand Down

0 comments on commit b95b6ab

Please sign in to comment.