IMP logo
IMP Reference Guide  2.13.0
The Integrative Modeling Platform
BoundingSphere3DSingletonScore.h
Go to the documentation of this file.
1 /**
2  * \file IMP/core/BoundingSphere3DSingletonScore.h
3  * \brief Score particles based on a bounding sphere - score would typically
4  * increase as particles are exiting the sphere boundaries, and must
5  * be zero within the sphere and positive outside of it.
6  *
7  * Copyright 2007-2020 IMP Inventors. All rights reserved.
8  */
9 
10 #ifndef IMPCORE_BOUNDING_SPHERE_3D_SINGLETON_SCORE_H
11 #define IMPCORE_BOUNDING_SPHERE_3D_SINGLETON_SCORE_H
12 
13 #include <IMP/core/core_config.h>
14 #include <IMP/generic.h>
15 #include <IMP/SingletonScore.h>
16 #include <IMP/singleton_macros.h>
17 #include <IMP/UnaryFunction.h>
18 #include <IMP/algebra/Sphere3D.h>
19 #include "XYZ.h"
20 #include "XYZR.h"
21 
22 IMPCORE_BEGIN_NAMESPACE
23 
24 //! Score XYZ or XYZR particles based on how far outside a sphere they are.
25 /** The radius of the particle is taken into account if it is XYZR decorated.
26  A particle that is contained within the bounding sphere has
27  a score of 0. The UnaryFunction passed should return 0 when given
28  a feature size of 0 and a positive value when the feature is positive.
29  */
30 template <class UF>
33  algebra::Sphere3D sphere_;
34 
35  public:
37 
38  virtual double evaluate_index(Model *m, ParticleIndex p,
41  Model *m, const ParticleIndexes &pis) const IMP_OVERRIDE {
42  return IMP::get_particles(m, pis);
43  }
46  ;
47 };
48 
49 #if !defined(SWIG) && !defined(IMP_DOXYGEN)
50 template <class UF>
52  UF *f, const algebra::Sphere3D &sphere)
53  : f_(f), sphere_(sphere) {
54  IMP_USAGE_CHECK(std::abs(f_->evaluate(0)) < .000001,
55  "The unary function should return "
56  " 0 when passed a value of 0. Not "
57  << f_->evaluate(0));
58 }
59 template <class UF>
61  Model *m, ParticleIndex pi,
62  DerivativeAccumulator *da) const {
64  static const double MIN_DISTANCE = .000001;
65 
66  core::XYZ xyz(m, pi);
67  algebra::Vector3D v_from_origin= (xyz.get_coordinates() - sphere_.get_center());
68  double d_from_origin= v_from_origin.get_magnitude();
69  double d_from_surface= d_from_origin - sphere_.get_radius();
70  if(core::XYZR::get_is_setup(m,pi)){
71  core::XYZR xyzr(m,pi);
72  d_from_surface += xyzr.get_radius();
73  }
74  bool inside = d_from_surface<MIN_DISTANCE; // use MIN_DISTANCE for numerical stability
75  if (inside) {
76  return 0.0;
77  }
78  IMP_LOG_VERBOSE("Particle " << Showable(pi) << " is outside sphere: " << xyz
79  << " of " << sphere_ << std::endl);
80  if (da) {
81  IMP::DerivativePair dp= f_->evaluate_with_derivative(d_from_surface);
82  algebra::Vector3D deriv= v_from_origin.get_unit_vector() * dp.second;
83  xyz.add_to_derivatives(deriv, *da);
84  return dp.first;
85  } else {
86  return f_->evaluate(d_from_surface);
87  }
88 }
89 
90 #endif
91 
92 IMP_GENERIC_OBJECT(BoundingSphere3DSingletonScore, bounding_sphere_3d_singleton_score,
93  UnaryFunction,
94  (UnaryFunction *f, const algebra::Sphere3D &sphere),
95  (f, sphere));
96 
97 IMPCORE_END_NAMESPACE
98 
99 #endif /* IMPCORE_BOUNDING_SPHERE_3D_SINGLETON_SCORE_H */
SphereD< 3 > Sphere3D
Typedef for Python.
Definition: SphereD.h:96
#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
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
virtual ModelObjectsTemp do_get_inputs(Model *m, const ParticleIndexes &pis) const
Overload this method to specify the inputs.
Abstract class for scoring object(s) of type ParticleIndex.
#define IMP_SINGLETON_SCORE_METHODS(Name)
A decorator for a particle with x,y,z coordinates.
Definition: XYZ.h:30
Define SingletonScore.
std::pair< double, double > DerivativePair
A pair representing a function value with its first derivative.
Definition: types.h:23
Score XYZ or XYZR particles based on how far outside a sphere they are.
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
Simple 3D sphere class.
Decorator for a sphere-like particle.
#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.
virtual double evaluate_index(Model *m, ParticleIndex p, DerivativeAccumulator *da) const
Compute the score and the derivative if needed.
Various important functionality for implementing decorators.
A decorator for a particle with x,y,z coordinates and a radius.
Definition: XYZR.h:27