IMP logo
IMP Reference Guide  develop.7482b7c7af, 2026/12/05
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-2022 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"
23IMPEM_BEGIN_NAMESPACE
24
25enum KernelType {
26 GAUSSIAN,
27 BINARIZED_SPHERE,
28 SPHERE
29};
30//! Class for sampling a density map from particles
31class 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, double resolution,
56 double 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.),
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
101
102 //! Update the simulation resolution
104
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 */
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(double resolution, double voxel_size,
118 int sig_cutoff);
119 void set_header(const algebra::Vector3D &lower_bound,
120 const algebra::Vector3D &upper_bound, double maxradius,
121 double resolution, double 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
138IMPEM_END_NAMESPACE
139
140#endif /* IMPEM_SAMPLED_DENSITY_MAP_H */
Metadata for a density file.
Class for handling density maps.
Calculates and stores Gaussian kernel parameters.
A decorator for particles with mass.
Decorator for a sphere-like particle.
Basic types used by IMP.
An axis-aligned bounding box.
static FloatKey get_mass_key()
Calculates and stores Gaussian kernel parameters.
Class for sampling a density map from particles.
SampledDensityMap(KernelType kt=GAUSSIAN)
Creates a new density map for sampled map.
float get_minimum_resampled_value()
Get minimum density value between voxels that correspond to particles.
virtual void resample()
Resample beads on an EM grid.
void project(const ParticlesTemp &ps, int x_margin, int y_margin, int z_margin, algebra::Vector3D shift=algebra::Vector3D(0., 0., 0.), FloatKey mass_key=atom::Mass::get_mass_key())
Project particles on the grid by their mass value.
void update_resolution(Float res)
Update the simulation resolution.
IMP::algebra::BoundingBoxD< 3 > calculate_particles_bounding_box(const Particles &ps)
Calculate the parameters of the particles bounding box.
void determine_grid_size(double resolution, double voxel_size, int sig_cutoff)
SampledDensityMap(const DensityHeader &header, KernelType kt=GAUSSIAN)
The size of the map is determined by the header and the data is allocated.
SampledDensityMap(const ParticlesTemp &ps, double resolution, double voxel_size, IMP::FloatKey mass_key=IMP::atom::Mass::get_mass_key(), int sig_cutoff=3, KernelType kt=GAUSSIAN)
Generate a sampled density map from the particles.
KernelParameters kernel_params_
kernel handling
void set_particles(const ParticlesTemp &ps, IMP::FloatKey mass_key=IMP::atom::Mass::get_mass_key())
setting particles in case they were not set by the constructor
Definitions for EMBED.
An approximation of the exponential function.
masking tools
IMP::Vector< IMP::Pointer< SampledDensityMap > > SampledDensityMaps
Vector< Pointer< Particle > > Particles
A list of reference-counted Particle objects.
Definition base_types.h:138
double Float
Basic floating-point value (could be float, double...).
Definition types.h:19
VectorD< 3 > Vector3D
Definition VectorD.h:407
Key< 0 > 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 lists of object pointers.
#define IMP_REF_COUNTED_DESTRUCTOR(Name)
Set up destructor for a ref counted object.