IMP logo
IMP Reference Guide  2.18.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-2022 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/exception.h>
15 #include <IMP/log.h>
16 #include <map>
17 #include <cmath>
18 #include <algorithm>
19 #include <iostream>
20 #include <iomanip>
21 #include <vector>
22 #include <limits>
23 #include <IMP/em/internal/RadiusDependentKernelParameters.h>
24 #include <boost/serialization/access.hpp>
25 #include <boost/serialization/split_member.hpp>
26 
27 IMPEM_BEGIN_NAMESPACE
28 
29 //! Calculates and stores Gaussian kernel parameters
30 class IMPEMEXPORT KernelParameters {
31  public:
32  KernelParameters() { initialized_ = false; }
33 
34  KernelParameters(float resolution) {
35  init(resolution);
36  initialized_ = true;
37  }
38 
40 
41  //! Get sigma as a function of the resolution according to the
42  //! full width at half maximum criterion
43  inline float get_rsig() const { return rsig_; }
44 
45  //! Get squared sigma as a function of the resolution according to the
46  //! full width at half maximum criterion
47  inline float get_rsigsq() const { return rsigsq_; }
48 
49  //! Get the inverse of sigma squared
50  inline float get_inv_rsigsq() const { return inv_rsigsq_; }
51 
52  //! Gets the number of sigma used.
53  /**
54  \note We use 3, which means that 99% of the density is considered
55  */
56  inline float get_timessig() const { return timessig_; }
57 
58  //! Get the non-sigma portion of the Gaussian normalization factor
59  inline float get_sq2pi3() const { return sq2pi3_; }
60 
61  //! Get the Gaussian normalization factor
62  inline float get_rnormfac() const { return rnormfac_; }
63 
64  //! Get the length of the Gaussian (sigma*number_of_sigmas_used)
65  inline float get_rkdist() const { return rkdist_; }
66 
67  //! Get the squared length of the Gaussian (sigma*number_of_sigmas_used)
68  inline float get_rkdistsq() const { return rkdistsq_; }
69 
70  //! Gets the value of lim parameter
71  inline float get_lim() const { return lim_; }
72 
73 #if !defined(SWIG) && !defined(IMP_DOXYGEN)
74  //! Get radius dependent kernel parameters
75  /**
76  \param[in] radius searching for parameters of this radius
77  \param[in] eps tolerance around radius to search for
78  \note cached values are used if available for radius +/- eps
79  */
80  const internal::RadiusDependentKernelParameters& get_params(float radius,
81  float eps = 0.001);
82 #endif
83 
84  IMP_SHOWABLE_INLINE(KernelParameters, out << "rsig: " << rsig_ << std::endl;);
85 
86  protected:
87  float resolution_;
88  float timessig_; // 3.0 is used by default
89  float rsig_, rsigsq_, inv_rsigsq_; // resolution dependent sigma
90  float sq2pi3_, rnormfac_;
91  float rkdist_, rkdistsq_, lim_;
92  bool initialized_;
93  typedef std::map<float, const internal::RadiusDependentKernelParameters *>
94  KernelMap;
95  KernelMap radii2params_;
96 
97  void init(float resolution);
98 
99 #ifndef SWIG
100  friend class boost::serialization::access;
101 
102  template<class Archive> void save(Archive &ar, const unsigned int) const {
103  ar << resolution_;
104  }
105 
106  template<class Archive> void load(Archive &ar, const unsigned int) {
107  float resolution;
108  ar >> resolution;
109  init(resolution);
110  initialized_ = true;
111  }
112 
113  BOOST_SERIALIZATION_SPLIT_MEMBER()
114 #endif
115 
116 };
117 
119 
120 #if !defined(IMP_DOXYGEN) && !defined(SWIG)
121 class IMPEMEXPORT Kernel3D {
122  public:
123  Kernel3D() {}
124  Kernel3D(const Kernel3D& other) {
125  size_ = other.size_;
126  dim_ext_ = other.dim_ext_;
127  data_.reset(new double[size_]);
128  std::copy(other.data_.get(), other.data_.get() + size_, data_.get());
129  }
130  Kernel3D(int size, int ext) {
131  size_ = size;
132  dim_ext_ = ext;
133  data_.reset(new double[size_]);
134  IMP_INTERNAL_CHECK(data_, "Can not allocate vector\n");
135  for (int i = 0; i < size_; i++) data_[i] = 0.;
136  }
137  double* get_data() const { return data_.get(); }
138  int get_size() const { return size_; }
139  int get_extent() const { return dim_ext_; }
140 
141  protected:
142  boost::scoped_array<double> data_;
143  int size_;
144  int dim_ext_;
145 };
146 IMPEMEXPORT
147 Kernel3D create_3d_gaussian(double sigma, double sigma_factor);
148 IMPEMEXPORT
149 Kernel3D create_3d_laplacian();
150 //! Truncate a kernel according to an input sigma
151 IMPEMEXPORT
152 Kernel3D get_truncated(double* data, int extent, double sigmap,
153  double sigma_fac);
154 #endif
155 IMPEM_END_NAMESPACE
156 
157 #endif /* IMPEM_KERNEL_PARAMETERS_H */
Basic types used by IMP.
#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 and stores Gaussian kernel parameters.
Exception definitions and assertions.
A more IMP-like version of the std::vector.
Definition: Vector.h:42
#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:139
#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_rkdistsq() const
Get the squared length of the Gaussian (sigma*number_of_sigmas_used)
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.
float get_timessig() const
Gets the number of sigma used.
Logging and error reporting support.