IMP
2.0.1
The Integrative Modeling Platform
Main Page
Related Pages
Modules
Namespaces
Classes
Files
Examples
File List
File Members
HarmonicWell.h
Go to the documentation of this file.
1
/**
2
* \file IMP/core/HarmonicWell.h \brief Harmonic function.
3
*
4
* Copyright 2007-2013 IMP Inventors. All rights reserved.
5
*/
6
7
#ifndef IMPCORE_HARMONIC_WELL_H
8
#define IMPCORE_HARMONIC_WELL_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
//! A well with harmonic barriers
17
/** The well is defined by a center, a width and a k. The score is
18
0 if the feature is within the width/2.0. Outside of the width
19
the score is a harmonic.
20
\see TruncatedHarmonic
21
\see Harmonic
22
\see HarmonicUpperBound
23
\see HarmonicLowerBound
24
*/
25
class
HarmonicWell
:
public
UnaryFunction
26
{
27
double
get_score(
double
x)
const
{
28
if
(x < lb_)
return
.5*k_*square(x-lb_);
29
else
if
(x > ub_)
return
.5*k_*square(x-ub_);
30
else
return
0;
31
}
32
double
get_derivative(
double
x)
const
{
33
if
(x < lb_)
return
k_*(x-lb_);
34
else
if
(x > ub_)
return
k_*(x-ub_);
35
else
return
0;
36
}
37
public
:
38
//! Initialize with the lower and upper bounds and the spring constant
39
HarmonicWell
(
const
FloatRange
& well,
double
k) : lb_(well.first),
40
ub_(well.second),
41
k_(k) {
42
IMP_USAGE_CHECK
(well.first <= well.second,
43
"The width should be non-negative"
);
44
IMP_USAGE_CHECK
(k >=0,
"The k should be non-negative"
);
45
}
46
47
virtual
DerivativePair
evaluate_with_derivative
(
double
feature)
const
{
48
return
DerivativePair
(get_score(feature), get_derivative(feature));
49
}
50
51
virtual
double
evaluate
(
double
feature)
const
{
return
get_score(feature); }
52
53
IMP_OBJECT_METHODS
(
HarmonicWell
);
54
55
private
:
56
double
lb_, ub_, k_;
57
};
58
59
IMP_OBJECTS
(
HarmonicWell
,
HarmonicWells
);
60
61
IMPCORE_END_NAMESPACE
62
63
#endif
/* IMPCORE_HARMONIC_WELL_H */