IMP logo
IMP Reference Guide  2.7.0
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-2017 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 
26 IMPEM_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  */
39 class 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  */
62  FloatPair norm_factors = FloatPair(0., 0.),
63  FloatKey weight_key = atom::Mass::get_mass_key(),
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_; }
70  virtual double unprotected_evaluate(IMP::DerivativeAccumulator *accum)
71  const IMP_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
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 
112 IMPEM_END_NAMESPACE
113 
114 #endif /* IMPEM_FIT_RESTRAINT_H */
A decorator for particles with mass.
Perform coarse fitting between two density objects.
Calculates and stores Gaussian kernel parameters.
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
Definition: object_macros.h:25
Simple atom decorator.
Storage of a model, its restraints, constraints and particles.
std::pair< double, double > FloatPair
A generic pair of floats.
Definition: types.h:27
SampledDensityMap * get_model_dens_map() const
Return the predicted density map of the model.
Definition: FitRestraint.h:67
#define IMP_LIST(protection, Ucname, lcname, Data, PluralData)
A macro to provide a uniform interface for storing lists of objects.
Class for handling density maps.
Decorator for helping deal with a hierarchy of molecules.
Class for handling density maps.
Definition: DensityMap.h:93
Class for sampling a density map from particles.
Refine a particle into a list of particles.
A smart pointer to a ref-counted Object that is a class member.
Definition: Pointer.h:146
Calculate score based on fit to EM map.
Definition: FitRestraint.h:39
Class to handle individual particles of a Model object.
Definition: Particle.h:41
Abstract base class for all restraints.
Decorator for a sphere-like particle.
Sampled density map.
virtual ModelObjectsTemp do_get_inputs() const =0
#define IMP_OVERRIDE
Cause a compile error if this method does not override a parent method.
Class for adding derivatives from restraints to the model.
A restraint is a term in an IMP ScoringFunction.
Definition: Restraint.h:52