From 18424d1212cd3d77d6876728f37f9030d2092510 Mon Sep 17 00:00:00 2001 From: Aliaksander Stsepaniuk Date: Wed, 10 Aug 2022 17:07:52 +0300 Subject: [PATCH 1/3] #815 Replace ObjArray with std::vector IndigoDeconvolution update --- api/c/indigo/src/indigo_deconvolution.cpp | 32 ++++++++++++----------- api/c/indigo/src/indigo_deconvolution.h | 5 ++-- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/api/c/indigo/src/indigo_deconvolution.cpp b/api/c/indigo/src/indigo_deconvolution.cpp index 69c06f1ab4..f184bc58be 100644 --- a/api/c/indigo/src/indigo_deconvolution.cpp +++ b/api/c/indigo/src/indigo_deconvolution.cpp @@ -217,8 +217,8 @@ int IndigoDeconvolution::_rGroupsEmbedding(Graph& graph1, Graph& graph2, int* ma * Order - atom number for scaffold * Index - atom number for Rgroup */ - ObjArray>& attachment_order = deco_match.attachmentOrder; - ObjArray>& attachment_index = deco_match.attachmentIndex; + std::vector>& attachment_order = deco_match.attachmentOrder; + std::vector>& attachment_index = deco_match.attachmentIndex; visited_atoms.clear_resize(graph2.vertexEnd()); visited_atoms.zerofill(); @@ -226,8 +226,8 @@ int IndigoDeconvolution::_rGroupsEmbedding(Graph& graph1, Graph& graph2, int* ma attachment_index.clear(); attachment_order.clear(); - attachment_index.push(); - attachment_order.push(); + attachment_index.emplace_back(); + attachment_order.emplace_back(); /* * Calculate scaffold atoms and Rgroup atoms */ @@ -294,8 +294,8 @@ int IndigoDeconvolution::_rGroupsEmbedding(Graph& graph1, Graph& graph2, int* ma } ++n_rgroups; - attachment_index.push(); - attachment_order.push(); + attachment_index.emplace_back(); + attachment_order.emplace_back(); } visited_atoms[start_idx] = 1; @@ -338,8 +338,8 @@ int IndigoDeconvolution::_rGroupsEmbedding(Graph& graph1, Graph& graph2, int* ma attachment_index[n_rgroups].push(edge.end); attachment_order[n_rgroups].push(edge.beg); - attachment_index.push(); - attachment_order.push(); + attachment_index.emplace_back(); + attachment_order.emplace_back(); ++n_rgroups; } @@ -376,8 +376,8 @@ void IndigoDeconvolution::createRgroups(IndigoDecompositionMatch& deco_match, bo Array& visited_atoms = deco_match.visitedAtoms; - ObjArray>& attachment_order = deco_match.attachmentOrder; - ObjArray>& attachment_index = deco_match.attachmentIndex; + std::vector>& attachment_order = deco_match.attachmentOrder; + std::vector>& attachment_index = deco_match.attachmentIndex; int n_rgroups = deco_match.getRgroupNumber(); /* @@ -657,11 +657,13 @@ void IndigoDecompositionMatch::copy(IndigoDecompositionMatch& other) attachmentIndex.clear(); for (int i = 0; i < other.attachmentOrder.size(); ++i) { - attachmentOrder.push().copy(other.attachmentOrder[i]); + attachmentOrder.emplace_back(); + attachmentOrder.back().copy(other.attachmentOrder[i]); } for (int i = 0; i < other.attachmentIndex.size(); ++i) { - attachmentIndex.push().copy(other.attachmentIndex[i]); + attachmentIndex.emplace_back(); + attachmentIndex.back().copy(other.attachmentIndex[i]); } mol_out.clone_KeepIndices(other.mol_out, 0); @@ -1123,7 +1125,7 @@ int IndigoDeconvolution::_createRgMap(IndigoDecompositionMatch& deco_match, int int max_rg_idx = match_rgroups.at("max_rg_idx").at(0); int n_rgroups = deco_match.getRgroupNumber(); - ObjArray>& attachment_order = deco_match.attachmentOrder; + std::vector>& attachment_order = deco_match.attachmentOrder; Array& map = deco_match.lastInvMapping; int result_num = 0; @@ -1408,8 +1410,8 @@ bool IndigoDeconvolution::DecompositionEnumerator::_foundOrder(ObjArray, tmp_buf); - ObjArray>& attachment_order = match.attachmentOrder; - ObjArray>& attachment_index = match.attachmentIndex; + std::vector>& attachment_order = match.attachmentOrder; + std::vector>& attachment_index = match.attachmentIndex; tmp_buf.copy(attachment_order[old_idx]); attachment_order[old_idx].copy(attachment_order[new_idx]); diff --git a/api/c/indigo/src/indigo_deconvolution.h b/api/c/indigo/src/indigo_deconvolution.h index ac1e669fee..ca5888be45 100644 --- a/api/c/indigo/src/indigo_deconvolution.h +++ b/api/c/indigo/src/indigo_deconvolution.h @@ -20,6 +20,7 @@ #define __indigo_deconvolution__ #include +#include #include "base_cpp/obj_list.h" #include "base_cpp/properties_map.h" @@ -178,8 +179,8 @@ class DLLEXPORT IndigoDecompositionMatch : public IndigoObject Array scaffoldAtoms; Array lastMapping; Array lastInvMapping; - ObjArray> attachmentOrder; - ObjArray> attachmentIndex; + std::vector> attachmentOrder; + std::vector> attachmentIndex; ObjList> scafAutoMaps; int getRgroupNumber() const From 5eac32b53dabf89823ef81f4086a2a1e71e2d701 Mon Sep 17 00:00:00 2001 From: Aliaksander Stsepaniuk Date: Wed, 14 Sep 2022 13:46:03 +0300 Subject: [PATCH 2/3] #815 Replace ObjList with std::vector in IndigoDeconvolution --- api/c/indigo/src/indigo_deconvolution.cpp | 44 ++++++++++++++--------- api/c/indigo/src/indigo_deconvolution.h | 10 +++--- core/indigo-core/common/base_cpp/array.h | 2 +- 3 files changed, 34 insertions(+), 22 deletions(-) diff --git a/api/c/indigo/src/indigo_deconvolution.cpp b/api/c/indigo/src/indigo_deconvolution.cpp index f184bc58be..3f9a7ccfea 100644 --- a/api/c/indigo/src/indigo_deconvolution.cpp +++ b/api/c/indigo/src/indigo_deconvolution.cpp @@ -16,6 +16,8 @@ * limitations under the License. ***************************************************************************/ + #include + #include "indigo_deconvolution.h" #include "base_cpp/array.h" #include "base_cpp/obj_array.h" @@ -690,13 +692,13 @@ void IndigoDecompositionMatch::removeRsitesFromMaps(Graph& query_graph) } } -void IndigoDecompositionMatch::copyScafAutoMaps(ObjList>& autoMaps) +void IndigoDecompositionMatch::copyScafAutoMaps(const std::vector>& autoMaps) { scafAutoMaps.clear(); - for (int i = autoMaps.begin(); i != autoMaps.end(); i = autoMaps.next(i)) + for (const auto& src: autoMaps) { - int idx = scafAutoMaps.add(); - scafAutoMaps.at(idx).copy(autoMaps[i]); + scafAutoMaps.emplace_back(); + scafAutoMaps.back().copy(src); } } @@ -953,7 +955,7 @@ void IndigoDeconvolution::addCompleteRGroup(IndigoDecompositionMatch& deco_match if (deco_match.scafAutoMaps.size() == 0) throw Error("internal error: can not calculate scaffold matchings for null automorphism"); - for (int aut_idx = deco_match.scafAutoMaps.begin(); aut_idx != deco_match.scafAutoMaps.end(); aut_idx = deco_match.scafAutoMaps.next(aut_idx)) + for (int aut_idx = 0; aut_idx < deco_match.scafAutoMaps.size(); ++aut_idx) { int new_rg_num = _createRgMap(deco_match, aut_idx, match_rgroups, &rg_map_buf, false); /* @@ -1239,8 +1241,8 @@ void IndigoDeconvolution::DecompositionEnumerator::calculateAutoMaps(Graph& sub) */ _scafAutoMaps.clear(); - int l_idx = _scafAutoMaps.add(); - Array& d_map = _scafAutoMaps.at(l_idx); + _scafAutoMaps.emplace_back(); + Array& d_map = _scafAutoMaps.back(); d_map.resize(sub.vertexEnd()); for (int i = 0; i < d_map.size(); ++i) { @@ -1342,9 +1344,8 @@ void IndigoDeconvolution::DecompositionEnumerator::addMatch(IndigoDecompositionM { direct_order.push(pair.first); } - for (int auto_idx = _autoMaps.begin(); auto_idx != _autoMaps.end(); auto_idx = _autoMaps.next(auto_idx)) + for (const Array& auto_map: _autoMaps) { - Array& auto_map = _autoMaps[auto_idx]; /* * Check for correctness and condition */ @@ -1436,7 +1437,7 @@ void IndigoDeconvolution::DecompositionEnumerator::_swapIndexes(IndigoDecomposit } } -void IndigoDeconvolution::DecompositionEnumerator::_refineAutoMaps(ObjList>& auto_maps, Graph& sub_in, Graph& super, Array& scaf_map) +void IndigoDeconvolution::DecompositionEnumerator::_refineAutoMaps(std::vector>& auto_maps, Graph& sub_in, Graph& super, Array& scaf_map) { QS_DEF(Array, indices_to_remove); indices_to_remove.clear(); @@ -1444,7 +1445,7 @@ void IndigoDeconvolution::DecompositionEnumerator::_refineAutoMaps(ObjList& auto_map = auto_maps.at(auto_idx); @@ -1515,10 +1516,21 @@ void IndigoDeconvolution::DecompositionEnumerator::_refineAutoMaps(ObjList& r_sites) @@ -1560,9 +1572,9 @@ void IndigoDeconvolution::DecompositionEnumerator::_addAllRsites(QueryMolecule& bool IndigoDeconvolution::DecompositionEnumerator::_cbAutoCheckAutomorphism(Graph&, const Array& mapping, const void* context) { - ObjList>& auto_maps = *(ObjList>*)context; - int l_idx = auto_maps.add(); - auto_maps.at(l_idx).copy(mapping); + std::vector>& auto_maps = *(std::vector>*)context; + auto_maps.emplace_back(); + auto_maps.back().copy(mapping); return false; } diff --git a/api/c/indigo/src/indigo_deconvolution.h b/api/c/indigo/src/indigo_deconvolution.h index ca5888be45..eafc847ce8 100644 --- a/api/c/indigo/src/indigo_deconvolution.h +++ b/api/c/indigo/src/indigo_deconvolution.h @@ -109,12 +109,12 @@ class DLLEXPORT IndigoDeconvolution : public IndigoObject DecompositionEnumerator(const DecompositionEnumerator&); // no implicit copy bool _foundOrder(ObjArray>& rsite_orders, Array& swap_order); void _swapIndexes(IndigoDecompositionMatch&, int old_idx, int new_idx); - void _refineAutoMaps(ObjList>& auto_maps, Graph& sub, Graph& super, Array& scaf_map); + void _refineAutoMaps(std::vector>& auto_maps, Graph& sub, Graph& super, Array& scaf_map); void _addAllRsites(QueryMolecule&, IndigoDecompositionMatch&, std::map&); static bool _cbAutoCheckAutomorphism(Graph& graph, const Array& mapping, const void* context); - ObjList> _autoMaps; - ObjList> _scafAutoMaps; + std::vector> _autoMaps; + std::vector> _scafAutoMaps; }; void addCompleteRGroup(IndigoDecompositionMatch& emb_context, bool change_scaffold, Array* rg_map); @@ -181,7 +181,7 @@ class DLLEXPORT IndigoDecompositionMatch : public IndigoObject Array lastInvMapping; std::vector> attachmentOrder; std::vector> attachmentIndex; - ObjList> scafAutoMaps; + std::vector> scafAutoMaps; int getRgroupNumber() const { @@ -191,7 +191,7 @@ class DLLEXPORT IndigoDecompositionMatch : public IndigoObject void renumber(Array& map, Array& inv_map); void copy(IndigoDecompositionMatch& other); void removeRsitesFromMaps(Graph& query_graph); - void copyScafAutoMaps(ObjList>& autoMaps); + void copyScafAutoMaps(const std::vector>& autoMaps); void completeScaffold(); Molecule mol_out; diff --git a/core/indigo-core/common/base_cpp/array.h b/core/indigo-core/common/base_cpp/array.h index bb83161e89..9501b40b76 100644 --- a/core/indigo-core/common/base_cpp/array.h +++ b/core/indigo-core/common/base_cpp/array.h @@ -44,7 +44,7 @@ namespace indigo { } - Array(Array&& other) : _reserved(other._reserved), _length(other._length), _array(other._array) + Array(Array&& other) noexcept : _reserved(other._reserved), _length(other._length), _array(other._array) { other._array = nullptr; other._length = 0; From 42ab5494980bbb50168b6f912f329ebdeced2fb9 Mon Sep 17 00:00:00 2001 From: Alexander Stepaniuk Date: Thu, 15 Sep 2022 13:29:50 +0300 Subject: [PATCH 3/3] Issue #815 Fix formatting --- api/c/indigo/src/indigo_deconvolution.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/api/c/indigo/src/indigo_deconvolution.cpp b/api/c/indigo/src/indigo_deconvolution.cpp index 3f9a7ccfea..b030bb619c 100644 --- a/api/c/indigo/src/indigo_deconvolution.cpp +++ b/api/c/indigo/src/indigo_deconvolution.cpp @@ -16,9 +16,8 @@ * limitations under the License. ***************************************************************************/ - #include +#include -#include "indigo_deconvolution.h" #include "base_cpp/array.h" #include "base_cpp/obj_array.h" #include "base_cpp/obj_list.h" @@ -26,6 +25,7 @@ #include "base_cpp/tlscont.h" #include "graph/automorphism_search.h" #include "indigo_array.h" +#include "indigo_deconvolution.h" #include "indigo_molecule.h" #include "molecule/elements.h" #include "molecule/max_common_submolecule.h" @@ -695,7 +695,7 @@ void IndigoDecompositionMatch::removeRsitesFromMaps(Graph& query_graph) void IndigoDecompositionMatch::copyScafAutoMaps(const std::vector>& autoMaps) { scafAutoMaps.clear(); - for (const auto& src: autoMaps) + for (const auto& src : autoMaps) { scafAutoMaps.emplace_back(); scafAutoMaps.back().copy(src); @@ -1344,7 +1344,7 @@ void IndigoDeconvolution::DecompositionEnumerator::addMatch(IndigoDecompositionM { direct_order.push(pair.first); } - for (const Array& auto_map: _autoMaps) + for (const Array& auto_map : _autoMaps) { /* * Check for correctness and condition @@ -1522,7 +1522,7 @@ void IndigoDeconvolution::DecompositionEnumerator::_refineAutoMaps(std::vector