IMP logo
IMP Reference Guide  develop.7482b7c7af, 2026/12/05
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-2022 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"
17#include "IMP/Restraint.h"
18#include "IMP/Pointer.h"
19#include "IMP/macros.h"
20#include "IMP/base_types.h"
21
22IMPEM2D_BEGIN_NAMESPACE
23
24//! Comparison function for the keys of the mapping between quaternion of
25//! rotation and their corresponding cached mask
26class 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
38typedef std::pair<Ints, unsigned int> KeyIndexPair;
39typedef std::map<Ints, unsigned int, IntsOrder> KeyIndexMap;
40typedef std::vector<KeyIndexMap> KeyIndexMaps;
41
42//! Fit rigid bodies to an image.
43class IMPEM2DEXPORT RigidBodiesImageFitRestraint : public Restraint {
44 virtual double unprotected_evaluate(IMP::DerivativeAccumulator *accum)
45 const override;
46 virtual IMP::ModelObjectsTemp do_get_inputs() const 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_;
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 */
70 RigidBodiesImageFitRestraint(ScoreFunction *scf, const core::RigidBodies &rbs,
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 */
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 */
94IMPEM2DEXPORT Ints get_unique_index(const algebra::Rotation3D &rot);
95
96IMPEM2D_END_NAMESPACE
97
98#endif /* IMPEM2D_RIGID_BODIES_IMAGE_FIT_RESTRAINT_H */
IMP images for Electron Microscopy Copyright 2007-2026 IMP Inventors. All rights reserved.
A nullptr-initialized pointer to an IMP Object.
Abstract base class for all restraints.
Simple 3D rotation class.
Basic types used by IMP.
Class for adding derivatives from restraints to the model.
Restraint(Model *m, std::string name)
Create a restraint and register it with the model.
3D rotation class.
Definition Rotation3D.h:52
A decorator for a rigid body.
2D Electron Microscopy images in IMP
Definition Image.h:27
Parameters needed for the core projection routine.
Definition project.h:31
void set_orientations(const core::RigidBody &rb, const algebra::Rotation3Ds &rots)
Set the possible rotations that a rigid body can have.
unsigned int get_number_of_masks(const core::RigidBody &rb) const
Return the number of precomputed masks associated with the rigid body.
RigidBodiesImageFitRestraint(ScoreFunction *scf, const core::RigidBodies &rbs, Image *img)
Initialize the class.
Base class for all scoring functions related to em2d.
Definition scores2D.h:55
Various general useful macros for IMP.
IMP::Vector< Rotation3D > Rotation3Ds
Definition Rotation3D.h:313
Ints get_unique_index(const algebra::Rotation3D &rot)
Map a rotation to a list of 4 "unique" integers.
IMP::Vector< IMP::Pointer< RigidBodiesImageFitRestraint > > RigidBodiesImageFitRestraints
IMP::Vector< Int > Ints
Standard way to pass a bunch of Int values.
Definition types.h:48
IMP::Vector< IMP::WeakPointer< ModelObject > > ModelObjectsTemp
Definition base_types.h:122
#define IMP_OBJECTS(Name, PluralName)
Define the types for storing lists of object pointers.
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
Generation of projections from models or density maps Copyright 2007-2026 IMP Inventors....
functionality for defining rigid bodies
Scoring functions for 2D Copyright 2007-2026 IMP Inventors. All rights reserved.
A smart pointer to a ref-counted Object that is a class member.
Definition Pointer.h:144
A smart pointer to a reference counted object.
Definition Pointer.h:88