IMP  2.0.1
The Integrative Modeling Platform
DistanceToSingletonScore.h
Go to the documentation of this file.
1 /**
2  * \file IMP/core/DistanceToSingletonScore.h
3  * \brief A Score on the distance to a fixed point.
4  *
5  * Copyright 2007-2013 IMP Inventors. All rights reserved.
6  */
7 
8 #ifndef IMPCORE_DISTANCE_TO_SINGLETON_SCORE_H
9 #define IMPCORE_DISTANCE_TO_SINGLETON_SCORE_H
10 
11 #include <IMP/core/core_config.h>
12 #include "XYZ.h"
13 #include "internal/evaluate_distance_pair_score.h"
14 #include <IMP/generic.h>
15 #include <IMP/algebra/Vector3D.h>
16 #include <IMP/SingletonScore.h>
17 #include <IMP/Pointer.h>
18 #include <IMP/singleton_macros.h>
19 #include <IMP/UnaryFunction.h>
20 #include <boost/lambda/lambda.hpp>
21 
22 IMPCORE_BEGIN_NAMESPACE
23 
24 //! Apply a function to the distance to a fixed point.
25 /** A particle is scored based on the distance between it and a constant
26  point as passed to a UnaryFunction. This is useful for anchoring
27  constraining particles within a sphere.
28 
29  To restrain a set of particles store in SingletonContainer pc in a sphere
30  do the following:
31  \htmlinclude restrain_in_sphere.py
32  */
33 template <class UF>
35 {
36  IMP::OwnerPointer<UF> f_;
38  struct StaticD
39  {
41  StaticD(algebra::Vector3D v): v_(v){}
42  Float get_coordinate(unsigned int i) {return v_[i];}
43  void add_to_derivatives(algebra::Vector3D v, DerivativeAccumulator){
44  IMP_UNUSED(v);
45  IMP_WARN( "DistanceTo dropped deriv of " << v << std::endl);
46  }
47  };
48 public:
50  const algebra::Vector3D& pt);
52 };
53 
54 #if !defined(SWIG) && !defined(IMP_DOXYGEN)
55 
56 
57 template <class UF>
60  const algebra::Vector3D &v)
61  : f_(f), pt_(v){}
62 template <class UF>
63 Float GenericDistanceToSingletonScore<UF>::evaluate(Particle *b,
64  DerivativeAccumulator *da) const
65 {
66  Float v= internal::evaluate_distance_pair_score(XYZ(b),
67  StaticD(pt_), da,
68  f_.get(), boost::lambda::_1);
69  IMP_LOG_VERBOSE( "DistanceTo from " << XYZ(b) << " to "
70  << pt_ << " scored " << v << std::endl);
71  return v;
72 }
73 template <class UF>
74 void GenericDistanceToSingletonScore<UF>::do_show(std::ostream &out) const
75 {
76  out << "function " << *f_;
77 }
78 
79 #endif
80 
81 /** Use an IMP::UnaryFunction to score a distance to a point.*/
82 IMP_GENERIC_OBJECT(DistanceToSingletonScore, distance_to_singleton_score,
84  (UnaryFunction *f, const algebra::Vector3D& pt),
85  (f, pt));
86 
87 
88 
89 //! Apply a function to the distance to a fixed point.
90 /** A particle is scored based on the distance between it and a constant
91  point as passed to a UnaryFunction. This is useful for anchoring
92  constraining particles within a sphere.
93 
94  To restrain a set of particles store in SingletonContainer pc in a sphere
95  do the following:
96  \htmlinclude restrain_in_sphere.py
97  */
98 class IMPCOREEXPORT SphereDistanceToSingletonScore : public SingletonScore
99 {
100  IMP::OwnerPointer<UnaryFunction> f_;
101  algebra::Vector3D pt_;
102  struct StaticD
103  {
105  StaticD(algebra::Vector3D v): v_(v){}
106  Float get_coordinate(unsigned int i) {return v_[i];}
107  void add_to_derivatives(algebra::Vector3D v, DerivativeAccumulator){
108  IMP_UNUSED(v);
109  IMP_LOG_VERBOSE( "DistanceTo dropped deriv of " << v << std::endl);
110  }
111  };
112 public:
114  const algebra::Vector3D& pt);
116 };
117 
118 IMPCORE_END_NAMESPACE
119 
120 #endif /* IMPCORE_DISTANCE_TO_SINGLETON_SCORE_H */