IMP logo
IMP Reference Guide  2.14.0
The Integrative Modeling Platform
ZBiasSingletonScore.h
Go to the documentation of this file.
1 /**
2  * \file ZBiasSingletonScore.h
3  * \brief score that biases particles to go down the Z axis
4  *
5  * Copyright 2007-2020 IMP Inventors. All rights reserved.
6  */
7 
8 #ifndef IMPNPCTRANSPORT_Z_BIAS_SINGLETON_SCORE_H
9 #define IMPNPCTRANSPORT_Z_BIAS_SINGLETON_SCORE_H
10 
11 #include "npctransport_config.h"
12 #include "enums.h"
13 #include <IMP/SingletonScore.h>
14 #include <IMP/singleton_macros.h>
15 #include <IMP/algebra/Vector3D.h>
16 #include <limits>
17 
18 IMPNPCTRANSPORT_BEGIN_NAMESPACE
19 
20 
21 //! Score that biases particles to go down the Z axis
22 class IMPNPCTRANSPORTEXPORT ZBiasSingletonScore
23  : public SingletonScore {
24  private:
25  algebra::Vector3D v_deriv_; // deriv of force, which is of form (0,0,k)
26  double max_r2_; // maximal square r (distance from origin on x,y plane)
27  public:
28  /**
29  Exclude particles from the range of z coordinates [bottom_..top_]
30  with repulsive force constant k
31 
32  @param k repulsive force constant
33  @param max_r maximal distance from origin on x,y plane (radius
34  relative to pore axis) in which force is applied.
35  if 0.0, no limitation
36  */
38  ( double k,
39  double max_r = HALF_SQRT_MAX_DOUBLE) // half for numerical margin error
40  : max_r2_( max_r * max_r )
41  {
42  set_k(k);
43  }
44 
45 
46  /**
47  returns the force constant for pulling to high z
48  (negative = pull to low z)
49  */
50  double get_k() const { return v_deriv_[2]; }
51 
52  /**
53  sets the force constant for pulling to high z
54  (negative = pull to low z)
55 
56  @param k force contant
57  */
58  void set_k(double k) {
59  v_deriv_ = algebra::Vector3D(0, 0, k);
60  }
61 
62  virtual double evaluate_index(Model *m, ParticleIndex pi,
64  {
65  core::XYZR d(m,pi);
66  double r2 = std::pow(d.get_x(), 2) + std::pow(d.get_y(), 2);
67  if (r2 > max_r2_) {
68  // nothing to add to derivatives( = 0);
69  return 0.0; // TODO: this is not smooth around pore edge - problem
70  }
71  double const& k = v_deriv_[2];
72  double score = k * d.get_z();
73  if (da) {
74  IMP_LOG(VERBOSE, "result in " << score
75  << " and " << v_deriv_ << std::endl);
76  d.add_to_derivatives(v_deriv_, *da);
77  }
78  return score;
79  }
80 
82  const ParticleIndexes &pis) const
84  { return IMP::get_particles(m, pis); }
85 
88 };
89 
90 IMPNPCTRANSPORT_END_NAMESPACE
91 
92 #endif /* IMPNPCTRANSPORT_Z_BIAS_SINGLETON_SCORE_H */
void add_to_derivatives(const algebra::Vector3D &v, DerivativeAccumulator &d)
Add the vector v to the derivative vector of the x,y,z coordinates.
Definition: XYZ.h:82
useful enums and contants
Float get_y() const
Definition: XYZ.h:55
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
Definition: object_macros.h:25
Macros for various classes.
ParticlesTemp get_particles(Model *m, const ParticleIndexes &ps)
Float get_x() const
Definition: XYZ.h:54
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
Score that biases particles to go down the Z axis.
Abstract class for scoring object(s) of type ParticleIndex.
#define IMP_SINGLETON_SCORE_METHODS(Name)
Define SingletonScore.
VectorD< 3 > Vector3D
Definition: VectorD.h:421
virtual double evaluate_index(Model *m, ParticleIndex pi, DerivativeAccumulator *da) const
Compute the score and the derivative if needed.
Simple 3D vector class.
Float get_z() const
Definition: XYZ.h:56
#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 ModelObjectsTemp do_get_inputs(Model *m, const ParticleIndexes &pis) const
Overload this method to specify the inputs.
A decorator for a particle with x,y,z coordinates and a radius.
Definition: XYZR.h:27