51 #include <basic/options/option.hh>
52 #include <basic/options/keys/OptionKeys.hh>
53 #include <basic/options/keys/in.OptionKeys.gen.hh>
54 #include <basic/options/keys/out.OptionKeys.gen.hh>
55 #include <basic/options/keys/run.OptionKeys.gen.hh>
56 #include <basic/options/keys/frags.OptionKeys.gen.hh>
57 #include <basic/options/keys/relax.OptionKeys.gen.hh>
58 #include <basic/Tracer.hh>
59 #include <numeric/xyz.functions.hh>
60 #include <numeric/xyzVector.hh>
61 #include <utility/exit.hh>
62 #include <utility/file/file_sys_util.hh>
63 #include <numeric/random/random.hh>
68 static numeric::random::RandomGenerator
RG(10420);
71 namespace frag_picker {
76 static basic::Tracer
TR(
"protocols.frag_picker.nonlocal.NonlocalFrags");
79 using namespace basic::options;
80 using namespace basic::options::OptionKeys;
83 option.add_relevant( in::file::s );
84 option.add_relevant( in::file::l );
85 option.add_relevant( in::file::list );
86 option.add_relevant( frags::nonlocal::single_chain );
88 option.add_relevant( frags::nonlocal::relax_input );
89 option.add_relevant( frags::nonlocal::relax_input_with_coordinate_constraints );
90 option.add_relevant( frags::nonlocal::relax_frags_repeats );
91 option.add_relevant( frags::contacts::min_seq_sep );
92 option.add_relevant( frags::contacts::dist_cutoffs );
94 option.add_relevant( frags::nonlocal::min_contacts_per_res );
95 option.add_relevant( frags::nonlocal::max_rmsd_after_relax );
98 option.add_relevant( frags::nonlocal::output_idealized );
99 option.add_relevant( frags::nonlocal::output_frags_pdbs );
101 option.add_relevant( frags::frag_sizes );
105 single_chain_( false ),
106 relax_input_( false ),
107 relax_input_with_coordinate_constraints_( false ),
108 relax_frags_repeats_( 1 ),
109 checkpointfile_(
"nonlocalfrags.checkpoint" ),
111 ca_dist_squared_( 100.0 ),
112 min_contacts_per_res_( 1 ),
113 max_rmsd_after_relax_( 1.5 ),
114 max_ddg_score_( -4.0 ),
115 output_frags_pdbs_( false ),
116 output_idealized_( false )
122 using namespace basic::options;
123 using namespace basic::options::OptionKeys;
125 if (!option[ in::file::s ].user() && !option[ in::file::l ].user() && !option[ in::file::list ].user()) {
126 utility_exit_with_message(
"Error: in:file:s or in:file:l option required!" );
128 if (option[ frags::nonlocal::single_chain ].user()) {
131 if (option[ frags::nonlocal::relax_input ].user()) {
132 relax_input_ = option[ frags::nonlocal::relax_input ]();
134 if (option[ frags::nonlocal::relax_input_with_coordinate_constraints ].user()) {
137 if (option[ frags::nonlocal::relax_frags_repeats ].user()) {
141 if (option[ frags::contacts::min_seq_sep ].user()) {
142 min_seq_sep_ = option[ frags::contacts::min_seq_sep ]();
144 if (option[ frags::contacts::dist_cutoffs ].user()) {
146 if (dist_cutoffs.size() != 1)
147 utility_exit_with_message(
"Error: only one frags::contacts::dist_cutoffs value is allowed!" );
148 Real min_dist = dist_cutoffs[1];
151 if (option[ frags::nonlocal::min_contacts_per_res ].user()) {
155 if (option[ frags::nonlocal::max_ddg_score ].user()) {
158 if (option[ frags::nonlocal::max_rmsd_after_relax ].user()) {
162 if (option[ frags::frag_sizes ].user()) {
167 if (option[ frags::nonlocal::output_idealized ].user()) {
171 if (option[ frags::nonlocal::output_frags_pdbs ].user()) {
176 option[ out::file::silent_struct_type ].value(
"binary");
182 std::map<std::string, std::string>::iterator it;
187 TR.Info <<
"Recovered checkpoint " << tag << std::endl;
194 std::ofstream checkpoint(
checkpointfile_.c_str(), std::ios_base::app );
195 if (!checkpoint.good()) {
196 TR.Debug <<
"Warning: cannot open checkpoint file for writing!" << std::endl;
202 boinc_begin_critical_section();
205 Size pdbinfonumberj, pdbinfonumberk, contact_cnt;
206 Real sub_pose_score, relaxed_rmsd, relaxed_score, relaxed_ddg_score;
208 std::istringstream line_stream(data);
209 line_stream >> pdbinfonumberj >> chainj >> pdbinfonumberk >> chaink >>
210 contact_cnt >> sub_pose_score >> relaxed_rmsd >> relaxed_score >> relaxed_ddg_score;
211 if (line_stream.fail()) {
212 TR.Debug <<
"Warning: cannot parse checkpoint data!" << std::endl;
215 checkpoint << tag <<
" " << data << std::endl;
218 checkpoint << tag << std::endl;
222 boinc_end_critical_section();
224 TR.Info <<
"Write checkpoint " << tag << std::endl;
231 while( getline(checkpoint,line) ) {
232 Size pdbinfonumberj, pdbinfonumberk, contact_cnt;
233 Real sub_pose_score, relaxed_rmsd, relaxed_score, relaxed_ddg_score;
236 std::istringstream line_stream(line);
238 if (line_stream.eof()) {
241 line_stream >> pdbinfonumberj >> chainj >> pdbinfonumberk >> chaink >>
242 contact_cnt >> sub_pose_score >> relaxed_rmsd >> relaxed_score >> relaxed_ddg_score;
243 if (line_stream.fail()) utility_exit_with_message(
"Error: checkpoint file parse error!" );
244 std::stringstream data;
245 data << pdbinfonumberj <<
" " << chainj <<
" " << pdbinfonumberk <<
" " << chaink <<
246 " " << contact_cnt <<
" " << sub_pose_score <<
" " << relaxed_rmsd <<
" " << relaxed_score <<
247 " " << relaxed_ddg_score;
250 TR.Info <<
"Read checkpoint " << tag << std::endl;
256 using namespace basic::options;
257 using namespace basic::options::OptionKeys;
267 jd->job_outputter()->clear_evaluators();
272 Real unmodified_pose_score = (*scorefxn)( pose );
276 #ifdef BOINC_GRAPHICS
279 protocols::boinc::Boinc::attach_graphics_current_pose_observer( pose );
285 #ifdef BOINC_GRAPHICS
287 protocols::boinc::Boinc::update_graphics_low_energy( pose, unmodified_pose_score );
288 protocols::boinc::Boinc::update_graphics_last_accepted( pose, unmodified_pose_score );
289 protocols::boinc::Boinc::update_mc_trial_info( step_cnt++,
"Relax_" + input_tag );
293 option[OptionKeys::relax::constrain_relax_to_start_coords].value(
true);
297 bool origval = option[run::delete_checkpoints]();
298 option[run::delete_checkpoints].value(
false);
300 relax_protocol->set_current_tag( output_name );
301 relax_protocol->apply( pose );
303 option[run::delete_checkpoints].value(origval);
307 option[OptionKeys::relax::constrain_relax_to_start_coords].value(
false);
316 for (
Size ii = 1; ii <= unmodified_pose.total_residue(); ++ii ) {
324 std::stringstream scorestr;
325 scorestr << unmodified_pose_score;
343 Size total_len = frag_len*2;
348 #ifdef BOINC_GRAPHICS
350 Real min_relaxed_score = 100000000.0;
354 Size contact_cnt = 0;
355 bool continue_k =
false;
357 for (
Size k=j+frag_len+min_seq_sep_; k<=total_residue-frag_len; ++k ) {
361 std::stringstream sstream;
362 sstream <<
"_" << frag_len <<
"_" << j <<
"_" << k;
367 #ifdef BOINC_GRAPHICS
368 protocols::boinc::Boinc::update_mc_trial_info( step_cnt++,
"NonLocalFrags_" + input_tag + tag );
379 Size prev_chain_m, prev_chain_n;
380 Size prev_resnum_m, prev_resnum_n;
382 for (
Size m=0; m<frag_len; ++m) {
384 if (!rsd_m.
has(
"CA") || !rsd_m.
is_protein()) { continue_k =
true;
break; }
386 Size resnum_m = pdbinfo->number(j+m);
389 if (m>0 && (chain_m != prev_chain_m || resnum_m != prev_resnum_m+1 ||
390 ca_xyz_m.distance_squared(prev_ca_xyz_m) > 25)) {
391 continue_k =
true;
break;
393 prev_chain_m = chain_m;
394 prev_resnum_m = resnum_m;
395 prev_ca_xyz_m = ca_xyz_m;
396 for (
Size n=0; n<frag_len; ++n) {
400 Size resnum_n = pdbinfo->number(k+n);
403 if (n>0 && (chain_n != prev_chain_n || resnum_n != prev_resnum_n+1 ||
404 ca_xyz_n.distance_squared(prev_ca_xyz_n) > 25)) {
405 continue_k =
true;
break;
407 prev_chain_n = chain_n;
408 prev_resnum_n = resnum_n;
409 prev_ca_xyz_n = ca_xyz_n;
412 if (continue_k)
break;
415 if (!continue_k && contact_cnt >= min_contacts) {
418 #ifdef BOINC_GRAPHICS
419 protocols::boinc::Boinc::update_mc_trial_info( step_cnt++,
"NonLocalFrags_" + input_tag + tag );
422 Size midpoint =
static_cast<Size>(ceil(frag_len / 2.0));
424 int jump_id = tree.
new_jump( midpoint, frag_len+midpoint, frag_len );
430 for (
Size m=0; m<frag_len; ++m) positions.push_back( j+m );
431 for (
Size m=0; m<frag_len; ++m) positions.push_back( k+m );
435 sub_pose.conformation().detect_disulfides();
438 sub_pose.conformation().insert_chain_ending( frag_len );
442 Real sub_pose_score = (*scorefxn)( sub_pose );
443 #ifdef BOINC_GRAPHICS
444 protocols::boinc::Boinc::attach_graphics_current_pose_observer( relax_sub_pose );
445 protocols::boinc::Boinc::update_graphics_low_energy( relax_sub_pose, sub_pose_score );
447 sub_pose_relax_protocol->set_current_tag( output_name + tag );
448 sub_pose_relax_protocol->apply( relax_sub_pose );
456 Real relaxed_score = (*scorefxn)( relax_sub_pose );
460 Real relaxed_ddg_score = ddg.compute( relax_sub_pose );
466 #ifdef BOINC_GRAPHICS
467 if (relaxed_score < min_relaxed_score) {
468 min_relaxed_score = relaxed_score;
469 best_energy_pose = relax_sub_pose;
470 protocols::boinc::Boinc::update_graphics_low_energy( best_energy_pose, min_relaxed_score, protocols::boinc::Boinc::PERSIST );
478 std::stringstream pair_data;
479 pair_data << pdbinfo->number(j) <<
" " << pdbinfo->chain(j) <<
" " << pdbinfo->number(k) <<
" " << pdbinfo->chain(k) <<
480 " " << contact_cnt <<
" " << sub_pose_score <<
" " << relaxed_rmsd <<
" " << relaxed_score <<
" " << relaxed_ddg_score;
487 TR.Debug << output_name << tag <<
" " << pair_data.str() << std::endl;
492 #ifdef BOINC_GRAPHICS
493 protocols::boinc::Boinc::update_graphics_last_accepted( relax_sub_pose, relaxed_score );
511 #ifdef BOINC_GRAPHICS
512 Real score = (*scorefxn)(idealize_pose);
513 protocols::boinc::Boinc::attach_graphics_current_pose_observer( idealize_pose );
514 protocols::boinc::Boinc::update_graphics_last_accepted( idealize_pose, score );
515 protocols::boinc::Boinc::update_graphics_low_energy( idealize_pose, score, protocols::boinc::Boinc::RESET );
516 protocols::boinc::Boinc::update_mc_trial_info( step_cnt++,
"Idealize_" + input_tag );
520 TR.Info <<
"Idealize pose" << std::endl;
522 idealizer.
fast(
false );
524 idealizer.
apply( idealize_pose );
525 Real idealize_score = (*scorefxn)(idealize_pose);
527 std::stringstream scorestr;
528 scorestr << idealize_score;
531 #ifdef BOINC_GRAPHICS
532 protocols::boinc::Boinc::update_mc_trial_info( step_cnt++,
"Relax_" + input_tag );
538 option[OptionKeys::relax::constrain_relax_to_start_coords].value(
true);
542 bool origval = option[run::delete_checkpoints]();
543 option[run::delete_checkpoints].value(
false);
545 relax_protocol->set_current_tag( output_name +
"_ideal" );
547 relax_protocol->apply( idealize_pose );
549 option[run::delete_checkpoints].value(origval);
553 option[OptionKeys::relax::constrain_relax_to_start_coords].value(
false);
562 for (
Size ii = 1; ii <= unmodified_pose.total_residue(); ++ii ) {
572 boinc_begin_critical_section();
580 std::string origprefix = option[ out::prefix ].value();
581 option[ out::prefix ].value(
"relaxed_");
582 if (!jd->job_outputter()->job_has_completed( jd->current_job() ) && relaxed_pose.total_residue()) {
583 (*scorefxn)(relaxed_pose);
584 jd->job_outputter()->final_pose( jd->current_job(), relaxed_pose );
586 option[ out::prefix ].value(origprefix);
592 return "NonlocalFrags";