IMP  2.2.1
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
48  non-zero.*/
49  template <unsigned int D>
52  return std::max(p0_.get_maximum_range(m, p), p1_.get_maximum_range(m, p));
53  }
54  kernel::ModelObjectsTemp get_inputs(
55  kernel::Model *m, const kernel::ParticleIndexes &pis) const {
56  return p0_.get_inputs(m, pis) + p1_.get_inputs(m, pis);
57  }
58  void show(std::ostream &out) const {
59  p0_.show(out);
60  p1_.show(out);
61  }
62 };
63 
64 IMPSCOREFUNCTOR_END_NAMESPACE
65 
66 #endif /* IMPSCORE_FUNCTOR_ADD_SCORES_H */
double get_maximum_range(kernel::Model *m, const base::Array< D, kernel::ParticleIndex > &p) const
Definition: AddScores.h:50
A class to store an fixed array of same-typed values.
Definition: base/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: base/types.h:23
void show(Hierarchy h, std::ostream &out=std::cout)
Print out a molecular hierarchy.
Class for storing model, its restraints, constraints, and particles.
Definition: kernel/Model.h:72