10 #ifndef IMPMULTI_STATE_SAXS_MULTI_STATE_MODEL_SCORE_H
11 #define IMPMULTI_STATE_SAXS_MULTI_STATE_MODEL_SCORE_H
22 IMPMULTISTATE_BEGIN_NAMESPACE
25 template <
typename ScoringFunctionT>
36 bool c1_c2_approximate,
37 double min_c1 = 0.99,
double max_c1 = 1.05,
38 double min_c2 = -0.5,
double max_c2 = 2.0,
39 bool use_offset =
false);
52 const std::string fit_file_name)
const;
54 std::string get_state_name(
unsigned int id)
const {
return profiles_[id]->get_name(); }
56 std::string get_dataset_name()
const {
return exp_profile_->get_name(); }
58 double get_average_c1()
const {
return average_c1_; }
59 double get_average_c2()
const {
return average_c2_; }
82 double min_c1_, max_c1_, min_c2_, max_c2_;
83 double average_c1_, average_c2_;
86 bool c1_c2_approximate_;
89 bool c1_c2_no_fitting_;
94 template <
typename ScoringFunctionT>
98 bool c1_c2_approximate,
99 double min_c1,
double max_c1,
100 double min_c2,
double max_c2,
102 profiles_(profiles), exp_profile_(exp_profile),
103 min_c1_(min_c1), max_c1_(max_c1), min_c2_(min_c2), max_c2_(max_c2),
104 c1_c2_approximate_(c1_c2_approximate), c1_c2_no_fitting_(false),
105 use_offset_(use_offset) {
107 if(profiles_.size() < 1) {
108 IMP_THROW(
"SAXSMultiStateModelScore - please provide at least one profile"
113 resample(exp_profile_, profiles_, resampled_profiles_);
119 set_average_c1_c2(score_, resampled_profiles_);
122 template <
typename ScoringFunctionT>
123 void SAXSMultiStateModelScore<ScoringFunctionT>::resample(
124 const saxs::Profile* exp_profile,
128 resampled_profiles.reserve(profiles.size());
129 for(
unsigned int i=0; i<profiles.size(); i++) {
130 saxs::Profile *resampled_profile =
131 new saxs::Profile(exp_profile->get_min_q(), exp_profile->get_max_q(),
132 exp_profile->get_delta_q());
133 profiles[i]->resample(exp_profile, resampled_profile);
134 resampled_profiles.push_back(resampled_profile);
135 if(!profiles[i]->is_partial_profile()) c1_c2_no_fitting_ =
true;
139 template <
typename ScoringFunctionT>
140 void SAXSMultiStateModelScore<ScoringFunctionT>::set_average_c1_c2(
141 saxs::WeightedProfileFitter<ScoringFunctionT>* score,
143 if(c1_c2_no_fitting_)
return;
147 for(
unsigned int i=0; i<profiles.size(); i++) {
148 profiles_temp[0] = profiles[i];
149 saxs::WeightedFitParameters fp =
150 score->fit_profile(profiles_temp, min_c1_, max_c1_, min_c2_, max_c2_, use_offset_);
151 average_c1_ += fp.get_c1();
152 average_c2_ += fp.get_c2();
154 average_c1_ /= profiles.size();
155 average_c2_ /= profiles.size();
158 template <
typename ScoringFunctionT>
159 void SAXSMultiStateModelScore<ScoringFunctionT>::set_average_c1_c2(
160 const Vector<saxs::WeightedFitParameters>& fps) {
161 if(c1_c2_no_fitting_)
return;
164 for(
unsigned int i=0; i<fps.size(); i++) {
165 c1 += fps[i].get_c1();
166 c2 += fps[i].get_c2();
176 template <
typename ScoringFunctionT>
177 double SAXSMultiStateModelScore<ScoringFunctionT>::get_score(
const MultiStateModel& m,
178 Vector<double>& weights)
const {
179 const Vector<unsigned int>& states = m.get_states();
181 for(
unsigned int i=0; i<states.size(); i++) {
182 profiles[i] = resampled_profiles_[states[i]];
183 if(c1_c2_approximate_ && !c1_c2_no_fitting_)
184 profiles[i]->sum_partial_profiles(average_c1_, average_c2_);
188 if(c1_c2_approximate_ || c1_c2_no_fitting_) {
189 chi_square = score_->compute_score(profiles, weights, use_offset_);
191 saxs::WeightedFitParameters fp =
192 score_->fit_profile(profiles, min_c1_, max_c1_, min_c2_, max_c2_, use_offset_);
193 chi_square = fp.get_chi_square();
198 template <
typename ScoringFunctionT>
199 double SAXSMultiStateModelScore<ScoringFunctionT>::get_score(
const MultiStateModel& m)
const {
200 Vector<double> weights;
201 return get_score(m, weights);
205 template <
typename ScoringFunctionT>
206 saxs::WeightedFitParameters
207 SAXSMultiStateModelScore<ScoringFunctionT>::get_fit_parameters(MultiStateModel& m)
const {
209 if(c1_c2_no_fitting_) {
210 Vector<double> weights;
211 double s = get_score(m, weights);
212 saxs::WeightedFitParameters wfp(s, 1.0, 0.0, weights);
216 const Vector<unsigned int>& states = m.get_states();
218 for(
unsigned int i=0; i<states.size(); i++)
219 profiles[i] = resampled_profiles_[states[i]];
221 saxs::WeightedFitParameters fp =
222 score_->fit_profile(profiles, min_c1_, max_c1_, min_c2_, max_c2_, use_offset_);
223 m.set_score(fp.get_chi_square());
227 template <
typename ScoringFunctionT>
228 saxs::WeightedFitParameters
229 SAXSMultiStateModelScore<ScoringFunctionT>::get_fit_parameters()
const {
231 if(c1_c2_no_fitting_) {
232 Vector<double> weights;
233 double s = score_->compute_score(resampled_profiles_, weights, use_offset_);
234 saxs::WeightedFitParameters wfp(s, 1.0, 0.0, weights);
238 saxs::WeightedFitParameters fp = score_->fit_profile(resampled_profiles_,
240 min_c2_, max_c2_, use_offset_);
244 template <
typename ScoringFunctionT>
245 void SAXSMultiStateModelScore<ScoringFunctionT>::write_fit_file(MultiStateModel& m,
246 const saxs::WeightedFitParameters& fp,
247 const std::string fit_file_name)
const {
249 const Vector<unsigned int>& states = m.get_states();
251 for(
unsigned int i=0; i<states.size(); i++)
252 profiles[i] = resampled_profiles_[states[i]];
253 score_->write_fit_file(profiles, fp, fit_file_name, use_offset_);
256 IMPMULTISTATE_END_NAMESPACE
IMP::Vector< IMP::Pointer< Profile > > Profiles
base class for MultiStateModel scoring classes
Fitting of multiple profiles to the experimental one. The weights of the profiles are computed analyt...
Base class for MultiStateModel scoring classes.
A more IMP-like version of the std::vector.
An input/output exception.
Fitting of multiple profiles to the experimental one.
Keep track of multiple states.
IMP::Vector< IMP::WeakPointer< Profile > > ProfilesTemp
#define IMP_THROW(message, exception_name)
Throw an exception with a message.
Parameters of a weighted fit, from WeightedProfileFitter.
A shared base class to help in debugging and things.
Keep track of multiple states.
A class for profile storing and computation.