IMP logo
IMP Reference Guide  2.10.0
The Integrative Modeling Platform
RigidBodiesImageFitRestraint.h
Go to the documentation of this file.
1 /**
2  * \file IMP/em2d/RigidBodiesImageFitRestraint.h
3  * \brief Fit rigid bodies to an image.
4  *
5  * Copyright 2007-2018 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 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 Restraint {
44  virtual double unprotected_evaluate(IMP::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  PointerMember<ScoreFunction> score_function_;
54  core::RigidBodies rigid_bodies_;
55  Pointer<Image> image_; // Image to used when scoring
56  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 ValueException if the rigid body is not in the set used
83  to construct the restraint
84  */
85  unsigned int get_number_of_masks(const core::RigidBody &rb) const;
86 };
88 
89 //! Map a rotation to a list of 4 "unique" integers
90 /** Each integer is simply the integer part and the first 2 decimal places
91  of the floating point value from the quaternion. This list of integers
92  can then be used as a key for rotations.
93  */
94 IMPEM2DEXPORT Ints get_unique_index(const algebra::Rotation3D &rot);
95 
96 IMPEM2D_END_NAMESPACE
97 
98 #endif /* IMPEM2D_RIGID_BODIES_IMAGE_FIT_RESTRAINT_H */
Generation of projections from models or density maps Copyright 2007-2018 IMP Inventors. All rights reserved.
Basic types used by IMP.
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
Definition: object_macros.h:25
Various general useful macros for IMP.
IMP images for Electron Microscopy using openCV matrices Copyright 2007-2018 IMP Inventors. All rights reserved.
A smart pointer to a reference counted object.
Definition: Pointer.h:87
Scoring functions for 2D Copyright 2007-2018 IMP Inventors. All rights reserved.
functionality for defining rigid bodies
A smart pointer to a ref-counted Object that is a class member.
Definition: Pointer.h:146
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 lists of object pointers.
Definition: object_macros.h:44
A nullptr-initialized pointer to an IMP Object.
Ints get_unique_index(const algebra::Rotation3D &rot)
Map a rotation to a list of 4 "unique" integers.
Abstract base class for all restraints.
A decorator for a rigid body.
Definition: rigid_bodies.h:82
virtual ModelObjectsTemp do_get_inputs() const =0
#define IMP_OVERRIDE
Cause a compile error if this method does not override a parent method.
Class for adding derivatives from restraints to the model.
2D Electron Microscopy images in IMP
Definition: Image.h:27
A restraint is a term in an IMP ScoringFunction.
Definition: Restraint.h:54