IMP  2.2.0
The Integrative Modeling Platform
DOFsSampler.h
Go to the documentation of this file.
1 /**
2  * \file IMP/kinematics/DOFsSampler.h \brief
3  *
4  * Copyright 2007-2014 Sali Lab. All rights reserved.
5  *
6  */
7 
8 #ifndef IMPKINEMATICS_DO_FS_SAMPLER_H
9 #define IMPKINEMATICS_DO_FS_SAMPLER_H
10 
11 #include "kinematics_config.h"
12 #include "DOFValues.h"
13 
14 IMPKINEMATICS_BEGIN_NAMESPACE
15 
16 /**
17  a base class for sampling certain combinations of degrees of freedom
18  */
21 
22  public:
23  /** Constructs the dofs sampler over specified dofs
24  */
26  : IMP::base::Object("IMP_KINEMATICS_DOFSSAMPLER"),
27  dofs_(dofs),
28  last_sample_(DOFValues(dofs)) {}
29 
30  /**
31  @return a sample on the dofs over which this class samples
32  */
33  DOFValues get_sample() const {
34  last_sample_ = do_get_sample();
35  return last_sample_;
36  }
37 
38  // TODO: should it be a class function? it is not strictly related to the
39  // class
40  /**
41  apply set of dof values in values over objects associated with
42  this DOFsSampler (e.g., joints)
43  */
44  virtual void apply(const DOFValues& values) = 0;
45 
46  /**
47  calls apply(), using values from the last sample returned by
48  get_sample() (or values of initial dofs provided to constructor,
49  if no sample was taken yet)
50  */
51  void apply_last_sample() { apply(last_sample_); }
52 
53  /**
54  make a new sample of the dofs over which this class samples,
55  and apply them to objects associated with this sampler (e.g.
56  joints)
57  */
58  void sample_and_apply() { apply(get_sample()); }
59 
60  /** Returns the dofs over which this sampler works
61  */
62  DOFs const& get_dofs() const { return dofs_; }
63 
64  /** Returns the i'th dof over which this sampler works
65  */
66  DOF const* get_dof(unsigned int i) const {
67  IMP_USAGE_CHECK(i < dofs_.size(),
68  "Accessing out-of-range dof in DOFsSampler");
69  return dofs_[i];
70  }
71 
72  unsigned int get_number_of_dofs() const { return dofs_.size(); }
73 
74  protected:
75  virtual DOFValues do_get_sample() const = 0;
76 
77  private:
78  //! DOFs over which to sample
79  DOFs dofs_;
80 
81  //! It is assumed that get_sample() implementations set this to its return
82  //! value
83  mutable DOFValues last_sample_;
84 };
85 
87 
88 IMPKINEMATICS_END_NAMESPACE
89 
90 #endif /* IMPKINEMATICS_DO_FS_SAMPLER_H */
a simple class for storage of DOF values.
#define IMP_USAGE_CHECK(expr, message)
A runtime test for incorrect usage of a class or method.
DOF const * get_dof(unsigned int i) const
Definition: DOFsSampler.h:66
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
Common base class for heavy weight IMP objects.
Definition: base/Object.h:106
#define IMP_OBJECTS(Name, PluralName)
Define the types for storing sets of objects.
DOFValues get_sample() const
Definition: DOFsSampler.h:33
DOFs const & get_dofs() const
Definition: DOFsSampler.h:62
IMP::base::Vector< IMP::base::Pointer< DOF > > DOFs
Definition: DOF.h:70