IMP  2.4.0
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-2015 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 
16 IMPMISC_BEGIN_NAMESPACE
17 
18 //! Track the pairs of particles passed.
19 /** Primarily for testing.
20  */
21 class LogPairScore : public PairScore {
22  mutable boost::unordered_map<kernel::ParticlePair, unsigned int> map_;
23 
24  public:
25  //! create with an empty map
27  virtual double evaluate_index(kernel::Model *m,
32  return kernel::ModelObjectsTemp();
33  }
36 
37  //! Get a list of all pairs (without multiplicity)
40  for (boost::unordered_map<kernel::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 kernel::ParticlePair &pp) const {
51  return map_.find(pp) != map_.end();
52  }
53 };
54 
55 // doxygen spits out warnings
56 #ifndef IMP_DOXYGEN
57 
58 inline Float LogPairScore::evaluate_index(kernel::Model *m,
60  DerivativeAccumulator *) const {
61  kernel::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 
70 IMPMISC_END_NAMESPACE
71 
72 #endif /* IMPMISC_LOG_PAIR_SCORE_H */
kernel::ParticlePairsTemp get_particle_pairs() const
Get a list of all pairs (without multiplicity)
Definition: LogPairScore.h:38
Class for adding derivatives from restraints to the model.
IMP::base::Vector< IMP::base::WeakPointer< kernel::ModelObject > > ModelObjectsTemp
Particle * get_particle(ParticleIndex p) const
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
Definition: object_macros.h:25
Track the pairs of particles passed.
Definition: LogPairScore.h:21
#define IMP_PAIR_SCORE_METHODS(Name)
LogPairScore()
create with an empty map
Definition: LogPairScore.h:26
bool get_contains(const kernel::ParticlePair &pp) const
Return true if the pair is in the list.
Definition: LogPairScore.h:50
virtual kernel::ModelObjectsTemp do_get_inputs(kernel::Model *, const kernel::ParticleIndexes &) const
Definition: LogPairScore.h:30
A class to store an fixed array of same-typed values.
Definition: Array.h:33
Abstract class for scoring object(s) of type ParticlePair.
Import IMP/kernel/PairScore.h in the namespace.
void clear()
Clear the lst of pairs.
Definition: LogPairScore.h:48
double Float
Basic floating-point value (could be float, double...)
Definition: types.h:20
#define IMP_OVERRIDE
Cause a compile error if this method does not override a parent method.
Class for storing model, its restraints, constraints, and particles.
Definition: kernel/Model.h:73
Import IMP/kernel/generic.h in the namespace.