IMP logo
IMP Reference Guide  2.10.1
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-2018 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  //! Update the simulation resolution
103  void update_resolution(Float res);
104 
105  IMP_REF_COUNTED_DESTRUCTOR(SampledDensityMap);
106 
107  protected:
108  //! Calculate the parameters of the particles bounding box
109  /** \param[in] ps particles with XYZ, radius and weight attributes
110  \return the particles bounding box
111  */
112  IMP::algebra::BoundingBoxD<3> calculate_particles_bounding_box(
113  const Particles &ps);
114 
115  //! Determine the size of the grid as a function of the particles
116  //! and the resolution.
117  void determine_grid_size(emreal resolution, emreal voxel_size,
118  int sig_cutoff);
119  void set_header(const algebra::Vector3D &lower_bound,
120  const algebra::Vector3D &upper_bound, emreal maxradius,
121  emreal resolution, emreal voxel_size, int sig_offset);
122 
123  protected:
124  void set_neighbor_mask(float radius);
125 
126  protected:
127  //! kernel handling
129  // DistanceMask distance_mask_;
130  Particles ps_;
131  core::XYZRs xyzr_; // each voxel decorator would contain X,Y,Z,R
132  FloatKey weight_key_;
133  FloatKey x_key_, y_key_, z_key_;
134  KernelType kt_;
135 };
137 
138 IMPEM_END_NAMESPACE
139 
140 #endif /* IMPEM_SAMPLED_DENSITY_MAP_H */
static FloatKey get_mass_key()
A decorator for particles with mass.
Basic types used by IMP.
Key< 0 > FloatKey
The type used to identify float attributes in the Particles.
Definition: base_types.h:32
Definitions for EMBED.
Calculates and stores Gaussian kernel parameters.
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:93
Class for sampling a density map from particles.
#define IMP_OBJECTS(Name, PluralName)
Define the types for storing lists of object pointers.
Definition: object_macros.h:44
KernelParameters kernel_params_
kernel handling
VectorD< 3 > Vector3D
Definition: VectorD.h:395
double Float
Basic floating-point value (could be float, double...)
Definition: types.h:20
SampledDensityMap(KernelType kt=GAUSSIAN)
Creates a new density map for sampled map.
Decorator for a sphere-like particle.