Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FastRelax.cc
Go to the documentation of this file.
1 // -*- mode:c++;tab-width:2;indent-tabs-mode:t;show-trailing-whitespace:t;rm-trailing-spaces:t -*-
2 // vi: set ts=2 noet:
3 //
4 // (c) Copyright Rosetta Commons Member Institutions.
5 // (c) This file is part of the Rosetta software suite and is made available under license.
6 // (c) The Rosetta software is developed by the contributing members of the Rosetta Commons.
7 // (c) For more information, see http://www.rosettacommons.org. Questions about this can be
8 // (c) addressed to University of Washington UW TechTransfer, email: license@u.washington.edu.
9 
10 /// @file src/protocols/relax/FastRelax.cc
11 /// @brief The FastRelax Protocol
12 /// @detailed
13 /// @author Mike Tyka
14 /// @author Roland A. Pache
15 
16 /*
17 Format for relax script file
18 
19 repeat <loopcount>
20 
21 starts a section to be repeated <loopcount> times - end the block with "endrepeat".
22 Nested loop are NOT supported.
23 
24 endrepeat
25 
26 is the end marker of a loop. loops may *NOT* be nested! (this is not a programming language. well it is. but a very simple one.)
27 
28 accept_to_best
29 
30 compares the energy of the current pose and the best_pose and replaces the best pose
31 with the current pose if it's energy is lower.
32 
33 load_best
34 
35 Load the best_pose into the current working pose, replacing it.
36 
37 load_start
38 
39 Load the starting pose into the current working pose, replacing it.
40 
41 Sets the best_pose to the current pose whatever the energy of the current pose.
42 
43 dump <number>
44 
45 DUmps a pdbfile called dump_<number>.pdb
46 
47 dumpall:<true/false>
48 
49 Will dump a pdb for every repack/min/ramp_repack_min hereafter with an incrementing number
50 
51 scale:<scoretype> <scale>
52 
53 Scales the scoretype's default value by whatever the scale number is.
54 For ex, scale:fa_rep 0.1 will take the original fa_rep weight and set it
55 to 0.1 * original weight.
56 
57 rscale:<scoretype> <lower limit> <upper limit>
58 
59 Like scale, but picks a random number between the limits to multiply by
60 
61 weight:<scoretype> <weight>
62 
63 Sets the weight of the scoretype to whatever the weight number is.
64 ALSO CHANGES DEFAULT WEIGHT. This is so in weight, scale, scale routines
65 the scale will be using the user-defined weight, which seems to make more sense.
66 For ex, weight:fa_rep 0.2 will take set fa_rep to 0.2
67 
68 show_weights
69 
70 Outputs the current weights. If a parameter is not outputted, then its weight
71 is 0. Most useful when redirecting stdout to a file, and only one input structure.
72 
73 coord_cst_weight <scale>
74 
75 Sets the coordinate_constraint weight to <scale>*start_weight.
76 This is used when using the commandline options -constrain_relax_to_native_coords and
77 -constrain_relax_to_start_coords.
78 
79 switch:<torsion/cartesian>
80 
81 Switches to the torsion minimizer (AtomTreeMinimzer, dfp minimizer) or the cartesian
82 minimizer (CartesianMinimizer, lbfgs). Obviously ignores command line flags.
83 
84 repack
85 
86 Triggers a full repack
87 
88 min <tolerance>
89 
90 Triggers a dfp minimization with a given tolernace (0.001 is a decent value)
91 
92 ramp_repack_min <scale:fa_rep> <min_tolerance> [ <coord_cst_weight = 0.0> ]
93 
94 Causes a typical ramp, then repack then minimize cycle - i.e. bascially combines
95 the three commands scale:fa_rep, repack and min (and possible coord_cst_weight)
96 
97 These two command scripts are equivalent:
98 --------
99 scale:fa_rep 0.5
100 repack
101 min 0.001
102 --------
103 and
104 
105 --------
106 ramp_repack_min 0.5 0.001
107 --------
108 
109 batch_shave <keep_proportion>
110 
111 Valid for batchrelax only - ignored in normal FastRelax
112 In Batchrelax it will remove the worst structures from the current pool and leave only
113 <keep_proportion>. I.e. the command
114 
115 batch_shave 0.75
116 
117 Will remove the worst 75% of structures from the current working pool.
118 
119 
120 exit
121 
122 will quit with immediate effect
123 
124 
125 
126 
127 A typical FastRelax command_script is: (thi sin fact is the default command script)
128 
129 repeat 5
130 ramp_repack_min 0.02 0.01 1.0
131 ramp_repack_min 0.250 0.01 0.5
132 ramp_repack_min 0.550 0.01 0.0
133 ramp_repack_min 1 0.00001 0.0
134 accept_to_best
135 endrepeat
136 
137 
138 
139 
140 */
141 //Project Headers
143 #include <protocols/relax/Ramady.hh>
145 #include <protocols/relax/util.hh>
146 
147 //Core Headers
149 #include <core/io/pdb/pose_io.hh>
153 #include <core/kinematics/util.hh>
156 #include <core/pose/Pose.hh>
157 #include <core/pose/util.hh>
161 #include <core/scoring/rms_util.hh>
163 #include <core/scoring/ScoreType.hh>
165 
166 //Protocol Headers
172 #include <utility/excn/Exceptions.hh>
177 
178 //Basic Headers
179 #include <basic/options/keys/run.OptionKeys.gen.hh>
180 #include <basic/options/keys/relax.OptionKeys.gen.hh>
181 #include <basic/options/keys/evaluation.OptionKeys.gen.hh>
182 #include <basic/options/option.hh>
183 #include <basic/Tracer.hh>
184 
185 //Utility Headers
186 #include <utility/tag/Tag.hh>
187 #include <utility/string_util.hh>
188 #include <utility/vector0.hh>
189 #include <utility/vector1.hh>
190 #include <numeric/random/random.fwd.hh>
191 
192 // ObjexxFCL Headers
193 #include <ObjexxFCL/string.functions.hh>
194 
195 //C++ Headers
196 #include <fstream>
197 
198 
199 
200 #ifdef GL_GRAPHICS
202 #endif
203 
204 #if defined(WIN32) || defined(__CYGWIN__)
205  #include <ctime>
206 #endif
207 
208 #ifdef BOINC_GRAPHICS
209 #include <protocols/boinc/boinc.hh>
210 #endif
211 
212 using basic::T;
213 using basic::Error;
214 using basic::Warning;
215 
216 static basic::Tracer TR("protocols.relax.FastRelax");
217 
218 using namespace core;
219 using namespace core::io::silent ;
220 using io::pdb::dump_pdb;
221 ////////////////////////////////////////////////////////////////////////////////////////////////////
222 
223 namespace protocols {
224 namespace relax {
225 ////////////////////////////////////////////////////////////////////////////////////////////////////
226 
227 
228 
229 using namespace ObjexxFCL;
230 
231 
232 
233 
235 FastRelaxCreator::keyname() const
236 {
237  return FastRelaxCreator::mover_name();
238 }
239 
241 FastRelaxCreator::create_mover() const {
242  return new FastRelax();
243 }
244 
246 FastRelaxCreator::mover_name()
247 {
248  return "FastRelax";
249 }
250 
251 
252 
253 
254 
255 
256 
257 
258 
259 /// ---------------------------------------------------------------------------------
260 /// FastRelax main code:
261 /// ---------------------------------------------------------------------------------
262 
263 FastRelax::FastRelax(
264  core::Size standard_repeats
265 ) :
266  RelaxProtocolBase("FastRelax" ),
267  checkpoints_("FastRelax"),
268  movemap_tag_( NULL )
269 {
270  set_to_default();
271  if( standard_repeats == 0 ) standard_repeats = default_repeats_;
273  read_script_file( "NO CST RAMPING", standard_repeats );
274  } else {
275  read_script_file( "", standard_repeats );
276  }
277 }
278 
279 
280 
282  core::scoring::ScoreFunctionOP scorefxn_in,
283  core::Size standard_repeats
284 ) :
285  RelaxProtocolBase("FastRelax", scorefxn_in ),
286  checkpoints_("FastRelax"),
287  movemap_tag_( NULL )
288 {
289  set_to_default();
290  if( standard_repeats == 0 ) standard_repeats = default_repeats_;
292  read_script_file( "NO CST RAMPING", standard_repeats );
293  } else {
294  read_script_file( "", standard_repeats );
295  }
296 }
297 
298 
299 
301  core::scoring::ScoreFunctionOP scorefxn_in,
302  const std::string & script_file
303 ) :
304  RelaxProtocolBase("FastRelax", scorefxn_in ),
305  checkpoints_("FastRelax"),
306  movemap_tag_( NULL )
307 {
308  set_to_default();
309  read_script_file( script_file );
310 }
311 
313  core::scoring::ScoreFunctionOP scorefxn_in,
314  core::Size standard_repeats,
315  const std::string & script_file
316 ) :
317  RelaxProtocolBase("FastRelax", scorefxn_in ),
318  checkpoints_("FastRelax"),
319  movemap_tag_( NULL )
320 {
321  set_to_default();
322  if( standard_repeats == 0 ) standard_repeats = default_repeats_;
323  read_script_file( script_file , standard_repeats );
324 }
325 
326 /// @brief destructor - this class has no dynamic allocation, so
327 //// nothing needs to be cleaned. C++ will take care of that for us.
329 
330 
331 /// Return a copy of ourselves
334  return new FastRelax(*this);
335 }
336 
337 void
339  utility::tag::TagPtr const tag,
343  core::pose::Pose const & pose
344 ) {
345  std::string const scorefxn( tag->getOption<std::string>( "scorefxn", "score12" ));
346  //set_scorefxn( new core::scoring::ScoreFunction( *data.get< core::scoring::ScoreFunction * >( "scorefxns", scorefxn) ) );
347  //fpd ^^^ please use clone()
348  set_scorefxn( data.get< core::scoring::ScoreFunction * >( "scorefxns", scorefxn)->clone() );
349 
351  mm->set_chi( true );
352  mm->set_bb( true );
353  mm->set_jump( true );
354 
356 
357  // initially, all backbone torsions are movable
358  protocols::rosetta_scripts::parse_movemap( tag, pose, mm, data, false);
359  set_movemap(mm);
360 
361  default_repeats_ = tag->getOption< int >( "repeats", 8 );
362  std::string script_file = tag->getOption< std::string >("relaxscript", "" );
363 
364  bool batch = tag->getOption< bool >( "batch", false );
365  cartesian (tag->getOption< bool >( "cartesian", false ) );
366 
367  if (batch) {
369  } else if( script_file == "" ) {
371  } else {
372  read_script_file( script_file );
373  }
374 }
375 
376 void FastRelax::parse_def( utility::lua::LuaObject const & def,
377  utility::lua::LuaObject const & score_fxns,
378  utility::lua::LuaObject const & tasks,
380  if( def["scorefxn"] ) {
381  set_scorefxn( protocols::elscripts::parse_scoredef( def["scorefxn"], score_fxns ) );
382  } else {
383  set_scorefxn( score_fxns["score12"].to<core::scoring::ScoreFunctionSP>()->clone() );
384  }
385 
387  mm->set_chi( true );
388  mm->set_bb( true );
389  mm->set_jump( true );
390  // initially, all backbone torsions are movable
391  if( def["movemap"] )
392  protocols::elscripts::parse_movemapdef( def["movemap"], mm );
393  set_movemap(mm);
394 
395  if( def["tasks"] ) {
396  core::pack::task::TaskFactoryOP new_task_factory( protocols::elscripts::parse_taskdef( def["tasks"], tasks ));
397  if ( new_task_factory == 0) return;
398  set_task_factory(new_task_factory);
399  }
400 
401  default_repeats_ = def["repeats"] ? def["repeats"].to<int>() : 8;
402  std::string script_file = def["relaxscript"] ? def["relaxscript"].to<std::string>() : "";
403 
404  bool batch = def["batch"] ? def["batch"].to<bool>() : false;
405  cartesian (def["cartesian"] ? def["cartesian"].to<bool>() : false );
406 
407  if (batch) {
409  } else if( script_file == "" ) {
411  } else {
412  read_script_file( script_file );
413  }
414 }
415 
416 ////////////////////////////////////////////////////////////////////////////////////////////////////
418 {
419  using namespace basic::options;
420 
421  default_repeats_ = basic::options::option[ OptionKeys::relax::default_repeats ]();
422  ramady_ = basic::options::option[ OptionKeys::relax::ramady ]();
423  repack_ = basic::options::option[ OptionKeys::relax::chi_move]();
424  test_cycles_ = basic::options::option[ OptionKeys::run::test_cycles ]();
425  script_max_accept_ = basic::options::option[ OptionKeys::relax::script_max_accept ]();
426  symmetric_rmsd_ = option[ basic::options::OptionKeys::evaluation::symmetric_rmsd ]();
427 
428  force_nonideal_ = false;
429 
430  //fpd additional ramady options
431  ramady_num_rebuild_ = basic::options::option[ OptionKeys::relax::ramady_max_rebuild ]();
432  ramady_cutoff_ = basic::options::option[ OptionKeys::relax::ramady_cutoff ]();
433  ramady_force_ = basic::options::option[ OptionKeys::relax::ramady_force ]();
434  ramady_rms_limit_ = basic::options::option[ OptionKeys::relax::ramady_rms_limit ]();
435 
436  // cartesian
437 
438  // dumpall
439  dumpall_ = false;
440 
441 }
442 
443 
444 
445 // grab the score and remember the pose if the score is better then ever before.
447  const core::scoring::ScoreFunctionOP local_scorefxn,
448  core::pose::Pose &pose,
449  core::pose::Pose &best_pose,
450  const core::pose::Pose &start_pose,
451  core::Real &best_score,
452  core::Size &accept_count
453 )
454 {
455  using namespace core::scoring;
456  using namespace core::conformation;
457  core::Real score = (*local_scorefxn)( pose );
458  if( ( score < best_score) || (accept_count == 0) ){
459  best_score = score;
460  best_pose = pose;
461  }
462  #ifdef BOINC_GRAPHICS
463  boinc::Boinc::update_graphics_low_energy( best_pose, best_score );
464  boinc::Boinc::update_graphics_last_accepted( pose, score );
465  //boinc::Boinc::update_mc_trial_info( total_count , "FastRelax" ); // total_count not defined
466  #endif
467  core::Real rms = 0, irms = 0;
469  rms = CA_rmsd_symmetric( *get_native_pose() , best_pose );
470  irms = CA_rmsd_symmetric( start_pose , best_pose );
471  } else {
472  rms = native_CA_rmsd( *get_native_pose() , best_pose );
473  irms = native_CA_rmsd( start_pose , best_pose );
474  }
475  TR << "MRP: " << accept_count << " " << score << " " << best_score << " " << rms << " " << irms << " " << std::endl;
476 }
477 
478 
480  core::pose::Pose &pose,
481  core::Real tolerance,
482  core::kinematics::MoveMapOP local_movemap,
483  core::scoring::ScoreFunctionOP local_scorefxn
484 ){
485  using namespace core::scoring;
486  using namespace core::conformation;
487 
489  if ( core::pose::symmetry::is_symmetric( pose ) ) {
490  min_mover = new simple_moves::symmetry::SymMinMover( local_movemap, local_scorefxn, min_type_, tolerance, true );
491  } else {
492  min_mover = new protocols::simple_moves::MinMover( local_movemap, local_scorefxn, min_type_, tolerance, true );
493  }
494  min_mover->cartesian( cartesian_ );
495  min_mover->apply( pose );
496 }
497 
498 
499 ////////////////////////////////////////////////////////////////////////////////////////////////////
501  using namespace core::scoring;
502  using namespace core::conformation;
503  using namespace core::pack;
504  using namespace core::pack::task;
505  using namespace core::kinematics;
506  using namespace protocols;
507 
508  TR.Debug << "================== FastRelax: " << script_.size() << " ===============================" << std::endl;
510 
511 #if defined GL_GRAPHICS
513 #endif
514  // One out of 10 times dont bother doing Ramady Relax. You may wonder why - the reason is that occasionally
515  // there are phi-pso pairs outside of the commonly allowed ranges which are *correct* for some sort of quirk
516  // of nature. In that case using ramady relax screws things up, so to allow for that chance only execture ramady relax
517  // 90% of the time.
518  bool do_rama_repair = ramady_;
519  if( !ramady_force_ && numeric::random::uniform() <= 0.1 ) do_rama_repair = false;
520 
521 
522  // Relax is a fullatom protocol so switch the residue set here. The rotamers
523  // wont be properly packed at this stage but it doesnt really matter.
524  // They'll get repacked shortly.
525  if( !pose.is_fullatom() ){
527  }
528 
529  // Make a local copy of movemap, called local movemap. The reason is that
530  // the "constrain to coordinates" codes will wanna mess witht the movemap..
531  core::kinematics::MoveMapOP local_movemap = get_movemap()->clone();
532  initialize_movemap( pose, *local_movemap );
533  make_dna_rigid(pose,*local_movemap);
534  set_movemap(local_movemap);
535 
536  // Deal with constraint options and add coodrinate constraints for all or parts of the structure.
537  set_up_constraints( pose, *local_movemap );
538 
539  // Make sure we only allow symmetrical degrees of freedom to move and convert the local_movemap
540  // to a local movemap
541  if ( core::pose::symmetry::is_symmetric( pose ) ) {
542  core::pose::symmetry::make_symmetric_movemap( pose, *local_movemap );
543  }
544 
545  // make a copy of the energy function too. SInce we're going to be ramping around with weights,
546  // we dont want to modify the existing scorefunction
547  ScoreFunctionOP local_scorefxn( get_scorefxn()->clone() );
548 
549  // Remember the oroiginal weights - we're gonna be changing these during the ramp ups/downs
550  core::scoring::EnergyMap full_weights = local_scorefxn()->weights();
551 
552  // Set up the packer task for packing.
553  PackerTaskOP task_;
554  if ( get_task_factory() != 0 ) {
555  task_ = get_task_factory()->create_task_and_apply_taskoperations( pose );
556  } else {
557  task_ = TaskFactory::create_packer_task( pose ); //!!!!!!!!!!! << who tf put this comment here and why ?
558  }
559 
560  utility::vector1<bool> allow_repack( pose.total_residue(), repack_);
561  if ( !basic::options::option[ basic::options::OptionKeys::relax::chi_move].user() ) {
562  for ( Size pos = 1; pos <= pose.total_residue(); pos++ ) {
563  allow_repack[ pos ] = local_movemap->get_chi( pos );
564  }
565  }
566  task_->initialize_from_command_line().restrict_to_repacking().restrict_to_residues(allow_repack);
567  task_->or_include_current( true );
568 
569  if( limit_aroma_chi2() ) {
571  lp_op.apply( pose, *task_ );
572  }
573 
574  protocols::simple_moves::PackRotamersMoverOP pack_full_repack_ = new protocols::simple_moves::PackRotamersMover( local_scorefxn, task_ );
575 
576  // If symmmetric pose then create a symmeteric rotamers mover
577  if ( core::pose::symmetry::is_symmetric( pose ) ) {
578  pack_full_repack_ = new simple_moves::symmetry::SymPackRotamersMover( local_scorefxn, task_ );
579  }
580  (*local_scorefxn)( pose );
581 
582 
583  /// prints something like this ***1***C***1*********2***C********3****C****2********3*****
584  /// **********xxxxxxxxxxxxx************************************
585  if ( basic::options::option[ basic::options::OptionKeys::run::debug ]() ) {
587  }
588 
589 
590  /// OK, start of actual protocol
591  pose::Pose start_pose=pose;
592  pose::Pose best_pose=pose;
593  core::Real best_score=100000000.0;
594  core::Size accept_count = 0;
595  core::Size chk_counter = 0;
596 
597  int repeat_step=0;
598  int repeat_count=-1;
599  int total_repeat_count = 0;
600 
601 
602  // Optain the native pose
603  if( !get_native_pose() ) set_native_pose( new Pose( start_pose ) );
604 
605  // Statistic information
606  std::vector< core::Real > best_score_log;
607  std::vector< core::Real > curr_score_log;
608 
609  // for dry runs, literally just score the pose and quit.
610  if( dry_run() ){
611  (*local_scorefxn)( pose );
612  return;
613  }
614 
615  // Deal with disulphides - i have no idea what this does, ask Rob VErnon, he put this here.
616  apply_disulfides(pose);
617 
618  int total_count=0;
619  int dump_counter=0;
620  for ( core::Size ncmd = 0; ncmd < script_.size(); ncmd ++ ){
621  total_count++;
622  if ( basic::options::option[ basic::options::OptionKeys::run::debug ]() ) local_scorefxn->show( TR, pose );
623  if ( basic::options::option[ basic::options::OptionKeys::run::debug ]() ) pose.constraint_set()->show_numbers( TR.Debug );
624 
625  // No MC is used, so update graphics manually
626  #ifdef BOINC_GRAPHICS
627  boinc::Boinc::update_graphics_current( pose );
628  #endif
629 
630  RelaxScriptCommand cmd = script_[ncmd];
631 
632  TR.Debug << "Command: " << cmd.command << std::endl;
633 
634  if( cmd.command == "repeat" ){
635  if( cmd.nparams < 1 ){ utility_exit_with_message( "ERROR: Syntax: " + cmd.command + "<number_of_repeats> " ); }
636  repeat_count = (int) cmd.param1;
637  repeat_step = ncmd;
638  } else
639 
640  if( cmd.command == "endrepeat" ){
641  TR.Debug << "CMD: Repeat: " << repeat_count << std::endl;
642  repeat_count -- ;
643  total_repeat_count ++ ;
644  if( repeat_count <= 0 ){}
645  else{
646  ncmd = repeat_step;
647  }
648  } else
649  if( cmd.command == "dump" ){
650  if( cmd.nparams < 1 ){ utility_exit_with_message( "ERROR: Syntax: " + cmd.command + "<number> " ); }
651  pose.dump_pdb( "dump_" + right_string_of( (int) cmd.param1, 4, '0' ) );
652  } else
653 
654  if( cmd.command.substr(0,7) == "dumpall" ){
655  if( cmd.command.substr(8) == "true" )
656  dumpall_ = true;
657  if( cmd.command.substr(8) == "false" )
658  dumpall_ = false;
659  } else
660 
661  if( cmd.command == "repack" ){
662  //if( cmd.nparams < 0 ){ utility_exit_with_message( "More parameters expected after : " + cmd.command ); }
663  chk_counter++;
664  std::string checkpoint_id = "chk" + string_of( chk_counter );
665  if (!checkpoints_.recover_checkpoint( pose, get_current_tag(), checkpoint_id, true, true )){
666  pack_full_repack_->apply( pose );
667  checkpoints_.checkpoint( pose, get_current_tag(), checkpoint_id, true );
668  }
669  if ( dumpall_ ) {
670  pose.dump_pdb( "dump_" + right_string_of( dump_counter, 4, '0' ) );
671  dump_counter++;
672  }
673  } else
674 
675  if( cmd.command == "min" ){
676  if( cmd.nparams < 1 ){ utility_exit_with_message( "ERROR: Syntax " + cmd.command + " <min_tolerance> " ); }
677 
678  chk_counter++;
679  std::string checkpoint_id = "chk" + string_of( chk_counter );
680  if (!checkpoints_.recover_checkpoint( pose, get_current_tag(), checkpoint_id, true, true )){
681  do_minimize( pose, cmd.param1, local_movemap, local_scorefxn );
682  checkpoints_.checkpoint( pose, get_current_tag(), checkpoint_id, true );
683  }
684  if ( dumpall_) {
685  pose.dump_pdb( "dump_" + right_string_of( dump_counter, 4, '0' ) );
686  dump_counter++;
687  }
688  } else
689 
690  if( cmd.command.substr(0,5) == "scale" ){
691  // no input validation as of now, relax will just die
692  scoring::ScoreType scale_param = scoring::score_type_from_name(cmd.command.substr(6));
693  local_scorefxn->set_weight( scale_param, full_weights[ scale_param ] * cmd.param1 );
694  } else
695 
696  if( cmd.command.substr(0,6) == "rscale" ){
697  // no input validation as of now, relax will just die
698  scoring::ScoreType scale_param = scoring::score_type_from_name(cmd.command.substr(7));
699  local_scorefxn->set_weight( scale_param, full_weights[ scale_param ] * ((cmd.param2 - cmd.param1 ) * numeric::random::uniform() + cmd.param1 ));
700  } else
701 
702  if( cmd.command.substr(0,6) == "switch" ){
703  // no input validation as of now, relax will just die
704  if( cmd.command.substr(7) == "torsion" ) {
705  TR << "Using AtomTreeMinimizer with dfp" << std::endl;
706  cartesian( false );
707  } else if( cmd.command.substr(7) == "cartesian" ) {
708  TR << "Using CartesianMinizer with lbfgs" << std::endl;
709  cartesian( true );
710  }
711  } else
712 
713  if( cmd.command.substr(0,6) == "weight" ){
714  // no input validation as of now, relax will just die
715  scoring::ScoreType scale_param = scoring::score_type_from_name(cmd.command.substr(7));
716  local_scorefxn->set_weight( scale_param, cmd.param1 );
717  // I'm not too sure if the changing the default weight makes sense
718  full_weights[ scale_param ] = cmd.param1;
719  } else
720  if( cmd.command == "batch_shave" ){ // grab the score and remember the pose if the score is better then ever before.
721  } else
722  if( cmd.command == "show_weights" ){
723  local_scorefxn->show(TR, pose);
724  } else
725 
726  if( cmd.command == "ramp_repack_min" ){
727  if( cmd.nparams < 2 ){ utility_exit_with_message( "More parameters expected after : " + cmd.command ); }
728 
729  // The first parameter is the relate repulsive weight
730  local_scorefxn->set_weight( scoring::fa_rep, full_weights[ scoring::fa_rep ] * cmd.param1 );
731 
732  // The third paramter is the coordinate constraint weight
733  if( constrain_coords() && (cmd.nparams >= 3) ){
734  local_scorefxn->set_weight( scoring::coordinate_constraint, full_weights[ scoring::coordinate_constraint ] * cmd.param3 );
735  }
736 
737  // decide when to call ramady repair code
738  if( total_repeat_count > 1 && repeat_count > 2 ){
739  if( cmd.param1 < 0.2 ){
740  if( do_rama_repair ){
742  }
743  }
744  }
745 
746  chk_counter++;
747  std::string checkpoint_id = "chk" + string_of( chk_counter );
748  if (!checkpoints_.recover_checkpoint( pose, get_current_tag(), checkpoint_id, true, true )){
749  pack_full_repack_->apply( pose );
750  do_minimize( pose, cmd.param2, local_movemap, local_scorefxn );
751  checkpoints_.checkpoint( pose, get_current_tag(), checkpoint_id, true );
752  }
753 
754 
755  // print some debug info
756  if ( basic::options::option[ basic::options::OptionKeys::run::debug ]() ) {
757  core::Real imedscore = (*local_scorefxn)( pose );
758  core::pose::setPoseExtraScores( pose, "R" + right_string_of( total_count ,5,'0'), imedscore );
759  }
760 
761  if ( dumpall_ ) {
762  pose.dump_pdb( "dump_" + right_string_of( dump_counter, 4, '0' ) );
763  dump_counter++;
764  }
765  } else
766 
767 
768  if( cmd.command == "accept_to_best" ){
769  // grab the score and remember the pose if the score is better then ever before.
770  core::Real score = (*local_scorefxn)( pose );
771  if( ( score < best_score) || (accept_count == 0) ){
772  best_score = score;
773  best_pose = pose;
774  }
775  #ifdef BOINC_GRAPHICS
776  boinc::Boinc::update_graphics_low_energy( best_pose, best_score );
777  boinc::Boinc::update_graphics_last_accepted( pose, score );
778  boinc::Boinc::update_mc_trial_info( total_count , "FastRelax" );
779  #endif
780  core::Real rms = 0, irms = 0;
782  rms = CA_rmsd_symmetric( *get_native_pose() , best_pose );
783  irms = CA_rmsd_symmetric( start_pose , best_pose );
784  } else {
785  rms = native_CA_rmsd( *get_native_pose() , best_pose );
786  irms = native_CA_rmsd( start_pose , best_pose );
787  }
788  TR << "MRP: " << accept_count << " " << score << " " << best_score << " " << rms << " " << irms << " " << std::endl;
789  best_score_log.push_back( best_score );
790  curr_score_log.push_back( score );
791 
792  accept_count++;
793  if ( accept_count > script_max_accept_ ) break;
794  if( test_cycles_ || dry_run() ) break;
795 
796  } else
797 
798 
799  if( cmd.command == "load_best" ){
800  pose = best_pose;
801  } else
802  if( cmd.command == "load_start" ){
803  pose = start_pose;
804  } else
805 
806  if( cmd.command == "exit" ){
807  utility_exit_with_message( "EXIT INVOKED" );
808  } else
809 
810  {
811  utility_exit_with_message( "Unknown command: " + cmd.command );
812  }
813 
814  core::Real rms( -1.0 );
815  if ( get_native_pose() ) {
816  rms = native_CA_rmsd( *get_native_pose() , pose );
818  rms = CA_rmsd_symmetric( *get_native_pose() , best_pose );
819  }
820  }
821  core::Real irms = native_CA_rmsd( start_pose , pose );
823  irms = CA_rmsd_symmetric( start_pose , best_pose ); //need to make a symmetrical verision?
824  }
825 
826  TR << "CMD: " << cmd.command << " "
827  << (*local_scorefxn)( pose ) << " "
828  << rms << " "
829  << irms << " "
830  << local_scorefxn->get_weight( scoring::fa_rep )
831  << std::endl;
832  }
833 
834  pose = best_pose;
835  (*local_scorefxn)( pose );
836 
837  if ( basic::options::option[ basic::options::OptionKeys::run::debug ]() ) {
838  for( Size j = 0; j < best_score_log.size(); j++ )
839  core::pose::setPoseExtraScores( pose, "B" + right_string_of(j,3,'0'), best_score_log[j]);
840 
841  for( Size j = 0; j < curr_score_log.size(); j ++ )
842  core::pose::setPoseExtraScores( pose, "S" + right_string_of(j,3,'0'), curr_score_log[j] );
843  }
844 
845 
846 
848 }
849 
852  return "FastRelax";
853 }
854 
855 // Override the stored script with the default script for batchrelax
857  script_.clear();
858 
859  std::vector< std::string > filelines;
860  std::string line;
861 
862  //fpd
863  //fpd sets a "reasonable" script for performing batch relax
864  //fpd uses 'default_repeats'
865  if (repeats == 0)
866  repeats = default_repeats_;
867  runtime_assert( repeats > 0 );
868 
869  // repeat 1
870  filelines.push_back( "ramp_repack_min 0.02 0.01" );
871  filelines.push_back( "batch_shave 0.25" );
872  filelines.push_back( "ramp_repack_min 0.250 0.01" );
873  filelines.push_back( "batch_shave 0.25" );
874  filelines.push_back( "ramp_repack_min 0.550 0.01" );
875  filelines.push_back( "batch_shave 0.25" );
876  filelines.push_back( "ramp_repack_min 1 0.00001" );
877  filelines.push_back( "accept_to_best" );
878 
879  // repeats 2->n
880  for (core::Size i=2; i<=repeats; ++i) {
881  filelines.push_back( "ramp_repack_min 0.02 0.01" );
882  filelines.push_back( "ramp_repack_min 0.250 0.01" );
883  filelines.push_back( "batch_shave 0.25" );
884  filelines.push_back( "ramp_repack_min 0.550 0.01" );
885  filelines.push_back( "ramp_repack_min 1 0.00001" );
886  filelines.push_back( "accept_to_best" );
887  }
888  int linecount=0;
889 
890  script_.clear();
891 
892  core::Size i;
893  for( i =0; i< filelines.size(); i++ ){
894  line = filelines[i];
895  TR.Debug << line << std::endl;
896  linecount++;
898 
899  if ( tokens.size() > 0 ) {
900  RelaxScriptCommand newcmd;
901  newcmd.command = tokens[1];
902 
903  if (tokens.size() > 1) {newcmd.param1 = atof(tokens[2].c_str()); newcmd.nparams = 1;}
904  if (tokens.size() > 2) {newcmd.param2 = atof(tokens[3].c_str()); newcmd.nparams = 2;}
905  if (tokens.size() > 3) {newcmd.param3 = atof(tokens[4].c_str()); newcmd.nparams = 3;}
906  if (tokens.size() > 4) {newcmd.param4 = atof(tokens[5].c_str()); newcmd.nparams = 4;}
907 
908  script_.push_back( newcmd );
909  }
910  }
911 }
912 
913 
914 void FastRelax::read_script_file( const std::string &script_file, core::Size standard_repeats ){
915  using namespace ObjexxFCL;
916  script_.clear();
917  std::vector< std::string > filelines;
918  std::string line;
919 
920  runtime_assert( standard_repeats > 0 );
921  if( script_file == "" ){
922  TR << "================== Using default script ==================" << std::endl;
923  filelines.push_back( "repeat " + string_of( standard_repeats ) );
924  filelines.push_back( "ramp_repack_min 0.02 0.01 1.0" );
925  filelines.push_back( "ramp_repack_min 0.250 0.01 0.5" );
926  filelines.push_back( "ramp_repack_min 0.550 0.01 0.0" );
927  filelines.push_back( "ramp_repack_min 1 0.00001 0.0" );
928  filelines.push_back( "accept_to_best" );
929  filelines.push_back( "endrepeat " );
930  }else if (script_file == "NO CST RAMPING"){
931  TR << "================== Using default script ==================" << std::endl;
932  filelines.push_back( "repeat " + string_of( standard_repeats ) );
933  filelines.push_back( "ramp_repack_min 0.02 0.01 1.0" );
934  filelines.push_back( "ramp_repack_min 0.250 0.01 1.0" );
935  filelines.push_back( "ramp_repack_min 0.550 0.01 1.0" );
936  filelines.push_back( "ramp_repack_min 1 0.00001 1.0" );
937  filelines.push_back( "accept_to_best" );
938  filelines.push_back( "endrepeat " );
939  }
940  else{
941  std::ifstream infile( script_file.c_str() );
942  TR.Debug << "================== Reading script file: ==================" << std::endl;
943  if (!infile.good()) {
944  utility_exit_with_message( "[ERROR] Error opening script file '" + script_file + "'" );
945  }
946  while( getline(infile,line) ) {
947  filelines.push_back( line );
948  }
949  infile.close();
950  }
951 
952  int linecount=0;
953 
954  script_.clear();
955 
956  core::Size i;
957  for( i =0; i< filelines.size(); i++ ){
958  line = filelines[i];
959  TR.Debug << line << std::endl;
960  linecount++;
962 
963  if ( tokens.size() > 0 ) {
964  RelaxScriptCommand newcmd;
965  newcmd.command = tokens[1];
966 
967  if (tokens.size() > 1) {newcmd.param1 = atof(tokens[2].c_str()); newcmd.nparams = 1;}
968  if (tokens.size() > 2) {newcmd.param2 = atof(tokens[3].c_str()); newcmd.nparams = 2;}
969  if (tokens.size() > 3) {newcmd.param3 = atof(tokens[4].c_str()); newcmd.nparams = 3;}
970  if (tokens.size() > 4) {newcmd.param4 = atof(tokens[5].c_str()); newcmd.nparams = 4;}
971 
972  script_.push_back( newcmd );
973  }
974  }
975 
976 
977 }
978 
979 
980 
981 
982 // Batch Relax stuff
983 
984 
985 
986 
987 struct SRelaxPose {
988  SRelaxPose(): active(true), accept_count(0){}
989 
992  bool active;
999  std::vector< core::Real > best_score_log;
1000  std::vector< core::Real > curr_score_log;
1001 
1003  return sizeof ( SRelaxPose ) + current_struct->mem_footprint() + start_struct->mem_footprint() + best_struct->mem_footprint() + (best_score_log.size()+curr_score_log.size())*sizeof( core::Real);
1004  }
1005 };
1006 
1007 
1009  std::vector < SilentStructOP > & input_structs,
1010  core::scoring::constraints::ConstraintSetOP input_csts, // = NULL
1011  core::Real decay_rate // = 0.5
1012  ){
1013  using namespace basic::options;
1014  using namespace core::scoring;
1015  using namespace core::conformation;
1016  using namespace core::pack;
1017  using namespace core::pack::task;
1018  using namespace core::kinematics;
1019  using namespace protocols;
1020 
1021 
1022 
1023 
1024  PackerTaskOP task_;
1026  core::kinematics::MoveMapOP local_movemap = get_movemap()->clone();
1027  core::pose::Pose pose;
1028 
1029 
1030 
1031  TR.Debug << "================== RelaxScriptBatchRelax: " << script_.size() << " ===============================" << std::endl;
1032  TR.Info << "BatchRelax: Size: " << input_structs.size() << " Scriptlength: " << script_.size() << std::endl;
1033 
1034  // 432mb
1035 
1036  if ( input_structs.size() < 1 ) return;
1037 
1038  ScoreFunctionOP local_scorefxn( get_scorefxn()->clone() );
1039  core::scoring::EnergyMap full_weights = local_scorefxn()->weights();
1040  if ( dry_run() ) {
1041  return;
1042  }
1043  // Set up rama-repair if requested - one out of 10 times dont bother
1044  bool do_rama_repair = ramady_;
1045  if( !ramady_force_ && numeric::random::uniform() <= 0.1 ) do_rama_repair = false;
1046 
1047  // 432/436mb
1048 
1049  // create a local array of relax_decoys
1050  std::vector < SRelaxPose > relax_decoys;
1051  core::Size total_mem = 0;
1052  for( core::Size i = 0; i < input_structs.size(); ++i ){
1053  TR.Debug << "iClock" << clock() << std::endl;
1054 
1055  SRelaxPose new_relax_decoy;
1056 
1057  input_structs[i]->fill_pose( pose );
1058  if ( input_csts ) pose.constraint_set( input_csts );
1059  // 432mb
1060  if( !pose.is_fullatom() ){
1061  TR.Debug << "Switching struct to fullatom" << std::endl;
1063  //core::Real afterscore = (*local_scorefxn)(pose);
1064  }
1065  // 453mb
1066 
1067 
1068  //pose.dump_pdb("test_" + string_of( i ) + ".pdb" );
1069  new_relax_decoy.active = true;
1070  new_relax_decoy.initial_score = (input_structs[i])->get_energy("censcore");
1071 
1072  new_relax_decoy.initial_rms = 0;
1073  if ( get_native_pose() ) {
1074  new_relax_decoy.initial_rms = native_CA_rmsd( *get_native_pose() , pose );
1075  }
1076 
1077  new_relax_decoy.best_score = (*local_scorefxn)(pose);
1078  new_relax_decoy.current_score = new_relax_decoy.best_score;
1079  new_relax_decoy.current_struct = force_nonideal_?
1082  new_relax_decoy.start_struct = force_nonideal_?
1085  new_relax_decoy.best_struct = force_nonideal_?
1088  new_relax_decoy.current_struct->fill_struct( pose );
1089  new_relax_decoy.start_struct->fill_struct( pose );
1090  new_relax_decoy.best_struct->fill_struct( pose );
1091  new_relax_decoy.current_struct->copy_scores( *(input_structs[i]) );
1092  new_relax_decoy.start_struct->copy_scores( *(input_structs[i]) );
1093  new_relax_decoy.best_struct->copy_scores( *(input_structs[i]) );
1094 
1095  TR.Trace << "Fillstruct: " << new_relax_decoy.best_score << std::endl;
1096 
1097  initialize_movemap( pose, *local_movemap );
1098  TR.Trace << "SRelaxPose mem: " << new_relax_decoy.mem_footprint() << std::endl;
1099  total_mem += new_relax_decoy.mem_footprint();
1100  relax_decoys.push_back( new_relax_decoy );
1101  // 453 mb
1102  if( i == 0 ){
1103  if ( get_task_factory() != 0 ) {
1104  pack_full_repack_ = new protocols::simple_moves::PackRotamersMover();
1105  if ( core::pose::symmetry::is_symmetric( pose ) ) {
1106  pack_full_repack_ = new simple_moves::symmetry::SymPackRotamersMover();
1107  }
1108  pack_full_repack_->score_function(local_scorefxn);
1109  pack_full_repack_->task_factory(get_task_factory());
1110  } else {
1111  task_ = TaskFactory::create_packer_task( pose );
1112 
1113  bool const repack = basic::options::option[ basic::options::OptionKeys::relax::chi_move]();
1114  utility::vector1<bool> allow_repack( pose.total_residue(), repack);
1115 
1116  if ( !basic::options::option[ basic::options::OptionKeys::relax::chi_move].user() ) {
1117  for ( Size pos = 1; pos <= pose.total_residue(); pos++ ) {
1118  allow_repack[ pos ] = local_movemap->get_chi( pos );
1119  }
1120  }
1121 
1122  task_->initialize_from_command_line().restrict_to_repacking().restrict_to_residues(allow_repack);
1123  task_->or_include_current( true );
1124  pack_full_repack_ = new protocols::simple_moves::PackRotamersMover( local_scorefxn, task_ );
1125  if ( core::pose::symmetry::is_symmetric( pose ) ) {
1126  pack_full_repack_ = new simple_moves::symmetry::SymPackRotamersMover( local_scorefxn, task_ );
1127  }
1128  }
1129  (*local_scorefxn)( pose );
1130 
1131  // Make sure we only allow symmetrical degrees of freedom to move
1132  if ( core::pose::symmetry::is_symmetric( pose ) ) {
1133  core::pose::symmetry::make_symmetric_movemap( pose, *local_movemap );
1134  }
1135 
1136  if ( basic::options::option[ basic::options::OptionKeys::run::debug ]() ) {
1137  kinematics::simple_visualize_fold_tree_and_movemap_bb_chi( pose.fold_tree(), *local_movemap, TR );
1138  }
1139  }
1140  // 453 mb
1141  }
1142  relax_decoys.reserve( relax_decoys.size() );
1143 
1144  TR.Debug << "BatchRelax mem: " << total_mem << std::endl;
1145 
1146  /// RUN
1147 
1148  int repeat_step=0;
1149  int repeat_count=-1;
1150  int total_repeat_count = 0;
1151 
1152  int total_count=0;
1153  for ( core::Size ncmd = 0; ncmd < script_.size(); ncmd ++ ){
1154  total_count++;
1155 
1156  RelaxScriptCommand cmd = script_[ncmd];
1157  TR.Debug << "Command: " << cmd.command << std::endl;
1158 
1159  if( cmd.command == "repeat" ){
1160  if( cmd.nparams < 1 ){ utility_exit_with_message( "ERROR: Syntax: " + cmd.command + "<number_of_repeats> " ); }
1161  repeat_count = (int) cmd.param1;
1162  repeat_step = ncmd;
1163  } else
1164 
1165  if( cmd.command == "endrepeat" ){
1166  TR.Debug << "CMD: Repeat: " << repeat_count << std::endl;
1167  repeat_count -- ;
1168  total_repeat_count ++ ;
1169  if( repeat_count <= 0 ){}
1170  else{
1171  ncmd = repeat_step;
1172  }
1173  } else
1174  if( cmd.command == "dump" ){
1175  if( cmd.nparams < 1 ){ utility_exit_with_message( "More parameters expected after : " + cmd.command ); }
1176 
1177  for( core::Size index=0; index < relax_decoys.size(); ++ index ){
1178  relax_decoys[index].current_struct->fill_pose( pose );
1179  pose.dump_pdb( "dump_" + right_string_of( index, 4, '0' ) + "_" + right_string_of( (int) cmd.param1, 4, '0' ) );
1180  }
1181  } else
1182 
1183  if( cmd.command == "repack" ){
1184  for( core::Size index=0; index < relax_decoys.size(); ++ index ){
1185  if ( !relax_decoys[index].active ) continue;
1186  relax_decoys[index].current_struct->fill_pose( pose );
1187  if ( input_csts ) pose.constraint_set( input_csts );
1188  pack_full_repack_->apply( pose );
1189  core::Real score = (*local_scorefxn)(pose);
1190  relax_decoys[index].current_score = score;
1191  relax_decoys[index].current_struct->fill_struct( pose );
1192  }
1193 
1194  } else
1195 
1196  if( cmd.command == "min" ){
1197  if( cmd.nparams < 1 ){ utility_exit_with_message( "More parameters expected after : " + cmd.command ); }
1198 
1199  for( core::Size index=0; index < relax_decoys.size(); ++ index ){
1200  if ( !relax_decoys[index].active ) continue;
1201  relax_decoys[index].current_struct->fill_pose( pose );
1202  if ( input_csts ) pose.constraint_set( input_csts );
1203  do_minimize( pose, cmd.param1, local_movemap, local_scorefxn );
1204  core::Real score = (*local_scorefxn)(pose);
1205  relax_decoys[index].current_score = score;
1206  relax_decoys[index].current_struct->fill_struct( pose );
1207  }
1208 
1209  } else
1210 
1211 
1212  if( cmd.command.substr(0,5) == "scale" ){
1213  // no input validation as of now, relax will just die
1214  scoring::ScoreType scale_param = scoring::score_type_from_name(cmd.command.substr(6));
1215  local_scorefxn->set_weight( scale_param, full_weights[ scale_param ] * cmd.param1 );
1216  } else
1217 
1218  if( cmd.command.substr(0,6) == "rscale" ){
1219  // no input validation as of now, relax will just die
1220  scoring::ScoreType scale_param = scoring::score_type_from_name(cmd.command.substr(7));
1221  local_scorefxn->set_weight( scale_param, full_weights[ scale_param ] * ((cmd.param2 - cmd.param1 ) * numeric::random::uniform() + cmd.param1 ));
1222  } else
1223 
1224  if( cmd.command.substr(0,6) == "switch" ){
1225  // no input validation as of now, relax will just die
1226  if( cmd.command.substr(7) == "torsion" ) {
1227  TR << "Using AtomTreeMinimizer" << std::endl;
1228  cartesian( false );
1229  } else if( cmd.command.substr(7) == "cartesian" ) {
1230  TR << "Using CartesianMinimizer" << std::endl;
1231  cartesian( true );
1232  }
1233  } else
1234 
1235  if( cmd.command.substr(0,6) == "weight" ){
1236  // no input validation as of now, relax will just die
1237  scoring::ScoreType scale_param = scoring::score_type_from_name(cmd.command.substr(7));
1238  local_scorefxn->set_weight( scale_param, cmd.param1 );
1239  // I'm not too sure if the changing the default weight makes sense
1240  full_weights[ scale_param ] = cmd.param1;
1241  } else
1242 
1243  if( cmd.command == "show_weights" ){
1244  local_scorefxn->show(TR, pose);
1245  } else
1246 
1247  if( cmd.command == "ramp_repack_min" ){
1248  if( cmd.nparams < 2 ){ utility_exit_with_message( "More parameters expected after : " + cmd.command ); }
1249  local_scorefxn->set_weight( scoring::fa_rep, full_weights[ scoring::fa_rep ] * cmd.param1 );
1250 
1251 
1252  for( core::Size index=0; index < relax_decoys.size(); ++ index ){
1253  try {
1254  clock_t starttime = clock();
1255  if ( !relax_decoys[index].active ) continue;
1256  relax_decoys[index].current_struct->fill_pose( pose );
1257  if ( input_csts ) pose.constraint_set( input_csts );
1258  if( total_repeat_count > 1 && repeat_count > 2 ){
1259  if( cmd.param1 < 0.2 ){
1260  if( do_rama_repair ){
1262  }
1263  }
1264  }
1265 
1266  pack_full_repack_->apply( pose );
1267  do_minimize( pose, cmd.param2, local_movemap, local_scorefxn );
1268  relax_decoys[index].current_score = (*local_scorefxn)(pose);
1269  relax_decoys[index].current_struct->fill_struct( pose );
1270 
1271  clock_t endtime = clock();
1272  TR.Debug << "time:" << endtime - starttime << " Score: " << relax_decoys[index].current_score << std::endl;
1273  } catch ( utility::excn::EXCN_Base& excn ) {
1274  std::cerr << "Ramp_repack_min exception: " << std::endl;
1275  excn.show( std::cerr );
1276  // just deactivate this pose
1277  relax_decoys[index].active = false;
1278  // and need to "reset scoring" of the pose we reuse
1279  TR << "Throwing out one structure due to scoring problems!" << std::endl;
1280  pose.scoring_end(*local_scorefxn);
1281  }
1282  }
1283 
1284  } else
1285  if( cmd.command == "batch_shave" ){
1286  if( cmd.nparams < 1 ){ utility_exit_with_message( "More parameters expected after : " + cmd.command ); }
1287  core::Real reduce_factor = cmd.param1;
1288  if( (reduce_factor <= 0) || (reduce_factor >= 1.0) ){ utility_exit_with_message( "Parameter after : " + cmd.command + " should be > 0 and < 1 " ); }
1289 
1290  TR.Debug << "SHAVE FACTOR: " << reduce_factor << std::endl;
1291 
1292  std::vector < core::Real > energies;
1293  for( core::Size index=0; index < relax_decoys.size(); ++ index ){
1294  if ( !relax_decoys[index].active ) continue;
1295  TR.Debug << "SHAVE: " << relax_decoys[index].current_score << std::endl;
1296  energies.push_back( relax_decoys[index].current_score );
1297  TR.Debug << relax_decoys[index].current_score << std::endl;
1298  }
1299 
1300  if ( energies.size() < 1 ){
1301  TR.Debug << "ERROR: Cannot shave off structures - there are not enough left" << std::endl;
1302  continue;
1303  }
1304 
1305  std::sort( energies.begin(), energies.end() );
1306  core::Size cutoff_index = core::Size( floor(core::Real(energies.size()) * (reduce_factor)) );
1307  TR.Debug << "Energies: cutoff index " << cutoff_index << std::endl;
1308  core::Real cutoff_energy = energies[ cutoff_index ];
1309  TR.Debug << "Energies: cutoff " << cutoff_energy << std::endl;
1310  for( core::Size index=0; index < relax_decoys.size(); ++ index ){
1311  if ( !relax_decoys[index].active ) continue;
1312  TR.Debug << "Shaving candidate: " << index << " " << relax_decoys[index].current_score << " " << cutoff_energy << std::endl;
1313  if ( relax_decoys[index].current_score > cutoff_energy ) relax_decoys[index].active = false;
1314  }
1315 
1316 
1317  } else
1318  if( cmd.command == "accept_to_best" ){ // grab the score and remember the pose if the score is better then ever before.
1319 
1320 
1321  std::vector < core::Real > energies;
1322 
1323  for( core::Size index=0; index < relax_decoys.size(); ++ index ){
1324  if ( !relax_decoys[index].active ) continue;
1325  relax_decoys[index].current_struct->fill_pose( pose );
1326  if ( input_csts ) pose.constraint_set( input_csts );
1327  core::Real score = 0;
1328  try {
1329  score = (*local_scorefxn)( pose );
1330  } catch ( utility::excn::EXCN_Base& excn ) {
1331  std::cerr << "Accept_to_best scoring exception: " << std::endl;
1332  excn.show( std::cerr );
1333  // just deactivate this pose
1334  relax_decoys[index].active = false;
1335  // and need to "reset scoring" of the pose we reuse
1336  TR << "Throwing out one structure due to scoring problems!" << std::endl;
1337  pose.scoring_end(*local_scorefxn);
1338  continue;
1339  }
1340  TR.Debug << "Comparison: " << score << " " << relax_decoys[index].best_score << std::endl;
1341 
1342  if( ( score < relax_decoys[index].best_score) || (relax_decoys[index].accept_count == 0) ){
1343  relax_decoys[index].best_score = score;
1344  relax_decoys[index].best_struct->fill_struct( pose );
1345 #ifdef DEBUG
1346  core::pose::Pose pose_check;
1347  relax_decoys[index].best_struct->fill_pose( pose_check );
1348  if ( input_csts ) pose.constraint_set( input_csts );
1349  core::Real score_check = (*local_scorefxn)( pose_check );
1350  TR.Debug << "Sanity: "<< score << " == " << score_check << std::endl;
1351 #endif
1352  }
1353 
1354  if ( get_native_pose() ) {
1355  if ( core::pose::symmetry::is_symmetric( pose ) && option[ basic::options::OptionKeys::evaluation::symmetric_rmsd ].user() ) {
1357  TR << "MRP: " << index << " " << relax_decoys[index].accept_count << " " << score << " " << relax_decoys[index].best_score << " "
1358  << rms << " "
1359  << std::endl;
1360 
1361  } else {
1363  TR << "MRP: " << index << " " << relax_decoys[index].accept_count << " " << score << " " << relax_decoys[index].best_score << " "
1364  << rms << " "
1365  << std::endl;
1366  }
1367  } else {
1368  TR << "MRP: " << index << " " << relax_decoys[index].accept_count << " " << score << " " << relax_decoys[index].best_score << " "
1369  << std::endl;
1370  }
1371 
1372  relax_decoys[index].curr_score_log.push_back( score );
1373  relax_decoys[index].accept_count ++ ;
1374  energies.push_back( relax_decoys[index].best_score );
1375  }
1376 
1377 
1378  // now decide who to keep relaxing and who to abandon!
1379  if ( energies.size() < 1 ){
1380  TR.Debug << "Cannot shave off structures - there are not enough left" << std::endl;
1381  continue;
1382  }
1383  std::sort( energies.begin(), energies.end() );
1384  core::Real cutoff_energy = energies[ core::Size( floor(core::Real(energies.size()) * (decay_rate)) )];
1385  for( core::Size index=0; index < relax_decoys.size(); ++ index ){
1386  if ( !relax_decoys[index].active ) continue;
1387  if ( relax_decoys[index].best_score > cutoff_energy ) relax_decoys[index].active = false;
1388  }
1389 
1390  } else
1391 
1392  if( cmd.command == "exit" ){
1393  utility_exit_with_message( "EXIT INVOKED FROM SEQUENCE RELAX SCRIPT" );
1394  } else
1395 
1396  {
1397  utility_exit_with_message( "Unknown command: " + cmd.command );
1398  }
1399 
1400  TR.Debug << "CMD: " << cmd.command << " Rep_Wght:"
1401  << local_scorefxn->get_weight( scoring::fa_rep )
1402  << std::endl;
1403  }
1404 
1405 
1406 
1407  input_structs.clear();
1408  // Finally return all the scores;
1409  for( core::Size index=0; index < relax_decoys.size(); ++ index ){
1410  relax_decoys[index].best_struct->fill_pose( pose );
1411  if ( input_csts ) pose.constraint_set( input_csts );
1412  setPoseExtraScores( pose, "giveup", relax_decoys[index].accept_count );
1413  core::Real rms = 0;
1414  core::Real gdtmm = 0;
1415  if ( get_native_pose() ){
1416  rms = native_CA_rmsd( *get_native_pose() , pose );
1417  gdtmm = native_CA_gdtmm( *get_native_pose() , pose );
1418  TR.Trace << "BRELAXRMS: " << rms << " " << gdtmm << std::endl;
1419  }
1420  //pose.dump_pdb("best_relax_step_"+string_of( index )+".pdb" );
1421  core::Real score = (*local_scorefxn)( pose );
1422  TR << "BRELAX: Rms: "<< rms
1423  << " CenScore: " << relax_decoys[index].initial_score
1424  << " CenRMS: " << relax_decoys[index].initial_rms
1425  << " FAScore: " << score
1426  << " Check: " << relax_decoys[index].best_score
1427  << " Acc: " << relax_decoys[index].accept_count
1428  << " Go: " << (relax_decoys[index].active ? " 1" : " 0") << std::endl;
1429 
1430  if ( !relax_decoys[index].active ) continue;
1431 
1432  SilentStructOP new_struct = force_nonideal_?
1435  new_struct->fill_struct( pose );
1436  new_struct->copy_scores( *(relax_decoys[index].start_struct) );
1437  new_struct->energies_from_pose( pose );
1438  new_struct->add_energy("rms", rms, 1.0 );
1439  new_struct->add_energy("gdtmm", gdtmm, 1.0 );
1440  input_structs.push_back( new_struct );
1441  }
1442 
1443 
1444 }
1445 
1447  using namespace core::conformation;
1448  //if DNA present set so it doesn't move
1449  for ( Size i=1; i<=pose.total_residue() ; ++i ) {
1450  if( pose.residue(i).is_DNA()){
1451  TR << "turning off DNA bb and chi move" << std::endl;
1452  mm->set_bb( i, false );
1453  mm->set_chi( i, false );
1454  }
1455  }
1456  //end DNA rigidity
1457 }
1458 
1459 
1460 } // namespace relax
1461 
1462 } // namespace protocols
1463 
1464