IMP  2.4.0
The Integrative Modeling Platform
KernelParameters.h
Go to the documentation of this file.
1 /**
2  * \file IMP/em/KernelParameters.h
3  * \brief Calculates and stores Gaussian kernel parameters.
4  *
5  * Copyright 2007-2015 IMP Inventors. All rights reserved.
6  *
7  */
8 
9 #ifndef IMPEM_KERNEL_PARAMETERS_H
10 #define IMPEM_KERNEL_PARAMETERS_H
11 #include "def.h"
12 #include <IMP/base_types.h>
13 #include <boost/scoped_array.hpp>
14 #include <IMP/base/exception.h>
15 #include <IMP/base/log.h>
16 #include <map>
17 #include <cmath>
18 #include <algorithm>
19 #include <iostream>
20 #include <iomanip>
21 #include <vector>
22 #include <limits>
23 
24 IMPEM_BEGIN_NAMESPACE
25 
26 //! Calculates kernel parameters as a function of a specific radius.
28  public:
29  RadiusDependentKernelParameters(float radii, float rsigsq, float timessig,
30  float sq2pi3, float inv_rsigsq,
31  float rnormfac, float rkdist);
32  //! Show
33  void show(std::ostream& s = std::cout) const;
34  //! Gets the value of the volume sigma
35  inline float get_vsig() const { return vsig_; }
36  //! Gets the value of volume sigma squared
37  inline float get_vsigsq() const { return vsigsq_; }
38  //! Gets the inverse sigma squared
39  inline float get_inv_sigsq() const { return inv_sigsq_; }
40  //! Gets the sigma value
41  inline float get_sig() const { return sig_; }
42  //! Gets the value of kdist parameter
43  inline float get_kdist() const { return kdist_; }
44  //! Gets the value of normfac parameter
45  inline float get_normfac() const { return normfac_; }
47  vsig_ = std::numeric_limits<float>::quiet_NaN();
48  vsigsq_ = std::numeric_limits<float>::quiet_NaN();
49  inv_sigsq_ = std::numeric_limits<float>::quiet_NaN();
50  sig_ = std::numeric_limits<float>::quiet_NaN();
51  kdist_ = std::numeric_limits<float>::quiet_NaN();
52  normfac_ = std::numeric_limits<float>::quiet_NaN();
53  }
54 
55  protected:
56  //! vsig
57  float vsig_;
58  //! square of vsig
59  float vsigsq_;
60  //! the inverse of sigma square
61  float inv_sigsq_;
62  //! the sigma
63  float sig_;
64  //! the kernel distance (= elements for summation)
65  float kdist_;
66  //! normalization factor
67  float normfac_;
68 };
69 
72 
73 //! Calculates and stores Gaussian kernel parameters as a function
74 //! of a specific radius.
75 class IMPEMEXPORT KernelParameters {
76  public:
77  KernelParameters() { initialized_ = false; }
78 
79  KernelParameters(float resolution) {
80  init(resolution);
81  initialized_ = true;
82  }
83 
85 
86  //! Sets the parameters that depend on the radius of a given particle.
87  /** The other variables of the parameters
88  (rsigsq,timessig,sq2pi3,inv_rsigsq,rnormfac,rkdist) must have been set.
89  \param[in] radius the radius
90  \return the radius based parameters
91  */
92  const RadiusDependentKernelParameters& set_params(float radius);
93 
94  //! Finds the precomputed parameters given a particle radius.
95  /**
96  \param[in] radius searching for parameters of this radius
97  \param[in] eps used for numerical stability
98  \note The parameters are indexes by the radius. To maintain
99  numerical stability, look for a radius within +-eps from the
100  queried radius.
101  \note if parameters for this radius were not found, a warning is printed
102  and the parameters are calculated using set_params().
103  */
104  const RadiusDependentKernelParameters& get_params(float radius,
105  float eps = 0.001);
106 
107  //! Get sigma as a function of the resolution according to the
108  //! full width at half maximum criterion
109  inline float get_rsig() const { return rsig_; }
110  //! Get squared sigma as a function of the resolution according to the
111  //! full width at half maximum criterion
112  inline float get_rsigsq() const { return rsigsq_; }
113  //! Get the inverse of sigma squared
114  inline float get_inv_rsigsq() const { return inv_rsigsq_; }
115  //! Gets the number of sigma used.
116  /**
117  \note We use 3, which means that 99% of the density is considered
118  */
119  inline float get_timessig() const { return timessig_; }
120  //! Get the non-sigma portion of the Gaussian normalization factor
121  inline float get_sq2pi3() const { return sq2pi3_; }
122  //! Get the Gaussian normalization factor
123  inline float get_rnormfac() const { return rnormfac_; }
124  //! Get the length of the Gaussian (sigma*number_of_sigmas_used)
125  inline float get_rkdist() const { return rkdist_; }
126  //! Gets the value of lim parameter
127  inline float get_lim() const { return lim_; }
128 
129  IMP_SHOWABLE_INLINE(KernelParameters, out << "rsig: " << rsig_ << std::endl;);
130 
131  protected:
132  float rsig_, rsigsq_, timessig_, sq2pi3_, inv_rsigsq_, rnormfac_, rkdist_,
133  lim_;
134  bool initialized_;
135  std::map<float, const RadiusDependentKernelParameters*> radii2params_;
136  void init(float resolution);
137 };
138 
140 
141 #if !defined(IMP_DOXYGEN) && !defined(SWIG)
142 class IMPEMEXPORT Kernel3D {
143  public:
144  Kernel3D() {}
145  Kernel3D(const Kernel3D& other) {
146  size_ = other.size_;
147  dim_ext_ = other.dim_ext_;
148  data_.reset(new double[size_]);
149  std::copy(other.data_.get(), other.data_.get() + size_, data_.get());
150  }
151  Kernel3D(int size, int ext) {
152  size_ = size;
153  dim_ext_ = ext;
154  data_.reset(new double[size_]);
155  IMP_INTERNAL_CHECK(data_, "Can not allocate vector\n");
156  for (int i = 0; i < size_; i++) data_[i] = 0.;
157  }
158  double* get_data() const { return data_.get(); }
159  int get_size() const { return size_; }
160  int get_extent() const { return dim_ext_; }
161 
162  protected:
163  boost::scoped_array<double> data_;
164  int size_;
165  int dim_ext_;
166 };
167 IMPEMEXPORT
168 Kernel3D create_3d_gaussian(double sigma, double sigma_factor);
169 IMPEMEXPORT
170 Kernel3D create_3d_laplacian();
171 //! Truncate a kernel according to an input sigma
172 IMPEMEXPORT
173 Kernel3D get_truncated(double* data, int extent, double sigmap,
174  double sigma_fac);
175 #endif
176 IMPEM_END_NAMESPACE
177 
178 #endif /* IMPEM_KERNEL_PARAMETERS_H */
float get_sig() const
Gets the sigma value.
Import IMP/kernel/base_types.h in the namespace.
#define IMP_SHOWABLE_INLINE(Name, how_to_show)
Declare the methods needed by an object that can be printed.
float get_rnormfac() const
Get the Gaussian normalization factor.
Definitions for EMBED.
Calculates kernel parameters as a function of a specific radius.
Exception definitions and assertions.
float get_inv_sigsq() const
Gets the inverse sigma squared.
#define IMP_INTERNAL_CHECK(expr, message)
An assertion to check for internal errors in IMP. An IMP::ErrorException will be thrown.
Definition: check_macros.h:141
float kdist_
the kernel distance (= elements for summation)
#define IMP_VALUES(Name, PluralName)
Define the type for storing sets of values.
Definition: value_macros.h:23
float get_rkdist() const
Get the length of the Gaussian (sigma*number_of_sigmas_used)
float get_lim() const
Gets the value of lim parameter.
float get_kdist() const
Gets the value of kdist parameter.
float inv_sigsq_
the inverse of sigma square
float get_vsig() const
Gets the value of the volume sigma.
float get_sq2pi3() const
Get the non-sigma portion of the Gaussian normalization factor.
float get_inv_rsigsq() const
Get the inverse of sigma squared.
void show(Hierarchy h, std::ostream &out=std::cout)
Print out a molecular hierarchy.
float get_normfac() const
Gets the value of normfac parameter.
float get_timessig() const
Gets the number of sigma used.
Logging and error reporting support.
float get_vsigsq() const
Gets the value of volume sigma squared.