IMP  2.1.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-2013 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,BINARIZED_SPHERE,SPHERE
27 };
28 //! Class for sampling a density map from particles
29 class IMPEMEXPORT SampledDensityMap: public DensityMap
30 {
31 
32 public:
33 
34 
35  //! Creates a new density map for sampled map.
36  /** The header of the map is not determined and no data is being allocated
37  */
38  SampledDensityMap(KernelType kt=GAUSSIAN):
39  DensityMap("SampledDensityMap%1%"),kt_(kt) {
40  }
41 
42  //! The size of the map is determined by the header and the data is allocated.
43  SampledDensityMap(const DensityHeader &header,
44  KernelType kt=GAUSSIAN);
45 
46  //! Generate a sampled density map from the particles.
47  /** /param[in] ps particles with XYZ, radius and weight attributes
48  /param[in] resolution half width the Gaussian
49  /param[in] voxel_size
50  /param[in] sig_cutoff Choose what should be the sigma cutoff for
51  accurate sampling. It is used in two functions;
52  (i) to determine the size of the grid dimensions
53  (ii) to determine the voxels around the coords participating
54  in the sampling procedure.
55  */
56  SampledDensityMap(const kernel::ParticlesTemp &ps, emreal resolution,
57  emreal voxel_size,
59  int sig_cuttoff=3, KernelType kt=GAUSSIAN);
60 
61  //! Resample beads on an EM grid
62  /**
63  \note The density of a particle p centered at pl at position gl is:
64  \f$\frac{{Z}e^{\frac{{-0.5}({p_l}-{g_l})}{\sigma}}}{\sqrt{{2}{\pi}\sigma}}\f$
65  , such that \f${Z}\f$ is the weight of the particle and \f${\sigma}\f$
66  is defined to be \f${0.425}\f$ times the resolution,
67  to follow the 'full width at half maxima'
68  criterion. For more details please refer to Topf et al, Structure, 2008.
69  */
70  virtual void resample();
71 
72  //! Project particles on the grid by their mass value
73  /**
74  \param ps the particles to project
75  \param[in] x_margin sampling is restricted to [x_margin,nx-x_margin]
76  \param[in] y_margin sampling is restricted to [y_margin,ny-y_margin]
77  \param[in] z_margin sampling is restricted to [z_margin,nz-z_margin]
78  \param[in] shift the positions of all particles are shifted by
79  this value before projection
80  \param[in] mass_key key to obtain particle mass
81  */
82  void project(const kernel::ParticlesTemp &ps,
83  int x_margin,int y_margin,int z_margin,
84  algebra::Vector3D shift=algebra::Vector3D(0.,0.,0.),
85  FloatKey mass_key=atom::Mass::get_mass_key());
86 
87  //! setting particles in case they were not set by the constructor
88  void set_particles(const kernel::ParticlesTemp &ps,
90 
91 #if !defined(DOXYGEN) && !defined(SWIG)
92  KernelParameters *get_kernel_params() { return &kernel_params_;}
93 #endif
94 
95  inline const core::XYZRs & get_xyzr_particles() const {return xyzr_;}
96  // would go away on§ce we have a XYZRW decorator and the next function as well
97  inline const kernel::Particles & get_sampled_particles() const {return ps_;}
98  inline FloatKey get_weight_key() const {return weight_key_;}
99 
100  //! Get minimum density value between voxels that correspond to particles
101  float get_minimum_resampled_value();
102 
103  IMP_REF_COUNTED_DESTRUCTOR(SampledDensityMap);
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  */
110  calculate_particles_bounding_box(const kernel::Particles &ps);
111 
112 
113  //! Determine the size of the grid as a function of the particles
114  //! and the resolution.
115  void determine_grid_size(emreal resolution, emreal voxel_size,int sig_cutoff);
116  void set_header(const algebra::Vector3D &lower_bound,
117  const algebra::Vector3D &upper_bound,
118  emreal maxradius, emreal resolution, emreal voxel_size,
119  int sig_offset);
120  protected:
121  void set_neighbor_mask(float radius);
122 protected:
123  //! kernel handling
125  // DistanceMask distance_mask_;
126  kernel::Particles ps_;
127  core::XYZRs xyzr_; //each voxel decorator would contain X,Y,Z,R
128  FloatKey weight_key_;
129  FloatKey x_key_,y_key_,z_key_;
130  KernelType kt_;
131 };
133 
134 IMPEM_END_NAMESPACE
135 
136 #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
#define IMP_REF_COUNTED_DESTRUCTOR(Name)
Ref counted objects should have private destructors.
Calculates and stores gaussian kernel parameters.
An approximation of the exponential function.
Class for handling density maps.
Class for handling density maps.
Definition: DensityMap.h:98
Class for sampling a density map from particles.
#define IMP_OBJECTS(Name, PluralName)
Define the types for storing sets of objects.
KernelParameters kernel_params_
kernel handling
VectorD< 3 > Vector3D
Definition: VectorD.h:587
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.