IMP logo
IMP Reference Guide  2.16.0
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-2021 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 
30  double feature) const IMP_OVERRIDE {
31  return DerivativePair(0.5 * k_ * square(feature - mean_),
32  k_ * (feature - mean_));
33  }
34 
35  virtual double evaluate(double feature) const IMP_OVERRIDE {
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
Return the spring constant.
Definition: core/Harmonic.h:45
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
Definition: object_macros.h:25
Single variable function.
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
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
For backwards compatibility.
std::pair< double, double > DerivativePair
A pair representing a function value with its first derivative.
Definition: types.h:23
Float get_mean() const
Return the mean of this function.
Definition: core/Harmonic.h:42
double Float
Basic floating-point value (could be float, double...)
Definition: 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
Abstract single variable functor class for score functions.
Definition: UnaryFunction.h:25
#define IMP_OVERRIDE
Cause a compile error if this method does not override a parent method.
Harmonic function (symmetric about the mean)
Definition: core/Harmonic.h:24