IMP logo
IMP Reference Guide  2.14.0
The Integrative Modeling Platform
AnchorToCylindricalPorePairScore.h
1 /**
2  * \file AnchorToCylidnricalPorePairScore.h
3  * \brief A chore for anchoring a bead to a pore
4  *
5  * Copyright 2007-2020 IMP Inventors. All rights reserved.
6  */
7 
8 #ifndef IMPNPCTRANSPORT_ANCHOR_TO_CYLINDRICAL_PORE_PAIR_SCORE_H
9 #define IMPNPCTRANSPORT_ANCHOR_TO_CYLINDRICAL_PORE_PAIR_SCORE_H
10 
11 #include "npctransport_config.h"
13 #include <IMP/check_macros.h>
14 #include <IMP/PairScore.h>
15 #include <IMP/pair_macros.h>
16 #include <IMP/core/XYZR.h>
18 
19 IMPNPCTRANSPORT_BEGIN_NAMESPACE
20 
21 /**
22  a score for anchoring a bead to a reference point defined relatively to the surface of a cylindrical pore. The reference point is at a fixed angle about the pore central axis, radial distance from the pore edge, and z coordinate.
23 */
24 class IMPNPCTRANSPORTEXPORT
26 {
27  private:
28  algebra::Vector2D normalized_xy_; // normalized direction of equilibrium point in x,y plane
29  Float pore_radial_d_; // equilibrium distance of anchor point from pore surface in x,y plane
30  score_functor::Harmonic ds_; // distance score
31  mutable algebra::Vector3D reference_point_; // current value of equilibrium reference point
32 
33  public:
34  /** Initialize a harmonic distance score between an anchor bead
35  and an equilibrium reference point that is evaluated according to the specified
36  equilibrium values, relative to the cylindrical pore at the time of score
37  evaluation.
38 
39  @param rot_angle equilibrium counter-clockwise angle of the anchor bead
40  in the x,y plane relative to the x axis, in Radians
41  @param radial_d equilibrium radial distance from the pore surface (positive = inside pore; negative = outside)
42  @param z equilibrium z coordinate
43  @param k the harmonic force coefficient between the bead and the equilibrium
44  reference point
45  */
47  Float pore_radial_d,
48  Float z,
49  Float k);
50 
51  /** initialized the score using current anchor_bead orientation
52  relative to scp for initializing the values of the equilibrium
53  rotation angle of the anchor about the pore central axis,
54  its radial distance from the pore surface, and its z coordinate
55 
56  @param scp The porus slab
57  @param initial_anchor_point The coordinates that are used as reference
58  for initializing the anchor equilibrium values relative to the slab
59  @param k The harmonic force coefficient between the bead and the equilibrium
60  reference point
61  */
63  algebra::Vector3D initial_anchor_point,
64  Float k);
65 
66  public:
67  //! Evaluate score for particle pair pip in model m
68  /**
69  Evaluate score for particle pair pip in model m, where pip[0] is
70  a SlabWithCylindricalPore and pip[1] is the anchored bead.
71  The score is a harmonic distance restraint between the anchored bead
72  and the equilibrium reference point relative to the porous slab
73  (see constructors for details).
74 
75  If da is not null, use it to accumulate derivatives in model.
76  */
77  virtual double evaluate_index
78  (Model *m,
79  const ParticleIndexPair& pip,
81 
83  const ParticleIndexes &pis) const
85 
88 
89  private:
90 
91  // update internal variable holding current reference point for fast access
92  // based on decorated particle slab
93  // @param pr current pore radius
94  void update_reference_point_for_pore_radius
95  (Float pr) const;
96 };
97 
98 inline void
99 AnchorToCylidnricalPorePairScore
100 ::update_reference_point_for_pore_radius
101 ( Float pr) const
102 {
103  Float r= pr - pore_radial_d_;
104  reference_point_[0]= normalized_xy_[0]*r;
105  reference_point_[1]= normalized_xy_[1]*r;
106  }
107 
108 //
109 inline double
110 AnchorToCylidnricalPorePairScore
111 ::evaluate_index
112 ( Model *m,
113  const ParticleIndexPair& pip,
114  DerivativeAccumulator *da ) const
115 {
116  IMP_USAGE_CHECK(SlabWithCylindricalPore::get_is_setup(m, pip[0]),
117  "pip[0] is not a SlabWithCylindricalPore in evaluate_index()");
118  SlabWithCylindricalPore slab(m, pip[0]);
119  update_reference_point_for_pore_radius(slab.get_pore_radius());
120  IMP::core::XYZ xyz(m, pip[1]);
121  if(!xyz.get_coordinates_are_optimized()){
122  return false;
123  }
124  algebra::Vector3D rp_to_xyz =
125  reference_point_ - xyz.get_coordinates();
126  double sq = rp_to_xyz.get_squared_magnitude();
127  double dist = std::sqrt(sq);
128  if (da) {
129  std::pair<double, double> sp =
130  ds_.get_score_and_derivative(m, pip, dist);
131  static const double MIN_DISTANCE = .00001;
132  algebra::Vector3D rp_to_xyz_norm;
133  if (dist > MIN_DISTANCE) {
134  rp_to_xyz_norm = rp_to_xyz / dist;
135  } else {
136  rp_to_xyz_norm = algebra::get_zero_vector_d<3>();
137  }
138  algebra::Vector3D deriv_on_rp(rp_to_xyz_norm * sp.second);
139  if(slab.get_pore_radius_is_optimized()){
140  // transform derivative of slab reference position to derivative of pore radius
141  double deriv_on_pore_radius_squared=
142  deriv_on_rp[0]*deriv_on_rp[0] + deriv_on_rp[1]*deriv_on_rp[1];
143  slab.add_to_pore_radius_derivative(sqrt(deriv_on_pore_radius_squared), *da);
144  }
145  m->add_to_coordinate_derivatives(pip[1], -deriv_on_rp, *da);
146  return sp.first;
147  } else {
148  return ds_.get_score(m, pip, dist);
149  }
150 }
151 
152 
153 
154 
155 IMPNPCTRANSPORT_END_NAMESPACE
156 
157 #endif /* IMPNPCTRANSPORT_ANCHOR_TO_CYLINDRICAL_PORE_PAIR_SCORE_H */
void add_to_pore_radius_derivative(double v, DerivativeAccumulator &d)
Definition: SlabWithPore.h:102
Abstract class for scoring object(s) of type ParticleIndexPair.
Definition: PairScore.h:37
Macros for various classes.
VectorD< 2 > Vector2D
Definition: VectorD.h:417
#define IMP_PAIR_SCORE_METHODS(Name)
Definition: pair_macros.h:25
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
Definition: object_macros.h:25
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
A harmonic score on the directed distance between a pair of particles, centered at 0...
A decorator for a particle that's a slab with a cylindrical pore.
Float get_pore_radius() const
get cylindrical pore radius
Definition: SlabWithPore.h:91
Define PairScore.
virtual ModelObjectsTemp do_get_inputs(Model *m, const ParticleIndexes &pis) const =0
Overload this method to specify the inputs.
A decorator for a particle with x,y,z coordinates.
Definition: XYZ.h:30
Exception definitions and assertions.
VectorD< 3 > Vector3D
Definition: VectorD.h:421
double Float
Basic floating-point value (could be float, double...)
Definition: types.h:20
#define IMP_USAGE_CHECK(expr, message)
A runtime test for incorrect usage of a class or method.
Definition: check_macros.h:168
Decorator for a sphere-like particle.
virtual double evaluate_index(Model *m, const ParticleIndexPair &vt, DerivativeAccumulator *da) const =0
Compute the score and the derivative if needed.
#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.