IMP logo
IMP Reference Guide  2.5.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-2015 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  we may want to make it more general. this will require
20  turning it into virtual class
21 */
22 class IMPKINEMATICSEXPORT DirectionalDOF {
23  public:
24  DirectionalDOF(const DOFs& dofs) : 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  step_number_ = 0;
35  for (unsigned int i = 0; i < dofs_.size(); i++) {
36  int dof_step_number =
37  dofs_[i]->get_number_of_steps(endpoint1_[i], endpoint2_[i]);
38  if (dof_step_number > step_number_) step_number_ = dof_step_number;
39  }
40 
41  for (unsigned int i = 0; i < dofs_.size(); i++) {
42  current_delta_[i] = (endpoint2_[i] - endpoint1_[i]) / step_number_;
43  }
44 
45  current_step_number_ = 0;
46  delta_ = 1.0 / step_number_;
47  value_ = 0.0;
48  }
49 
50  // return current DOF
51  DOFValues get_dofs_values() {
52  DOFValues ret = endpoint1_;
53  for (unsigned int i = 0; i < ret.size(); i++) {
54  ret[i] += current_step_number_ * current_delta_[i];
55  }
56  return ret;
57  }
58 
59  double get_value() const { return value_; }
60 
61 #ifndef SWIG
62  void operator++(int) {
63  current_step_number_++;
64  value_ += delta_;
65  }
66  void operator--(int) {
67  current_step_number_--;
68  value_ -= delta_;
69  }
70 #endif
71 
72  protected:
73  DOFs dofs_; // can be a pointer
74  DOFValues endpoint1_;
75  DOFValues endpoint2_;
76 
77  // step size for each DOF for endpoint1 and endpoint2
78  DOFValues current_delta_;
79 
80  // step number based on current_delta_
81  int step_number_;
82 
83  // counter for step_number_
84  int current_step_number_;
85 
86  // follows curr_step_number_ between 0 and 1
87  double value_;
88 
89  // delta for value
90  double delta_;
91 
92  public:
93  IMP_SHOWABLE_INLINE(DirectionalDOF, {
94  out << "(direction dof from " << endpoint1_ << " to " << endpoint2_
95  << " ; step number " << current_step_number_ << ")";
96  });
97 };
98 
99 IMP_VALUES(DirectionalDOF, DirectionalDOFs);
100 
101 IMPKINEMATICS_END_NAMESPACE
102 
103 #endif /* IMPKINEMATICS_DIRECTIONAL_DO_FS_H */
#define IMP_SHOWABLE_INLINE(Name, how_to_show)
Declare the methods needed by an object that can be printed.
single degree of freedom
IMP::Vector< IMP::Pointer< DOF > > DOFs
Definition: DOF.h:70
#define IMP_VALUES(Name, PluralName)
Define the type for storing sets of values.
Definition: value_macros.h:23