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>
22 IMPMISC_BEGIN_NAMESPACE
43 template <
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());
156 std::string name =
"MetricClosePairsFinder%1%")
175 return get_close_pairs_internal(m, index, index,
true);
184 return get_close_pairs_internal(m, indexa, indexb,
false);
196 template <
class LowerBound,
class UpperBound>
202 IMPMISC_END_NAMESPACE
IMP::Vector< ParticleIndexPair, std::allocator< ParticleIndexPair > > ParticleIndexPairs
virtual ModelObjectsTemp do_get_inputs(Model *m, const ParticleIndexes &pis) const override
Overload this method to specify the inputs.
A base class for algorithms to find spatial proximities.
Functions and adaptors for dealing with particle indexes.
virtual IntPairs get_close_pairs(const algebra::BoundingBox3Ds &) const override
#define IMP_FAILURE(message)
A runtime failure for IMP.
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
#define IMP_OBJECT_LOG
Set the log level to the object's log level.
ParticlesTemp get_particles(Model *m, const ParticleIndexes &ps)
Get the particles from a list of indexes.
#define IMP_LOG_VERBOSE(expr)
Class for storing model, its restraints, constraints, and particles.
Ints get_index(const ParticlesTemp &particles, const Subset &subset, const Subsets &excluded)
virtual IntPairs get_close_pairs(const algebra::BoundingBox3Ds &, 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
core::ClosePairsFinder * create_metric_close_pairs_finder(LowerBound lb, UpperBound ub)
virtual ParticleIndexPairs get_close_pairs(Model *m, const ParticleIndexes &pca, const ParticleIndexes &pcb) const override
return all close pairs among pc in model m
A nullptr-initialized pointer to an IMP Object.
A base class for algorithms to detect proximities.
#define IMP_USAGE_CHECK(expr, message)
A runtime test for incorrect usage of a class or method.
Random number generators used by IMP.
double get_distance(const Line3D &s, const Vector3D &p)
Get closest distance between a line and a point.
RandomNumberGenerator random_number_generator
A shared non-GPU random number generator.