IMP logo
IMP Reference Guide  develop.e004443c3b,2024/04/25
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-2022 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  }
47  // depend on get_is_trivially_zero
48  template <unsigned int D>
49  double get_score(Model *m, const Array<D, ParticleIndex> &pp,
50  double distance) const {
51  if (distance < 0) {
52  return P::get_score(m, pp, distance) - k_attr_ * attr_range_;
53  } else {
54  IMP_USAGE_CHECK(distance <= attr_range_, "It is trivially 0.");
55  return k_attr_ * (distance - attr_range_);
56  }
57  }
58  template <unsigned int D>
59  DerivativePair get_score_and_derivative(
60  Model *m, const Array<D, ParticleIndex> &p, double distance) const {
61  if (distance < 0) {
62  DerivativePair dp = P::get_score_and_derivative(m, p, distance);
63  return DerivativePair(dp.first - k_attr_ * attr_range_, dp.second);
64  } else {
65  return DerivativePair(k_attr_ * (distance - attr_range_), k_attr_);
66  }
67  }
68  template <unsigned int D>
69  double get_maximum_range(Model *,
70  const Array<D, ParticleIndex> &) const {
71  return attr_range_;
72  }
73  template <unsigned int D>
74  bool get_is_trivially_zero(Model *, const Array<D, ParticleIndex> &,
75  double squared_distance) const {
76  return squared_distance > algebra::get_squared(attr_range_);
77  }
78 
80  out << "LinearInteraction attr-range " << attr_range_
81  << " attr-k " << k_attr_
82  << " rep-k " << P::get_k() );
83 };
84 //#endif
85 
87 
88 
90 
91 IMPNPCTRANSPORT_END_NAMESPACE
92 
93 #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 a fixed array of same-typed values.
Definition: Array.h:40
A more IMP-like version of the std::vector.
Definition: Vector.h:50
Class for storing model, its restraints, constraints, and particles.
Definition: Model.h:86
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:22
#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
Macros to help with objects that can be printed to a stream.