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);
55 std::string get_state_name(
unsigned int id)
const IMP_OVERRIDE {
56 return profiles_[id]->get_name();
60 return exp_profile_->get_name();
63 double get_average_c1()
const {
return average_c1_; }
64 double get_average_c2()
const {
return average_c2_; }
87 double min_c1_, max_c1_, min_c2_, max_c2_;
88 double average_c1_, average_c2_;
91 bool c1_c2_approximate_;
94 bool c1_c2_no_fitting_;
99 template <
typename ScoringFunctionT>
103 bool c1_c2_approximate,
104 double min_c1,
double max_c1,
105 double min_c2,
double max_c2,
107 profiles_(profiles), exp_profile_(exp_profile),
108 min_c1_(min_c1), max_c1_(max_c1), min_c2_(min_c2), max_c2_(max_c2),
109 c1_c2_approximate_(c1_c2_approximate), c1_c2_no_fitting_(false),
110 use_offset_(use_offset) {
112 if(profiles_.size() < 1) {
113 IMP_THROW(
"SAXSMultiStateModelScore - please provide at least one profile"
118 resample(exp_profile_, profiles_, resampled_profiles_);
124 set_average_c1_c2(score_, resampled_profiles_);
127 template <
typename ScoringFunctionT>
128 void SAXSMultiStateModelScore<ScoringFunctionT>::resample(
129 const saxs::Profile* exp_profile,
133 resampled_profiles.reserve(profiles.size());
134 for(
unsigned int i=0; i<profiles.size(); i++) {
135 saxs::Profile *resampled_profile =
136 new saxs::Profile(exp_profile->get_min_q(), exp_profile->get_max_q(),
137 exp_profile->get_delta_q());
138 profiles[i]->resample(exp_profile, resampled_profile);
139 resampled_profiles.push_back(resampled_profile);
140 if(!profiles[i]->is_partial_profile()) c1_c2_no_fitting_ =
true;
144 template <
typename ScoringFunctionT>
145 void SAXSMultiStateModelScore<ScoringFunctionT>::set_average_c1_c2(
146 saxs::WeightedProfileFitter<ScoringFunctionT>* score,
148 if(c1_c2_no_fitting_)
return;
152 for(
unsigned int i=0; i<profiles.size(); i++) {
153 profiles_temp[0] = profiles[i];
154 saxs::WeightedFitParameters fp =
155 score->fit_profile(profiles_temp, min_c1_, max_c1_, min_c2_, max_c2_, use_offset_);
156 average_c1_ += fp.get_c1();
157 average_c2_ += fp.get_c2();
159 average_c1_ /= profiles.size();
160 average_c2_ /= profiles.size();
163 template <
typename ScoringFunctionT>
164 void SAXSMultiStateModelScore<ScoringFunctionT>::set_average_c1_c2(
165 const Vector<saxs::WeightedFitParameters>& fps) {
166 if(c1_c2_no_fitting_)
return;
169 for(
unsigned int i=0; i<fps.size(); i++) {
170 c1 += fps[i].get_c1();
171 c2 += fps[i].get_c2();
181 template <
typename ScoringFunctionT>
182 double SAXSMultiStateModelScore<ScoringFunctionT>::get_score(
const MultiStateModel& m,
183 Vector<double>& weights)
const {
184 const Vector<unsigned int>& states = m.get_states();
186 for(
unsigned int i=0; i<states.size(); i++) {
187 profiles[i] = resampled_profiles_[states[i]];
188 if(c1_c2_approximate_ && !c1_c2_no_fitting_)
189 profiles[i]->sum_partial_profiles(average_c1_, average_c2_);
193 if(c1_c2_approximate_ || c1_c2_no_fitting_) {
194 chi_square = score_->compute_score(profiles, weights, use_offset_);
196 saxs::WeightedFitParameters fp =
197 score_->fit_profile(profiles, min_c1_, max_c1_, min_c2_, max_c2_, use_offset_);
198 chi_square = fp.get_chi_square();
203 template <
typename ScoringFunctionT>
204 double SAXSMultiStateModelScore<ScoringFunctionT>::get_score(
const MultiStateModel& m)
const {
205 Vector<double> weights;
206 return get_score(m, weights);
210 template <
typename ScoringFunctionT>
211 saxs::WeightedFitParameters
212 SAXSMultiStateModelScore<ScoringFunctionT>::get_fit_parameters(MultiStateModel& m)
const {
214 if(c1_c2_no_fitting_) {
215 Vector<double> weights;
216 double s = get_score(m, weights);
217 saxs::WeightedFitParameters wfp(s, 1.0, 0.0, weights);
221 const Vector<unsigned int>& states = m.get_states();
223 for(
unsigned int i=0; i<states.size(); i++)
224 profiles[i] = resampled_profiles_[states[i]];
226 saxs::WeightedFitParameters fp =
227 score_->fit_profile(profiles, min_c1_, max_c1_, min_c2_, max_c2_, use_offset_);
228 m.set_score(fp.get_chi_square());
232 template <
typename ScoringFunctionT>
233 saxs::WeightedFitParameters
234 SAXSMultiStateModelScore<ScoringFunctionT>::get_fit_parameters()
const {
236 if(c1_c2_no_fitting_) {
237 Vector<double> weights;
238 double s = score_->compute_score(resampled_profiles_, weights, use_offset_);
239 saxs::WeightedFitParameters wfp(s, 1.0, 0.0, weights);
243 saxs::WeightedFitParameters fp = score_->fit_profile(resampled_profiles_,
245 min_c2_, max_c2_, use_offset_);
249 template <
typename ScoringFunctionT>
250 void SAXSMultiStateModelScore<ScoringFunctionT>::write_fit_file(MultiStateModel& m,
251 const saxs::WeightedFitParameters& fp,
252 const std::string fit_file_name)
const {
254 const Vector<unsigned int>& states = m.get_states();
256 for(
unsigned int i=0; i<states.size(); i++)
257 profiles[i] = resampled_profiles_[states[i]];
258 score_->write_fit_file(profiles, fp, fit_file_name, use_offset_);
261 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.
#define IMP_OVERRIDE
Cause a compile error if this method does not override a parent method.
A class for profile storing and computation.