IMP  2.1.0
The Integrative Modeling Platform
RigidBodiesImageFitRestraint.h
Go to the documentation of this file.
1 /**
2  * \file em2d/RigidBodiesImageFitRestraint.h
3  * \brief Fit kernel::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/base/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 //! Fit rigid bodies to an image.
44 class IMPEM2DEXPORT RigidBodiesImageFitRestraint: public kernel::Restraint {
45  virtual double
46  unprotected_evaluate(IMP::kernel::DerivativeAccumulator *accum)
47  const IMP_OVERRIDE;
48  virtual IMP::kernel::ModelObjectsTemp do_get_inputs() const IMP_OVERRIDE;
50 
51 protected:
52  // Storage for all the masks of the rigid bodies
53  std::vector<em2d::Images> rigid_bodies_masks_;
54  KeyIndexMaps maps_;
55  base::Pointer<ScoreFunction> score_function_;
56  core::RigidBodies rigid_bodies_;
57  base::Pointer<Image> image_; // Image to used when scoring
58  base::Pointer<Image> projection_;
59  ProjectingParameters params_;
60  bool params_set_;
61 
62  // Return the internal identity index for the rigid body
63  unsigned int get_rigid_body_index(const core::RigidBody &rb) const;
64 
65 public:
66 
67  /*! Initialize the class
68  \param[in] scf Score function used to compute the value of the restraint
69  \param[in] rbs Rigid bodies that are restrained
70  \param[in] img Image used to compute the restraint
71  */
73  const core::RigidBodies &rbs,
74  Image *img);
75 
76 
77  void set_projecting_parameters(const ProjectingParameters &p);
78 
79  /*! Set the possible rotations that a rigid body can have. A projection of
80  the rigid body in all posible orientations is stored
81  */
82  void set_orientations(const core::RigidBody &rb,
83  const algebra::Rotation3Ds &rots);
84 
85  /*! Return the number of precomputed masks associated with the rigid body
86  Throws an exception if the rigid body is not in the set used to construct
87  the restraint
88  */
89  unsigned int get_number_of_masks(const core::RigidBody &rb) const;
90 
91 };
93 
94 // For a unique 4 ints ( 2 first decimal positions) for a rotation
95 IMPEM2DEXPORT Ints get_unique_index(const algebra::Rotation3D &rot);
96 
97 IMPEM2D_END_NAMESPACE
98 
99 #endif /* IMPEM2D_RIGID_BODIES_IMAGE_FIT_RESTRAINT_H */
Generation of projections from models or density maps Copyright 2007-2013 IMP Inventors. All rights reserved.
Import IMP/kernel/base_types.h in the namespace.
Class for adding derivatives from restraints to the model.
A nullptr-initialized pointer to an IMP Object.
A smart pointer to a reference counted object.
Definition: base/Pointer.h:87
Import IMP/kernel/macros.h in the namespace.
IMP images for Electron Microscopy using openCV matrices Copyright 2007-2013 IMP Inventors. All rights reserved.
Scoring functions for 2D Copyright 2007-2013 IMP Inventors. All rights reserved.
functionality for defining rigid bodies
A restraint is a term in an IMP ScoringFunction.
Base class for all scoring functions related to em2d.
Definition: scores2D.h:58
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
Simple 3D rotation class.
#define IMP_OBJECTS(Name, PluralName)
Define the types for storing sets of objects.
Parameters needed for the core projection routine.
Definition: project.h:31
3D rotation class.
Definition: Rotation3D.h:45
virtual ModelObjectsTemp do_get_inputs() const =0
Import IMP/kernel/Restraint.h in the namespace.
A decorator for a rigid body.
Definition: rigid_bodies.h:75
2D Electron Microscopy images in IMP
Definition: Image.h:32
IMP::base::Vector< Int > Ints
Standard way to pass a bunch of Int values.
Definition: base/types.h:49