IMP logo
IMP Reference Guide  develop.7482b7c7af, 2026/12/05
The Integrative Modeling Platform
score_functor/Harmonic.h
Go to the documentation of this file.
1/**
2 * \file IMP/score_functor/Harmonic.h
3 * \brief A harmonic score on the directed distance between a pair of particles,
4 * centered at 0.
5 *
6 * Copyright 2007-2022 IMP Inventors. All rights reserved.
7 */
8
9#ifndef IMPSCORE_FUNCTOR_HARMONIC_H
10#define IMPSCORE_FUNCTOR_HARMONIC_H
11
12#include <IMP/score_functor/score_functor_config.h>
13#include "Score.h"
14#include <IMP/algebra/utility.h>
15#include <cereal/access.hpp>
16
17IMPSCOREFUNCTOR_BEGIN_NAMESPACE
18
19/** A harmonic score on the directed distance between a pair of particles,
20 centered at 0.
21*/
22class Harmonic : public Score {
23 double k_;
24
25 friend class cereal::access;
26 template<class Archive> void serialize(Archive &ar) {
27 ar(k_);
28 }
29 public:
30 Harmonic(double k) : k_(k) {}
31 Harmonic() {}
32 template <unsigned int D>
33 double get_score(Model *,
35 double distance) const {
36 return .5 * k_ * algebra::get_squared(distance);
37 }
38 template <unsigned int D>
39 DerivativePair get_score_and_derivative(
40 Model *m, const Array<D, ParticleIndex> &p,
41 double distance) const {
42 return DerivativePair(get_score(m, p, distance), k_ * (distance));
43 }
44 double get_k() const { return k_; }
45 void set_k(double k) { k_ = k; }
46};
47
48IMPSCOREFUNCTOR_END_NAMESPACE
49
50#endif /* IMPSCORE_FUNCTOR_HARMONIC_H */
A Score on the distance between a pair of particles.
Functions to deal with very common math operations.
A class to store a fixed array of same-typed values.
Definition Array.h:40
Class for storing model, its restraints, constraints, and particles.
Definition Model.h:111
std::pair< double, double > DerivativePair
A pair representing a function value with its first derivative.
Definition types.h:22