9#ifndef IMPMISC_METRIC_CLOSE_PAIRS_FINDER_H
10#define IMPMISC_METRIC_CLOSE_PAIRS_FINDER_H
12#include <IMP/misc/misc_config.h>
17#include <boost/version.hpp>
18#include <boost/unordered_map.hpp>
22IMPMISC_BEGIN_NAMESPACE
43template <
class LowerBound,
class UpperBound>
51 typedef boost::unordered_map<ParticleIndex, Data> Index;
53 unsigned int index_size = std::min<unsigned int>(
54 1U, std::sqrt(
static_cast<double>(inputs.size())));
55#if IMP_COMPILER_HAS_RANDOM_SHUFFLE && BOOST_VERSION < 107500
58 std::random_shuffle(inputs.begin(), inputs.end());
64 inputs.begin() + index_size);
65 for (
unsigned int i = 0; i < index_size; ++i) {
69 for (
unsigned int i = 0; i < inputs.size(); ++i) {
70 double min_dist = std::numeric_limits<double>::max();
72 for (
unsigned int j = 0; j < indexes.size(); ++j) {
76 "The bounds are not ordered.");
79 if (cur_dist < min_dist) {
80 min_index = indexes[j];
84 ret[min_index].access_indexes().push_back(inputs[i]);
85 ret[min_index].set_width(std::min(min_dist, ret[min_index].get_width()));
87 for (
typename Index::const_iterator it = ret.begin(); it != ret.end();
96 for (
unsigned int i = 0; i < p.size(); ++i) {
97 for (
unsigned int j = 0; j < i; ++j) {
100 "The bounds are not ordered.");
112 for (
unsigned int i = 0; i < pa.size(); ++i) {
113 for (
unsigned int j = 0; j < pb.size(); ++j) {
116 "The bounds are not ordered.");
127 bool is_same)
const {
129 for (
typename Index::const_iterator ita = ia.begin(); ita != ia.end();
131 for (
typename Index::const_iterator itb = ib.begin(); itb != ib.end();
134 if (ita->first < itb->first)
continue;
135 if (ita->first == itb->first) {
136 ret += get_close_pairs_internal(m, ita->second.get_indexes());
143 "The bounds are not ordered.");
145 ita->second.get_width() - itb->second.get_width()) {
146 ret += get_close_pairs_internal(m, ita->second.get_indexes(),
147 itb->second.get_indexes());
155 MetricClosePairsFinder(LowerBound lb, UpperBound ub,
156 std::string name =
"MetricClosePairsFinder%1%")
174 Index index = get_index(m, pc);
175 return get_close_pairs_internal(m, index, index,
true);
182 Index indexa = get_index(m, pca);
183 Index indexb = get_index(m, pcb);
184 return get_close_pairs_internal(m, indexa, indexb,
false);
196template <
class LowerBound,
class UpperBound>
A base class for algorithms to detect proximities.
A nullptr-initialized pointer to an IMP Object.
#define IMP_FAILURE(message)
A runtime failure for IMP.
#define IMP_USAGE_CHECK(expr, message)
A runtime test for incorrect usage of a class or method.
Class for storing model, its restraints, constraints, and particles.
A base class for algorithms to find spatial proximities.
virtual ParticleIndexPairs get_close_pairs(Model *m, const ParticleIndexes &pca, const ParticleIndexes &pcb) const override
return all close pairs among pc in model m
virtual IntPairs get_close_pairs(const algebra::BoundingBox3Ds &) const override
virtual ParticleIndexPairs get_close_pairs(Model *m, const ParticleIndexes &pc) const override
return all close pairs among pc in model m
virtual IntPairs get_close_pairs(const algebra::BoundingBox3Ds &, const algebra::BoundingBox3Ds &) const override
virtual ModelObjectsTemp do_get_inputs(Model *m, const ParticleIndexes &pis) const override
Overload this method to specify the inputs.
#define IMP_LOG_VERBOSE(expr)
#define IMP_OBJECT_LOG
Set the log level to the object's log level.
IMP::Vector< BoundingBox3D > BoundingBox3Ds
core::ClosePairsFinder * create_metric_close_pairs_finder(LowerBound lb, UpperBound ub)
Index< ParticleIndexTag > ParticleIndex
ParticlesTemp get_particles(Model *m, const ParticleIndexes &ps)
Get the particles from a list of indexes.
IMP::Vector< ParticleIndexPair, std::allocator< ParticleIndexPair > > ParticleIndexPairs
IMP::Vector< IntPair > IntPairs
Vector< ParticleIndex, std::allocator< ParticleIndex > > ParticleIndexes
A list of particles, each identified by its ParticleIndex.
Array< 2, ParticleIndex > ParticleIndexPair
An ordered pair of particles, each identified by its ParticleIndex.
IMP::Vector< IMP::WeakPointer< ModelObject > > ModelObjectsTemp
RandomNumberGenerator random_number_generator
A shared non-GPU random number generator.
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
Functions and adaptors for dealing with particle indexes.
Random number generators used by IMP.