IMP  2.2.0
The Integrative Modeling Platform
RigidBodiesImageFitRestraint.h
Go to the documentation of this file.
1 /**
2  * \file IMP/em2d/RigidBodiesImageFitRestraint.h
3  * \brief Fit kernel::Restraint
4  *
5  * Copyright 2007-2014 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 //! Fit rigid bodies to an image.
43 class IMPEM2DEXPORT RigidBodiesImageFitRestraint : public kernel::Restraint {
44  virtual double unprotected_evaluate(IMP::kernel::DerivativeAccumulator *accum)
45  const IMP_OVERRIDE;
46  virtual IMP::kernel::ModelObjectsTemp do_get_inputs() const IMP_OVERRIDE;
48 
49  protected:
50  // Storage for all the masks of the rigid bodies
51  std::vector<em2d::Images> rigid_bodies_masks_;
52  KeyIndexMaps maps_;
53  base::Pointer<ScoreFunction> score_function_;
54  core::RigidBodies rigid_bodies_;
55  base::Pointer<Image> image_; // Image to used when scoring
56  base::Pointer<Image> projection_;
57  ProjectingParameters params_;
58  bool params_set_;
59 
60  // Return the internal identity index for the rigid body
61  unsigned int get_rigid_body_index(const core::RigidBody &rb) const;
62 
63  public:
64  /*! Initialize the class
65  \param[in] scf Score function used to compute the value of the restraint
66  \param[in] rbs Rigid bodies that are restrained
67  \param[in] img Image used to compute the restraint
68  */
70  Image *img);
71 
72  void set_projecting_parameters(const ProjectingParameters &p);
73 
74  /*! Set the possible rotations that a rigid body can have. A projection of
75  the rigid body in all posible orientations is stored
76  */
77  void set_orientations(const core::RigidBody &rb,
78  const algebra::Rotation3Ds &rots);
79 
80  /*! Return the number of precomputed masks associated with the rigid body
81  Throws an exception if the rigid body is not in the set used to construct
82  the restraint
83  */
84  unsigned int get_number_of_masks(const core::RigidBody &rb) const;
85 };
87 
88 // For a unique 4 ints ( 2 first decimal positions) for a rotation
89 IMPEM2DEXPORT Ints get_unique_index(const algebra::Rotation3D &rot);
90 
91 IMPEM2D_END_NAMESPACE
92 
93 #endif /* IMPEM2D_RIGID_BODIES_IMAGE_FIT_RESTRAINT_H */
Generation of projections from models or density maps Copyright 2007-2014 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-2014 IMP Inventors. All rights reserved.
Scoring functions for 2D Copyright 2007-2014 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:55
#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:30
3D rotation class.
Definition: Rotation3D.h:46
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:27
IMP::base::Vector< Int > Ints
Standard way to pass a bunch of Int values.
Definition: base/types.h:49