IMP logo
IMP Reference Guide  2.22.0
The Integrative Modeling Platform
directional_DOFs.h
Go to the documentation of this file.
1 /**
2  * \file IMP/kinematics/directional_DOFs.h
3  * \brief
4  * \authors Dina Schneidman, Barak Raveh
5  *
6  * Copyright 2007-2022 IMP Inventors. All rights reserved.
7  *
8  */
9 
10 #ifndef IMPKINEMATICS_DIRECTIONAL_DO_FS_H
11 #define IMPKINEMATICS_DIRECTIONAL_DO_FS_H
12 
13 #include "DOF.h"
14 
15 IMPKINEMATICS_BEGIN_NAMESPACE
16 
17 /**
18  this is a linear one.
19  \note We may want to make it more general. This will require
20  turning it into a virtual class.
21 */
22 class IMPKINEMATICSEXPORT DirectionalDOF : public IMP::Object {
23  public:
24  DirectionalDOF(const DOFs& dofs) : Object("DirectionalDOF%1%"), dofs_(dofs) {}
25 
26  void set_end_points(const DOFValues& q1, const DOFValues& q2) {
27  endpoint1_ = q1;
28  endpoint2_ = q2;
29  current_delta_.resize(dofs_.size());
30  // TODO: check that the size of dofs_, q1 and q2 is the same
31  // IMP_CHECK...
32 
33  // determine step size based on each DOF
34  // Total number of steps between endpoint1 and endpoint2
35  // determined by the number of steps between the largest DOF
36  step_number_ = 0;
37  for (unsigned int i = 0; i < dofs_.size(); i++) {
38  int dof_step_number =
39  dofs_[i]->get_number_of_steps(endpoint1_[i], endpoint2_[i]);
40  if (dof_step_number > step_number_) step_number_ = dof_step_number;
41  }
42  // current_delta_ is the delta in values of q between start and endpoints
43  for (unsigned int i = 0; i < dofs_.size(); i++) {
44  current_delta_[i] = (endpoint2_[i] - endpoint1_[i]) / step_number_;
45  }
46 
47  current_step_number_ = 0;
48  delta_ = 1.0 / step_number_;
49  value_ = 0.0;
50  }
51 
52  // return current DOF
53  DOFValues get_dofs_values() {
54  DOFValues ret = endpoint1_;
55  for (unsigned int i = 0; i < ret.size(); i++) {
56  ret[i] += current_step_number_ * current_delta_[i];
57  }
58  return ret;
59  }
60 
61  double get_value() const { return value_; }
62 
63 #ifndef SWIG
64  void operator++(int) {
65  current_step_number_++;
66  value_ += delta_;
67  }
68  void operator--(int) {
69  current_step_number_--;
70  value_ -= delta_;
71  }
72 #endif
73 
75 
76  protected:
77  DOFs dofs_; // can be a pointer
78  DOFValues endpoint1_;
79  DOFValues endpoint2_;
80 
81  // step size for each DOF for endpoint1 and endpoint2
82  DOFValues current_delta_;
83 
84  // step number based on current_delta_
85  int step_number_;
86 
87  // counter for step_number_
88  int current_step_number_;
89 
90  // follows curr_step_number_ between 0 and 1
91  double value_;
92 
93  // delta for value
94  double delta_;
95 };
96 
98 
99 IMPKINEMATICS_END_NAMESPACE
100 
101 #endif /* IMPKINEMATICS_DIRECTIONAL_DO_FS_H */
single degree of freedom
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
Definition: object_macros.h:25
Common base class for heavy weight IMP objects.
Definition: Object.h:111
A class that holds DOF values for DOFs.
Definition: DOFValues.h:23
#define IMP_OBJECTS(Name, PluralName)
Define the types for storing lists of object pointers.
Definition: object_macros.h:44
Object(std::string name)
Construct an object with the given name.