IMP logo
IMP Reference Guide  2.12.0
The Integrative Modeling Platform
functor_linear_distance_pair_scores_typedefs.h
Go to the documentation of this file.
1 /**
2  * \file functor_linear_distance_pair_scores_typedefs.h
3  * \brief Typedefs for the functor scores on the distance between a pair of particles.
4  *
5  * Copyright 2007-2019 IMP Inventors. All rights reserved.
6  */
7 
8 #ifndef IMPNPCTRANSPORT_FUNCTOR_LINEAR_DISTANCE_PAIR_SCORES_TYPEDEFS_H
9 #define IMPNPCTRANSPORT_FUNCTOR_LINEAR_DISTANCE_PAIR_SCORES_TYPEDEFS_H
10 
11 #include "npctransport_config.h"
12 #include <IMP/showable_macros.h>
13 #include <IMP/algebra/utility.h>
18 
19 #include <boost/array.hpp>
20 
21 IMPNPCTRANSPORT_BEGIN_NAMESPACE
22 
23 //#ifndef SWIG
24 typedef score_functor::SphereDistance<score_functor::LinearLowerBound>
25  LinearSoftSphereScore;
26 //#endif
27 
28 //#ifndef SWIG
29 /**
30  A soft linear attractive / repulsive score between two spheres.
31  The score is 0 if the spheres are beyond the attractive range.
32  Within the attractive range, the score decreases linearly (= attraction)
33  with slope k_attr_ until the spheres touch. Once the spheres begin to
34  penetrate each other, the score rises linearly with slope k_rep_
35  (= repulsion), though it may be negative for small penetration.
36 */
39  double attr_range_; // range of attraction between particles
40  double k_attr_; // attraction coefficient
41  public:
42  LinearInteraction(double krep, double attr_range, double kattr) : P(krep) {
43  attr_range_ = attr_range;
44  k_attr_ = kattr;
45  }
46  // depend on get_is_trivially_zero
47  template <unsigned int D>
48  double get_score(Model *m, const Array<D, ParticleIndex> &pp,
49  double distance) const {
50  if (distance < 0) {
51  return P::get_score(m, pp, distance) - k_attr_ * attr_range_;
52  } else {
53  IMP_USAGE_CHECK(distance <= attr_range_, "It is trivially 0.");
54  return k_attr_ * (distance - attr_range_);
55  }
56  }
57  template <unsigned int D>
58  DerivativePair get_score_and_derivative(
59  Model *m, const Array<D, ParticleIndex> &p, double distance) const {
60  if (distance < 0) {
61  DerivativePair dp = P::get_score_and_derivative(m, p, distance);
62  return DerivativePair(dp.first - k_attr_ * attr_range_, dp.second);
63  } else {
64  return DerivativePair(k_attr_ * (distance - attr_range_), k_attr_);
65  }
66  }
67  template <unsigned int D>
68  double get_maximum_range(Model *,
69  const Array<D, ParticleIndex> &) const {
70  return attr_range_;
71  }
72  template <unsigned int D>
73  bool get_is_trivially_zero(Model *, const Array<D, ParticleIndex> &,
74  double squared_distance) const {
75  return squared_distance > algebra::get_squared(attr_range_);
76  }
77 
79  out << "LinearInteraction attr-range " << attr_range_
80  << " attr-k " << k_attr_
81  << " rep-k " << P::get_k() );
82 };
83 //#endif
84 
86 
87 
89 
90 IMPNPCTRANSPORT_END_NAMESPACE
91 
92 #endif /* IMPNPCTRANSPORT_FUNCTOR_LINEAR_DISTANCE_PAIR_SCORES_TYPEDEFS_H */
Various important macros for implementing decorators.
#define IMP_SHOWABLE_INLINE(Name, how_to_show)
Declare the methods needed by an object that can be printed.
A Score on the distance between a pair of particles.
A Score on the distance between a pair of particles.
A class to store an fixed array of same-typed values.
Definition: Array.h:33
A more IMP-like version of the std::vector.
Definition: Vector.h:39
Class for storing model, its restraints, constraints, and particles.
Definition: Model.h:72
Functions to deal with very common math operations.
A Score on the distance between a pair of particles.
std::pair< double, double > DerivativePair
A pair representing a function value with its first derivative.
Definition: types.h:23
#define IMP_OBJECTS(Name, PluralName)
Define the types for storing lists of object pointers.
Definition: object_macros.h:44
#define IMP_USAGE_CHECK(expr, message)
A runtime test for incorrect usage of a class or method.
Definition: check_macros.h:168
Various general useful macros for IMP.