InteractionGraph get_interaction_graph(ScoringFunctionAdaptor rsi, const ParticlesTemp &ps) { if (ps.empty()) return InteractionGraph(); InteractionGraph ret(ps.size()); Restraints rs = create_decomposition(rsi->create_restraints()); // Model *m= ps[0]->get_model(); boost::unordered_map<ModelObject *, int> map; InteractionGraphVertexName pm = boost::get(boost::vertex_name, ret); DependencyGraph dg = get_dependency_graph(ps[0]->get_model()); DependencyGraphVertexIndex index = IMP::get_vertex_index(dg); /*IMP_IF_LOG(VERBOSE) { IMP_LOG_VERBOSE( "dependency graph is \n"); IMP::internal::show_as_graphviz(dg, std::cout); }*/ for (unsigned int i = 0; i < ps.size(); ++i) { ParticlesTemp t = get_dependent_particles( ps[i], ParticlesTemp(ps.begin(), ps.end()), dg, index); for (unsigned int j = 0; j < t.size(); ++j) { IMP_USAGE_CHECK(map.find(t[j]) == map.end(), "Currently particles which depend on more " << "than one particle " << "from the input set are not supported." << " Particle \"" << t[j]->get_name() << "\" depends on \"" << ps[i]->get_name() << "\" and \"" << ps[map.find(t[j])->second]->get_name() << "\""); map[t[j]] = i; } IMP_IF_LOG(VERBOSE) { IMP_LOG_VERBOSE("Particle \"" << ps[i]->get_name() << "\" controls "); for (unsigned int i = 0; i < t.size(); ++i) { IMP_LOG_VERBOSE("\"" << t[i]->get_name() << "\" "); } IMP_LOG_VERBOSE(std::endl); } pm[i] = ps[i]; } IMP::Restraints all_rs = IMP::get_restraints(rs); for (Restraints::const_iterator it = all_rs.begin(); it != all_rs.end(); ++it) { ModelObjectsTemp pl = (*it)->get_inputs(); add_edges(ps, pl, map, *it, ret); } /* Make sure that composite score states (eg the normalizer for rigid body rotations) don't induce interactions among unconnected particles.*/ ScoreStatesTemp ss = get_required_score_states(rs); for (ScoreStatesTemp::const_iterator it = ss.begin(); it != ss.end(); ++it) { ModelObjectsTemps interactions = (*it)->get_interactions(); for (unsigned int i = 0; i < interactions.size(); ++i) { add_edges(ps, interactions[i], map, *it, ret); } } IMP_INTERNAL_CHECK(boost::num_vertices(ret) == ps.size(), "Wrong number of vertices " << boost::num_vertices(ret) << " vs " << ps.size()); return ret; }
void Optimizer::update_states() const { IMP_LOG_VERBOSE("Updating OptimizerStates " << std::flush); BOOST_FOREACH(ScoreState * ss, get_required_score_states()) { ss->before_evaluate(); } for (OptimizerStateConstIterator it = optimizer_states_begin(); it != optimizer_states_end(); ++it) { IMP_CHECK_OBJECT(*it); (*it)->update(); IMP_LOG_VERBOSE("." << std::flush); } IMP_LOG_VERBOSE("done." << std::endl); }
void ScoreState::handle_set_has_required_score_states(bool tf) { if (tf) { IMP_USAGE_CHECK(update_order_ == -1, "Already had update order"); if (!get_model()->do_get_required_score_states(this).empty()) { update_order_ = get_required_score_states().back()->get_update_order() + 1; IMP_LOG_VERBOSE( "Update order for " << get_name() << " is " << update_order_ << " due to " << get_model()->do_get_required_score_states(this).back()->get_name() << std::endl); } else { update_order_ = 0; } } else { update_order_ = -1; } }