IMP  2.3.0
The Integrative Modeling Platform
SampledDensityMap.h
Go to the documentation of this file.
1 /**
2  * \file IMP/em/SampledDensityMap.h
3  * \brief Sampled density map.
4  *
5  * Copyright 2007-2014 IMP Inventors. All rights reserved.
6  *
7  */
8 
9 #ifndef IMPEM_SAMPLED_DENSITY_MAP_H
10 #define IMPEM_SAMPLED_DENSITY_MAP_H
11 
12 #include <IMP/em/em_config.h>
13 #include "exp.h"
14 #include "DensityMap.h"
15 #include "DensityHeader.h"
16 #include "def.h"
17 #include "KernelParameters.h"
18 #include <vector>
19 #include "IMP/base_types.h"
20 #include "IMP/core/XYZR.h"
21 #include "IMP/atom/Mass.h"
22 #include "masking.h"
23 IMPEM_BEGIN_NAMESPACE
24 
25 enum KernelType {
26  GAUSSIAN,
27  BINARIZED_SPHERE,
28  SPHERE
29 };
30 //! Class for sampling a density map from particles
31 class IMPEMEXPORT SampledDensityMap : public DensityMap {
32 
33  public:
34  //! Creates a new density map for sampled map.
35  /** The header of the map is not determined and no data is being allocated
36  */
37  SampledDensityMap(KernelType kt = GAUSSIAN)
38  : DensityMap("SampledDensityMap%1%"), kt_(kt) {}
39 
40  //! The size of the map is determined by the header and the data is allocated.
41  SampledDensityMap(const DensityHeader &header, KernelType kt = GAUSSIAN);
42 
43  //! Generate a sampled density map from the particles.
44  /** \param[in] ps particles with XYZ, radius and weight attributes
45  \param[in] resolution half width the Gaussian
46  \param[in] voxel_size
47  \param[in] sig_cutoff Choose what should be the sigma cutoff for
48  accurate sampling. It is used in two functions;
49  (i) to determine the size of the grid dimensions
50  (ii) to determine the voxels around the coords participating
51  in the sampling procedure.
52  */
53  SampledDensityMap(const kernel::ParticlesTemp &ps, emreal resolution,
54  emreal voxel_size,
56  int sig_cuttoff = 3, KernelType kt = GAUSSIAN);
57 
58  //! Resample beads on an EM grid
59  /**
60  \note The density of a particle p centered at pl at position gl is:
61  \f$\frac{{Z}e^{\frac{{-0.5}({p_l}-{g_l})}{\sigma}}}{\sqrt{{2}{\pi}\sigma}}\f$
62  , such that \f${Z}\f$ is the weight of the particle and \f${\sigma}\f$
63  is defined to be \f${0.425}\f$ times the resolution,
64  to follow the 'full width at half maxima'
65  criterion. For more details please refer to Topf et al, Structure, 2008.
66  */
67  virtual void resample();
68 
69  //! Project particles on the grid by their mass value
70  /**
71  \param ps the particles to project
72  \param[in] x_margin sampling is restricted to [x_margin,nx-x_margin]
73  \param[in] y_margin sampling is restricted to [y_margin,ny-y_margin]
74  \param[in] z_margin sampling is restricted to [z_margin,nz-z_margin]
75  \param[in] shift the positions of all particles are shifted by
76  this value before projection
77  \param[in] mass_key key to obtain particle mass
78  */
79  void project(const kernel::ParticlesTemp &ps, int x_margin, int y_margin,
80  int z_margin,
81  algebra::Vector3D shift = algebra::Vector3D(0., 0., 0.),
82  FloatKey mass_key = atom::Mass::get_mass_key());
83 
84  //! setting particles in case they were not set by the constructor
85  void set_particles(const kernel::ParticlesTemp &ps,
87 
88 #if !defined(DOXYGEN) && !defined(SWIG)
89  KernelParameters *get_kernel_params() { return &kernel_params_; }
90 #endif
91 
92  inline const core::XYZRs &get_xyzr_particles() const { return xyzr_; }
93  // would go away once we have a XYZRW decorator and the next function as well
94  inline const kernel::Particles &get_sampled_particles() const { return ps_; }
95  inline FloatKey get_weight_key() const { return weight_key_; }
96 
97  //! Get minimum density value between voxels that correspond to particles
98  float get_minimum_resampled_value();
99 
100  IMP_REF_COUNTED_DESTRUCTOR(SampledDensityMap);
101 
102  protected:
103  //! Calculate the parameters of the particles bounding box
104  /** \param[in] ps particles with XYZ, radius and weight attributes
105  \return the particles bounding box
106  */
107  IMP::algebra::BoundingBoxD<3> calculate_particles_bounding_box(
108  const kernel::Particles &ps);
109 
110  //! Determine the size of the grid as a function of the particles
111  //! and the resolution.
112  void determine_grid_size(emreal resolution, emreal voxel_size,
113  int sig_cutoff);
114  void set_header(const algebra::Vector3D &lower_bound,
115  const algebra::Vector3D &upper_bound, emreal maxradius,
116  emreal resolution, emreal voxel_size, int sig_offset);
117 
118  protected:
119  void set_neighbor_mask(float radius);
120 
121  protected:
122  //! kernel handling
124  // DistanceMask distance_mask_;
125  kernel::Particles ps_;
126  core::XYZRs xyzr_; // each voxel decorator would contain X,Y,Z,R
127  FloatKey weight_key_;
128  FloatKey x_key_, y_key_, z_key_;
129  KernelType kt_;
130 };
132 
133 IMPEM_END_NAMESPACE
134 
135 #endif /* IMPEM_SAMPLED_DENSITY_MAP_H */
static FloatKey get_mass_key()
A decorator for particles with mass.
Import IMP/kernel/base_types.h in the namespace.
Definitions for EMBED.
Metadata for a density file.
masking tools
Calculates and stores Gaussian kernel parameters.
#define IMP_REF_COUNTED_DESTRUCTOR(Name)
Ref counted objects should have private destructors.
An approximation of the exponential function.
Class for handling density maps.
Class for handling density maps.
Definition: DensityMap.h:94
Class for sampling a density map from particles.
#define IMP_OBJECTS(Name, PluralName)
Define the types for storing sets of objects.
Definition: object_macros.h:52
KernelParameters kernel_params_
kernel handling
VectorD< 3 > Vector3D
Definition: VectorD.h:395
SampledDensityMap(KernelType kt=GAUSSIAN)
Creates a new density map for sampled map.
Decorator for a sphere-like particle.
Key< 0, true > FloatKey
The type used to identify float attributes in the Particles.