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);
51 const std::string fit_file_name)
const;
53 std::string get_state_name(
unsigned int id)
const {
return profiles_[id]->get_name(); }
55 std::string get_dataset_name()
const {
return exp_profile_->get_name(); }
57 double get_average_c1()
const {
return average_c1_; }
58 double get_average_c2()
const {
return average_c2_; }
81 double min_c1_, max_c1_, min_c2_, max_c2_;
82 double average_c1_, average_c2_;
85 bool c1_c2_approximate_;
88 bool c1_c2_no_fitting_;
91 template <
typename ScoringFunctionT>
95 bool c1_c2_approximate,
96 double min_c1,
double max_c1,
97 double min_c2,
double max_c2) :
98 profiles_(profiles), exp_profile_(exp_profile),
99 min_c1_(min_c1), max_c1_(max_c1), min_c2_(min_c2), max_c2_(max_c2),
100 c1_c2_approximate_(c1_c2_approximate), c1_c2_no_fitting_(false) {
102 if(profiles_.size() < 1) {
103 IMP_THROW(
"SAXSMultiStateModelScore - please provide at least one profile"
108 resample(exp_profile_, profiles_, resampled_profiles_);
114 set_average_c1_c2(score_, resampled_profiles_);
117 template <
typename ScoringFunctionT>
118 void SAXSMultiStateModelScore<ScoringFunctionT>::resample(
119 const saxs::Profile* exp_profile,
123 resampled_profiles.reserve(profiles.size());
124 for(
unsigned int i=0; i<profiles.size(); i++) {
125 saxs::Profile *resampled_profile =
126 new saxs::Profile(exp_profile->get_min_q(), exp_profile->get_max_q(),
127 exp_profile->get_delta_q());
128 profiles[i]->resample(exp_profile, resampled_profile);
129 resampled_profiles.push_back(resampled_profile);
130 if(!profiles[i]->is_partial_profile()) c1_c2_no_fitting_ =
true;
134 template <
typename ScoringFunctionT>
135 void SAXSMultiStateModelScore<ScoringFunctionT>::set_average_c1_c2(
136 saxs::WeightedProfileFitter<ScoringFunctionT>* score,
138 if(c1_c2_no_fitting_)
return;
142 for(
unsigned int i=0; i<profiles.size(); i++) {
143 profiles_temp[0] = profiles[i];
144 saxs::WeightedFitParameters fp =
145 score->fit_profile(profiles_temp, min_c1_, max_c1_, min_c2_, max_c2_);
146 average_c1_ += fp.get_c1();
147 average_c2_ += fp.get_c2();
149 average_c1_ /= profiles.size();
150 average_c2_ /= profiles.size();
153 template <
typename ScoringFunctionT>
154 void SAXSMultiStateModelScore<ScoringFunctionT>::set_average_c1_c2(
155 const Vector<saxs::WeightedFitParameters>& fps) {
156 if(c1_c2_no_fitting_)
return;
159 for(
unsigned int i=0; i<fps.size(); i++) {
160 c1 += fps[i].get_c1();
161 c2 += fps[i].get_c2();
171 template <
typename ScoringFunctionT>
172 double SAXSMultiStateModelScore<ScoringFunctionT>::get_score(
const MultiStateModel& m,
173 Vector<double>& weights)
const {
174 const Vector<unsigned int>& states = m.get_states();
176 for(
unsigned int i=0; i<states.size(); i++) {
177 profiles[i] = resampled_profiles_[states[i]];
178 if(c1_c2_approximate_ && !c1_c2_no_fitting_)
179 profiles[i]->sum_partial_profiles(average_c1_, average_c2_);
183 if(c1_c2_approximate_ || c1_c2_no_fitting_) {
184 chi = score_->compute_score(profiles, weights);
186 saxs::WeightedFitParameters fp =
187 score_->fit_profile(profiles, min_c1_, max_c1_, min_c2_, max_c2_);
194 template <
typename ScoringFunctionT>
195 double SAXSMultiStateModelScore<ScoringFunctionT>::get_score(
const MultiStateModel& m)
const {
196 Vector<double> weights;
197 return get_score(m, weights);
201 template <
typename ScoringFunctionT>
202 saxs::WeightedFitParameters
203 SAXSMultiStateModelScore<ScoringFunctionT>::get_fit_parameters(MultiStateModel& m)
const {
205 if(c1_c2_no_fitting_) {
206 Vector<double> weights;
207 double s = get_score(m, weights);
208 saxs::WeightedFitParameters wfp(s, 1.0, 0.0, weights);
212 const Vector<unsigned int>& states = m.get_states();
214 for(
unsigned int i=0; i<states.size(); i++)
215 profiles[i] = resampled_profiles_[states[i]];
217 saxs::WeightedFitParameters fp =
218 score_->fit_profile(profiles, min_c1_, max_c1_, min_c2_, max_c2_);
219 m.set_score(fp.get_chi());
224 template <
typename ScoringFunctionT>
225 saxs::WeightedFitParameters
226 SAXSMultiStateModelScore<ScoringFunctionT>::get_fit_parameters()
const {
228 if(c1_c2_no_fitting_) {
229 Vector<double> weights;
230 double s = score_->compute_score(resampled_profiles_, weights);
231 saxs::WeightedFitParameters wfp(s, 1.0, 0.0, weights);
235 saxs::WeightedFitParameters fp = score_->fit_profile(resampled_profiles_,
241 template <
typename ScoringFunctionT>
242 void SAXSMultiStateModelScore<ScoringFunctionT>::write_fit_file(MultiStateModel& m,
243 const saxs::WeightedFitParameters& fp,
244 const std::string fit_file_name)
const {
246 const Vector<unsigned int>& states = m.get_states();
248 for(
unsigned int i=0; i<states.size(); i++)
249 profiles[i] = resampled_profiles_[states[i]];
250 score_->write_fit_file(profiles, fp, fit_file_name);
253 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.
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.