/
LogPairScore.h
72 lines (62 loc) · 1.98 KB
/
LogPairScore.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/**
* \file IMP/misc/LogPairScore.h
* \brief Track the particles pairs passed to the pair score.
*
* Copyright 2007-2022 IMP Inventors. All rights reserved.
*/
#ifndef IMPMISC_LOG_PAIR_SCORE_H
#define IMPMISC_LOG_PAIR_SCORE_H
#include <IMP/misc/misc_config.h>
#include <IMP/PairScore.h>
#include <IMP/generic.h>
#include <boost/unordered_map.hpp>
IMPMISC_BEGIN_NAMESPACE
//! Track the pairs of particles passed.
/** Primarily for testing.
*/
class LogPairScore : public PairScore {
mutable boost::unordered_map<ParticlePair, unsigned int> map_;
public:
//! create with an empty map
LogPairScore() {}
virtual double evaluate_index(Model *m,
const ParticleIndexPair &p,
DerivativeAccumulator *da) const override;
virtual ModelObjectsTemp do_get_inputs(
Model *, const ParticleIndexes &) const override {
return ModelObjectsTemp();
}
IMP_PAIR_SCORE_METHODS(LogPairScore);
IMP_OBJECT_METHODS(LogPairScore);
//! Get a list of all pairs (without multiplicity)
ParticlePairsTemp get_particle_pairs() const {
ParticlePairsTemp ret;
for (boost::unordered_map<ParticlePair,
unsigned int>::const_iterator it = map_.begin();
it != map_.end(); ++it) {
ret.push_back(it->first);
}
return ret;
}
//! Clear the lst of pairs
void clear() { map_.clear(); }
//! Return true if the pair is in the list
bool get_contains(const ParticlePair &pp) const {
return map_.find(pp) != map_.end();
}
};
// doxygen spits out warnings
#ifndef IMP_DOXYGEN
inline Float LogPairScore::evaluate_index(Model *m,
const ParticleIndexPair &p,
DerivativeAccumulator *) const {
ParticlePair pp(m->get_particle(p[0]), m->get_particle(p[1]));
if (map_.find(pp) == map_.end()) {
map_[pp] = 0;
}
++map_[pp];
return 0.;
}
#endif
IMPMISC_END_NAMESPACE
#endif /* IMPMISC_LOG_PAIR_SCORE_H */