IMP logo
IMP Reference Guide  2.5.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-2015 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 voxel size in angstroms
47  \param[in] mass_key key to use to weight particles
48  \param[in] sig_cutoff Choose what should be the sigma cutoff for
49  accurate sampling. It is used in two functions;
50  (i) to determine the size of the grid dimensions
51  (ii) to determine the voxels around the coords participating
52  in the sampling procedure.
53  \param[in] kt Type of kernel to use.
54  */
55  SampledDensityMap(const ParticlesTemp &ps, emreal resolution,
56  emreal voxel_size,
58  int sig_cutoff = 3, KernelType kt = GAUSSIAN);
59 
60  //! Resample beads on an EM grid
61  /**
62  \note The density of a particle p centered at pl at position gl is:
63  \f$\frac{{Z}e^{\frac{{-0.5}({p_l}-{g_l})}{\sigma}}}{\sqrt{{2}{\pi}\sigma}}\f$
64  , such that \f${Z}\f$ is the weight of the particle and \f${\sigma}\f$
65  is defined to be \f${0.425}\f$ times the resolution,
66  to follow the 'full width at half maxima'
67  criterion. For more details please refer to Topf et al, Structure, 2008.
68  */
69  virtual void resample();
70 
71  //! Project particles on the grid by their mass value
72  /**
73  \param ps the particles to project
74  \param[in] x_margin sampling is restricted to [x_margin,nx-x_margin]
75  \param[in] y_margin sampling is restricted to [y_margin,ny-y_margin]
76  \param[in] z_margin sampling is restricted to [z_margin,nz-z_margin]
77  \param[in] shift the positions of all particles are shifted by
78  this value before projection
79  \param[in] mass_key key to obtain particle mass
80  */
81  void project(const ParticlesTemp &ps, int x_margin, int y_margin,
82  int z_margin,
83  algebra::Vector3D shift = algebra::Vector3D(0., 0., 0.),
84  FloatKey mass_key = atom::Mass::get_mass_key());
85 
86  //! setting particles in case they were not set by the constructor
87  void set_particles(const ParticlesTemp &ps,
89 
90 #if !defined(DOXYGEN) && !defined(SWIG)
91  KernelParameters *get_kernel_params() { return &kernel_params_; }
92 #endif
93 
94  inline const core::XYZRs &get_xyzr_particles() const { return xyzr_; }
95  // would go away once we have a XYZRW decorator and the next function as well
96  inline const Particles &get_sampled_particles() const { return ps_; }
97  inline FloatKey get_weight_key() const { return weight_key_; }
98 
99  //! Get minimum density value between voxels that correspond to particles
100  float get_minimum_resampled_value();
101 
102  IMP_REF_COUNTED_DESTRUCTOR(SampledDensityMap);
103 
104  protected:
105  //! Calculate the parameters of the particles bounding box
106  /** \param[in] ps particles with XYZ, radius and weight attributes
107  \return the particles bounding box
108  */
109  IMP::algebra::BoundingBoxD<3> calculate_particles_bounding_box(
110  const Particles &ps);
111 
112  //! Determine the size of the grid as a function of the particles
113  //! and the resolution.
114  void determine_grid_size(emreal resolution, emreal voxel_size,
115  int sig_cutoff);
116  void set_header(const algebra::Vector3D &lower_bound,
117  const algebra::Vector3D &upper_bound, emreal maxradius,
118  emreal resolution, emreal voxel_size, int sig_offset);
119 
120  protected:
121  void set_neighbor_mask(float radius);
122 
123  protected:
124  //! kernel handling
126  // DistanceMask distance_mask_;
127  Particles ps_;
128  core::XYZRs xyzr_; // each voxel decorator would contain X,Y,Z,R
129  FloatKey weight_key_;
130  FloatKey x_key_, y_key_, z_key_;
131  KernelType kt_;
132 };
134 
135 IMPEM_END_NAMESPACE
136 
137 #endif /* IMPEM_SAMPLED_DENSITY_MAP_H */
static FloatKey get_mass_key()
A decorator for particles with mass.
Basic types used by IMP.
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.
Key< 0, true > FloatKey
The type used to identify float attributes in the Particles.
Definition: base_types.h:32
#define IMP_OBJECTS(Name, PluralName)
Define the types for storing sets of objects.
Definition: object_macros.h:42
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.