IMP  2.0.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-2013 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 
17 /** Apply two different scores and return the sum of the results.*/
18 template <class BaseDistanceScore0, class BaseDistanceScore1>
19 class AddScores: public Score {
20  typedef BaseDistanceScore0 P0;
21  typedef BaseDistanceScore1 P1;
22  P0 p0_;
23  P1 p1_;
24 public:
25  AddScores(BaseDistanceScore0 p0,
26  BaseDistanceScore1 p1): p0_(p0), p1_(p1){}
27  template <unsigned int D>
28  double get_score(Model *m, const base::Array<D, ParticleIndex>&pi,
29  double distance) const {
30  return p0_.get_score(m,pi, distance)
31  + p1_.get_score(m, pi, distance);
32  }
33  template <unsigned int D>
34  DerivativePair get_score_and_derivative(Model *m,
36  double distance) const {
37  DerivativePair ret0=p0_.get_score_and_derivative(m, p, distance);
38  DerivativePair ret1=p1_.get_score_and_derivative(m, p, distance);
39  return DerivativePair(ret0.first+ret1.first,
40  ret0.second+ret1.second);
41  }
42  template <unsigned int D>
43  bool get_is_trivially_zero(Model *m, const base::Array<D, ParticleIndex>& p,
44  double squared_distance) const {
45  return p0_.get_is_trivially_zero(m, p, squared_distance)
46  && p1_.get_is_trivially_zero(m, p, squared_distance);
47  }
48  /** Return an upper bound on the distance at which the score can be
49  non-zero.*/
50  template <unsigned int D>
51  double get_maximum_range(Model *m,
52  const base::Array<D, ParticleIndex>& p) const {
53  return std::max(p0_.get_maximum_range(m, p),
54  p1_.get_maximum_range(m, p));
55  }
56  ModelObjectsTemp get_inputs(Model *m,
57  const ParticleIndexes &pis) const {
58  return p0_.get_inputs(m, pis)
59  + p1_.get_inputs(m, pis);
60  }
61  void show(std::ostream &out) const{
62  p0_.show(out);
63  p1_.show(out);
64  }
65 };
66 
67 IMPSCOREFUNCTOR_END_NAMESPACE
68 
69 #endif /* IMPSCORE_FUNCTOR_ADD_SCORES_H */