/** * \file interaction_graph.cpp * \brief Score particles with respect to a tunnel. * * Copyright 2007-2010 IMP Inventors. All rights reserved. * */ #include #include #include #include #include #include IMPMISC_BEGIN_NAMESPACE typedef boost::graph_traits::edge_descriptor Edge; typedef boost::graph_traits::vertex_descriptor Vertex; typedef boost::property_map::type ParticleMap; typedef boost::property_map::type ObjectMap; namespace { void add_edges(const ParticlesTemp &pl, const std::map &map, Object *blame, InteractionGraph &g) { ObjectMap om= boost::get(boost::edge_name, g); for (unsigned int i=0; i< pl.size(); ++i) { Vertex vj=map.find(pl[i])->second; for (unsigned int k=0; k< i; ++k) { Vertex vk=map.find(pl[k])->second; Edge e; bool inserted; boost::tie(e, inserted)= boost::add_edge(vj, vk, g); if (inserted) { om[e]=blame; } } } } } InteractionGraph get_interaction_graph(Model *m) { InteractionGraph ret(m->get_number_of_particles()); ParticleMap pm= boost::get(boost::vertex_name, ret); std::map map; for (Model::ParticleIterator it= m->particles_begin(); it != m->particles_end(); ++it) { int i= map.size(); map[*it]= i; pm[i]= *it; } for (Model::RestraintIterator it= m->restraints_begin(); it != m->restraints_end(); ++it) { ParticlesTemp pl= (*it)->get_input_particles(); add_edges(pl, map, *it, ret); } for (Model::ScoreStateIterator it= m->score_states_begin(); it != m->score_states_end(); ++it) { ParticlesTemp pl= (*it)->get_input_particles(); add_edges(pl, map, *it, ret); } return ret; } IMPMISC_END_NAMESPACE