IMP logo
IMP Reference Guide  2.14.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-2020 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(Model *m, ParticleIndex p,
40  Model *m, const ParticleIndexes &pis) const IMP_OVERRIDE {
41  return IMP::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>
60  Model *m, ParticleIndex pi,
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,
95  UnaryFunction,
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 */
virtual double evaluate_index(Model *m, ParticleIndex p, DerivativeAccumulator *da) const
Compute the score and the derivative if needed.
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
Definition: object_macros.h:25
#define IMP_OBJECT_LOG
Set the log level to the object's log level.
Definition: log_macros.h:284
Single variable function.
Macros for various classes.
ParticlesTemp get_particles(Model *m, const ParticleIndexes &ps)
#define IMP_LOG_VERBOSE(expr)
Definition: log_macros.h:83
Score particles based on how far outside a box they are.
A more IMP-like version of the std::vector.
Definition: Vector.h:39
Simple XYZ decorator.
Class for storing model, its restraints, constraints, and particles.
Definition: Model.h:72
Abstract class for scoring object(s) of type ParticleIndex.
#define IMP_SINGLETON_SCORE_METHODS(Name)
A bounding box in D dimensions.
A decorator for a particle with x,y,z coordinates.
Definition: XYZ.h:30
Define SingletonScore.
VectorD< 3 > Vector3D
Definition: VectorD.h:421
#define IMP_USAGE_CHECK(expr, message)
A runtime test for incorrect usage of a class or method.
Definition: check_macros.h:168
virtual ModelObjectsTemp do_get_inputs(Model *m, const ParticleIndexes &pis) const
Overload this method to specify the inputs.
#define IMP_OVERRIDE
Cause a compile error if this method does not override a parent method.
Class for adding derivatives from restraints to the model.
Various important functionality for implementing decorators.