/** * \file MaximumPairRestraint.cpp * \brief The minimum score over a container. * * This file is generated by a script (core/tools/make-container). * Do not edit directly. * * Copyright 2007-2010 IMP Inventors. All rights reserved. * */ #include "IMP/container/MaximumPairRestraint.h" #include "IMP/core/internal/MinimalSet.h" #include IMPCONTAINER_BEGIN_NAMESPACE MaximumPairRestraint ::MaximumPairRestraint(PairScore *f, PairContainer *c, unsigned int n, std::string name): Restraint(name), f_(f), c_(c), n_(n){ } namespace { typedef core::internal::MinimalSet > MS; template MS find_minimal_set(It b, It e, F *f, unsigned int n) { IMP_LOG(TERSE, "Finding Maximum " << n << " of " << std::distance(b,e) << std::endl); MS bestn(n); for (It it= b; it != e; ++it) { double score= f->evaluate(*it, NULL); if (bestn.can_insert(score)) { bestn.insert(score, *it); } } return bestn; } } double MaximumPairRestraint ::unprotected_evaluate(DerivativeAccumulator *da) const { MS bestn= find_minimal_set(c_->particle_pairs_begin(), c_->particle_pairs_end(), f_.get(), n_); double score=0; for (unsigned int i=0; i< bestn.size(); ++i) { if (da) { f_->evaluate(bestn[i].second, da); } score+= bestn[i].first; } return score; } void MaximumPairRestraint::do_show(std::ostream &out) const { out << "container " << *c_ << std::endl; out << "score " << *f_ << std::endl; } ParticlesList MaximumPairRestraint::get_interacting_particles() const { MS bestn= find_minimal_set(c_->particle_pairs_begin(), c_->particle_pairs_end(), f_.get(), n_); ParticlesList ret; for (unsigned int i=0; i< bestn.size(); ++i) { ParticlesList pt=f_->get_interacting_particles(bestn[i].second); if (!pt.empty()) { ret.push_back(IMP::internal::get_union(pt)); } } return ret; } ParticlesTemp MaximumPairRestraint::get_input_particles() const { return IMP::internal::get_input_particles(c_.get(), f_.get()); } ContainersTemp MaximumPairRestraint::get_input_containers() const { return ContainersTemp(1, c_); } IMPCONTAINER_END_NAMESPACE