IMP  2.0.1
The Integrative Modeling Platform
AttributeSingletonScore.h
Go to the documentation of this file.
1 /**
2  * \file IMP/core/AttributeSingletonScore.h
3  * \brief A score based on the unmodified value of an attribute.
4  *
5  * Copyright 2007-2013 IMP Inventors. All rights reserved.
6  */
7 
8 #ifndef IMPCORE_ATTRIBUTE_SINGLETON_SCORE_H
9 #define IMPCORE_ATTRIBUTE_SINGLETON_SCORE_H
10 
11 #include <IMP/core/core_config.h>
12 #include <IMP/generic.h>
13 #include <IMP/SingletonScore.h>
14 #include <IMP/Pointer.h>
15 #include <IMP/UnaryFunction.h>
16 #include <IMP/singleton_macros.h>
17 
18 IMPCORE_BEGIN_NAMESPACE
19 
20 
21 //! Apply a function to an attribute.
22 /** This Score scores a particle by passing an attribute value directly
23  to a unary function.*/
24 template <class UF>
26  IMP::OwnerPointer<UF> f_;
27  FloatKey k_;
28 public:
29  //! Apply function f to attribete k
32 };
33 #if !defined(SWIG) && !defined(IMP_DOXYGEN)
34 template <class UF>
37  FloatKey k): f_(f),
38  k_(k){}
39 template <class UF>
40 inline Float GenericAttributeSingletonScore<UF>::evaluate(Particle *b,
41  DerivativeAccumulator *da) const
42 {
43  if (da) {
44  Float v, d;
45  boost::tie(v,d) = f_->UF::evaluate_with_derivative(b->get_value(k_));
46  b->add_to_derivative(k_, d, *da);
47  return v;
48  } else {
49  return f_->UF::evaluate(b->get_value(k_));
50  }
51 }
52 template <class UF>
53 inline void GenericAttributeSingletonScore<UF>::do_show(std::ostream &out) const
54 {
55  out << "function is " << *f_ << " on " << k_;
56 }
57 #endif
58 
59 /** For python users. C++ users should use create_attribute_singleton_score().*/
61 
62 /** Provide a compile time binding version of AttributeSingletonScore,
63  which runs faster than the runtime bound version. UF should be a subclass of
64  UnaryFunction (and not pointer to a generic UnaryFunction).*/
65 template <class UF>
68  FloatKey k) {
69  return new GenericAttributeSingletonScore<UF>(uf, k);
70 }
71 IMPCORE_END_NAMESPACE
72 
73 #endif /* IMPCORE_ATTRIBUTE_SINGLETON_SCORE_H */