void IncrementalScoringFunction::create_scoring_functions() { IMP_OBJECT_LOG; IMP_LOG_TERSE("Creating scoring functions" << std::endl); if (flattened_restraints_.empty()) return; boost::unordered_map<Restraint *, int> mp; IMP_LOG_TERSE("All restraints are " << flattened_restraints_ << std::endl); for (unsigned int i = 0; i < flattened_restraints_.size(); ++i) { mp[flattened_restraints_[i]] = i; } Restraints drs; for (unsigned int i = 0; i < nbl_.size(); ++i) { // This ensures that the score states needed for the non-bonded terms drs.push_back(nbl_[i]->get_dummy_restraint()); } Vector<RestraintsTemp> crs; IMP_FOREACH(ParticleIndex pi, all_) { RestraintsTemp cr = get_dependent_restraints(get_model(), pi); /* Remove any duplicates in cr (could happen with rigid bodies) */ std::sort(cr.begin(), cr.end()); cr.erase(std::unique(cr.begin(), cr.end()), cr.end()); crs.push_back(cr); }
void assign_blame(const RestraintsTemp &rs, const ParticlesTemp &ps, FloatKey attribute) { IMP_FUNCTION_LOG; for (unsigned int i = 0; i < ps.size(); ++i) { if (ps[i]->has_attribute(attribute)) { ps[i]->set_value(attribute, 0); } else { ps[i]->add_attribute(attribute, 0, false); } } Restraints drs; for (unsigned int i = 0; i < rs.size(); ++i) { Pointer<Restraint> rd = rs[i]->create_decomposition(); if (rd) { drs.push_back(rd); } } IMP_NEW(RestraintsScoringFunction, rsf, (drs)); rsf->evaluate(false); DependencyGraph dg = get_dependency_graph(IMP::internal::get_model(rs)); // attempt to get around boost/gcc bug and the most vexing parse DependencyGraphVertexIndex dgi((IMP::get_vertex_index(dg))); ControlledBy controlled_by; for (unsigned int i = 0; i < ps.size(); ++i) { ParticlesTemp cps = get_dependent_particles(ps[i], ps, dg, dgi); IMP_INTERNAL_CHECK(cps.size() > 0, "No dependent particles for " << ps[i]); for (unsigned int j = 0; j < cps.size(); ++j) { controlled_by[cps[j]] = ps[i]; } } for (unsigned int i = 0; i < drs.size(); ++i) { distribute_blame(drs[i], controlled_by, attribute, 1.0); } }
Restraints _ConstRestraint::do_create_decomposition() const { Restraints ret; for (unsigned int i = 0; i < ps_.size(); ++i) { ret.push_back( new _ConstRestraint(v_ / ps_.size(), ParticlesTemp(1, ps_[i]))); ret.back()->set_last_score(v_ / ps_.size()); } return ret; }
Restraints PredicateQuadsRestraint ::do_create_current_decomposition() const { Restraints ret; for (unsigned int i=0; i< restraints_.size(); ++i) { Pointer<Restraint> r=restraints_[i]->create_current_decomposition(); if (r) { RestraintSet *rs= dynamic_cast<RestraintSet*>(r.get()); if (rs) { ret+=rs->get_restraints(); } else { ret.push_back(r); } } } return ret; }
Restraints ConnectivityRestraint::do_create_current_decomposition() const { ParticlePairsTemp pp = get_connected_pairs(); Restraints ret; for (unsigned int i = 0; i < pp.size(); ++i) { IMP_NEW(PairRestraint, pr, (ps_, pp[i])); double score = pr->evaluate(false); /** We want to keep the edge even if it has weight 0 */ if (score == 0) pr->set_last_score(.00001); std::ostringstream oss; oss << get_name() << " " << i; pr->set_name(oss.str()); ret.push_back(pr); } return ret; }