IMP  2.4.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-2015 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 mapping between quaternion of
25 //! rotation and their corresponding cached 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;
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  /**
66  \param[in] scf Score function used to compute the value of the restraint
67  \param[in] rbs Rigid bodies that are restrained
68  \param[in] img Image used to compute the restraint
69  */
71  Image *img);
72 
73  void set_projecting_parameters(const ProjectingParameters &p);
74 
75  //! Set the possible rotations that a rigid body can have.
76  /** A projection of the rigid body in all possible orientations is stored
77  */
78  void set_orientations(const core::RigidBody &rb,
79  const algebra::Rotation3Ds &rots);
80 
81  //! Return the number of precomputed masks associated with the rigid body.
82  /** Throws an exception if the rigid body is not in the set used to construct
83  the restraint
84  */
85  unsigned int get_number_of_masks(const core::RigidBody &rb) const;
86 };
88 
89 //! For a unique 4 ints ( 2 first decimal positions) for a rotation
90 IMPEM2DEXPORT Ints get_unique_index(const algebra::Rotation3D &rot);
91 
92 IMPEM2D_END_NAMESPACE
93 
94 #endif /* IMPEM2D_RIGID_BODIES_IMAGE_FIT_RESTRAINT_H */
Generation of projections from models or density maps Copyright 2007-2015 IMP Inventors. All rights reserved.
Import IMP/kernel/base_types.h in the namespace.
Class for adding derivatives from restraints to the model.
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
Definition: object_macros.h:25
A smart pointer to a reference counted object.
Definition: Pointer.h:87
Import IMP/kernel/macros.h in the namespace.
IMP images for Electron Microscopy using openCV matrices Copyright 2007-2015 IMP Inventors. All rights reserved.
Scoring functions for 2D Copyright 2007-2015 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
Simple 3D rotation class.
Parameters needed for the core projection routine.
Definition: project.h:30
3D rotation class.
Definition: Rotation3D.h:46
#define IMP_OBJECTS(Name, PluralName)
Define the types for storing sets of objects.
Definition: object_macros.h:52
A nullptr-initialized pointer to an IMP Object.
virtual ModelObjectsTemp do_get_inputs() const =0
Ints get_unique_index(const algebra::Rotation3D &rot)
For a unique 4 ints ( 2 first decimal positions) for a rotation.
Import IMP/kernel/Restraint.h in the namespace.
A decorator for a rigid body.
Definition: rigid_bodies.h:75
#define IMP_OVERRIDE
Cause a compile error if this method does not override a parent method.
2D Electron Microscopy images in IMP
Definition: Image.h:27