IMP  2.4.0
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-2015 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,
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,
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.
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
Definition: object_macros.h:25
Import IMP/kernel/UnaryFunction.h in the namespace.
IMP::kernel::UnaryFunction UnaryFunction
ParticlesTemp get_particles(kernel::Model *m, const ParticleIndexes &ps)
Import IMP/kernel/singleton_macros.h in the namespace.
#define IMP_LOG_VERBOSE(expr)
Definition: log_macros.h:94
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
#define IMP_WARN(expr)
Write a warning to a log.
Definition: log_macros.h:66
virtual double evaluate_index(kernel::Model *m, kernel::ParticleIndex p, DerivativeAccumulator *da) const
Compute the score and the derivative if needed.
#define IMP_UNUSED(variable)
Apply a function to the distance to a fixed point.
Import IMP/kernel/SingletonScore.h in the namespace.
A nullptr-initialized pointer to an IMP Object.
Abstract class for scoring object(s) of type Particle.
VectorD< 3 > Vector3D
Definition: VectorD.h:395
double Float
Basic floating-point value (could be float, double...)
Definition: types.h:20
Simple 3D vector class.
Apply a function to the distance to a fixed point.
#define IMP_OVERRIDE
Cause a compile error if this method does not override a parent method.
#define IMP_SINGLETON_SCORE_METHODS(Name)
Class for storing model, its restraints, constraints, and particles.
Definition: kernel/Model.h:73
Import IMP/kernel/generic.h in the namespace.