IMP logo
IMP Reference Guide  develop.7482b7c7af, 2026/12/05
The Integrative Modeling Platform
Cosine.h
Go to the documentation of this file.
1/**
2 * \file IMP/core/Cosine.h \brief Cosine function.
3 *
4 * Copyright 2007-2022 IMP Inventors. All rights reserved.
5 */
6
7#ifndef IMPCORE_COSINE_H
8#define IMPCORE_COSINE_H
9
10#include <IMP/core/core_config.h>
11#include <IMP/UnaryFunction.h>
12#include <cereal/access.hpp>
13#include <cereal/types/base_class.hpp>
14#include <cereal/types/polymorphic.hpp>
15
16IMPCORE_BEGIN_NAMESPACE
17
18//! %Cosine function.
19/** This evaluates the function
20 |k| - k cos(nf + a)
21 where k is a force constant, n the periodicity, a the phase, and f the
22 input value. This is most commonly used for dihedral angle restraints,
23 e.g. in the CHARMM force field.
24 */
25class IMPCOREEXPORT Cosine : public UnaryFunction {
26 public:
27 //! Constructor.
28 /** \param[in] force_constant Force constant (score units)
29 \param[in] periodicity Periodicity (generally 1-6)
30 \param[in] phase Phase (radians)
31 */
32 Cosine(Float force_constant, int periodicity, Float phase)
33 : force_constant_(force_constant),
34 periodicity_(periodicity),
35 phase_(phase) {}
36
37 Cosine() {}
38
40 double feature) const override;
41
42 virtual double evaluate(double feature) const override;
43
44 Float get_force_constant() const { return force_constant_; }
45 int get_periodicity() const { return periodicity_; }
46 Float get_phase() const { return phase_; }
47
49
50 void do_show(std::ostream &out) const;
51
52 private:
53 Float force_constant_;
54 int periodicity_;
55 Float phase_;
56
57 friend class cereal::access;
58
59 template<class Archive> void serialize(Archive &ar) {
60 ar(cereal::base_class<UnaryFunction>(this),
61 force_constant_, periodicity_, phase_);
62 }
64};
65
66IMPCORE_END_NAMESPACE
67
68#endif /* IMPCORE_COSINE_H */
Single variable function.
Cosine function.
Definition Cosine.h:25
Cosine(Float force_constant, int periodicity, Float phase)
Constructor.
Definition Cosine.h:32
virtual double evaluate(double feature) const override
Calculate score with respect to the given feature.
virtual DerivativePair evaluate_with_derivative(double feature) const override
Calculate score and derivative with respect to the given feature.
double Float
Basic floating-point value (could be float, double...).
Definition types.h:19
std::pair< double, double > DerivativePair
A pair representing a function value with its first derivative.
Definition types.h:22
#define IMP_OBJECT_SERIALIZE_DECL(Name)
Declare methods needed for serialization of Object pointers.
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.