IMP  2.2.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-2014 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/base/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  \include core/restrain_in_sphere.py
32  */
33 template <class UF>
37  struct StaticD {
39  StaticD(algebra::Vector3D v) : v_(v) {}
40  Float get_coordinate(unsigned int i) { return v_[i]; }
41  void add_to_derivatives(algebra::Vector3D v, DerivativeAccumulator) {
42  IMP_UNUSED(v);
43  IMP_WARN("DistanceTo dropped deriv of " << v << std::endl);
44  }
45  };
46 
47  public:
49  virtual double evaluate_index(kernel::Model *m, kernel::ParticleIndex p,
50  DerivativeAccumulator *da) const IMP_OVERRIDE;
52  kernel::Model *m, const kernel::ParticleIndexes &pis) const IMP_OVERRIDE {
53  return IMP::kernel::get_particles(m, pis);
54  }
57  ;
58 };
59 
60 #if !defined(SWIG) && !defined(IMP_DOXYGEN)
61 
62 template <class UF>
64  UF *f, const algebra::Vector3D &v)
65  : f_(f), pt_(v) {}
66 template <class UF>
69  DerivativeAccumulator *da) const {
70  double v = internal::evaluate_distance_pair_score(
71  XYZ(m, pi), StaticD(pt_), da, f_.get(), boost::lambda::_1);
72  IMP_LOG_VERBOSE("DistanceTo from " << XYZ(m, pi) << " to " << pt_
73  << " scored " << v << std::endl);
74  return v;
75 }
76 
77 #endif
78 
79 /** Use an IMP::UnaryFunction to score a distance to a point.*/
80 IMP_GENERIC_OBJECT(DistanceToSingletonScore, distance_to_singleton_score,
82  (UnaryFunction *f, const algebra::Vector3D &pt), (f, pt));
83 
84 //! Apply a function to the distance to a fixed point.
85 /** A particle is scored based on the distance between it and a constant
86  point as passed to a UnaryFunction. This is useful for anchoring
87  constraining particles within a sphere.
88 
89  To restrain a set of particles store in SingletonContainer pc in a sphere
90  do the following:
91  \include core/restrain_in_sphere.py
92  */
93 class IMPCOREEXPORT SphereDistanceToSingletonScore : public SingletonScore {
96  struct StaticD {
98  StaticD(algebra::Vector3D v) : v_(v) {}
99  Float get_coordinate(unsigned int i) { return v_[i]; }
100  void add_to_derivatives(algebra::Vector3D v, DerivativeAccumulator) {
101  IMP_UNUSED(v);
102  IMP_LOG_VERBOSE("DistanceTo dropped deriv of " << v << std::endl);
103  }
104  };
105 
106  public:
108  virtual double evaluate_index(kernel::Model *m, kernel::ParticleIndex p,
109  DerivativeAccumulator *da) const IMP_OVERRIDE;
111  kernel::Model *m, const kernel::ParticleIndexes &pis) const IMP_OVERRIDE {
112  return IMP::kernel::get_particles(m, pis);
113  }
116  ;
117 };
118 
119 IMPCORE_END_NAMESPACE
120 
121 #endif /* IMPCORE_DISTANCE_TO_SINGLETON_SCORE_H */
GenericDistanceToSingletonScore< UnaryFunction > DistanceToSingletonScore
virtual kernel::ModelObjectsTemp do_get_inputs(kernel::Model *m, const kernel::ParticleIndexes &pis) const
Class for adding derivatives from restraints to the model.
A nullptr-initialized pointer to an IMP Object.
#define IMP_WARN(expr)
Write a warning to a log.
Import IMP/kernel/UnaryFunction.h in the namespace.
IMP::kernel::UnaryFunction UnaryFunction
ParticlesTemp get_particles(kernel::Model *m, const ParticleIndexes &ps)
#define IMP_UNUSED(variable)
Import IMP/kernel/singleton_macros.h in the namespace.
Abstract single variable functor class for score functions.
Simple xyz decorator.
virtual kernel::ModelObjectsTemp do_get_inputs(kernel::Model *m, const kernel::ParticleIndexes &pis) const
virtual double evaluate_index(kernel::Model *m, kernel::ParticleIndex p, DerivativeAccumulator *da) const
Compute the score and the derivative if needed.
Apply a function to the distance to a fixed point.
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
Import IMP/kernel/SingletonScore.h in the namespace.
Abstract score function.
VectorD< 3 > Vector3D
Definition: VectorD.h:395
double Float
Basic floating-point value (could be float, double...)
Definition: base/types.h:20
Simple 3D vector class.
Apply a function to the distance to a fixed point.
#define IMP_LOG_VERBOSE(expr)
#define IMP_SINGLETON_SCORE_METHODS(Name)
Class for storing model, its restraints, constraints, and particles.
Definition: kernel/Model.h:72
Import IMP/kernel/generic.h in the namespace.