8 #ifndef IMPSCORE_FUNCTOR_OPEN_CUBIC_SPLINE_H
9 #define IMPSCORE_FUNCTOR_OPEN_CUBIC_SPLINE_H
11 #include <IMP/score_functor/score_functor_config.h>
13 #include "internal/RawOpenCubicSpline.h"
14 IMPSCOREFUNCTOR_BEGIN_NAMESPACE
25 double inverse_spacing_;
26 internal::RawOpenCubicSpline spline_;
42 inverse_spacing_(1.0 / spacing_),
43 spline_(values, spacing_, inverse_spacing_),
45 maxrange_(minrange_ + spacing_ * (values.size() - 1)),
48 "The spacing between values must be positive.");
49 IMP_USAGE_CHECK(values.size() >= 1,
"You must provide at least one value.");
52 template <
unsigned int D>
53 double get_score(
Model *,
55 double distance)
const {
57 if (distance < minrange_ || distance > maxrange_) {
59 if (distance < minrange_)
60 return spline_.get_first();
62 return spline_.get_last();
64 IMP_THROW(
"Value " << distance <<
" out of range [" << minrange_ <<
", "
68 return spline_.evaluate(distance - minrange_, spacing_, inverse_spacing_);
70 template <
unsigned int D>
72 Model *,
const Array<D, ParticleIndex> &,
73 double distance)
const {
75 if (distance < minrange_ || distance > maxrange_) {
77 if (distance < minrange_)
78 return std::make_pair(spline_.get_first(), 0.0);
80 return std::make_pair(spline_.get_last(), 0.0);
82 IMP_THROW(
"Value " << distance <<
" out of range [" << minrange_ <<
", "
83 << maxrange_ <<
"] for open cubic spline", ValueException);
86 return spline_.evaluate_with_derivative(distance - minrange_, spacing_,
89 template <
unsigned int D>
90 double get_maximum_range(
91 Model *,
const Array<D, ParticleIndex> &)
const {
92 if (!extend_ || spline_.get_last() == 0)
95 return std::numeric_limits<double>::max();
97 template <
unsigned int D>
98 bool get_is_trivially_zero(Model *,
99 const Array<D, ParticleIndex> &,
100 double squared_distance)
const {
101 if (!extend_ || spline_.get_last() == 0) {
102 return squared_distance > algebra::get_squared(maxrange_);
108 IMPSCOREFUNCTOR_END_NAMESPACE
A class to store an fixed array of same-typed values.
Class for storing model, its restraints, constraints, and particles.
OpenCubicSpline(const Floats &values, Float minrange, Float spacing, bool extend=false)
Constructor.
A Score on the distance between a pair of particles.
std::pair< double, double > DerivativePair
A pair representing a function value with its first derivative.
Open cubic spline function.
#define IMP_THROW(message, exception_name)
Throw an exception with a message.
double Float
Basic floating-point value (could be float, double...)
#define IMP_USAGE_CHECK(expr, message)
A runtime test for incorrect usage of a class or method.
A functor for computing a distance based score for D particles.
An exception for an invalid value being passed to IMP.