IMP  2.0.0
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-2013 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>
31 {
32  IMP::OwnerPointer<UF> f_;
34 public:
36  const algebra::BoundingBoxD<3> &bb);
37 
39 };
40 
41 #if !defined(SWIG) && !defined(IMP_DOXYGEN)
42 template <class UF>
45  const algebra::BoundingBox3D &bb ): f_(f), bb_(bb){
46  IMP_USAGE_CHECK(std::abs(f_->evaluate(0)) <.1,
47  "The unary function should return "
48  " 0 when passed a value of 0. Not " << f_->evaluate(0));
49 }
50 template <class UF>
51 double GenericBoundingBox3DSingletonScore<UF>::evaluate(Particle *p,
52  DerivativeAccumulator *da) const {
54  core::XYZ d(p);
56  bool outside=false;
57  for (unsigned int i=0; i< 3; ++i) {
58  if (bb_.get_corner(0)[i] > d.get_coordinate(i)) {
59  cp[i]=bb_.get_corner(0)[i];
60  outside=true;
61  } else if (bb_.get_corner(1)[i] < d.get_coordinate(i)) {
62  cp[i]=bb_.get_corner(1)[i];
63  outside=true;
64  } else {
65  cp[i]= d.get_coordinate(i);
66  }
67  }
68  if (outside) {
69  IMP_LOG_VERBOSE( "Particle " << Showable(p) << " is outside box: "
70  << d << " of " << bb_ << std::endl);
71  algebra::Vector3D deriv;
72  double v= internal::compute_distance_pair_score(d.get_coordinates()-cp,
73  f_.get(),&deriv,
74  boost::lambda::_1);
75  if (da) {
76  d.add_to_derivatives(deriv, *da);
77  }
78  return v;
79  } else {
80  return 0;
81  }
82 }
83 template <class UF>
84 void GenericBoundingBox3DSingletonScore<UF>::do_show(std::ostream &out) const {
85  out << "box is " << bb_ << std::endl;
86 }
87 
88 
89 
90 #endif
91 
92 IMP_GENERIC_OBJECT(BoundingBox3DSingletonScore, bounding_box_3d_singleton_score,
94  const algebra::BoundingBoxD<3> &bb),
95  (f, bb));
96 
97 
98 
99 IMPCORE_END_NAMESPACE
100 
101 #endif /* IMPCORE_BOUNDING_BOX_3DSINGLETON_SCORE_H */