IMP  2.0.1
The Integrative Modeling Platform
score_functor/HarmonicUpperBound.h
Go to the documentation of this file.
1 /**
2  * \file IMP/score_functor/HarmonicUpperBound.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_HARMONIC_UPPER_BOUND_H
9 #define IMPSCORE_FUNCTOR_HARMONIC_UPPER_BOUND_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 /** A DistanceScore that scores with a harmonic on distances above 0.*/
18 class HarmonicUpperBound: public Score {
19  double k_;
20 public:
21  HarmonicUpperBound(double k): k_(k){}
22  template <unsigned int D>
23  double get_score(Model *, const base::Array<D, ParticleIndex>&,
24  double distance) const {
25  if (distance <0) return 0;
26  else return .5*k_*algebra::get_squared(distance);
27  }
28  template <unsigned int D>
29  DerivativePair get_score_and_derivative(Model *m,
31  double distance) const {
32  if (distance < 0) return DerivativePair(0,0);
33  else return DerivativePair(get_score(m,p,distance),
34  k_*(distance));
35  }
36 };
37 
38 IMPSCOREFUNCTOR_END_NAMESPACE
39 
40 #endif /* IMPSCORE_FUNCTOR_HARMONIC_UPPER_BOUND_H */