00001 /** 00002 * \file DerivativeAccumulator.h \brief Class for adding derivatives from 00003 * restraints to the model. 00004 * 00005 * Copyright 2007-2010 IMP Inventors. All rights reserved. 00006 * 00007 */ 00008 00009 #ifndef IMP_DERIVATIVE_ACCUMULATOR_H 00010 #define IMP_DERIVATIVE_ACCUMULATOR_H 00011 00012 #include "kernel_config.h" 00013 #include "base_types.h" 00014 #include "utility.h" 00015 #include "macros.h" 00016 #include <vector> 00017 00018 IMP_BEGIN_NAMESPACE 00019 00020 //! Class for adding derivatives from restraints to the model. 00021 /** This class was created so that restraints can be weighted using 00022 a RestraintSet and that the derivatives would be scaled appropriately */ 00023 class IMPEXPORT DerivativeAccumulator 00024 { 00025 public: 00026 //! the weight is one by default 00027 DerivativeAccumulator(Float weight=1.0) 00028 : weight_(weight) {} 00029 00030 //! The weight is multiplied by the new weight 00031 DerivativeAccumulator(const DerivativeAccumulator ©, Float weight=1.0) 00032 : weight_(copy.weight_ * weight) {} 00033 00034 //! Scale a value appropriately. 00035 /** \param[in] value Value to add to the float attribute derivative. 00036 */ 00037 Float operator()(const Float value) const { 00038 IMP_INTERNAL_CHECK(!is_nan(value), "Can't set derivative to NaN."); 00039 return value * weight_; 00040 } 00041 00042 private: 00043 Float weight_; 00044 }; 00045 00046 IMP_VALUES(DerivativeAccumulator); 00047 00048 IMP_END_NAMESPACE 00049 00050 #endif /* IMP_DERIVATIVE_ACCUMULATOR_H */