IMP  2.2.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-2014 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>
12 #include <IMP/utility.h>
13 
14 IMPCORE_BEGIN_NAMESPACE
15 
16 //! %Harmonic function (symmetric about the mean)
17 /** This is a simple score modeling an harmonic oscillator. The score is
18  0.5 * k * x * x, where k is the 'force constant' and x is the distance
19  from the mean.
20  \see TruncatedHarmonic
21  \see HarmonicUpperBound
22  \see HarmonicLowerBound
23  */
24 class Harmonic : public UnaryFunction {
25  public:
26  /** Create with the given mean and the spring constant k */
27  Harmonic(Float mean, Float k) : mean_(mean), k_(k) {}
28 
29  virtual DerivativePair evaluate_with_derivative(double feature) const {
30  return DerivativePair(0.5 * k_ * square(feature - mean_),
31  k_ * (feature - mean_));
32  }
33 
34  virtual double evaluate(double feature) const {
35  return 0.5 * k_ * square(feature - mean_);
36  }
37 
39 
40  //! \return the mean of this function
41  Float get_mean() const { return mean_; }
42 
43  //! \return the spring constant
44  Float get_k() const { return k_; }
45 
46  //! Set the mean of this function
47  void set_mean(Float mean) { mean_ = mean; }
48 
49  //! Set the spring constant
50  void set_k(Float k) { k_ = k; }
51 
52  //! Return the k to use for a given Gaussian standard deviation.
53  /** Given the standard deviation of a Gaussian distribution, get
54  the force constant of the harmonic score function that yields that
55  same distribution. For temperature in Kelvin, this assumes the score
56  function is energy in kcal/mol, and thus returns a force constant in
57  kcal/mol/A/A.
58  \param[in] sd Gaussian standard deviation, in angstroms
59  \param[in] t System temperature, in Kelvin
60  \return Force constant
61  */
63  // Gas constant in kcal/mol K
64  const static Float R = 8.31441 / 4186.8;
65  return R * t / square(sd);
66  }
67 
68  private:
69  Float mean_;
70  Float k_;
71 };
72 
73 IMPCORE_END_NAMESPACE
74 
75 #endif /* IMPCORE_HARMONIC_H */
Float get_k() const
Definition: core/Harmonic.h:44
Import IMP/kernel/UnaryFunction.h in the namespace.
void set_k(Float k)
Set the spring constant.
Definition: core/Harmonic.h:50
virtual double evaluate(double feature) const
Calculate score with respect to the given feature.
Definition: core/Harmonic.h:34
void set_mean(Float mean)
Set the mean of this function.
Definition: core/Harmonic.h:47
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:62
#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:41
double Float
Basic floating-point value (could be float, double...)
Definition: base/types.h:20
Harmonic(Float mean, Float k)
Definition: core/Harmonic.h:27
virtual DerivativePair evaluate_with_derivative(double feature) const
Calculate score and derivative with respect to the given feature.
Definition: core/Harmonic.h:29
Harmonic function (symmetric about the mean)
Definition: core/Harmonic.h:24