52 #include <basic/options/option.hh>
53 #include <basic/options/keys/PCS.OptionKeys.gen.hh>
61 #include <basic/datacache/BasicDataCache.hh>
62 #include <basic/Tracer.hh>
74 #include <utility/vector1.hh>
98 basic::Tracer
TR_PcsEnergy(
"protocols.scoring.methods.pcs.PcsEnergy");
106 std::cerr <<
"Error, = operator not correctly implemented in the PcsEnergy" << std::endl;
107 utility_exit_with_message(
"Exiting");
108 if (
this != &other ) {
165 for ( i_multi_data = 1; i_multi_data <= pcs_d_c_m.
get_n_multi_data(); ++i_multi_data){
199 using namespace basic::options;
200 using namespace basic::options::OptionKeys;
206 for(i_multi_data = 1; i_multi_data <= n_multi_data; ++i_multi_data ){
223 for( i2 = 1; i2 <= vec_filename.size() ; i2++ ){
228 if(vec_filename.size() == 0){
229 utility_exit_with_message(
"Missing input file for PCS. Review your setup file");
240 pcs_d_c_OP =
new PcsDataCenter(pcs_i_c, start, end, individual_scale);
243 (*pcs_d_c_m_OP).get_PCS_data_all().push_back(*pcs_d_c_OP);
253 return *pcs_d_c_m_OP;
272 using namespace basic::options;
273 using namespace basic::options::OptionKeys;
274 using namespace core;
280 if( option[ basic::options::OptionKeys::PCS::write_extra ].user() ){
283 std::string file_dump (option[ basic::options::OptionKeys::PCS::write_extra ]());
285 std::ofstream myfile;
287 myfile.open (file_dump.c_str(), std::ios::out);
288 myfile <<
"# Tensor: Xxx Xxy Xxz Xyy Xyz x y z" << std::endl;
289 myfile <<
"# Spins: res_num atom_name PCS_exp PCS_calc PCS_dev PCS_abs_dev" << std::endl;
292 myfile.open (file_dump.c_str(), std::ios::app);
294 if (!myfile.is_open ()){
295 std::cerr <<
"Unable to open the file '" << file_dump <<
"'" << std::endl;
308 myfile <<
"#" << PCS_d_p_l.get_filename() <<
" RESCORE NUMBER " << n_rescore << std::endl;
319 myfile <<
"# Tensor: " << std::setw(10) << Xxx <<
" " << Xxy <<
" " << Xxz <<
" " << Xyy <<
" " << Xyz <<
" " << best_coo.x() <<
" " << best_coo.y() <<
" " << best_coo.z() << std::endl;
321 for ( j = 1; j <= PCS_d_p_l.get_n_pcs(); ++j){
327 core::Size res_num(PCS_d_l_a_s[idx].get_residue_num());
328 std::string atom_name(PCS_d_l_a_s[idx].get_atom_name());
330 r5 =
fill_A_line_fast(A, best_coo.x(), best_coo.y(), best_coo.z(), x, y, z);
331 core::Real PCS_calc(A[1]*Xxx + A[2]*Xxy + A[3]*Xxz + A[4]*Xyy + A[5]*Xyz);
334 core::Real PCS_abs_dev (fabs(PCS_exp - PCS_calc));
335 myfile << res_num <<
" " << atom_name << std::setw(10) << PCS_exp <<
" " << PCS_calc<<
" " << PCS_dev<<
" " << PCS_abs_dev<<
" " << std::endl;
351 using namespace core;
352 using namespace basic::options;
353 using namespace basic::options::OptionKeys;
365 if (pcs_weight_center == 0){
372 vec_tensor.push_back(PCS_t);
388 return (pcs_weight_center * pcs_score_total);
404 best_coo.assign(vect_to_opti[1], vect_to_opti[2], vect_to_opti[3]);
406 for(i = 1; i <= vec_best_tensor.size(); ++i){
407 vec_best_tensor[i].reset_tensor((
core::Real)vect_to_opti[3 + 5*(i-1) + 1],
413 return (optimized_cost);
428 best_coo.assign(vect_to_opti[1], vect_to_opti[2], vect_to_opti[3]);
430 return (optimized_cost);
447 utility_exit_with_message(
"n_lanthanides and vec_best_tensor size differs in minimize_tensors_from_PCS_data");
450 for(i = 1; i <= vec_best_tensor.size(); ++i){
451 vect_to_opt.push_back(vec_best_tensor[i].get_chi_xx());
452 vect_to_opt.push_back(vec_best_tensor[i].get_chi_xy());
453 vect_to_opt.push_back(vec_best_tensor[i].get_chi_xz());
454 vect_to_opt.push_back(vec_best_tensor[i].get_chi_yy());
455 vect_to_opt.push_back(vec_best_tensor[i].get_chi_yz());
467 for(i = 1; i <= vec_best_tensor.size(); ++i){
468 vec_best_tensor[i].reset_tensor((
core::Real)vect_to_opt[5*(i-1) + 1],
474 return (optimized_cost);
511 size_of = vec_best_score.size();
512 if((size_of != vec_best_tensor.size())||
514 std::cerr <<
"Problem in CA_search_scores_and_tensors function" << std::endl;
516 std::cerr <<
"vec_best_tensor.size() = " << vec_best_tensor.size();
517 std::cerr <<
"vec_best_score.size() = " << vec_best_score.size() << std::endl;
518 utility_exit_with_message(
"Exiting");
521 for( i = 1; i <= size_of; i++){
522 vec_tensor_temp.push_back(vec_best_tensor[i]);
525 vec_score_temp.resize(size_of);
528 vec_score_ref_current = & vec_score_temp;
529 vec_tensor_ref_current = & vec_tensor_temp;
532 best_coo.assign(0, 0, 0);
539 vec_tensor_junk.push_back(PCS_t_junk);
543 best_score = 999999999999999999999999999.9;
544 bool test_at_least_one_iteration =
false;
550 vect_to_opti.push_back(0);
551 vect_to_opti.push_back(0);
552 vect_to_opti.push_back(0);
555 vect_to_opti.push_back(0);
556 vect_to_opti.push_back(0);
557 vect_to_opti.push_back(0);
558 vect_to_opti.push_back(0);
559 vect_to_opti.push_back(0);
568 if(n_best_found > n_identical){
569 TR_PcsEnergy <<
"Found " << n_best_found <<
" the same value -> best score" << std::endl;
573 test_at_least_one_iteration =
true;
575 temp_coo.assign(x, y, z);
591 vect_to_opti[3 + (ii-1)*5 + 1] = pcs_t.
get_chi_xx();
592 vect_to_opti[3 + (ii-1)*5 + 2] = pcs_t.
get_chi_xy();
593 vect_to_opti[3 + (ii-1)*5 + 3] = pcs_t.
get_chi_xz();
594 vect_to_opti[3 + (ii-1)*5 + 4] = pcs_t.
get_chi_yy();
595 vect_to_opti[3 + (ii-1)*5 + 5] = pcs_t.
get_chi_yz();
604 if(fabs(score - best_score) < epsilon){
608 if ( score < best_score){
609 if(best_score - score > epsilon){
613 (*vec_tensor_ref_current)[i] = vec_tensor_junk[i];
618 if ( score < best_score){
621 best_coo.assign(temp_coo.x(), temp_coo.y(), temp_coo.z());
624 if((vec_score_ref_current != &vec_score_temp) && (vec_score_ref_current != &vec_best_score)){
625 std::cerr <<
"Problem in grid_search_scores_and_tensors function" << std::endl;
626 std::cerr <<
"The atomic switch is not working (1)" << std::endl;
627 utility_exit_with_message(
"Exiting");
629 if(vec_tensor_ref_current == &vec_best_tensor){
630 vec_tensor_ref_current = &vec_tensor_temp;
631 vec_score_ref_current = &vec_score_temp;
634 if(vec_tensor_ref_current != &vec_tensor_temp){
635 std::cerr <<
"Problem in grid_search_scores_and_tensors function" << std::endl;
636 std::cerr <<
"The atomic switch is not working (2)" << std::endl;
637 utility_exit_with_message(
"Exiting");
639 vec_tensor_ref_current = &vec_best_tensor;
640 vec_score_ref_current = &vec_best_score;
647 if(!(n_best_found > n_identical)){
651 if(test_at_least_one_iteration ==
false){
652 utility_exit_with_message(
"The description of the grid search given is too restrictive");
655 if( vec_tensor_ref_current == &vec_best_tensor ){
656 for(i = 1; i <= vec_best_score.size(); ++i){
657 vec_best_tensor[i].reset_from_ref(vec_tensor_temp[i]);
661 if( vec_score_ref_current == &vec_best_score ){
662 for(i = 1; i <= vec_best_score.size(); ++i){
663 vec_best_score[i] = vec_score_temp[i];
699 size_of = vec_best_score.size();
700 if((size_of != vec_best_tensor.size())||
702 std::cerr <<
"Problem in CA_search_scores_and_tensors function" << std::endl;
704 std::cerr <<
"vec_best_tensor.size() = " << vec_best_tensor.size();
705 std::cerr <<
"vec_best_score.size() = " << vec_best_score.size() << std::endl;
706 utility_exit_with_message(
"Exiting");
709 for( i = 1; i <= size_of; i++){
710 vec_tensor_temp.push_back(vec_best_tensor[i]);
713 vec_score_temp.resize(size_of);
716 vec_score_ref_current = & vec_score_temp;
717 vec_tensor_ref_current = & vec_tensor_temp;
720 best_coo.assign(0, 0, 0);
727 vec_tensor_junk.push_back(PCS_t_junk);
732 best_score = 999999999999999999999999999.9;
733 bool test_at_least_one_iteration =
false;
740 vect_to_opti.push_back(0);
741 vect_to_opti.push_back(0);
742 vect_to_opti.push_back(0);
748 if(n_best_found > n_identical){
749 TR_PcsEnergy <<
"Found " << n_best_found <<
" the same value -> best score" << std::endl;
753 test_at_least_one_iteration =
true;
755 temp_coo.assign(x, y, z);
768 if(fabs(score - best_score) < epsilon){
772 if ( score < best_score){
773 if(best_score - score > epsilon){
777 (*vec_tensor_ref_current)[i] = vec_tensor_junk[i];
782 if ( score < best_score){
785 best_coo.assign(temp_coo.x(), temp_coo.y(), temp_coo.z());
788 if((vec_score_ref_current != &vec_score_temp) && (vec_score_ref_current != &vec_best_score)){
789 std::cerr <<
"Problem in grid_search_scores_and_tensors function" << std::endl;
790 std::cerr <<
"The atomic switch is not working (1)" << std::endl;
791 utility_exit_with_message(
"Exiting");
793 if(vec_tensor_ref_current == &vec_best_tensor){
794 vec_tensor_ref_current = &vec_tensor_temp;
795 vec_score_ref_current = &vec_score_temp;
798 if(vec_tensor_ref_current != &vec_tensor_temp){
799 std::cerr <<
"Problem in grid_search_scores_and_tensors function" << std::endl;
800 std::cerr <<
"The atomic switch is not working (2)" << std::endl;
801 utility_exit_with_message(
"Exiting");
803 vec_tensor_ref_current = &vec_best_tensor;
804 vec_score_ref_current = &vec_best_score;
811 if(!(n_best_found > n_identical)){
815 if(test_at_least_one_iteration ==
false){
816 utility_exit_with_message(
"The description of the grid search given is too restrictive");
819 if( vec_tensor_ref_current == &vec_best_tensor ){
820 for(i = 1; i <= vec_best_score.size(); ++i){
821 vec_best_tensor[i].reset_from_ref(vec_tensor_temp[i]);
825 if( vec_score_ref_current == &vec_best_score ){
826 for(i = 1; i <= vec_best_score.size(); ++i){
827 vec_best_score[i] = vec_score_temp[i];