IMP  2.1.1
The Integrative Modeling Platform
core/Harmonic.h
Go to the documentation of this file.
1 /**
2  * \file IMP/core/Harmonic.h \brief Harmonic function.
3  *
4  * Copyright 2007-2013 IMP Inventors. All rights reserved.
5  */
6 
7 #ifndef IMPCORE_HARMONIC_H
8 #define IMPCORE_HARMONIC_H
9 
10 #include <IMP/core/core_config.h>
11 #include <IMP/UnaryFunction.h>
13 #include <IMP/utility.h>
14 
15 IMPCORE_BEGIN_NAMESPACE
16 
17 //! %Harmonic function (symmetric about the mean)
18 /** This is a simple score modeling an harmonic oscillator. The score is
19  0.5 * k * x * x, where k is the 'force constant' and x is the distance
20  from the mean.
21  \see TruncatedHarmonic
22  \see HarmonicUpperBound
23  \see HarmonicLowerBound
24  */
25 class Harmonic : public UnaryFunction {
26  public:
27  /** Create with the given mean and the spring constant k */
28  Harmonic(Float mean, Float k) : mean_(mean), k_(k) {}
29 
30  virtual DerivativePair evaluate_with_derivative(double feature) const {
31  return DerivativePair(0.5 * k_ * square(feature - mean_),
32  k_ * (feature - mean_));
33  }
34 
35  virtual double evaluate(double feature) const {
36  return 0.5 * k_ * square(feature - mean_);
37  }
38 
40 
41  //! \return the mean of this function
42  Float get_mean() const { return mean_; }
43 
44  //! \return the spring constant
45  Float get_k() const { return k_; }
46 
47  //! Set the mean of this function
48  void set_mean(Float mean) { mean_ = mean; }
49 
50  //! Set the spring constant
51  void set_k(Float k) { k_ = k; }
52 
53  //! Return the k to use for a given Gaussian standard deviation.
54  /** Given the standard deviation of a Gaussian distribution, get
55  the force constant of the harmonic score function that yields that
56  same distribution. For temperature in Kelvin, this assumes the score
57  function is energy in kcal/mol, and thus returns a force constant in
58  kcal/mol/A/A.
59  \param[in] sd Gaussian standard deviation, in angstroms
60  \param[in] t System temperature, in Kelvin
61  \return Force constant
62  */
64  // Gas constant in kcal/mol K
65  const static Float R = 8.31441 / 4186.8;
66  return R * t / square(sd);
67  }
68 
69  private:
70  Float mean_;
71  Float k_;
72 };
73 
74 IMPCORE_END_NAMESPACE
75 
76 #endif /* IMPCORE_HARMONIC_H */
Float get_k() const
Definition: core/Harmonic.h:45
Import IMP/kernel/UnaryFunction.h in the namespace.
void set_k(Float k)
Set the spring constant.
Definition: core/Harmonic.h:51
virtual double evaluate(double feature) const
Calculate score with respect to the given feature.
Definition: core/Harmonic.h:35
void set_mean(Float mean)
Set the mean of this function.
Definition: core/Harmonic.h:48
Abstract single variable functor class for score functions.
static Float get_k_from_standard_deviation(Float sd, Float t=297.15)
Return the k to use for a given Gaussian standard deviation.
Definition: core/Harmonic.h:63
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
Import IMP/kernel/utility.h in the namespace.
std::pair< double, double > DerivativePair
A pair representing a function value with its first derivative.
Definition: base/types.h:23
Float get_mean() const
Definition: core/Harmonic.h:42
Import IMP/kernel/unary_function_macros.h in the namespace.
double Float
Basic floating-point value (could be float, double...)
Definition: base/types.h:20
Harmonic(Float mean, Float k)
Definition: core/Harmonic.h:28
virtual DerivativePair evaluate_with_derivative(double feature) const
Calculate score and derivative with respect to the given feature.
Definition: core/Harmonic.h:30
Harmonic function (symmetric about the mean)
Definition: core/Harmonic.h:25