IMP logo
IMP Reference Guide  develop.7cb8855c60,2024/10/08
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 
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<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 
58 inline 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 
70 IMPMISC_END_NAMESPACE
71 
72 #endif /* IMPMISC_LOG_PAIR_SCORE_H */
Particle * get_particle(ParticleIndex p) const
Get the particle from an index.
Definition: Model.h:489
Abstract class for scoring object(s) of type ParticleIndexPair.
Definition: PairScore.h:44
#define IMP_PAIR_SCORE_METHODS(Name)
Definition: pair_macros.h:25
#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
LogPairScore()
create with an empty map
Definition: LogPairScore.h:26
A more IMP-like version of the std::vector.
Definition: Vector.h:50
IMP::Vector< IMP::WeakPointer< ModelObject > > ModelObjectsTemp
Definition: base_types.h:106
Class for storing model, its restraints, constraints, and particles.
Definition: Model.h:86
Define PairScore.
virtual ModelObjectsTemp do_get_inputs(Model *, const ParticleIndexes &) const override
Overload this method to specify the inputs.
Definition: LogPairScore.h:30
void clear()
Clear the lst of pairs.
Definition: LogPairScore.h:48
double Float
Basic floating-point value (could be float, double...)
Definition: types.h:19
bool get_contains(const ParticlePair &pp) const
Return true if the pair is in the list.
Definition: LogPairScore.h:50
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.
Compile-time generic restraint and constraint support.