diff --git a/modelling/doc/algorithms.rst b/modelling/doc/algorithms.rst index da9e0b925367faf68d6cabc648106800c41a50f0..66ab34525ddd7d8f74fb8481322c224990ba1d71 100644 --- a/modelling/doc/algorithms.rst +++ b/modelling/doc/algorithms.rst @@ -32,12 +32,13 @@ modelling problem. This typically massively reduces the problem size by solving small subproblems and allows to tackle larger problems in a feasible amount of computing time. -.. method:: ElEnumerador(mhandle, loop_candidates, start_resnums, chain_indices, weights) +.. method:: ElEnumerador(mhandle, loop_candidates, start_resnums, \ + chain_indices, weights, [fill_solution = true]) Searches the the loops in **loop_candidates** that optimize the score using the scorer that is set in **mhandle** and the given **weights**. - They get directly set in the model and in the scoring environment attached to - the **mhandle**. + If **fill_solution** is true, they get directly set in the model and in the + scoring environment attached to the **mhandle**. :param mhandle: A handle with valid scorer attached, that contains all scores for which you defined a weight in @@ -50,11 +51,19 @@ of computing time. :class:`LoopCandidates` belong. :param weights: The weights used for a linear combinations of scores + :param fill_solution: Whether to fill the solution in the model and + backbone_scorer_env of **mhandle** + + :type mhandle: :class:`ModellingHandle` :type loop_candidates: :class:`list` :type start_resnums: :class:`list` :type chain_indices: :class:`list` :type weights: :class:`dict` + :type fill_solution: :class:`bool` + + :returns: A list specifying the optimal index for every element in + **loop_candidates**. Rigid Blocks -------------------------------------------------------------------------------- diff --git a/modelling/pymod/export_el_enumerador.cc b/modelling/pymod/export_el_enumerador.cc index dbbcf009ca860c756abc9b6c2ac5d54d912e92b9..315f4680b3421993ff6914a9d6171be9ccc842b8 100644 --- a/modelling/pymod/export_el_enumerador.cc +++ b/modelling/pymod/export_el_enumerador.cc @@ -8,11 +8,12 @@ using namespace promod3::modelling; namespace{ -void WrapEnumerador(ModellingHandle& mhandle, - const boost::python::list& loop_candidates, - const boost::python::list& start_resnums, - const boost::python::list& chain_indices, - const boost::python::dict& weights){ +boost::python::list WrapEnumerador(ModellingHandle& mhandle, + const boost::python::list& loop_candidates, + const boost::python::list& start_resnums, + const boost::python::list& chain_indices, + const boost::python::dict& weights, + bool fill_solutions){ std::vector<promod3::modelling::LoopCandidates> v_loop_candidates; std::vector<uint> v_start_resnums; @@ -24,8 +25,17 @@ void WrapEnumerador(ModellingHandle& mhandle, promod3::core::ConvertListToVector(chain_indices, v_chain_indices); promod3::core::ConvertDictToMap(weights, m_weights); - promod3::modelling::ElEnumerador(mhandle, v_loop_candidates, v_start_resnums, - v_chain_indices, m_weights); + std::vector<int> solution = promod3::modelling::ElEnumerador(mhandle, + v_loop_candidates, + v_start_resnums, + v_chain_indices, + m_weights, + fill_solutions); + + boost::python::list return_list; + promod3::core::AppendVectorToList(solution,return_list); + + return return_list; } } @@ -36,6 +46,8 @@ void WrapEnumerador(ModellingHandle& mhandle, void export_el_enumerador(){ - def("ElEnumerador", &WrapEnumerador, (arg("mhandle"),arg("loop_candidates"),arg("start_resnums"),arg("chain_indices"),arg("weights"))); + def("ElEnumerador", &WrapEnumerador, (arg("mhandle"),arg("loop_candidates"), + arg("start_resnums"),arg("chain_indices"), + arg("weights"),arg("fill_solutions")=true)); } \ No newline at end of file diff --git a/modelling/src/el_enumerador.cc b/modelling/src/el_enumerador.cc index a0e72bfd03dd92a87ddf8563acfeeaf731d897f1..c3a8eca1bac33f62839205a02fefdb3f941a53b1 100644 --- a/modelling/src/el_enumerador.cc +++ b/modelling/src/el_enumerador.cc @@ -706,13 +706,19 @@ void Fill(promod3::modelling::ModellingHandle& mhandle, namespace promod3{ namespace modelling{ -void ElEnumerador(ModellingHandle& mhandle, - const std::vector<LoopCandidates>& loop_candidates, - const std::vector<uint>& start_resnums, - const std::vector<uint>& chain_indices, - const std::map<String,Real>& weights){ +std::vector<int> ElEnumerador(ModellingHandle& mhandle, + const std::vector<LoopCandidates>& loop_candidates, + const std::vector<uint>& start_resnums, + const std::vector<uint>& chain_indices, + const std::map<String,Real>& weights, + bool fill_solution){ CheckInput(mhandle, loop_candidates, start_resnums, chain_indices, weights); + std::vector<int> solution(loop_candidates.size(), 0); + + if(loop_candidates.empty()){ + return solution; + } if(loop_candidates.size() == 1){ //there is not much graph stuff to do... @@ -721,10 +727,12 @@ void ElEnumerador(ModellingHandle& mhandle, start_resnums[0], chain_indices[0], weights); - std::vector<int> solution(1, best_idx); - Fill(mhandle, solution, loop_candidates, start_resnums, - chain_indices); - return; + solution[0] = best_idx; + + if(fill_solution){ + Fill(mhandle, solution, loop_candidates, start_resnums, chain_indices); + } + return solution; } promod3::core::Graph graph = BuildInteractionGraph(loop_candidates, 10.0); @@ -742,7 +750,7 @@ void ElEnumerador(ModellingHandle& mhandle, std::vector<uint> component_start_resnums; for(uint j = 0; j < num_candidates; ++j){ - uint idx = indices[j]; + uint idx = indices[j]; component_loop_candidates.push_back(loop_candidates[idx]); component_chain_indices.push_back(chain_indices[idx]); component_start_resnums.push_back(start_resnums[idx]); @@ -765,25 +773,35 @@ void ElEnumerador(ModellingHandle& mhandle, std::vector<Real> loop_candidate_weights; Real sum = 0.0; - for(std::vector<promod3::modelling::LoopCandidates>::const_iterator i = + for(std::vector<promod3::modelling::LoopCandidates>::const_iterator j = component_loop_candidates.begin(); - i != component_loop_candidates.end(); ++i){ - loop_candidate_weights.push_back((*i)[0].size()); + j != component_loop_candidates.end(); ++j){ + loop_candidate_weights.push_back((*j)[0].size()); sum += loop_candidate_weights.back(); } - for(uint i = 0; i < loop_candidate_weights.size(); ++i){ - loop_candidate_weights[i] /= sum; + for(uint j = 0; j < loop_candidate_weights.size(); ++j){ + loop_candidate_weights[j] /= sum; } - std::vector<int> solution = TreeResolve(mhandle, component_loop_candidates, - component_start_resnums, - component_chain_indices, - weights, loop_candidate_weights, - component_graph); + std::vector<int> component_solution = TreeResolve(mhandle, + component_loop_candidates, + component_start_resnums, + component_chain_indices, + weights, + loop_candidate_weights, + component_graph); + + //fill in the component solution + for(uint j = 0; j < indices.size(); ++j){ + solution[indices[j]] = component_solution[j]; + } + } - Fill(mhandle, solution, component_loop_candidates, component_start_resnums, - component_chain_indices); + if(fill_solution){ + Fill(mhandle, solution, loop_candidates, start_resnums, chain_indices); } + + return solution; } }} //ns diff --git a/modelling/src/el_enumerador.hh b/modelling/src/el_enumerador.hh index 1d4c7339a3ba1f318300303ae5524d684939cb41..d72ec47a29ce3e9bf6a9ddb32fef5d9521051a7d 100644 --- a/modelling/src/el_enumerador.hh +++ b/modelling/src/el_enumerador.hh @@ -8,11 +8,12 @@ namespace promod3 { namespace modelling { -void ElEnumerador(ModellingHandle& mhandle, - const std::vector<LoopCandidates>& loop_candidates, - const std::vector<uint>& start_resnums, - const std::vector<uint>& chain_indices, - const std::map<String,Real>& weights); +std::vector<int> ElEnumerador(ModellingHandle& mhandle, + const std::vector<LoopCandidates>& loop_candidates, + const std::vector<uint>& start_resnums, + const std::vector<uint>& chain_indices, + const std::map<String,Real>& weights, + bool fill_solution = true); }} //ns