IMP logo
IMP Reference Guide  develop.7482b7c7af, 2026/12/05
The Integrative Modeling Platform
FitRestraint.h
Go to the documentation of this file.
1/**
2 * \file IMP/em/FitRestraint.h
3 * \brief Calculate score based on fit to EM map.
4 *
5 * Copyright 2007-2022 IMP Inventors. All rights reserved.
6 *
7 */
8
9#ifndef IMPEM_FIT_RESTRAINT_H
10#define IMPEM_FIT_RESTRAINT_H
11
12#include <IMP/em/em_config.h>
13#include "DensityMap.h"
14#include "CoarseCC.h"
15#include "SampledDensityMap.h"
16
17#include <IMP/atom/Hierarchy.h>
18#include <IMP/atom/Atom.h>
19#include <IMP/atom/Mass.h>
20#include <IMP/core/XYZR.h>
21#include <IMP/Model.h>
22#include <IMP/Restraint.h>
23#include <IMP/Refiner.h>
24#include <boost/unordered_map.hpp>
25
26IMPEM_BEGIN_NAMESPACE
27
28//! Calculate score based on fit to EM map
29/** The score is a function of the cross correlation between the
30 EM map and the map simulated from the particles. This is calculated
31 by means of a double sum over the two sets of voxels.
32
33 \note In most cases it is faster to approximate the two maps with
34 a Gaussian Mixture Model and to use that for the scoring, with
35 isd::GaussianEMRestraint.
36
37 \ingroup exp_restraint
38 */
39class IMPEMEXPORT FitRestraint : public Restraint {
40 public:
41 //! Constructor
42 /**
43 \param[in] ps The particles participating in the fitting score
44 \param[in] em_map The density map used in the fitting score
45 \param[in] norm_factors if set, they are used as normalization factors
46 for the cross correlation calculations. This is relevant when the
47 cross-correlation score of the entire system is decomposed.
48 \param[in] weight_key the name of the weight attribute of the particles
49 \param[in] scale multiply the fitting restraint score and derivatives
50 by this value
51 \param[in] use_rigid_bodies if some of the particles are part of
52 a rigid body,
53 use the rigid body for faster calculations
54 \param[in] kt KernelType to use for simulating density from particles
55 \note Rigid-bodies are interpolated and not resampled
56 if use_rigid_bodies option is selected.
57 This significantly reduces the running time but is less accurate.
58 If the user prefers to get more accurate results, provide
59 its members as input particles and not the rigid body.
60 */
61 FitRestraint(ParticlesTemp ps, DensityMap *em_map,
62 FloatPair norm_factors = FloatPair(0., 0.),
64 float scale = 1, bool use_rigid_bodies = true,
65 KernelType kt = GAUSSIAN);
66 //! Return the predicted density map of the model
67 SampledDensityMap *get_model_dens_map() const { return model_dens_map_; }
68 void set_scale_factor(float scale) { scalefac_ = scale; }
69 float get_scale_factor() const { return scalefac_; }
71 const override;
72 virtual IMP::ModelObjectsTemp do_get_inputs() const override;
74
75#ifndef SWIG
76 IMP_LIST(private, Particle, particle, Particle *, Particles);
77#endif
78 private:
79 //! Store particles
80 void store_particles(ParticlesTemp ps);
81 //! Resample the model density map
82 void resample() const;
83 //! Create density maps: one for each rigid body and one for the rest.
84 void initialize_model_density_map(FloatKey weight_key);
85
86 IMP::PointerMember<DensityMap> target_dens_map_;
87 mutable IMP::PointerMember<SampledDensityMap> model_dens_map_;
88 mutable SampledDensityMaps rb_model_dens_map_;
89 mutable IMP::PointerMember<SampledDensityMap> none_rb_model_dens_map_;
90 algebra::BoundingBoxD<3> target_bounding_box_;
91 // reference to the IMP environment
92 float scalefac_;
93 core::XYZs xyz_;
94 // derivatives
95 mutable algebra::Vector3Ds dv_;
96 algebra::ReferenceFrame3Ds rbs_orig_rf_;
97 FloatKey weight_key_;
98 KernelParameters *kernel_params_;
99 FloatPair norm_factors_;
100 bool use_rigid_bodies_;
101 // particle handling
102 // map particles to their rigid bodies
103 boost::unordered_map<core::RigidBody, Particles> member_map_;
104 Particles all_ps_;
105 // all particles that are not part of a rigid body
106 Particles not_part_of_rb_;
107 Particles part_of_rb_;
108 core::RigidBodies rbs_;
109 KernelType kt_;
110};
111
112IMPEM_END_NAMESPACE
113
114#endif /* IMPEM_FIT_RESTRAINT_H */
Simple atom decorator.
Perform coarse fitting between two density objects.
Class for handling density maps.
A decorator for particles with mass.
Storage of a model, its restraints, constraints and particles.
Refine a particle into a list of particles.
Abstract base class for all restraints.
Sampled density map.
Decorator for a sphere-like particle.
Decorator for helping deal with a hierarchy of molecules.
Class for adding derivatives from restraints to the model.
Class to handle individual particles of a Model object.
Definition Particle.h:45
Restraint(Model *m, std::string name)
Create a restraint and register it with the model.
An axis-aligned bounding box.
static FloatKey get_mass_key()
Class for handling density maps.
Definition DensityMap.h:95
FitRestraint(ParticlesTemp ps, DensityMap *em_map, FloatPair norm_factors=FloatPair(0., 0.), FloatKey weight_key=atom::Mass::get_mass_key(), float scale=1, bool use_rigid_bodies=true, KernelType kt=GAUSSIAN)
Constructor.
virtual double unprotected_evaluate(IMP::DerivativeAccumulator *accum) const override
Return the unweighted score for the restraint.
SampledDensityMap * get_model_dens_map() const
Return the predicted density map of the model.
virtual IMP::ModelObjectsTemp do_get_inputs() const override
Calculates and stores Gaussian kernel parameters.
Class for sampling a density map from particles.
#define IMP_LIST(protection, Ucname, lcname, Data, PluralData)
A macro to provide a uniform interface for storing lists of objects.
IMP::Vector< ReferenceFrame3D > ReferenceFrame3Ds
IMP::Vector< IMP::Pointer< SampledDensityMap > > SampledDensityMaps
Vector< VectorD< 3 > > Vector3Ds
Definition VectorD.h:409
Vector< Pointer< Particle > > Particles
A list of reference-counted Particle objects.
Definition base_types.h:138
Key< 0 > FloatKey
The type used to identify float attributes in the Particles.
Definition base_types.h:32
IMP::Vector< IMP::WeakPointer< ModelObject > > ModelObjectsTemp
Definition base_types.h:122
std::pair< double, double > FloatPair
A generic pair of floats.
Definition types.h:26
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
A smart pointer to a ref-counted Object that is a class member.
Definition Pointer.h:144