Skip to content

Commit

Permalink
Issue #520: api: replace RedBlackMap in IndigoDeconvolution (#803)
Browse files Browse the repository at this point in the history
* Issue #520: core: replace RedBlackMap and RedBlackSet implementation with standard containers
IndigoDeconvolution class is updated.

* Issue #520: core: replace RedBlackMap and RedBlackSet implementation with standard containers
Fix clang-formatter issue

* Issue #520: core: replace RedBlackMap and RedBlackSet implementation with standard containers
Removed internal usage of RedBlackMap from IndigoDeconvolution.

Co-authored-by: Alexander Stepaniuk <AStepanjuk@gmail.com>
Co-authored-by: Aliaksander Stsepaniuk <Aliaksander_Stsepaniuk@epam.com>
  • Loading branch information
3 people authored Aug 7, 2022
1 parent 774ebd6 commit 14d7805
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 21 deletions.
41 changes: 21 additions & 20 deletions api/c/indigo/src/indigo_deconvolution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,8 +370,8 @@ void IndigoDeconvolution::createRgroups(IndigoDecompositionMatch& deco_match, bo
QS_DEF(Array<int>, inv_scaf_map);
QS_DEF(Array<int>, rg_mapping);
QS_DEF(Array<int>, rgidx_map);
RedBlackMap<int, int> att_ord_map;
RedBlackMap<int, int> att_bond_map;
std::map<int, int> att_ord_map;
std::map<int, int> att_bond_map;
int att_order, att_idx;

Array<int>& visited_atoms = deco_match.visitedAtoms;
Expand Down Expand Up @@ -426,10 +426,11 @@ void IndigoDeconvolution::createRgroups(IndigoDecompositionMatch& deco_match, bo
/*
* Fulfil attachment order map
*/
if (!att_ord_map.find(att_order))
auto att_order_it = att_ord_map.find(att_order);
if (att_order_it == att_ord_map.end())
{
++att_val;
att_ord_map.insert(att_order, att_val);
att_order_it = att_ord_map.emplace(att_order, att_val).first;
}
/*
* Add a bond with the same order
Expand All @@ -445,7 +446,7 @@ void IndigoDeconvolution::createRgroups(IndigoDecompositionMatch& deco_match, bo
* Set Rsite attachment order one lower since old api was not changed
*/
if (!save_ap_bond_orders)
r_molecule.setRSiteAttachmentOrder(new_atom_idx, inv_scaf_map[att_order], att_ord_map.at(att_order) - 1);
r_molecule.setRSiteAttachmentOrder(new_atom_idx, inv_scaf_map[att_order], att_order_it->second - 1);
}
MoleculeRGroups& mol_rgroups = r_molecule.rgroups;

Expand Down Expand Up @@ -500,13 +501,14 @@ void IndigoDeconvolution::createRgroups(IndigoDecompositionMatch& deco_match, bo
/*
* Add AP saved on the previous iteration or add as a new for the following AP
*/
if (att_bond_map.find(edge_idx))
const auto edge_idx_it = att_bond_map.find(edge_idx);
if (edge_idx_it != att_bond_map.end())
{
fragment.addBond(ap_atom_idx, att_bond_map.at(edge_idx), mol_set.getBondOrder(edge_idx));
fragment.addBond(ap_atom_idx, edge_idx_it->second, mol_set.getBondOrder(edge_idx));
}
else
{
att_bond_map.insert(edge_idx, ap_atom_idx);
att_bond_map.emplace(edge_idx, ap_atom_idx);
}
}
else
Expand Down Expand Up @@ -1296,7 +1298,7 @@ void IndigoDeconvolution::DecompositionEnumerator::addMatch(IndigoDecompositionM
*/
QueryMolecule r_molecule;
ObjArray<Array<int>> rsite_orders;
RedBlackMap<int, int> r_sites;
std::map<int, int> r_sites;
QS_DEF(RedBlackSet<int>, processed_r);
QS_DEF(Array<int>, swap_order);
Array<int>& direct_order = rsite_orders.push();
Expand Down Expand Up @@ -1334,9 +1336,9 @@ void IndigoDeconvolution::DecompositionEnumerator::addMatch(IndigoDecompositionM
/*
* Add direct order automap
*/
for (int rs_idx = r_sites.begin(); rs_idx != r_sites.end(); rs_idx = r_sites.next(rs_idx))
for (const auto& pair : r_sites)
{
direct_order.push(r_sites.key(rs_idx));
direct_order.push(pair.first);
}
for (int auto_idx = _autoMaps.begin(); auto_idx != _autoMaps.end(); auto_idx = _autoMaps.next(auto_idx))
{
Expand All @@ -1345,10 +1347,10 @@ void IndigoDeconvolution::DecompositionEnumerator::addMatch(IndigoDecompositionM
* Check for correctness and condition
*/
swap_order.clear();
for (int rs_idx = r_sites.begin(); rs_idx != r_sites.end(); rs_idx = r_sites.next(rs_idx))
for (const auto& pair : r_sites)
{
int rs_key = r_sites.key(rs_idx);
if (!r_sites.find(auto_map[rs_key]))
auto rs_key = pair.first;
if (r_sites.find(auto_map[rs_key]) == r_sites.end())
throw IndigoDeconvolution::Error("internal error: incorrect automorphism for a scaffold");
/*
* Create swap order
Expand All @@ -1364,14 +1366,14 @@ void IndigoDeconvolution::DecompositionEnumerator::addMatch(IndigoDecompositionM
* Swap RGroup indexes
*/
processed_r.clear();
for (int rs_idx = r_sites.begin(); rs_idx != r_sites.end(); rs_idx = r_sites.next(rs_idx))
for (const auto& pair : r_sites)
{
int rs_key = r_sites.key(rs_idx);
auto rs_key = pair.first;
if (!processed_r.find(rs_key) && auto_map[rs_key] != rs_key)
{
processed_r.find_or_insert(rs_key);
processed_r.find_or_insert(auto_map[rs_key]);
_swapIndexes(nu_match, r_sites.value(rs_idx), r_sites.at(auto_map[rs_key]));
_swapIndexes(nu_match, pair.second, r_sites.at(auto_map[rs_key]));
}
}
}
Expand Down Expand Up @@ -1517,8 +1519,7 @@ void IndigoDeconvolution::DecompositionEnumerator::_refineAutoMaps(ObjList<Array
}
}

void IndigoDeconvolution::DecompositionEnumerator::_addAllRsites(QueryMolecule& r_molecule, IndigoDecompositionMatch& deco_match,
RedBlackMap<int, int>& r_sites)
void IndigoDeconvolution::DecompositionEnumerator::_addAllRsites(QueryMolecule& r_molecule, IndigoDecompositionMatch& deco_match, std::map<int, int>& r_sites)
{

r_sites.clear();
Expand All @@ -1536,7 +1537,7 @@ void IndigoDeconvolution::DecompositionEnumerator::_addAllRsites(QueryMolecule&
if (att_orders.size() > 0)
{
new_atom_idx = r_molecule.addAtom(new QueryMolecule::Atom(QueryMolecule::ATOM_RSITE, 0));
r_sites.insert(new_atom_idx, rg_idx);
r_sites.emplace(new_atom_idx, rg_idx);
}

/*
Expand Down
4 changes: 3 additions & 1 deletion api/c/indigo/src/indigo_deconvolution.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#ifndef __indigo_deconvolution__
#define __indigo_deconvolution__

#include <map>

#include "base_cpp/obj_list.h"
#include "base_cpp/properties_map.h"
#include "indigo_internal.h"
Expand Down Expand Up @@ -107,7 +109,7 @@ class DLLEXPORT IndigoDeconvolution : public IndigoObject
bool _foundOrder(ObjArray<Array<int>>& rsite_orders, Array<int>& swap_order);
void _swapIndexes(IndigoDecompositionMatch&, int old_idx, int new_idx);
void _refineAutoMaps(ObjList<Array<int>>& auto_maps, Graph& sub, Graph& super, Array<int>& scaf_map);
void _addAllRsites(QueryMolecule&, IndigoDecompositionMatch&, RedBlackMap<int, int>&);
void _addAllRsites(QueryMolecule&, IndigoDecompositionMatch&, std::map<int, int>&);

static bool _cbAutoCheckAutomorphism(Graph& graph, const Array<int>& mapping, const void* context);
ObjList<Array<int>> _autoMaps;
Expand Down

0 comments on commit 14d7805

Please sign in to comment.