IMP  2.3.1
The Integrative Modeling Platform
CoarseCC.h
Go to the documentation of this file.
1 /**
2  * \file IMP/em/CoarseCC.h
3  * \brief Perform coarse fitting between two density objects.
4  *
5  * Copyright 2007-2014 IMP Inventors. All rights reserved.
6  *
7  */
8 
9 #ifndef IMPEM_COARSE_CC_H
10 #define IMPEM_COARSE_CC_H
11 
12 #include <IMP/em/em_config.h>
13 #include "exp.h"
14 #include "DensityMap.h"
15 #include "SampledDensityMap.h"
16 #include "SurfaceShellDensityMap.h"
17 #include "def.h"
18 #include <vector>
19 #include <IMP/core/rigid_bodies.h>
20 #include <IMP/Refiner.h>
21 #include "masking.h"
22 
23 IMPEM_BEGIN_NAMESPACE
24 
25 //! Responsible for performing coarse fitting between two density objects.
26 /** The pixels involved are derived from the positions of N particles.
27  */
28 class IMPEMEXPORT CoarseCC : public IMP::base::Object {
29 
30  public:
31  CoarseCC() : Object("CoarseCC%1%") {}
32  //! Calculates the value of the EM fitting term.
33  /** \note The function returns scalefac*(1-ccc)
34  to support minimization optimization. The ccc value (cross
35  correlation coefficient) is calculate by the
36  cross_correlation_coefficient function.
37  \param[in] data DensityMap class containing the EM map. note:
38  correct RMSD and mean MUST be in the header!
39  \param[in] model_map SampledDensityMap class prepared to contain the
40  simulated EM map for the model.
41  \param[in] scalefactor scale factor to apply to the value of the cross
42  correlation term
43  \param[in] recalc_rms determines whether the RMS of both maps
44  should be recalculated prior to the correlation calculation.
45  False is faster, but potentially inaccurate
46  \param[in] resample if true, the model density map is resampled
47  \param[in] norm_factors if set these precalculated terms are used
48  for normalization
49  \return the value of the cross correlation term: scalefac*(1-ccc)
50  \see cross_correlation_coefficient
51  */
52  static float calc_score(DensityMap *data, SampledDensityMap *model_map,
53  float scalefactor, bool recalc_rms = true,
54  bool resample = true,
55  FloatPair norm_factors = FloatPair(0., 0.));
56 
57 #if !defined(IMP_DOXYGEN) && !defined(SWIG)
58  /**
59  Computes the derivatives of the cross correlation term scalefac*(1-ccc) at
60  each
61  voxel of the map.
62  \param[in] em_map the target density map.
63  \param[in] model_map the density map of the model
64  \param[in] model_ps the particles sampled in model_map
65  \param[in] mass_key the key of the mass attribute of the particles
66  \param[in] scalefac scale factor to apply to the value of the cross
67  correlation term
68  \return a vector of derivatives
69  \note: The function assumes that correct RMS are calculated for the densities
70  */
71  static algebra::Vector3Ds calc_derivatives(const DensityMap *em_map,
72  const DensityMap *model_map,
73  const kernel::Particles &model_ps,
74  const FloatKey &mass_key,
75  KernelParameters *kernel_params,
76  const float &scalefac,
77  const algebra::Vector3Ds &dv);
78 #endif
79 
80  //!Calculates the cross correlation coefficient between two maps
81  /** Cross correlation coefficient between the em density and the density of a
82  model. The function applied is:
83  \f$\frac{\sum_{i=1}^{N}{{td}_i}{{md}_i}-{N}
84  {{mean}_{td}}
85  {{mean}_{md}}}
86  {N\sigma_{{td}}\sigma_{{md}}}\f$, such that \f$N\f$ is the number of
87  voxels, \f${td}\f$ is the target density,
88  \f${tm}\f$ is the model density,
89  \param[in] grid1 The first 3D grid
90  \param[in] grid2 The second 3D grid
91  \param[in] grid2_voxel_data_threshold voxels with value lower
92  than threshold
93  in grid2 are not summed (avoid calculating correlation on
94  voxels below the threshold
95  \param[in] allow_padding determines whether the two maps should be padded
96  to have the same size before the calculation is performed.
97  If set to false and the grids are not of the same size,
98  the function will throw an exception.
99  \param[in] norm_factors if set these precalculated terms are used
100  for normalization
101  \return the cross correlation coefficient value between two density maps
102  \note This is not the local CC function
103  \todo check that the mean is always subtracted from the em-density.
104  The problem is that we divide by nvox*d1_mean*d2_mean, but if we
105  use voxel_data_threshold that does not consist of the entire map
106  this would be wrong. Fix it.
107  */
108  static double cross_correlation_coefficient(const DensityMap *grid1,
109  const DensityMap *grid2,
110  float grid2_voxel_data_threshold,
111  bool allow_padding = false,
112  FloatPair norm_factors =
113  FloatPair(0., 0.));
114 
115  //! Local cross correlation function
116  static float local_cross_correlation_coefficient(const DensityMap *em_map,
117  DensityMap *model_map,
118  float voxel_data_threshold);
119 
121 };
122 
123 IMPEM_END_NAMESPACE
124 
125 #endif /* IMPEM_COARSE_CC_H */
Definitions for EMBED.
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
Definition: object_macros.h:25
std::pair< double, double > FloatPair
A generic pair of floats.
Definition: types.h:27
masking tools
Represent a molecule as shells of distance from the surface.
An approximation of the exponential function.
Responsible for performing coarse fitting between two density objects.
Definition: CoarseCC.h:28
Class for handling density maps.
Class for handling density maps.
Definition: DensityMap.h:94
Class for sampling a density map from particles.
Import IMP/kernel/Refiner.h in the namespace.
Object(std::string name)
Construct an object with the given name.
functionality for defining rigid bodies
Common base class for heavy weight IMP objects.
Definition: Object.h:106
Sampled density map.