IMP logo
IMP Reference Guide  2.9.0
The Integrative Modeling Platform
AddScores.h
Go to the documentation of this file.
1 /**
2  * \file IMP/score_functor/AddScores.h
3  * \brief A Score on the distance between a pair of particles.
4  *
5  * Copyright 2007-2018 IMP Inventors. All rights reserved.
6  */
7 
8 #ifndef IMPSCORE_FUNCTOR_ADD_SCORES_H
9 #define IMPSCORE_FUNCTOR_ADD_SCORES_H
10 
11 #include <IMP/score_functor/score_functor_config.h>
12 #include "Score.h"
13 #include <IMP/algebra/utility.h>
14 IMPSCOREFUNCTOR_BEGIN_NAMESPACE
15 
16 /** Apply two different scores and return the sum of the results.*/
17 template <class BaseDistanceScore0, class BaseDistanceScore1>
18 class AddScores : public Score {
19  typedef BaseDistanceScore0 P0;
20  typedef BaseDistanceScore1 P1;
21  P0 p0_;
22  P1 p1_;
23 
24  public:
25  AddScores(BaseDistanceScore0 p0, BaseDistanceScore1 p1) : p0_(p0), p1_(p1) {}
26  template <unsigned int D>
27  double get_score(Model *m,
28  const Array<D, ParticleIndex> &pi,
29  double distance) const {
30  return p0_.get_score(m, pi, distance) + p1_.get_score(m, pi, distance);
31  }
32  template <unsigned int D>
33  DerivativePair get_score_and_derivative(
34  Model *m, const Array<D, ParticleIndex> &p,
35  double distance) const {
36  DerivativePair ret0 = p0_.get_score_and_derivative(m, p, distance);
37  DerivativePair ret1 = p1_.get_score_and_derivative(m, p, distance);
38  return DerivativePair(ret0.first + ret1.first, ret0.second + ret1.second);
39  }
40  template <unsigned int D>
41  bool get_is_trivially_zero(Model *m,
42  const Array<D, ParticleIndex> &p,
43  double squared_distance) const {
44  return p0_.get_is_trivially_zero(m, p, squared_distance) &&
45  p1_.get_is_trivially_zero(m, p, squared_distance);
46  }
47  //! Return an upper bound on the distance at which the score can be non-zero.
48  template <unsigned int D>
50  Model *m, const Array<D, ParticleIndex> &p) const {
51  return std::max(p0_.get_maximum_range(m, p), p1_.get_maximum_range(m, p));
52  }
53  ModelObjectsTemp get_inputs(
54  Model *m, const ParticleIndexes &pis) const {
55  return p0_.get_inputs(m, pis) + p1_.get_inputs(m, pis);
56  }
57  void show(std::ostream &out) const {
58  p0_.show(out);
59  p1_.show(out);
60  }
61 };
62 
63 IMPSCOREFUNCTOR_END_NAMESPACE
64 
65 #endif /* IMPSCORE_FUNCTOR_ADD_SCORES_H */
A class to store an fixed array of same-typed values.
Definition: Array.h:33
A more IMP-like version of the std::vector.
Definition: Vector.h:39
Class for storing model, its restraints, constraints, and particles.
Definition: Model.h:72
Functions to deal with very common math operations.
A Score on the distance between a pair of particles.
std::pair< double, double > DerivativePair
A pair representing a function value with its first derivative.
Definition: types.h:23
std::ostream & show(Hierarchy h, std::ostream &out=std::cout)
Print the hierarchy using a given decorator to display each node.
double get_maximum_range(Model *m, const Array< D, ParticleIndex > &p) const
Return an upper bound on the distance at which the score can be non-zero.
Definition: AddScores.h:49
A functor for computing a distance based score for two particles.
Definition: Score.h:20