IMP  2.0.1
The Integrative Modeling Platform
RigidBodiesImageFitRestraint.h
Go to the documentation of this file.
1 /**
2  * \file RigidBodiesImageFitRestraint.h
3  * \brief Fit Restraint
4  *
5  * Copyright 2007-2013 IMP Inventors. All rights reserved.
6  *
7  */
8 
9 #ifndef IMPEM2D_RIGID_BODIES_IMAGE_FIT_RESTRAINT_H
10 #define IMPEM2D_RIGID_BODIES_IMAGE_FIT_RESTRAINT_H
11 
12 #include "IMP/em2d/project.h"
13 #include "IMP/em2d/scores2D.h"
14 #include "IMP/em2d/Image.h"
15 #include "IMP/core/rigid_bodies.h"
16 #include "IMP/algebra/Rotation3D.h"
17 #include "IMP/Restraint.h"
18 #include "IMP/Pointer.h"
19 #include "IMP/macros.h"
20 #include "IMP/base_types.h"
21 
22 IMPEM2D_BEGIN_NAMESPACE
23 
24 // Comparison function for the keys of the maping between quaternion of
25 // rotation and their corresponding chached mask
26 class IntsOrder {
27 public:
28  // The vector with lower values goes first
29  bool operator()(const Ints &a, const Ints &b) const {
30  for (unsigned int i=0; i < a.size(); ++i) {
31  if(a[i] < b[i]) return true;
32  if(a[i] > b[i]) return false;
33  }
34  return false;
35  }
36 };
37 
38 typedef std::pair< Ints, unsigned int > KeyIndexPair;
39 typedef std::map< Ints, unsigned int, IntsOrder> KeyIndexMap;
40 typedef std::vector< KeyIndexMap > KeyIndexMaps;
41 
42 
43 
44 class IMPEM2DEXPORT RigidBodiesImageFitRestraint: public Restraint {
45  IMP_RESTRAINT(RigidBodiesImageFitRestraint);
46 
47 protected:
48  // Storage for all the masks of the rigid bodies
49  std::vector<em2d::Images> rigid_bodies_masks_;
50  KeyIndexMaps maps_;
51  Pointer<ScoreFunction> score_function_;
52  core::RigidBodies rigid_bodies_;
53  Pointer<Image> image_; // Image to used when scoring
54  Pointer<Image> projection_;
55  ProjectingParameters params_;
56  bool params_set_;
57 
58  // Return the internal identity index for the rigid body
59  unsigned int get_rigid_body_index(const core::RigidBody &rb) const;
60 
61 public:
62 
63  /*! Initialize the class
64  \param[in] scf Score function used to compute the value of the restraint
65  \param[in] Rbs Rigid bodies that are restrained
66  \param[in] img Image used to compute the restraint
67  */
68  RigidBodiesImageFitRestraint(ScoreFunction *scf,
69  const core::RigidBodies &rbs,
70  Image *img);
71 
72 
73  void set_projecting_parameters(const ProjectingParameters &p);
74 
75  /*! Set the possible rotations that a rigid body can have. A projection of
76  the rigid body in all posible orientations is stored
77  \param[in]
78  */
79  void set_orientations(const core::RigidBody &rb,
80  const algebra::Rotation3Ds &rots);
81 
82  /*! Return the number of precomputed masks associated with the rigid body
83  Throws an exception if the rigid body is not in the set used to construct
84  the restraint
85  */
86  unsigned int get_number_of_masks(const core::RigidBody &rb) const;
87 
88 };
89 IMP_OBJECTS(RigidBodiesImageFitRestraint,RigidBodiesImageFitRestraints);
90 
91 // For a unique 4 ints ( 2 first decimal positions) for a rotation
92 IMPEM2DEXPORT Ints get_unique_index(const algebra::Rotation3D &rot);
93 
94 IMPEM2D_END_NAMESPACE
95 
96 #endif /* IMPEM2D_RIGID_BODIES_IMAGE_FIT_RESTRAINT_H */