IMP  2.0.1
The Integrative Modeling Platform
DerivativeCalculator.h
Go to the documentation of this file.
1 /**
2  * \file IMP/saxs/DerivativeCalculator.h
3  * \brief A class for computing SAXS derivatives
4  *
5  * Copyright 2007-2013 IMP Inventors. All rights reserved.
6  *
7  */
8 
9 #ifndef IMPSAXS_DERIVATIVE_CALCULATOR_H
10 #define IMPSAXS_DERIVATIVE_CALCULATOR_H
11 
12 #include "Profile.h"
13 #include "ProfileFitter.h"
14 #include "Distribution.h"
15 
16 IMPSAXS_BEGIN_NAMESPACE
17 
18 //class ProfileFitter<ChiScore>;
19 
20 class IMPSAXSEXPORT DerivativeCalculator : public base::RefCounted {
21 public:
22  DerivativeCalculator(const Profile& exp_profile);
23 
24  /* compute the model-specific part of the derivative of the chi square
25  * e.g. -2 * c * w_tilda(q) * (Iexp(q)-c*Icalc(q) + o)
26  * for each q
27  */
28  std::vector<double> compute_gaussian_effect_size(const Profile& model_profile,
29  const ProfileFitter<ChiScore>* pf,
30  bool use_offset = false) const;
31 
32  /*
33  * loop over all particles and rigid bodies, and call
34  * compute_chisquare_derivative on them
35  */
36  void compute_all_derivatives(const Particles& particles,
37  const std::vector<Particles>& rigid_bodies,
38  const std::vector<core::RigidBody>& rigid_bodies_decorators,
39  const Profile& model_profile, const std::vector<double>& effect_size,
40  DerivativeAccumulator *acc) const;
41 
42 protected:
43  /*
44  * precompute sinc_cos function and derivative of distance distribution
45  */
46  DeltaDistributionFunction precompute_derivative_helpers(const Profile&
47  resampled_model_profile, const Particles& particles1,
48  const Particles& particles2, std::vector<Floats>& sinc_cos_values)
49  const ;
50 
51  /* compute dI(q)/dx_k for given q and k
52  * dI(q)/dx_k = - 2 E^2(q) \sum_l (x_k-x_l)/d_{kl}^2 f_l f_k (sinc(q*d_{kl}) -
53  * * cos(q*d_{kl}))
54  */
55  void compute_intensity_derivatives(const DeltaDistributionFunction&
56  delta_dist, const std::vector<Floats>& sinc_cos_values,
57  unsigned int iq, algebra::Vector3D &dIdx) const;
58 
59  //! compute derivatives for particles1 with respect to particles2
60  /**
61  This method is needed for rigid bodies when particles1 and particles2
62  are particles of two rigid bodies. In this case the particles of the
63  same rigid body are ignored.
64  \param[in] model_profile The current profile of particles
65  \param[in] particles1 Derivative will be computed for each particle
66  \param[in] particles2 Derivative will be computed relative to this set
67  \param[in] derivatives Output vector
68  \return chi square score for current particle setup
69  */
70  void compute_chisquare_derivative(const Profile& model_profile,
71  const Particles& particles1,
72  const Particles& particles2,
73  std::vector<algebra::Vector3D >& derivatives,
74  const std::vector<double>& effect_size) const;
75  void compute_chisquare_derivative(const Profile& model_profile,
76  const Particles& particles,
77  std::vector<algebra::Vector3D >& derivatives,
78  const std::vector<double>& effect_size) const
79  {
80  return compute_chisquare_derivative(model_profile, particles, particles,
81  derivatives, effect_size);
82  }
83 
84 protected:
85  const Profile exp_profile_; // experimental saxs profile
86 
87 private:
88  void compute_sinc_cos(Float pr_resolution, Float max_distance,
89  const Profile& model_profile,
90  std::vector<Floats>& output_values) const;
91 
92  void compute_profile_difference(const Profile& model_profile,
93  const Float c, const Float offset,
94  std::vector<double>& profile_diff) const;
95 
96 
97 };
98 
99 IMPSAXS_END_NAMESPACE
100 
101 #endif /* IMPSAXS_DERIVATIVE_CALCULATOR_H */