IMP logo
IMP Reference Guide  2.5.0
The Integrative Modeling Platform
Gaussian.h
Go to the documentation of this file.
1 /**
2  * \file IMP/core/Gaussian.h
3  * \brief Decorator to hold Gaussian3D
4  *
5  * Copyright 2007-2015 IMP Inventors. All rights reserved.
6  *
7  */
8 
9 #ifndef IMPCORE_GAUSSIAN_H
10 #define IMPCORE_GAUSSIAN_H
11 
12 #include <IMP/Object.h>
13 #include <IMP/core/core_config.h>
14 #include <IMP/algebra/Gaussian3D.h>
15 #include <IMP/Particle.h>
16 #include <IMP/Model.h>
17 #include <IMP/Decorator.h>
18 #include <IMP/decorator_macros.h>
19 #include <IMP/exception.h>
20 #include <IMP/core/rigid_bodies.h>
21 #include "internal/rigid_bodies.h"
22 #include <IMP/algebra/eigen3/Eigen/Dense>
23 
24 IMPCORE_BEGIN_NAMESPACE
25 
26 #if !defined(SWIG) && !defined(IMP_DOXYGEN)
27 
28 /** little class to store an Eigen::Matrix3d */
29 class IMPCOREEXPORT Matrix3D : public IMP::Object{
30  IMP_Eigen::Matrix3d mat_;
31  public:
32  Matrix3D(IMP_Eigen::Matrix3d mat,
33  std::string name="Matrix3DDensityMap%1%"):Object(name),mat_(mat){ }
34  IMP_Eigen::Matrix3d get_mat() const {return mat_;}
35 };
36 
37 #endif
38 
39 /** A decorator for a particle storing a Gaussian. */
40 class IMPCOREEXPORT Gaussian : public RigidBody {
41  // define variance and covariance keys
42  static void do_setup_particle(Model *m, ParticleIndex pi);
43  static void do_setup_particle(Model *m, ParticleIndex pi,
44  const algebra::Gaussian3D &g);
45 
46  public:
50 
51  static ObjectKey get_local_covariance_key();
52  static ObjectKey get_global_covariance_key();
53  static bool get_is_setup(Model *m, ParticleIndex pi) {
54  return m->get_has_attribute(get_local_covariance_key(), pi);
55  }
56 
57 
58  //! retrieve local covariance (as diagonal matrix)
59  IMP_Eigen::Matrix3d get_local_covariance() const {
60  /* Kind of evil, but dynamic_cast fails randomly here
61  on our RHEL 5 systems */
62  Matrix3D* local
63  = (Matrix3D*)get_model()->get_attribute(get_local_covariance_key(),
65  return local->get_mat();
66  }
67 
68  //! retrieve local variances as Vector3D
70  return algebra::Vector3D(get_local_covariance().diagonal()[0],
71  get_local_covariance().diagonal()[1],
72  get_local_covariance().diagonal()[2]);
73  }
74 
75  //! retrieve global covariance
76  IMP_Eigen::Matrix3d get_global_covariance() {
77  ObjectKey k = get_global_covariance_key();
79  if (!get_model()->get_has_attribute(k, pi)) {
80  update_global_covariance();
81  }
82  Matrix3D* global = (Matrix3D*)get_model()->get_attribute(k, pi);
83  return global->get_mat();
84  };
85 
86  //! create Gaussian3D from these attributes
88  return algebra::Gaussian3D(get_reference_frame(),get_variances());
89 }
90 
91  //! set the local-frame covariance.
92  void set_local_covariance(const IMP_Eigen::Vector3d covar) {
93  IMP_NEW(Matrix3D,local,(covar.asDiagonal()));
94  get_model()->set_attribute(get_local_covariance_key(),
96  local);
97  local->set_was_used(true);
98  // Force recalculation of global covariance on next access
100  }
101 
102  //! equivalent to set_local_covariance, used for backwards compatibility
104  set_local_covariance(IMP_Eigen::Vector3d(v.get_data()));
105  }
106 
107  //! set the global-frame covariance. does NOT update local frame!
108  void set_global_covariance(IMP_Eigen::Matrix3d covar){
109  IMP_NEW(Matrix3D,global,(covar));
110  ObjectKey k = get_global_covariance_key();
112  if (!get_model()->get_has_attribute(k, pi)) {
113  get_model()->add_cache_attribute(k, pi, global);
114  } else {
115  get_model()->set_attribute(k, pi, global);
116  }
117  global->set_was_used(true);
118  }
119 
120  //! update the global covariance
121  void update_global_covariance();
122 
123 
124  ////! Evaluate the Gaussian at a point?
125  //Float get_probability_at_point(const algebra::Vector3D &point) const;
126 };
127 IMP_DECORATORS(Gaussian, Gaussians, Particles);
128 
129 IMPCORE_END_NAMESPACE
130 
131 #endif /* IMPCORE_GAUSSIAN_H */
The base class for decorators.
void add_cache_attribute(TypeKey attribute_key, ParticleIndex particle, Type value)
ParticleIndex get_particle_index() const
Returns the particle index decorated by this decorator.
Definition: Decorator.h:186
void set_global_covariance(IMP_Eigen::Matrix3d covar)
set the global-frame covariance. does NOT update local frame!
Definition: Gaussian.h:108
#define IMP_DECORATOR_SETUP_1(Name, FirstArgumentType, first_argument_name)
Model * get_model() const
Returns the Model containing the particle.
Definition: Decorator.h:189
Storage of a model, its restraints, constraints and particles.
Exception definitions and assertions.
#define IMP_NEW(Typename, varname, args)
Declare a ref counted pointer to a new object.
Definition: object_macros.h:62
void clear_particle_caches(ParticleIndex pi)
Class for storing model, its restraints, constraints, and particles.
Definition: Model.h:72
A Gaussian distribution in 3D.
Definition: Gaussian3D.h:24
void set_local_covariance(const IMP_Eigen::Vector3d covar)
set the local-frame covariance.
Definition: Gaussian.h:92
IMP_Eigen::Matrix3d get_local_covariance() const
retrieve local covariance (as diagonal matrix)
Definition: Gaussian.h:59
Common base class for heavy weight IMP objects.
Definition: Object.h:106
functionality for defining rigid bodies
Various general useful macros for IMP.
void set_attribute(TypeKey attribute_key, ParticleIndex particle, Type value)
#define IMP_DECORATOR_SETUP_0(Name)
Classes to handle individual model particles. (Note that implementation of inline functions is in int...
A shared base class to help in debugging and things.
#define IMP_DECORATOR_METHODS(Name, Parent)
VectorD< 3 > Vector3D
Definition: VectorD.h:395
IMP_Eigen::Matrix3d get_global_covariance()
retrieve global covariance
Definition: Gaussian.h:76
#define IMP_DECORATORS(Name, PluralName, Parent)
Define the types for storing sets of decorators.
Gaussian shape.
algebra::Gaussian3D get_gaussian() const
create Gaussian3D from these attributes
Definition: Gaussian.h:87
A decorator for a rigid body.
Definition: rigid_bodies.h:75
void set_variances(const algebra::Vector3D v)
equivalent to set_local_covariance, used for backwards compatibility
Definition: Gaussian.h:103
Type get_attribute(TypeKey attribute_key, ParticleIndex particle)
algebra::Vector3D get_variances() const
retrieve local variances as Vector3D
Definition: Gaussian.h:69
IMP::algebra::ReferenceFrame3D get_reference_frame() const
Get the reference frame for the local coordinates.
Definition: rigid_bodies.h:182