IMP logo

Score.h

Go to the documentation of this file.
00001 /**
00002  *  \file Score.h   \brief A class for SAXS scoring and its derivatives
00003  *
00004  *  Copyright 2007-2011 IMP Inventors. All rights reserved.
00005  *
00006  */
00007 
00008 #ifndef IMPSAXS_SCORE_H
00009 #define IMPSAXS_SCORE_H
00010 
00011 #include "saxs_config.h"
00012 #include "Distribution.h"
00013 #include "Profile.h"
00014 
00015 #include <IMP/Model.h>
00016 
00017 #include <iostream>
00018 #include <vector>
00019 
00020 IMPSAXS_BEGIN_NAMESPACE
00021 
00022 class Profile;
00023 class Restraint;
00024 
00025 /**
00026   SAXS scoring class that allows to compute chi score for the fit between the
00027   experimental and computational profile. In addition, derivatives with respect
00028   to the experimental profile can be computed and further used for optimization.
00029 */
00030 class IMPSAXSEXPORT Score: public RefCounted {
00031 public:
00032   //! Constructor
00033   /**
00034      \param[in] exp_profile Experimental profile we want to fit
00035   */
00036   Score(const Profile& exp_profile);
00037 
00038   //! compute chi value
00039   Float compute_chi_score(const Profile& model_profile,
00040                           bool use_offset = false,
00041                           const std::string fit_file_name = "") const {
00042     return sqrt(compute_chi_square_score(model_profile,
00043                                          use_offset, fit_file_name));
00044   }
00045 
00046   //! fit experimental profile through optimization of c1 and c2 parameters
00047   /**
00048      \param[in] partial_profile  partial profiles computed
00049      \param[in] c1, c2 - the optimal values will be returned in these parameters
00050      c1 - adjusts the excluded volume, valid range [0.95 - 1.12]
00051      c2 - adjusts the density of hydration layer, valid range [-4.0 - 4.0]
00052      \return chi value
00053   */
00054   Float fit_profile(Profile& partial_profile, float& c1, float& c2,
00055                     bool fixed_c1 = false, bool fixed_c2 = false,
00056                     bool use_offset = false,
00057                     const std::string fit_file_name = "") const;
00058 
00059   //! fit experimental profile through optimization of c1 and c2 parameters
00060   Float fit_profile(Profile& partial_profile,
00061                     bool use_offset = false,
00062                     const std::string fit_file_name = "") const {
00063     // this function version is for python
00064     float c1, c2;
00065     return fit_profile(partial_profile, c1, c2, false, false,
00066                        use_offset, fit_file_name);
00067   }
00068 
00069   //! compute squared chi value
00070   Float compute_chi_square_score(const Profile& model_profile,
00071                                  bool use_offset = false,
00072                                  const std::string fit_file_name = "") const;
00073 
00074 
00075   //! computes scale factor given offset value
00076   Float compute_scale_factor(const Profile& model_profile,
00077                              Float offset = 0.0) const;
00078   // computes offset
00079   Float compute_offset(const Profile& model_profile) const;
00080 
00081  private:
00082   // required to fit the q values of computational profile to the experimental
00083   void resample(const Profile& model_profile, Profile& resampled_profile) const;
00084 
00085   // computes chi square
00086   Float compute_chi_square_score_internal(const Profile& model_profile,
00087                                           const std::string& fit_file_name,
00088                                           bool use_offset = false) const;
00089 
00090   // computes chi square given scale factor c and offset
00091   Float compute_chi_square_score_internal(const Profile& model_profile,
00092                                        const Float c, const Float offset) const;
00093 
00094   // writes 3 column fit file, given scale factor c, offset and chi square
00095   void write_SAXS_fit_file(const std::string& file_name,
00096                            const Profile& model_profile,
00097                            const Float chi_square,
00098                            const Float c=1, const Float offset=0) const;
00099 
00100 
00101   // helper function for derivatives
00102   void compute_profile_difference(const Profile& model_profile,
00103                                   const Float c, const Float offset,
00104                                   Floats& profile_diff) const;
00105 
00106   // helper function for derivatives
00107   void compute_sinc_cos(Float pr_resolution, Float max_distance,
00108                         const Profile& model_profile,
00109                         std::vector<Floats>& output_values) const;
00110   IMP_REF_COUNTED_DESTRUCTOR(Score);
00111   friend class Restraint;
00112   //! compute derivatives for particles1 with respect to particles2
00113   /**
00114      This method is needed for rigid bodies when particles1 and particles2
00115      are particles of two rigid bodies. In this case the particles of the
00116      same rigid body are ignored.
00117      \param[in] model_profile The current profile of particles
00118      \param[in] particles1 Derivative will be computed for each particle
00119      \param[in] particles2 Derivative will be computed relative to this set
00120      \param[in] derivatives Output vector
00121      \param[in] use_offset if true, non zero offset for fitting is used
00122      \return chi square score for current particle setup
00123   */
00124   void compute_chi_derivative(const Profile& model_profile,
00125                               const Particles& particles1,
00126                               const Particles& particles2,
00127                               std::vector<algebra::VectorD<3> >& derivatives,
00128                               bool use_offset = false) const;
00129   void compute_chi_derivative(const Profile& model_profile,
00130                               const Particles& particles,
00131                               std::vector<algebra::VectorD<3> >& derivatives,
00132                               bool use_offset = false) const {
00133     return compute_chi_derivative(model_profile, particles, particles,
00134                                   derivatives, use_offset);
00135   }
00136   // compute derivatives for each particle
00137   void compute_chi_real_derivative(const Profile& model_profile,
00138                                    const Particles& particles1,
00139                                    const Particles& particles2,
00140                               std::vector<algebra::VectorD<3> >& derivatives,
00141                                    bool use_offset) const;
00142 
00143 
00144   const Profile exp_profile_;   //  experimental saxs profile
00145 };
00146 
00147 IMPSAXS_END_NAMESPACE
00148 
00149 #endif  /* IMPSAXS_SCORE_H */

Generated on Thu Mar 24 2011 02:01:39 for IMP by doxygen 1.7.3