IMP  2.3.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-2014 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(kernel::Model *m,
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(
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(kernel::Model *m,
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>
51  return std::max(p0_.get_maximum_range(m, p), p1_.get_maximum_range(m, p));
52  }
53  kernel::ModelObjectsTemp get_inputs(
54  kernel::Model *m, const kernel::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 */
double get_maximum_range(kernel::Model *m, const base::Array< D, kernel::ParticleIndex > &p) const
Return an upper bound on the distance at which the score can be non-zero.
Definition: AddScores.h:49
A class to store an fixed array of same-typed values.
Definition: Array.h:33
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
void show(Hierarchy h, std::ostream &out=std::cout)
Print out a molecular hierarchy.
A functor for computing a distance based score for two particles.
Definition: Score.h:20
Class for storing model, its restraints, constraints, and particles.
Definition: kernel/Model.h:73