diff --git a/loop/src/idx_handler.cc b/loop/src/idx_handler.cc index 40558c48a9338389aceb3f878724a7f9aa86e2ee..5cee45a4da30b96e3c0c6e5be5943074290e15db 100644 --- a/loop/src/idx_handler.cc +++ b/loop/src/idx_handler.cc @@ -46,6 +46,34 @@ std::vector<uint> IdxHandler::ToIdxVector(uint start_resnum, uint num_residues, return idx; } +std::vector<uint> +IdxHandler::ToIdxVector(const std::vector<uint>& start_resnums, + const std::vector<uint>& num_residues, + const std::vector<uint>& chain_indices, + std::vector<uint>& loop_start_indices, + std::vector<uint>& loop_lengths, + bool enable_log) const { + // get loop indices (checks errors. resolves overlaps & reports merges/del.) + std::vector<uint> env_loop_start_indices; + ToLoopIndices(start_resnums, num_residues, chain_indices, + env_loop_start_indices, loop_lengths, enable_log); + + // process output to get idx-vector + std::vector<uint> indices; + const uint num_loops = loop_lengths.size(); + loop_start_indices.resize(num_loops); + for (uint i_loop = 0; i_loop < num_loops; ++i_loop) { + const uint loop_start_idx = indices.size(); + const uint loop_length = loop_lengths[i_loop]; + indices.resize(loop_start_idx + loop_length); + loop_start_indices[i_loop] = loop_start_idx; + for (uint i = 0; i < loop_length; ++i) { + indices[loop_start_idx + i] = env_loop_start_indices[i_loop] + i; + } + } + return indices; +} + void IdxHandler::SetupScoreCalculation(const loop::BackboneList& bb_list, uint start_resnum, uint chain_idx, uint& bb_list_size, uint& start_idx, diff --git a/loop/src/idx_handler.hh b/loop/src/idx_handler.hh index e91423f4d7be5b175cd42b776e9bf25262e12533..c16463f2f100a626206acdf50b78b480599e1c7b 100644 --- a/loop/src/idx_handler.hh +++ b/loop/src/idx_handler.hh @@ -42,6 +42,16 @@ public: std::vector<uint> ToIdxVector(uint start_resnum, uint num_residues, uint chain_idx) const; + // returns vector of indices for multiple loops + // -> uses ToLoopIndices below but loop_start_indices refer to returned index + // vector (all loop index vectors combined one after the other) + std::vector<uint> ToIdxVector(const std::vector<uint>& start_resnums, + const std::vector<uint>& num_residues, + const std::vector<uint>& chain_indices, + std::vector<uint>& loop_start_indices, + std::vector<uint>& loop_lengths, + bool enable_log = false) const; + // check input and set commonly used variables void SetupScoreCalculation(const loop::BackboneList& bb_list, uint start_resnum, uint chain_idx, diff --git a/loop/tests/test_idx_handler.cc b/loop/tests/test_idx_handler.cc index a93ca4607120f38e21977b9d4c010ec7b9560f8d..1ae50995d44229053a85ea9c7280fef941d13726 100644 --- a/loop/tests/test_idx_handler.cc +++ b/loop/tests/test_idx_handler.cc @@ -224,9 +224,34 @@ BOOST_AUTO_TEST_CASE(test_idx_handler_multi_loops) { BOOST_CHECK_EQUAL(loop_lengths.size(), 2u); BOOST_CHECK(HasLoop(loop_start_indices, loop_lengths, 10, 8)); BOOST_CHECK(HasLoop(loop_start_indices, loop_lengths, 5, 2)); - num_residues[0] = 2; + + // check ToIdxVector + std::vector<uint> res_indices + = idx_handler.ToIdxVector(start_resnums, num_residues, chain_indices, + loop_start_indices, loop_lengths); + BOOST_CHECK_EQUAL(res_indices.size(), 10u); + BOOST_CHECK_EQUAL(loop_start_indices.size(), 2u); + BOOST_CHECK_EQUAL(loop_lengths.size(), 2u); + BOOST_CHECK_EQUAL(loop_start_indices[0], 0u); + BOOST_CHECK_EQUAL(loop_start_indices[1], loop_lengths[0]); + // we cannot assume any order so we need to resolve both options + if (loop_lengths[0] == 8) { + BOOST_CHECK_EQUAL(loop_lengths[1], 2u); + for (uint i = 0; i < 10; ++i) { + if (i < 8) BOOST_CHECK_EQUAL(res_indices[i], 10 + i); + else BOOST_CHECK_EQUAL(res_indices[i], 5 + i - 8); + } + } else { + BOOST_CHECK_EQUAL(loop_lengths[0], 2u); + BOOST_CHECK_EQUAL(loop_lengths[1], 8u); + for (uint i = 0; i < 10; ++i) { + if (i < 2) BOOST_CHECK_EQUAL(res_indices[i], 5 + i); + else BOOST_CHECK_EQUAL(res_indices[i], 10 + i - 2); + } + } // exceptions + num_residues[0] = 2; start_resnums[0] = 9; BOOST_CHECK_THROW(idx_handler.ToLoopIndices(start_resnums, num_residues, chain_indices, loop_start_indices,