IMP  2.0.1
The Integrative Modeling Platform
kernel/DerivativeAccumulator.h
Go to the documentation of this file.
1 /**
2  * \file IMP/kernel/DerivativeAccumulator.h
3  * \brief Class for adding derivatives from
4  * restraints to the model.
5  *
6  * Copyright 2007-2013 IMP Inventors. All rights reserved.
7  *
8  */
9 
10 #ifndef IMPKERNEL_DERIVATIVE_ACCUMULATOR_H
11 #define IMPKERNEL_DERIVATIVE_ACCUMULATOR_H
12 
13 #include <IMP/kernel/kernel_config.h>
15 #include <IMP/base/check_macros.h>
16 #include <IMP/base/value_macros.h>
17 #include <IMP/base/math.h>
18 #include <IMP/base/exception.h>
19 
20 IMPKERNEL_BEGIN_NAMESPACE
21 
22 //! Class for adding derivatives from restraints to the model.
23 /** This class was created so that restraints can be weighted using
24  a RestraintSet and that the derivatives would be scaled appropriately */
25 class IMPKERNELEXPORT DerivativeAccumulator
26 {
27 public:
28  //! the weight is one by default
29  DerivativeAccumulator(double weight=1.0)
30  : weight_(weight) {}
31 
32  //! The weight is multiplied by the new weight
33  DerivativeAccumulator(const DerivativeAccumulator &copy, double weight=1.0)
34  : weight_(copy.weight_ * weight) {}
35 
36  //! Scale a value appropriately.
37  /** \param[in] value Value to add to the float attribute derivative.
38  */
39  double operator()(const double value) const {
41  "Can't set derivative to NaN.");
42  return value * weight_;
43  }
44  double get_weight() const {return weight_;}
46 
47 private:
48  double weight_;
49 };
50 
52 
53 IMPKERNEL_END_NAMESPACE
54 
55 #endif /* IMPKERNEL_DERIVATIVE_ACCUMULATOR_H */