IMP logo
IMP Reference Guide  2.12.0
The Integrative Modeling Platform
ProjectionParameters.h
Go to the documentation of this file.
1 /**
2  * \file IMP/em2d/ProjectionParameters.h
3  * \brief Decorator for projection parameters
4  * Copyright 2007-2019 IMP Inventors. All rights reserved.
5 */
6 
7 #ifndef IMPEM2D_PROJECTION_PARAMETERS_H
8 #define IMPEM2D_PROJECTION_PARAMETERS_H
9 
10 #include "IMP/em2d/em2d_config.h"
11 #include "IMP/algebra/Vector3D.h"
12 #include "IMP/algebra/Vector2D.h"
13 #include "IMP/algebra/Rotation3D.h"
14 #include "IMP/Decorator.h"
15 #include "IMP/decorator_macros.h"
16 #include "IMP/ScoreState.h"
17 
18 IMPEM2D_BEGIN_NAMESPACE
19 
20 //! Decorator for particles representing the parameters
21 //! Rotation and translation. In this cases, the translation is the translation
22 //! to apply to the model in 3D, in order to perform the registration
23 class IMPEM2DEXPORT ProjectionParameters : public Decorator {
24  static void do_setup_particle(Model *m, ParticleIndex pi);
25 
26  public:
29 
31 
32  //! Keys of the decorator
33  // FloatKeys get_keys();
34  static const FloatKeys &get_keys();
35 
36  //! ranges for the keys. Only adjust the translations, the rotations are
37  //! self adjusted
38  void set_proper_ranges_for_keys(
39  Model *m, const algebra::Vector3D &min_translation_values,
40  const algebra::Vector3D &max_translation_values);
41 
42  //! Return true if the particle is a set of projection parameters
43  static bool get_is_setup(Model *m, ParticleIndex pi);
44 
45  //! Get whether the parameters are optimized
46  /** \return true only if all of them are optimized.
47  */
48  bool get_parameters_optimized() const {
49  for (int i = 0; i < 6; ++i) {
50  if (get_particle()->get_is_optimized(get_keys()[i]) == false) {
51  return false;
52  }
53  }
54  return true;
55  }
56 
57  algebra::Vector3D get_translation() const {
58  return algebra::Vector3D(get_translation_x(), get_translation_y(), 0.0);
59  }
60 
61  void set_translation(const algebra::Vector3D &v) {
62  set_translation_x(v[0]);
63  set_translation_y(v[1]);
64  }
65 
66  algebra::Rotation3D get_rotation() const {
67  algebra::Vector4D v(get_quaternion_1(), get_quaternion_2(),
68  get_quaternion_3(), get_quaternion_4());
69  // normalize the vector. Given that the numbers generated with
70  // simplex are not necessarily a unit vector.
71  algebra::Vector4D unit = v.get_unit_vector();
72  return algebra::Rotation3D(unit[0], unit[1], unit[2], unit[3]);
73  }
74 
75  void set_rotation(const algebra::Rotation3D &R) {
76  set_quaternion_1(R.get_quaternion()[0]);
77  set_quaternion_2(R.get_quaternion()[1]);
78  set_quaternion_3(R.get_quaternion()[2]);
79  set_quaternion_4(R.get_quaternion()[3]);
80  }
81 
82  //! Set whether the parameters are optimized
83  inline void set_parameters_optimized(bool tf) const {
84  for (int i = 0; i < 6; ++i) {
85  get_particle()->set_is_optimized(get_keys()[i], tf);
86  }
87  }
88 
89  //! Get and set functions for the parameters
90  IMP_DECORATOR_GET_SET(quaternion_1, get_keys()[0], Float, double);
91  IMP_DECORATOR_GET_SET(quaternion_2, get_keys()[1], Float, double);
92  IMP_DECORATOR_GET_SET(quaternion_3, get_keys()[2], Float, double);
93  IMP_DECORATOR_GET_SET(quaternion_4, get_keys()[3], Float, double);
94  IMP_DECORATOR_GET_SET(translation_x, get_keys()[4], Float, double);
95  IMP_DECORATOR_GET_SET(translation_y, get_keys()[5], Float, double);
96 
97  private:
98  algebra::Rotation3D rotation_;
99  algebra::Vector3D translation_;
100 };
101 
103  Particles);
104 
105 //! Score state to give information about the values of a ProjectionParameters
106 //! Decorator
107 class IMPEM2DEXPORT ProjectionParametersScoreState : public ScoreState {
108  public:
110  : ScoreState(p->get_model(), "ProjectionParametersScoreState%1%") {
111  proj_params_ = p;
112  }
113  virtual void do_before_evaluate() IMP_OVERRIDE;
114  virtual void do_after_evaluate(DerivativeAccumulator *da) IMP_OVERRIDE;
118 
119  private:
120  // Particle to store the projection params
121  Pointer<Particle> proj_params_;
122 };
123 
124 IMPEM2D_END_NAMESPACE
125 
126 #endif /* IMPEM2D_PROJECTION_PARAMETERS_H */
The base class for decorators.
#define IMP_DECORATOR_GET_SET(name, AttributeKey, Type, ReturnType)
Define methods for getting and setting a particular simple field.
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
Definition: object_macros.h:25
Simple 2D vector class.
void set_parameters_optimized(bool tf) const
Set whether the parameters are optimized.
VectorD< 4 > Vector4D
Definition: VectorD.h:425
A smart pointer to a reference counted object.
Definition: Pointer.h:87
Class for storing model, its restraints, constraints, and particles.
Definition: Model.h:72
ScoreStates maintain invariants in the Model.
Definition: ScoreState.h:53
Various general useful macros for IMP.
#define IMP_DECORATOR_SETUP_0(Name)
Shared score state.
Simple 3D rotation class.
Particle * get_particle() const
Returns the particle decorated by this decorator.
Definition: Decorator.h:171
Interface to specialized Particle types (e.g. atoms)
Definition: Decorator.h:118
3D rotation class.
Definition: Rotation3D.h:51
virtual ModelObjectsTemp do_get_outputs() const =0
#define IMP_DECORATOR_METHODS(Name, Parent)
VectorD< 3 > Vector3D
Definition: VectorD.h:421
double Float
Basic floating-point value (could be float, double...)
Definition: types.h:20
Simple 3D vector class.
Class to handle individual particles of a Model object.
Definition: Particle.h:41
bool get_parameters_optimized() const
Get whether the parameters are optimized.
#define IMP_DECORATORS(Name, PluralName, Parent)
Define the types for storing sets of decorators.
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.