9 #ifndef IMPMISC_METRIC_CLOSE_PAIRS_FINDER_H
10 #define IMPMISC_METRIC_CLOSE_PAIRS_FINDER_H
12 #include <IMP/misc/misc_config.h>
16 #include <boost/unordered_map.hpp>
20 IMPMISC_BEGIN_NAMESPACE
41 template <
class LowerBound,
class UpperBound>
49 typedef boost::unordered_map<ParticleIndex, Data> Index;
51 unsigned int index_size = std::min<unsigned int>(
52 1U, std::sqrt(static_cast<double>(inputs.size())));
53 std::random_shuffle(inputs.begin(), inputs.end());
56 inputs.begin() + index_size);
57 for (
unsigned int i = 0; i < index_size; ++i) {
61 for (
unsigned int i = 0; i < inputs.size(); ++i) {
62 double min_dist = std::numeric_limits<double>::max();
64 for (
unsigned int j = 0; j < indexes.size(); ++j) {
68 "The bounds are not ordered.");
71 if (cur_dist < min_dist) {
72 min_index = indexes[j];
76 ret[min_index].access_indexes().push_back(inputs[i]);
77 ret[min_index].set_width(std::min(min_dist, ret[min_index].get_width()));
79 for (
typename Index::const_iterator it = ret.begin(); it != ret.end();
88 for (
unsigned int i = 0; i < p.size(); ++i) {
89 for (
unsigned int j = 0; j < i; ++j) {
92 "The bounds are not ordered.");
104 for (
unsigned int i = 0; i < pa.size(); ++i) {
105 for (
unsigned int j = 0; j < pb.size(); ++j) {
108 "The bounds are not ordered.");
119 bool is_same)
const {
121 for (
typename Index::const_iterator ita = ia.begin(); ita != ia.end();
123 for (
typename Index::const_iterator itb = ib.begin(); itb != ib.end();
126 if (ita->first < itb->first)
continue;
127 if (ita->first == itb->first) {
128 ret += get_close_pairs_internal(m, ita->second.get_indexes());
135 "The bounds are not ordered.");
137 ita->second.get_width() - itb->second.get_width()) {
138 ret += get_close_pairs_internal(m, ita->second.get_indexes(),
139 itb->second.get_indexes());
148 std::string name =
"MetricClosePairsFinder%1%")
167 return get_close_pairs_internal(m, index, index,
true);
176 return get_close_pairs_internal(m, indexa, indexb,
false);
188 template <
class LowerBound,
class UpperBound>
194 IMPMISC_END_NAMESPACE
virtual IntPairs get_close_pairs(const algebra::BoundingBox3Ds &, const algebra::BoundingBox3Ds &) const
A base class for algorithms to find spatial proximities.
Functions and adaptors for dealing with particle indexes.
IMP::Vector< ParticleIndexPair > ParticleIndexPairs
#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.
virtual IntPairs get_close_pairs(const algebra::BoundingBox3Ds &) const
ParticlesTemp get_particles(Model *m, const ParticleIndexes &ps)
Get the particles from a list of indexes.
#define IMP_LOG_VERBOSE(expr)
virtual ParticleIndexPairs get_close_pairs(Model *m, const ParticleIndexes &pc) const
return all close pairs among pc in model m
Class for storing model, its restraints, constraints, and particles.
Ints get_index(const ParticlesTemp &particles, const Subset &subset, const Subsets &excluded)
virtual ParticleIndexPairs get_close_pairs(Model *m, const ParticleIndexes &pca, const ParticleIndexes &pcb) const
return all close pairs among pc in model m
core::ClosePairsFinder * create_metric_close_pairs_finder(LowerBound lb, UpperBound ub)
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.
virtual ModelObjectsTemp do_get_inputs(Model *m, const ParticleIndexes &pis) const
Overload this method to specify the inputs.
double get_distance(const Line3D &s, const Vector3D &p)
Get closest distance between a line and a point.
#define IMP_OVERRIDE
Cause a compile error if this method does not override a parent method.