IMP logo
IMP Reference Guide  develop.7482b7c7af, 2026/12/05
The Integrative Modeling Platform
LogPairScore.h
Go to the documentation of this file.
1/**
2 * \file IMP/misc/LogPairScore.h
3 * \brief Track the particles pairs passed to the pair score.
4 *
5 * Copyright 2007-2022 IMP Inventors. All rights reserved.
6 */
7
8#ifndef IMPMISC_LOG_PAIR_SCORE_H
9#define IMPMISC_LOG_PAIR_SCORE_H
10
11#include <IMP/misc/misc_config.h>
12#include <IMP/PairScore.h>
13#include <IMP/generic.h>
14#include <boost/unordered_map.hpp>
15
16IMPMISC_BEGIN_NAMESPACE
17
18//! Track the pairs of particles passed.
19/** Primarily for testing.
20 */
21class LogPairScore : public PairScore {
22 mutable boost::unordered_map<ParticlePair, unsigned int> map_;
23
24 public:
25 //! create with an empty map
27 virtual double evaluate_index(Model *m,
28 const ParticleIndexPair &p,
29 DerivativeAccumulator *da) const override;
31 Model *, const ParticleIndexes &) const override {
32 return ModelObjectsTemp();
33 }
36
37 //! Get a list of all pairs (without multiplicity)
40 for (boost::unordered_map<ParticlePair,
41 unsigned int>::const_iterator it = map_.begin();
42 it != map_.end(); ++it) {
43 ret.push_back(it->first);
44 }
45 return ret;
46 }
47 //! Clear the lst of pairs
48 void clear() { map_.clear(); }
49 //! Return true if the pair is in the list
50 bool get_contains(const ParticlePair &pp) const {
51 return map_.find(pp) != map_.end();
52 }
53};
54
55// doxygen spits out warnings
56#ifndef IMP_DOXYGEN
57
58inline Float LogPairScore::evaluate_index(Model *m,
59 const ParticleIndexPair &p,
60 DerivativeAccumulator *) const {
61 ParticlePair pp(m->get_particle(p[0]), m->get_particle(p[1]));
62 if (map_.find(pp) == map_.end()) {
63 map_[pp] = 0;
64 }
65 ++map_[pp];
66 return 0.;
67}
68#endif
69
70IMPMISC_END_NAMESPACE
71
72#endif /* IMPMISC_LOG_PAIR_SCORE_H */
Define PairScore.
Class for adding derivatives from restraints to the model.
Class for storing model, its restraints, constraints, and particles.
Definition Model.h:111
Track the pairs of particles passed.
LogPairScore()
create with an empty map
void clear()
Clear the lst of pairs.
bool get_contains(const ParticlePair &pp) const
Return true if the pair is in the list.
virtual ModelObjectsTemp do_get_inputs(Model *, const ParticleIndexes &) const override
Overload this method to specify the inputs.
ParticlePairsTemp get_particle_pairs() const
Get a list of all pairs (without multiplicity).
virtual double evaluate_index(Model *m, const ParticleIndexPair &p, DerivativeAccumulator *da) const override
Compute the score and the derivative if needed.
Compile-time generic restraint and constraint support.
double Float
Basic floating-point value (could be float, double...).
Definition types.h:19
Vector< ParticleIndex, std::allocator< ParticleIndex > > ParticleIndexes
A list of particles, each identified by its ParticleIndex.
Definition base_types.h:199
Array< 2, ParticleIndex > ParticleIndexPair
An ordered pair of particles, each identified by its ParticleIndex.
Definition base_types.h:202
Array< 2, WeakPointer< Particle >, Particle * > ParticlePair
Definition base_types.h:180
IMP::Vector< ParticlePair > ParticlePairsTemp
Definition base_types.h:181
IMP::Vector< IMP::WeakPointer< ModelObject > > ModelObjectsTemp
Definition base_types.h:122
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
#define IMP_PAIR_SCORE_METHODS(Name)
Definition pair_macros.h:25