/** * \file RestraintEvaluatorFromFile.cpp * \brief A restraint evaluator file * * Copyright 2007-2010 IMP Inventors. All rights reserved. * */ #include "IMP/domino/RestraintEvaluatorFromFile.h" #include IMPDOMINO_BEGIN_NAMESPACE void write_combinations(const std::string &filename, const Combinations *combs,Particles &ps) { //write the combinations std::ofstream out_file(filename.c_str()); if (!out_file) { IMP_THROW("Can't open file " << filename << " for writing", IOException); } //add all combinations out_file<get_name()<<"|"<get_name()<<"||"<begin(); it != combs->end(); it++) { const CombState *c = it->second; out_file<get_state_num(ps[0])<<"|"<< c->get_state_num(ps[1])<<"|"<get_total_score()<< "|"<second<<":"<second; } void read_combinations(const std::string &filename, Combinations *combs, const Particles &ps) { std::ifstream scores_file(filename.c_str()); IMP_INTERNAL_CHECK(scores_file,"No such scores file " << filename< split_vector_type; split_vector_type split_vec; boost::split(split_vec, line, boost::is_any_of("|")); IMP_INTERNAL_CHECK(ps.size()==split_vec.size()-1, "the number of particles in the file does not corresponde to the " <<"number of input particles"<get_value(node_name_key())==split_vec[i], "wrong particle name:"<get_value(node_name_key()) <<":"<add_data_item(ps[i],atoi(split_vec[i].c_str())); } calc_state->update_total_score(0., atof(split_vec[split_vec.size()-2].c_str())); (*combs)[calc_state->partial_key(&ps)]=calc_state; } IMP_LOG(IMP::VERBOSE,"read " << combs->size() << " combinations"< to_sort_ps; for(Particles::const_iterator it = ps.begin(); it != ps.end(); it++) { to_sort_ps[(*it)->get_value(node_name_key())]=*it; } Particles sorted_ps; for(std::map::const_iterator it = to_sort_ps.begin(); it != to_sort_ps.end(); it++) { sorted_ps.push_back(it->second); } Combinations read_combs; IMP_LOG(VERBOSE,"start calculating scores from file:" <second; key=cs->partial_key(&sorted_ps); IMP_INTERNAL_CHECK(read_combs.find(key) != read_combs.end(), "read_combs does not have a key:"<second != NULL, "read_combs has a NULL value for key:"<get_total_score()<get_total_score(); } } IMPDOMINO_END_NAMESPACE