IMP  2.2.1
The Integrative Modeling Platform
BoundingBox3DSingletonScore.h
Go to the documentation of this file.
1 /**
2  * \file IMP/core/BoundingBox3DSingletonScore.h
3  * \brief Score particles based on a bounding box
4  *
5  * Copyright 2007-2014 IMP Inventors. All rights reserved.
6  */
7 
8 #ifndef IMPCORE_BOUNDING_BOX_3DSINGLETON_SCORE_H
9 #define IMPCORE_BOUNDING_BOX_3DSINGLETON_SCORE_H
10 
11 #include <IMP/core/core_config.h>
12 #include <IMP/generic.h>
13 #include <IMP/SingletonScore.h>
14 #include <IMP/singleton_macros.h>
15 #include <IMP/UnaryFunction.h>
17 #include "XYZ.h"
18 #include "internal/evaluate_distance_pair_score.h"
19 #include <boost/lambda/lambda.hpp>
20 
21 IMPCORE_BEGIN_NAMESPACE
22 
23 //! Score particles based on how far outside a box they are.
24 /** The radius of the particle is ignored, only the center coordinates
25  are used. A particle that is contained within the bounding box has
26  a score of 0. The UnaryFunction passed should return 0 when given
27  a feature size of 0 and a positive value when the feature is positive.
28  */
29 template <class UF>
33 
34  public:
36 
37  virtual double evaluate_index(kernel::Model *m, kernel::ParticleIndex p,
38  DerivativeAccumulator *da) const IMP_OVERRIDE;
40  kernel::Model *m, const kernel::ParticleIndexes &pis) const IMP_OVERRIDE {
41  return IMP::kernel::get_particles(m, pis);
42  }
45  ;
46 };
47 
48 #if !defined(SWIG) && !defined(IMP_DOXYGEN)
49 template <class UF>
51  UF *f, const algebra::BoundingBox3D &bb)
52  : f_(f), bb_(bb) {
53  IMP_USAGE_CHECK(std::abs(f_->evaluate(0)) < .1,
54  "The unary function should return "
55  " 0 when passed a value of 0. Not "
56  << f_->evaluate(0));
57 }
58 template <class UF>
61  DerivativeAccumulator *da) const {
63  core::XYZ d(m, pi);
65  bool outside = false;
66  for (unsigned int i = 0; i < 3; ++i) {
67  if (bb_.get_corner(0)[i] > d.get_coordinate(i)) {
68  cp[i] = bb_.get_corner(0)[i];
69  outside = true;
70  } else if (bb_.get_corner(1)[i] < d.get_coordinate(i)) {
71  cp[i] = bb_.get_corner(1)[i];
72  outside = true;
73  } else {
74  cp[i] = d.get_coordinate(i);
75  }
76  }
77  if (outside) {
78  IMP_LOG_VERBOSE("Particle " << Showable(pi) << " is outside box: " << d
79  << " of " << bb_ << std::endl);
80  algebra::Vector3D deriv;
81  double v = internal::compute_distance_pair_score(
82  d.get_coordinates() - cp, f_.get(), &deriv, boost::lambda::_1);
83  if (da) {
84  d.add_to_derivatives(deriv, *da);
85  }
86  return v;
87  } else {
88  return 0;
89  }
90 }
91 
92 #endif
93 
94 IMP_GENERIC_OBJECT(BoundingBox3DSingletonScore, bounding_box_3d_singleton_score,
96  (UnaryFunction *f, const algebra::BoundingBoxD<3> &bb),
97  (f, bb));
98 
99 IMPCORE_END_NAMESPACE
100 
101 #endif /* IMPCORE_BOUNDING_BOX_3DSINGLETON_SCORE_H */
Class for adding derivatives from restraints to the model.
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.
Score particles based on how far outside a box they are.
Simple xyz decorator.
virtual kernel::ModelObjectsTemp do_get_inputs(kernel::Model *m, const kernel::ParticleIndexes &pis) const
#define IMP_USAGE_CHECK(expr, message)
A runtime test for incorrect usage of a class or method.
A bounding box in D dimensions.
A decorator for a particle with x,y,z coordinates.
Definition: XYZ.h:30
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
Import IMP/kernel/SingletonScore.h in the namespace.
#define IMP_OBJECT_LOG
Set the log level to the object's log level.
Abstract score function.
VectorD< 3 > Vector3D
Definition: VectorD.h:395
virtual double evaluate_index(kernel::Model *m, kernel::ParticleIndex p, DerivativeAccumulator *da) const
Compute the score and the derivative if needed.
#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.