diff --git a/api/c/indigo/src/indigo_deconvolution.cpp b/api/c/indigo/src/indigo_deconvolution.cpp index 69c06f1ab4..b030bb619c 100644 --- a/api/c/indigo/src/indigo_deconvolution.cpp +++ b/api/c/indigo/src/indigo_deconvolution.cpp @@ -16,7 +16,8 @@ * limitations under the License. ***************************************************************************/ -#include "indigo_deconvolution.h" +#include + #include "base_cpp/array.h" #include "base_cpp/obj_array.h" #include "base_cpp/obj_list.h" @@ -24,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" @@ -217,8 +219,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 +228,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 +296,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 +340,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 +378,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 +659,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); @@ -688,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); } } @@ -951,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); /* @@ -1123,7 +1127,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; @@ -1237,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) { @@ -1340,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 */ @@ -1408,8 +1411,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]); @@ -1434,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(); @@ -1442,7 +1445,7 @@ void IndigoDeconvolution::DecompositionEnumerator::_refineAutoMaps(ObjList& auto_map = auto_maps.at(auto_idx); @@ -1513,10 +1516,21 @@ void IndigoDeconvolution::DecompositionEnumerator::_refineAutoMaps(ObjList& r_sites) @@ -1558,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 ac1e669fee..eafc847ce8 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" @@ -108,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); @@ -178,9 +179,9 @@ class DLLEXPORT IndigoDecompositionMatch : public IndigoObject Array scaffoldAtoms; Array lastMapping; Array lastInvMapping; - ObjArray> attachmentOrder; - ObjArray> attachmentIndex; - ObjList> scafAutoMaps; + std::vector> attachmentOrder; + std::vector> attachmentIndex; + std::vector> scafAutoMaps; int getRgroupNumber() const { @@ -190,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;