Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
AnchorMovers.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 protocols/anchored_design/AnchorMovers.cc
11 /// @brief Anchored design movers (protocol-level, perturb, refine)
12 /// @author Steven Lewis smlewi@gmail.com
13 
14 // Unit Headers
16 
17 // Package Headers
18 // AUTO-REMOVED #include <protocols/anchored_design/Anchor.hh>
22 #include <protocols/loops/Loops.hh>
23 
24 // Project Headers
28 
29 #include <core/fragment/FragSet.hh>
30 
33 
35 #include <core/scoring/rms_util.hh>
39 
43 
44 //needed for a benchmarking thing
46 // AUTO-REMOVED #include <protocols/toolbox/pose_metric_calculators/NeighborhoodByDistanceCalculator.hh>
47 // AUTO-REMOVED #include <core/pose/metrics/simple_calculators/InterfaceNeighborDefinitionCalculator.hh>
48 
49 #include <core/pose/Pose.hh>
51 #include <core/pose/util.hh>
52 
55 
56 #include <basic/MetricValue.hh>
57 
58 //movers and accessories
60 
61 #include <protocols/moves/Mover.fwd.hh> //MoverOP
62 #include <protocols/simple_moves/BackboneMover.hh> //SmallMover
65 #include <protocols/moves/MoverContainer.hh> //Sequence Mover
69 #include <protocols/simple_moves/SwitchResidueTypeSetMover.hh> //typeset swapping
76 
78 #include <protocols/jd2/Job.hh>
80 
81 // Utility Headers
82 #include <basic/options/option.hh>
83 #include <ObjexxFCL/FArray1D.hh> //necessary for fold tree tricks, RMS - AUGH!
84 #include <ObjexxFCL/FArray2D.hh>
85 #include <core/types.hh>
86 #include <basic/Tracer.hh>
87 #include <utility/exit.hh>
88 #include <numeric/angle.functions.hh>
89 #include <numeric/random/random.hh>
90 #include <numeric/xyzVector.hh>
91 // AUTO-REMOVED #include <numeric/xyz.io.hh>
92 
93 // C++ Headers
94 #include <iostream>
95 #include <sstream>
96 #include <list>
97 
98 // option key includes
99 #include <basic/options/keys/loops.OptionKeys.gen.hh>
100 #include <basic/options/keys/run.OptionKeys.gen.hh>
101 #include <basic/options/keys/AnchoredDesign.OptionKeys.gen.hh>
102 
103 #include <utility/vector0.hh>
104 #include <utility/vector1.hh>
105 #include <numeric/xyzVector.io.hh>
106 
107 
108 #if defined(WIN32) || defined(__CYGWIN__)
109  #include <ctime>
110 #endif
111 
112 
113 using basic::T;
114 using basic::Error;
115 using basic::Warning;
116 
117 static basic::Tracer T_design("protocols.AnchoredDesign.AnchoredDesignMover");
118 static basic::Tracer T_perturb("protocols.AnchoredDesign.AnchoredPerturbMover");
119 static basic::Tracer T_refine("protocols.AnchoredDesign.AnchoredRefineMover");
120 static basic::Tracer T_shared("protocols.AnchoredDesign.Anchor_Movers");
121 static numeric::random::RandomGenerator RG(37633224); //that's the combination on my luggage!
122 
123 namespace protocols{
124 namespace anchored_design{
125 
126 std::string const EMPTY_STRING("");
127 int const ANCHOR_TARGET(1); //jump between anchor and target
128 
129 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
130 /////////////////local helper functions - generally these only run when the debug flag is passed/////////////
131 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
132 ///@brief a local helper function, not in the header
134  core::pose::Pose const & pose,
135  core::pose::PoseOP posecopy,
136  std::string const & tag,
138 {
139  using namespace protocols::jd2;
140  mover->apply(*posecopy);
141  JobDistributor::get_instance()->job_outputter()->other_pose(JobDistributor::get_instance()->current_job(), *posecopy, tag);
142  *posecopy = pose;
143 }
144 
145 ///@brief a local helper function for debugging, not in the header
147 {
148  core::Size nres(pose.total_residue());
149  T_shared << "pose says 'is_cutpoint(#)': ";
150  for (core::Size i(1); i <= nres; ++i)
151  if (pose.fold_tree().is_cutpoint( i )) T_shared << i << " ";
152  T_shared << std::endl;
153 
154  T_shared << "pose says 'has_variant_type CUTPOINT_LOWER': ";
155  for (core::Size i(1); i <= nres; ++i)
156  if (pose.residue(i).has_variant_type( core::chemical::CUTPOINT_LOWER)) T_shared << i << " ";
157  T_shared << std::endl;
158 
159  T_shared << "pose says 'has_variant_type CUTPOINT_UPPER': ";
160  for (core::Size i(1); i <= nres; ++i)
161  if (pose.residue(i).has_variant_type( core::chemical::CUTPOINT_UPPER)) T_shared << i << " ";
162  T_shared << std::endl;
163 }
164 
165 
166 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
167 //////////////////////////AnchoredDesignMover////////////////////////////////////////////////////////////////
168 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
169 //@brief constructor with arguments
171  Mover(),
172  interface_( interface_in ),
173  RMSD_only_this_pose_( 0 ),
174  IAM_( new protocols::analysis::InterfaceAnalyzerMover(ANCHOR_TARGET) ),
175  rmsd_(false),
176  RMSD_only_this_(EMPTY_STRING),
177  delete_interface_native_sidechains_(false),
178  show_extended_(false),
179  randomize_input_sequence_(false),
180  vary_cutpoints_(false),
181  refine_only_(false),
182  filter_score_(std::numeric_limits<core::Real>::max()),
183  use_filter_score_(false),
184  filter_SASA_(0.0),
185  use_filter_SASA_(false),
186  use_filter_omega_(false),
187  autoinitialize_(true),
188  init_for_input_yet_(false)
189 {
190  protocols::moves::Mover::type( "AnchoredDesign" );
191 }
192 
193 //@brief constructor with no arguments
195  interface_( 0 ), //NULL pointer
196  RMSD_only_this_pose_( 0 ),
197  IAM_( new protocols::analysis::InterfaceAnalyzerMover(ANCHOR_TARGET) ),
198  rmsd_(false),
199  RMSD_only_this_(EMPTY_STRING),
200  delete_interface_native_sidechains_(false),
201  show_extended_(false),
202  randomize_input_sequence_(false),
203  vary_cutpoints_(false),
204  refine_only_(false),
205  filter_score_(std::numeric_limits<core::Real>::max()),
206  use_filter_score_(false),
207  filter_SASA_(0.0),
208  use_filter_SASA_(false),
209  use_filter_omega_(false),
210  autoinitialize_(true),
211  init_for_input_yet_(false)
212 {
213  protocols::moves::Mover::type( "AnchoredDesign" );
214 }
215 
216 ///@brief copy ctor
218  Mover(rhs)
219 {
220  *this = rhs;
221 }
222 
223 ///@brief assignment operator
225 
226  //abort self-assignment
227  if (this == &rhs) return *this;
228 
229  interface_ = rhs.interface_->clone();
230  //this is a shallow copy because it is only supposed to have one value anyway (only this!), what does it mean if you start mutating it? I don't know
232  //this is a shallow copy because the Mover can't be modified anyway, and it doesn't have a copy ctor at the moment, and it's not going to get one in the near future
233  IAM_ = rhs.IAM_;
234  rmsd_ = rhs.get_rmsd();
248  return *this;
249 }
250 
252 
254  //don't run this function twice
255  init_for_input_yet_ = true;
256 
257  //If the interface_ object doesn't exist yet, we must create one, giving it a pose to help it initialize
258  //it will exist if this object was created via the AnchorMoversData-supplying constructor
259  if(!interface_)
261 
262  //If nobody told us not to autoinitialize, read the options system for our other data
264 
265  //If we are in RMSD_only_this_ mode, we will need to set up that cached comparison pose
267  core::pose::Pose dummy;
270  }
271 
272  return;
273 }
274 
275 ///@details AnchoredDesignMover is mostly a container for other movers for the anchored design protocol.
277 {
278  clock_t starttime = clock();
279 
281 
282  core::pose::PoseCOP start_pose(0);
283 
284  //pre-pre-processing
285  if( rmsd_ ){
286  start_pose = new core::pose::Pose(pose);
287  }
288 
289  if( RMSD_only_this_ != EMPTY_STRING ){
290  core::pose::Pose dummy;
292  start_pose = RMSD_only_this_pose_;
293  } else { //if RMSD_only_this is active, we skip all the meat steps
294 
295 
296  //pre-processing
297  interface_->pick_new_cutpoints(vary_cutpoints_); //verifies that cutpoints are legal w/r/t anchor; chooses new ones if not; picks new random ones if bool is true
299  forget_initial_loops( pose ); //checks loop object is_extended internally
300 
303 
304  if( interface_->get_anchor_noise_constraints_mode() ){
305  interface_->anchor_noise_constraints_setup(pose);
306  perturb_anchor(pose);
307  }
308 
309  if( show_extended_
312  || interface_->get_anchor_noise_constraints_mode()){
313  using namespace protocols::jd2;
314  JobDistributor::get_instance()->job_outputter()->other_pose(JobDistributor::get_instance()->current_job(), pose, "preprocessed");
315  }
316 
317  //processing
318  if (!refine_only_){
320  anchor_perturb.apply( pose );
321  }
322 
323  //do not want constraints in centroid mode - for one, they're probably fullatom, and for two, the centroid scorefunction isn't so hot anyway
324  core::scoring::constraints::add_constraints_from_cmdline_to_pose( pose ); //protected internally if no constraints
325 
327  anchor_refine.apply( pose );
328 
329  //post-processing
331  LAM.apply( pose );
332 
333  //load sequence into Job output
334  protocols::jd2::JobDistributor::get_instance()->current_job()->add_string("SEQUENCE: " + pose.sequence());
335 
336  //load interface analysis info
337  IAM_->apply( pose );
338 
339  //load unconstrainted score
340  if(pose.constraint_set()->has_constraints()){
341  pose.constraint_set()->show_definition(T_design, pose);
342  core::pose::Pose nocstcopy(pose);
343  nocstcopy.remove_constraints();
344  protocols::jd2::JobDistributor::get_instance()->current_job()->add_string_real_pair("no_cst_total", ((*interface_->get_fullatom_scorefunction())(nocstcopy)));
345  }
346 
347  clock_t stoptime = clock();
348  T_design << "One perturb/refine took " << ((double) stoptime - starttime )/CLOCKS_PER_SEC << " seconds" << std::endl;
349  } //end RMSD_only_this block
350 
351  //post-post-processing
352  calculate_rmsd(pose, start_pose);
353 
354  filter(pose);
355  (*interface_->get_fullatom_scorefunction())(pose);
356  return;
357 }//AnchoredDesignMover::apply
358 
359 void
361 
362  if( rmsd_ ){
363  core::Real const rmsd(core::scoring::CA_rmsd(pose, *start_pose));
364  T_design << "CA_sup_RMSD for this trajectory: " << rmsd << std::endl;
365  protocols::jd2::JobDistributor::get_instance()->current_job()->add_string_real_pair("CA_sup_RMSD", rmsd);
366 
367  std::list<core::Size> loops_for_rmsd;
368  for (core::Size i(1), num_loops(interface_->num_loops()); i <= num_loops; ++i){
369  core::Size const loopstart(interface_->loop(i).start()), loopend(interface_->loop(i).stop());
370  for (core::Size j = loopstart; j <= loopend; ++j){
371  loops_for_rmsd.insert(loops_for_rmsd.end(), j);
372  }
373  }
374 
375  // T_design << "loop residues for RMSD:";
376  // for( std::list<core::Size>::const_iterator it(loops_for_rmsd.begin()), end(loops_for_rmsd.end()); it != end; ++it){
377  // T_design << " " << *it;
378  // }
379  // T_design << std::endl;
380 
381  core::Real const loop_rmsd(core::scoring::CA_rmsd(pose, *start_pose, loops_for_rmsd));
382  T_design << "loop_CA_sup_RMSD for this trajectory: " << loop_rmsd << std::endl;
383  protocols::jd2::JobDistributor::get_instance()->current_job()->add_string_real_pair("loop_CA_sup_RMSD", loop_rmsd);
384 
385  //chain 1 RMSD
386  core::Real const ch1_sup_rmsd(core::scoring::CA_rmsd(pose, *start_pose, pose.conformation().chain_begin(1), pose.conformation().chain_end(1)));
387  T_design << "chain 1 sup_RMSD for this trajectory: " << ch1_sup_rmsd << std::endl;
388  protocols::jd2::JobDistributor::get_instance()->current_job()->add_string_real_pair("ch1_CA_sup_RMSD", ch1_sup_rmsd);
389 
390  //chain 2 RMSD
391  core::Real const ch2_sup_rmsd(core::scoring::CA_rmsd(pose, *start_pose, pose.conformation().chain_begin(2), pose.conformation().chain_end(2)));
392  T_design << "chain 2 sup_RMSD for this trajectory: " << ch2_sup_rmsd << std::endl;
393  protocols::jd2::JobDistributor::get_instance()->current_job()->add_string_real_pair("ch2_CA_sup_RMSD", ch2_sup_rmsd);
394 
395  //also need no-superimpose RMSDs for chain1/2 to get lever arm effect
396  ObjexxFCL::FArray1D_bool ch1(pose.total_residue(), false), ch2(pose.total_residue(), false);
397 
398  for( core::Size i(pose.conformation().chain_begin(1)), end(pose.conformation().chain_end(1)); i<=end; ++i) ch1(i)=true;
399  //chain 1 RMSD
400  core::Real const ch1_rmsd(core::scoring::rmsd_no_super_subset(pose, *start_pose, ch1, core::scoring::is_protein_CA));
401  T_design << "chain 1 RMSD for this trajectory: " << ch1_rmsd << std::endl;
402  protocols::jd2::JobDistributor::get_instance()->current_job()->add_string_real_pair("ch1_CA_RMSD", ch1_rmsd);
403 
404  for( core::Size i(pose.conformation().chain_begin(2)), end(pose.conformation().chain_end(2)); i<=end; ++i) ch2(i)=true;
405  //chain 2 RMSD
406  core::Real const ch2_rmsd(core::scoring::rmsd_no_super_subset(pose, *start_pose, ch2, core::scoring::is_protein_CA));
407  T_design << "chain 2 RMSD for this trajectory: " << ch2_rmsd << std::endl;
408  protocols::jd2::JobDistributor::get_instance()->current_job()->add_string_real_pair("ch2_CA_RMSD", ch2_rmsd);
409 
410  //This next section is meant purely for benchmarking purposes. It assumes the moving chain is chain 2, and that the interface-definition calculator created by the standard AnchorClass default TaskFactory exists. It will use rmsd_with_super_subset on interface backbone atoms, because that's what docking does.
411  //chain 2 interface RMSD
412  if(true){
413 
414  //get interface set from calculator
415  std::string const & interface_calc(interface_->interface_calc());
416  //find the set of residues
417  typedef std::set< core::Size > SizeSet;
418  basic::MetricValue< SizeSet > mv_sizeset;
419  start_pose->metric(interface_calc, "interface_residues", mv_sizeset);
420  SizeSet const & sizeset(mv_sizeset.value());
421 
422  //convert this set into the type needed by rmsd_with_super_subset
423  T_design << "interface for rmsd";
424  ObjexxFCL::FArray1D_bool is_interface( pose.total_residue(), false );
425  for (SizeSet::const_iterator it = sizeset.begin(); it != sizeset.end(); ++it){
426  is_interface(*it) = true;
427  T_design << " " << *it;
428  }
429  T_design << std::endl;
430 
431  //ready to calculate
432  core::Real const I_sup_bb_rmsd(core::scoring::rmsd_with_super_subset(pose, *start_pose, is_interface, core::scoring::is_protein_backbone));
433  T_design << "interface backbone RMSD for this trajectory: " << I_sup_bb_rmsd << std::endl;
434  protocols::jd2::JobDistributor::get_instance()->current_job()->add_string_real_pair("I_sup_bb_RMSD", I_sup_bb_rmsd);
435 
436  }
437 
438  }
439  return;
440 }
441 
442 ///@details This is crazy. Sometimes loop redesign is overly biased by the starting loop sequence, because the centroid phase won't change the sequence, and the rama term may remember the conformation to well due to sequence preferences. This restricts sampling. So, this function creates a random sequence in the designable positions, based on what the design PackerTask thinks they can become. This code special cases histidine (to avoid double-allowing histidine, based on its two protonations).
444 
445  T_design << "entering randomize_input_sequence" << std::endl;
446 
447  //Get copy of "right" PackerTask
448  core::pack::task::PackerTaskCOP oldtask(interface_->get_task(pose));
449 
450  //there isn't much we can do to use the old task due to accumulation of status; also (and more importantly) using a task to pack is ruined by uneven numbers of rotamers (arginine would be favored over glycine).
451 
452  core::Size const nres(pose.total_residue());
453  for(core::Size i(1); i<=nres; ++i){ //for all positions
454  //if this position is designable, do something
456  ResidueLevelTask const & rlt(oldtask->residue_task(i));
457  if(rlt.being_designed()){
458  //get the list
459  ResidueLevelTask::ResidueTypeCOPList types(rlt.allowed_residue_types());
460 
461  //print possibilities before histidine check
462  T_design << "before HIS/D check, position " << i;
463 
464  for( ResidueLevelTask::ResidueTypeCOPListIter
465  allowed_iter = types.begin(),
466  allowed_end = types.end();
467  allowed_iter != allowed_end; ++allowed_iter ) {
468  T_design << " " << (*allowed_iter)->name();// << std::endl;
469  }
470  T_design << std::endl;
471 
472  //sweep for histidines
473  core::Size num_histidines(0); //count histidines we find; if more than 2 explode
474  core::chemical::ResidueTypeCOP histidine; //store the most recent histidine we find as we go
475  for( ResidueLevelTask::ResidueTypeCOPListIter
476  allowed_iter = types.begin(),
477  iter_next = types.begin(),
478  allowed_end = types.end();
479  allowed_iter != allowed_end; /* no increment: deletion + iterator incrementing = segfault! */ ) {
480  iter_next = allowed_iter;
481  ++iter_next;
482 
483  if ((*allowed_iter)->aa() == core::chemical::aa_his) { //we only want to look at histidines
484  ++num_histidines;
485  histidine=*allowed_iter;
486  types.erase( allowed_iter );
487  }
488  allowed_iter = iter_next;
489  }//histidine removal scan
490  if( num_histidines > 0 && num_histidines < 3 ){
491  types.push_back(histidine); //if we removed 1 or 2
492  } else if ( num_histidines < 3 ) {
493  utility_exit_with_message("removed more than 2 histidines in AnchoredDesign::randomize_input_sequence, something is wrong");
494  }
495 
496  //print possibilities after histidine check
497  T_design << "after HIS/D check, position " << i;
498 
499  for( ResidueLevelTask::ResidueTypeCOPListIter
500  allowed_iter = types.begin(),
501  allowed_end = types.end();
502  allowed_iter != allowed_end; ++allowed_iter ) {
503  T_design << " " << (*allowed_iter)->name();
504  }
505  T_design << std::endl;
506 
507  //now that that's out of the way, pick a ResidueType at random
508  core::Size const num_types(types.size());
509  core::Size const chosen_type_index(RG.random_range(1, num_types));
510  ResidueLevelTask::ResidueTypeCOPListIter iter = types.begin();
511  for(core::Size add(1); add<chosen_type_index; ++add) ++iter;
512  core::chemical::ResidueTypeCOP chosen_type(*iter);
513 
514  T_design << "chose at position " << i << chosen_type->name() << std::endl;
515  T_design << "chose at position " << i << chosen_type->name() << std::endl;
516 
517  //do a replace_replace with the chosen type
518  using namespace core::conformation;
519  ResidueCOP new_residue(ResidueFactory::create_residue( *chosen_type, pose.residue(i), pose.conformation()));
520  pose.replace_residue(i, *new_residue, true);
521 
522  }//if being designed
523  //if not being designed, do nothing
524  }//for all residues
525 
526  return;
527 }
528 
529 ///@details For benchmarking, it is a minor sin to allow native sidechains to leak through from the starting structure. AnchoredDesign runs best with use_input_sc because it does sidechain minimization, not because it needs starting sidechains. This function deletes the native sidechains by repacking the interface with use_input_sc forcibly off. DO NOT USE THIS FUNCTION for proper designs - it is meant for a specific benchmarking purpose.
531 
532  //create a TaskFactory for the deletion. Notice that it DOES NOT read all user inputs (ignoring the resfile and command line) and thus can only be used when you satisfy its assumptions. The assumptions are that you are A) doing fixed-sequence benchmarking, and B) starting from the correct interface structure. The factory is set up to detect the interface and repack those side chains, excepting the anchor, to with many rotamers. It does NOT pay attention to the flags that allow repacking of the anchor. It ASSUMES that the AnchorMoversData class has pregenerated some PoseMetricCalculators.
533  using namespace core::pack::task;
535 
536  //some code copied from AnchorClass.cc:AnchorMoversData::set_unset_packertask_factory. I chose to copy (gasp) because I do want the two to be uncoupled; if the other code evolves this should stay the same. Of course, the PoseMetricCalculators are still a dependency...
537  //operation to detect interface/loops; depends on preexistence of these calculators
538  std::string const & interface_calc(interface_->interface_calc());
539  std::string const & neighborhood_calc(interface_->neighborhood_calc());
541  calcs_and_calcns.push_back(std::make_pair(interface_calc, "interface_residues"));
542  calcs_and_calcns.push_back(std::make_pair(neighborhood_calc, "neighbors"));
543 
545  operation::TaskOperationOP rbcop(new RestrictByCalculatorsOperation( calcs_and_calcns ));
546 
547  tf->push_back(rbcop);
548 
549  //operation to protect anchor
551  for( core::Size i(interface_->anchor_start()); i<= interface_->anchor_end(); ++i){
552  prop->include_residue(i);
553  }
554 
555  tf->push_back(prop);
556 
557  //operations to allow ex flags to saturation
558  for(core::Size i(1), end(pose.total_residue()); i<=end; ++i){
561  //tf->push_back(operation::IncludeCurrentOP( new core::pack::task::operation::IncludeCurrent())); //this is exactly what we do not want - useful for testing that it worked right...
562  }
563 
564  //we DO NOT WANT design
565  tf->push_back(new operation::RestrictToRepacking());
566 
567  //print a copy of the task for double checking
568  //T_shared << *(tf->create_task_and_apply_taskoperations(pose)) << std::endl;
569 
570  //pose.dump_pdb("pre_delete_interface_sidechains_test.pdb");
571  //create a PackRotamersMover and do it
573  pack_mover->task_factory( tf );
574  pack_mover->score_function( interface_->get_fullatom_scorefunction() );
575  pack_mover->apply(pose);
576  //pose.dump_pdb("post_delete_interface_sidechains_test.pdb");
577  return;
578 }
579 
580 ///@details when using anchor_noise_constraints_mode, this function perturbs the initial anchor a bit. Requested test by a reviewer.
582 
583  //I think if we take the Stubs out of the existing Jump, all we have to do is change the vector part
586  Stub const & S1( pose.conformation().upstream_jump_stub( ANCHOR_TARGET ) );
587  Stub const & S2( pose.conformation().downstream_jump_stub( ANCHOR_TARGET ) );
588  core::Vector const & translation(S2.v);
589 
590  //store xyz to check momentarily
591  core::Size const anchor(interface_->anchor_start());
592  core::Size const CA(pose.residue_type(anchor).atom_index("CA"));
593  core::id::AtomID const anchor_ID(core::id::AtomID(CA, anchor));
594  core::Vector const original_anchor_xyz(pose.xyz(anchor_ID));
595 
596  //We want to make a change of plus or minus one angstrom. RG.uniform returns a range of 0 to 1, so the formula 2N-1 converts it to a range of -1 to 1 perturbation - we add this to the original coordinate.
597  core::Real const new_x(translation.x() + ((RG.uniform()*2.0) - 1.0));
598  core::Real const new_y(translation.y() + ((RG.uniform()*2.0) - 1.0));
599  core::Real const new_z(translation.z() + ((RG.uniform()*2.0) - 1.0));
600 
601  T_design << "perturb_anchor: old/new, x->y->z\n"
602  << translation.x() << " " << new_x << "\n"
603  << translation.y() << " " << new_y << "\n"
604  << translation.z() << " " << new_z << std::endl;
605 
606  core::Vector const new_trans(new_x, new_y, new_z);
607 
608  pose.set_jump(ANCHOR_TARGET, Jump(S1, Stub( S2.M, new_trans ) ));
609 
610  core::Vector const new_anchor_xyz(pose.xyz(anchor_ID));
611 
612  T_design << "perturb_anchor: old and new CA positions:\n"
613  << original_anchor_xyz << '\n'
614  << new_anchor_xyz << std::endl;
615 
616  return;
617 }
618 
621  return "AnchoredDesignMover";
622 }
623 
625  return new AnchoredDesignMover;
626 }
627 
629  return new AnchoredDesignMover(*this);
630 }
631 
633 
634 ///@details generally returns true; will return false for RMSD_only_this mode
636 
638 
639  std::ostringstream failure;
640  bool fail(false);
641 
642  if(use_filter_score_) {
643  core::Real const pscore((*interface_->get_fullatom_scorefunction())(pose));
644  if( pscore > filter_score_) {
645  failure << "failed total score filter; score " << pscore;
646  fail = true;
647  }
648  }
649 
650  if( use_filter_SASA_ && !fail ){
651  basic::MetricValue< core::Real > mv_delta_sasa;
652  pose.metric("InterfaceSasaDefinition_1", "delta_sasa", mv_delta_sasa); //magic string: this calculator was created by the InterfaceAnalyzerMover
653  if(mv_delta_sasa.value() < filter_SASA_){
654  failure << "failed interface SASA filter; sasa " << mv_delta_sasa.value();
655  fail = true;
656  }
657  }
658 
659  if( use_filter_omega_ && !fail){
660  core::Size const num_loops = interface_->num_loops();
661  for (core::Size i(1); i <= num_loops; ++i){
662  core::Size const loopstart(interface_->loop(i).start()), loopend(interface_->loop(i).stop());
663  for (core::Size j = loopstart; j <= loopend; ++j){
664  core::Real const omega(numeric::principal_angle_degrees(pose.omega(j)));
665  if( pose.residue(j).is_upper_terminus() ) continue; //omega will fail for c-term
666  if( (omega < 160) && (omega > -160) ) {
667  failure << "failed omega at " << j << " " << omega;
668  fail = true;
669  i = num_loops + 1; //break out of parent loop
670  break; //and this loop
671  } //if omega is bad
672  } //for residues in loop
673  } //for each loop
674  }//if filter active
675 
676  if( !fail ) { //succeed case
677  set_last_move_status(protocols::moves::MS_SUCCESS); //this call is unnecessary but let's be safe
678  return;
679  }
680 
681  //print failure
682  T_design << failure.str() << std::endl;
684  return;
685 }
686 
687 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
688 ///@details uses fold_tree::tree_from_jumps_and_cuts to make the necessary fold tree and apply it to the pose
690 {
691  core::Size const nres = pose.total_residue();
692 
693  //we'll need to know where the chainbreak is (we are assuming there is only one)
694  core::Size const chain1end(pose.conformation().chain_end(1));
695  if( pose.conformation().num_chains() != 2 ) //2 is the value we expect
696  Warning() << "AnchoredDesign only tested with two chains; later chains may(?) be rigidly attached to chain 2 COOH, or not move at all, or who knows what";
697 
698  core::Size const num_loops(interface_->num_loops());
699  core::Size num_jumps(num_loops+1);//one extra for the inter-rigid-body jump
700 
701  //these may need to be redimensioned
702  utility::vector1<int> jump_starts(num_jumps, 0), jump_stops(num_jumps, 0), cuts(num_jumps, 0);
703 
704  //using core::Real;
705  core::Real anchorstart(interface_->anchor_start()), anchorend(interface_->anchor_end());
706  core::Size anchormid(core::Size(std::ceil(anchorstart + (anchorend - anchorstart)/2.0)));
707 
708  Size anchor_jump_end( anchormid > chain1end ? chain1end : chain1end+1);
709  jump_starts[ANCHOR_TARGET] = anchormid < anchor_jump_end ? anchormid : anchor_jump_end; //max
710  jump_stops[ ANCHOR_TARGET] = anchormid > anchor_jump_end ? anchormid : anchor_jump_end; //min
711  cuts[ANCHOR_TARGET] = chain1end;
712  assert(anchormid != anchor_jump_end);
713 
714 // jumps(1, ANCHOR_TARGET) = anchormid < anchor_jump_end ? anchormid : anchor_jump_end; //max
715 // jumps(2, ANCHOR_TARGET) = anchormid > anchor_jump_end ? anchormid : anchor_jump_end; //min
716 // assert(anchormid != anchor_jump_end);
717 // cuts(ANCHOR_TARGET) = chain1end;
718 
719  int jump_num = ANCHOR_TARGET; //this reserves earlier jump numbers for the anchor
720  //iterate over all loops
721  for( core::Size i(1); i <= num_loops; ++i ){
722  //if this is a terminal loop, don't mess with fold_tree, we won't need space in the vectors
723  if ( pose.residue(interface_->loop(i).start()).is_terminus() //or
724  || pose.residue(interface_->loop(i).stop() ).is_terminus() ) {
725  jump_starts.pop_back();
726  jump_stops.pop_back();
727  cuts.pop_back();
728  --num_jumps; //one fewer jump to set up
729  continue;
730  }
731 
732  jump_num++;
733  jump_starts[jump_num] = interface_->loop(i).start() - 1;
734  jump_stops[ jump_num] = interface_->loop(i).stop() + 1;
735  cuts[jump_num] = interface_->loop(i).cut();
736 
737  //label cutpoints properly
741  }//over all loops
742 
743  //convert the vectors into FArrays
744  assert(cuts.size() == num_jumps);
745  ObjexxFCL::FArray2D<int> Fjumps(2, num_jumps);
746  ObjexxFCL::FArray1D<int> Fcuts(num_jumps);
747  for(core::Size i(1); i<=num_jumps; ++i){
748  Fjumps(1, i) = jump_starts[i];
749  Fjumps(2, i) = jump_stops[i];
750  Fcuts(i) = cuts[i];
751  }
752 
753  //instantiate, create, output, apply our fold tree
754  core::kinematics::FoldTree foldtree(nres);
755  foldtree.tree_from_jumps_and_cuts(nres, num_jumps, Fjumps, Fcuts, 1, true);
756  //foldtree.reorder(1);
757  T_design << "anchored_design_fold_tree: " << foldtree << std::flush;
758 
759  //do it harder, better, faster, stronger
760  core::kinematics::Edge const & anchoredge(foldtree.jump_edge(ANCHOR_TARGET));
761  core::kinematics::Edge const new_anchoredge( anchoredge.start(), anchoredge.stop(), ANCHOR_TARGET, "CA", "CA", true);
762  foldtree.delete_edge(anchoredge);
763  foldtree.add_edge(new_anchoredge);
764  foldtree.reorder(1);
765  T_design << "anchored_design_fold_tree: " << foldtree << std::flush;
766 
767  pose.fold_tree(foldtree);
768  dump_cutpoint_info(pose);
769 }//AnchoredDesignMover::set_fold_tree_and_cutpoints
770 
771 ///@details implements the is_extended boolean for the Loop class. If the boolean is on, this function resets phi/psi for those regions to be extended (-150phi, 150psi). This function does not affect omega, or residues outside of defined loops, or the anchor.
773 
774  //for each loop
775  core::Size const num_loops(interface_->num_loops());
776  for( core::Size loop(1); loop <= num_loops; ++loop ){
777  //if loop has extended boolean set
778  if( interface_->loop(loop).is_extended() ){
779  //iterate through loop residues
780  core::Size const loop_start(interface_->loop(loop).start()), loop_end(interface_->loop(loop).stop());
781  for( core::Size res(loop_start); res<=loop_end; ++res ){
782  //check movemap before alteration
783  using namespace core::id;
784  if(interface_->movemap_cen_all()->get_bb(res)){
785  pose.set_phi(res, -150.0);
786  pose.set_psi(res, 150.0);
787  }//if mm says ok
788  }//for each residue
789  }//if loop is extended
790  }//for each loop
791 
792  return;
793 }
794 
795 
796 //option system replacement getters and setters
797 ///@brief run RMSD calculations
798 bool AnchoredDesignMover::get_rmsd() const {return rmsd_;}
799 ///@brief run only RMSD calculations against this input, don't do actual AnchoredDesign
801 ///@brief delete the input sidechains (independently from use_input_sc in the packer) - used to prevent leakage of sidechains in benchmarking mode
803 ///@brief show_extended demonstrates that the code really forgets the input structure
805 ///@brief randomize_input_sequence to complement loop extension in forgetting the input
807 ///@brief pick a different cutpoint than the input; useful when you want to sample cutpoints
809 ///@brief skip the perturbation step - useful when you already have a good structure
811 ///@brief filter based on total complex score
813 ///@brief filter based on complex SASA
815 ///@brief filter based on omega angles in the loops - filter out cis omegas
817 ///@brief whether to automatically initialize from the options system; defaults to true
819 
820 ///@brief run RMSD calculations
821 void AnchoredDesignMover::set_rmsd(bool const rmsd) { rmsd_ = rmsd;}
822 ///@brief run only RMSD calculations against this input, don't do actual AnchoredDesign
823 void AnchoredDesignMover::set_RMSD_only_this(std::string const & RMSD_only_this) { RMSD_only_this_ = RMSD_only_this;}
824 ///@brief delete the input sidechains (independently from use_input_sc in the packer) - used to prevent leakage of sidechains in benchmarking mode
826 ///@brief show_extended demonstrates that the code really forsets the input structure
827 void AnchoredDesignMover::set_show_extended(bool const show_extended) { show_extended_ = show_extended;}
828 ///@brief randomize_input_sequence to complement loop extension in forgetting the input
830 ///@brief pick a different cutpoint than the input { _ = ;} useful when you want to sample cutpoints
831 void AnchoredDesignMover::set_vary_cutpoints(bool const vary_cutpoints) { vary_cutpoints_ = vary_cutpoints;}
832 ///@brief skip the perturbation step - useful when you already have a good structure
833 void AnchoredDesignMover::set_refine_only(bool const refine_only) { refine_only_ = refine_only;}
834 ///@brief filter based on total complex score
836  filter_score_ = filter_score;
837  use_filter_score_ = true;}
838 ///@brief filter based on complex SASA
840  filter_SASA_ = filter_SASA;
841  use_filter_SASA_ = true;}
842 ///@brief filter based on omega angles in the loops - filter out cis omegas
843 void AnchoredDesignMover::set_filter_omega(bool const filter_omega) { use_filter_omega_ = filter_omega;}
844 ///@brief whether to automatically initialize from the options system; defaults to true
845 void AnchoredDesignMover::set_autoinitialize(bool const autoinitialize) { autoinitialize_ = autoinitialize;}
846 
848 
849  using namespace basic::options;
850  using namespace basic::options::OptionKeys::AnchoredDesign;
851 
852  //bool rmsd_;
853  rmsd_ = option[ OptionKeys::AnchoredDesign::rmsd ].value();
854 
855  //std::string RMSD_only_this_;
856  if( option[ testing::RMSD_only_this ].user() ){
857  RMSD_only_this_ = option[ testing::RMSD_only_this ].value();
858  } else {
860  }
861 
862  //bool delete_interface_native_sidechains_;
863  delete_interface_native_sidechains_ = option[ testing::delete_interface_native_sidechains].value();
864 
865  //bool show_extended_;
866  show_extended_ = option[show_extended].value();
867 
868  //bool randomize_input_sequence_;
869  randomize_input_sequence_ = option[ testing::randomize_input_sequence ].value();
870 
871  //bool vary_cutpoints_;
872  vary_cutpoints_ = option[ vary_cutpoints ].value();
873 
874  //bool refine_only_;
875  refine_only_ = option[ refine_only ].value();
876 
877  //core::Real filter_score_;
878  if( option[ OptionKeys::AnchoredDesign::filters::score].user() ){
879  filter_score_ = option[ OptionKeys::AnchoredDesign::filters::score].value();
880  use_filter_score_ = true;
881  } else {
882  use_filter_score_ = false;
883  }
884 
885  //core::Real filter_SASA_;
886  if( option[ OptionKeys::AnchoredDesign::filters::sasa].user() ){
887  filter_SASA_ = option[ OptionKeys::AnchoredDesign::filters::sasa].value();
888  use_filter_SASA_ = true;
889  } else {
890  use_filter_SASA_ = false;
891  }
892 
893  //bool filter_omega_;
895 
896  return;
897 }
898 
899 ///////////////////////////////////////////////////////////////////////////////////////////////////////////
900 ///////////////////////////AnchoredPerturbMover////////////////////////////////////////////////////////////
901 ///////////////////////////////////////////////////////////////////////////////////////////////////////////
903  Mover(), interface_( interface_in )
904 {
905  protocols::moves::Mover::type( "AnchoredPerturb" );
906  read_options();
907 }
908 
910 
911 ///@details AnchoredPerturbMover takes a pose, swaps it into centroid mode, and perturbs the structure of
912 ///its mobile loops. The perturbation step is under Monte Carlo control so it won't finish with a terrible
913 ///structure. It adds sidechains back on (unchanged relative to the alpha carbon) at the end, but does not
914 ///repack those sidechains.
916 {
917  clock_t starttime = clock();
918  T_perturb << "entering perturb steps" << std::endl;
919 
920  core::pose::Pose const saved_input_pose( pose ); //used to return sidechains later
921 
922  core::pose::PoseOP posecopy( NULL );
923  //if(debug_) posecopy = new core::pose::Pose( pose ); //after centroid-izing
924  int counter(1);
925  std::stringstream outputfilename;
926 
927  //score the protein
928  T_perturb << "fullatom score of starting PDB: " << (*(interface_->get_fullatom_scorefunction()))(pose) << std::endl;
929  (*(interface_->get_fullatom_scorefunction())).show( T_perturb, pose );
930  T_perturb << std::flush; //show doesn't flush the buffer
931 
933  typeset_swap.apply( pose );
934  if(debug_) posecopy = new core::pose::Pose( pose );
935 
936  //centroid score
937  T_perturb << "centroid score of starting PDB: " << (*(interface_->get_centroid_scorefunction()))(pose) << std::endl;
938  (*(interface_->get_centroid_scorefunction())).show( T_perturb, pose );
939  T_perturb << std::flush; //show doesn't flush the buffer
940 
941  /*
942  for each loop
943  perturbmover of either type
944  ccd close
945  minimize
946  MC evaluate
947  */
948 
949  //make the sequence mover. other movers are inserted into it (their handles go out of scope!)
953 
954  //loop to add perturbing movers for each loop (this setup does each loop equally and sequentially)
955  core::Size num_loops(interface_->num_loops());
956  for( core::Size i(1); i <= num_loops; ++i ){
957  ///////////////////////////generate perturb mover///////////////////////////////
958  //somewhat complex logic here, as there are three options for internal loops:
959  // 1) SmallMover plus CCD closure
960  // 2) Fragment insertion plus CCD closure, which is chosen over 1) if fragments are present
961  // 3) Kinematic loop closure, which does not need separate perturb/close steps
962  // We could also allow 3 with 1 OR 2 - try kinematic sometimes, and CCD sometimes
963  // there are two possibilities for terminal flexible regions: SmallMover or fragments (no loop closure needed).
964 
966  protocols::moves::MoverOP perturb_mover;
968  //handles for clarity
969  core::Size const loop_start(interface_->loop(i).start());
970  core::Size const loop_end(interface_->loop(i).stop());
971  bool const internal(!( pose.residue(loop_start).is_terminus() || pose.residue(loop_end).is_terminus() ));
972 
973  if( perturb_CCD_off_ && perturb_KIC_off_ ) utility_exit_with_message( "cannot pass both AnchoredDesign::perturb_CCD_off AND AnchoredDesign::perturb_KIC_off; this turns off both types of loop remodeling" );
974 
975  //option 3: kinematic; no perturbation or closure needed
976  if( internal && !perturb_KIC_off_){
977  //make kinematic mover
981  KinematicMoverOP kin_mover( new KinematicMover() );//temperature, default 0.8
982  KinematicMoverCAP kin_mover_cap(*kin_mover);
983  kin_mover->set_temperature( perturb_temp_ );
984 
985  //set up kinematic mover - this is borrowed from loops_main.cc, perturb_one_loop_with_alc(), SVN 24219, #932-946
986  kin_mover->set_vary_bondangles( false );
987  kin_mover->set_sample_nonpivot_torsions( nonpivot_torsion_sampling_ );
988  kin_mover->set_rama_check( true );
989  kin_mover->set_idealize_loop_first( false );
990 
991  //make kinematic perturber
994  KinematicPerturberOP TsamplingKP( new TorsionSamplingKinematicPerturber(kin_mover_cap));
995  TsamplingKP->set_movemap(interface_->movemap_cen(i));
996  kin_mover->set_perturber(TsamplingKP);
997 
1000  KinematicWrapperOP kin_wrapper( new KinematicWrapper(kin_mover, interface_->loop(i)));
1001  kin_wrapper->respect_this_movemap(interface_->movemap_cen(i));
1002  oneloop_random->add_mover(kin_wrapper, 1);
1003  T_perturb << "creating KinematicWrapper with loop " << loop_start << " " << loop_end << std::endl;
1004  }//if using kinematic
1005 
1006  //if this is a terminal extension, or if we want CCD
1007  if (!internal || !perturb_CCD_off_) {
1008  //now, check whether perturb is fragment based or not
1009  if ( !interface_->get_frags() /*if NULL*/ || no_frags_ ) {
1010  core::Size nmoves(5);
1013  protocols::simple_moves::SmallMoverOP small_mover = new protocols::simple_moves::SmallMover(interface_->movemap_cen(i), 0.8, nmoves);
1014  small_mover->angle_max( 'H', 180.0 );
1015  small_mover->angle_max( 'E', 180.0 );
1016  small_mover->angle_max( 'L', 180.0 );
1017  perturb_mover = small_mover;
1018  T_perturb << "creating SmallMover-based perturbation for loop " << loop_start << " " << loop_end << std::endl;
1019  } //smallmover based perturb
1020  else {
1021  /*T_perturb << "For loop start " << loop_start << " end " << loop_end
1022  << " fragments exist; preferring fragments over small moves" << std::endl;*/
1024  protocols::simple_moves::ClassicFragmentMoverOP frag_mover = new ClassicFragmentMover(interface_->get_frags(), interface_->movemap_cen(i));
1025  frag_mover->enable_end_bias_check(false);
1026  perturb_mover = frag_mover;
1027  T_perturb << "creating fragment-based perturbation for loop " << loop_start << " " << loop_end << std::endl;
1028  } //fragment based perturb
1029 
1030  oneloop_subsequence->add_mover(perturb_mover);
1031 
1032  if( debug_ ) {
1033  outputfilename.str(""); //clears stream
1034  outputfilename << "perturbed_" << counter;
1035  debug_dump_pose(pose, posecopy, outputfilename.str(), perturb_mover);
1036  }
1037 
1038  //now we need to add on closure, if the loop is not terminal and we didn't use KinematicMover above
1039  if( internal && !perturb_CCD_off_ ){
1040  ///////////////////////////generate CCD close mover///////////////////////////////
1042  oneloop_subsequence->add_mover(new CcdLoopClosureMover(interface_->loop(i), interface_->movemap_cen_omegafixed(i)));
1043  T_perturb << "creating CCD-closure after perturbation for loop " << loop_start << " " << loop_end << std::endl;
1044 
1045  if( debug_ ){
1046  outputfilename.str(""); //clears stream
1047  outputfilename << "perturbed_CCD_" << counter;
1048  debug_dump_pose(pose, posecopy, outputfilename.str(), oneloop_subsequence);
1049  }//debug
1050  }//if internal (for CCD)
1051  oneloop_random->add_mover(oneloop_subsequence, 1);
1052  }//if (CCD) or terminal
1053 
1054  ++counter;
1055 
1056  allloops_subsequence->add_mover(oneloop_random); //keep track of all loops as a sequence
1057  backbone_mover->add_mover(oneloop_random, 1.0); //add to random mover with large weight
1058  } //end for loop over protein loops
1059 
1060  backbone_mover->add_mover(allloops_subsequence, 0.25); //run all loops combinatorially some small fraction of time
1061  //backbone_mover now randomly chooses one loop (equal probabilities) or all at once a small amount of the time
1062  perturb_sequence->add_mover(backbone_mover);
1063 
1064  if( debug_ ) debug_dump_pose(pose, posecopy, "perturbed_nomin", allloops_subsequence);
1065 
1066  /////////////////////////minimizer mover/////////////////////////////////////////
1070  interface_->movemap_cen_all(),
1071  interface_->get_centroid_scorefunction_min(),
1072  min_type_,
1073  0.01,
1074  true /*use_nblist*/ );
1075 
1076  perturb_sequence->add_mover(min_mover);
1077 
1078  if( debug_ ) {
1079  debug_dump_pose(pose, posecopy, "perturbed_min", min_mover);
1080  dump_cutpoint_info( pose );
1081  debug_dump_pose(pose, posecopy, "perturbed_all", perturb_sequence);
1082  }
1083 
1084  /////////////////////////wrap the sequence in a trial/////////////////////////////////////////
1085  //make the monte carlo object
1088  MonteCarloOP mc( new MonteCarlo(
1089  pose,
1090  *(interface_->get_centroid_scorefunction()),
1091  perturb_temp_ ) );//temperature, default 0.8
1092  protocols::moves::TrialMoverOP trial_mover = new protocols::moves::TrialMover( perturb_sequence, mc );
1093 
1094  /////////////////////////wrap in a for loop output preference/////////////////////////////////
1095  T_perturb << " Current Low total cycles =" << perturb_cycles_ << std::endl;
1096  for ( core::Size i = 1; i <= perturb_cycles_; ++i ) {
1097  trial_mover->apply( pose );
1098  T_perturb << i << " " << mc->last_accepted_score() << " " << mc->lowest_score() << std::endl;
1099  }//end the exciting for loop
1100  mc -> recover_low( pose );
1101 
1102  if ( perturb_show_ ) {
1103  using namespace protocols::jd2;
1104  JobDistributor::get_instance()->job_outputter()->other_pose(JobDistributor::get_instance()->current_job(), pose, "perturbed_centroid_final");
1105  }
1106 
1107  //show centroid score (duplicates last line above)
1108  T_perturb << "centroid score of final perturbed PDB: " << (*(interface_->get_centroid_scorefunction()))(pose)
1109  << std::endl;
1110  (*(interface_->get_centroid_scorefunction())).show( T_perturb, pose );
1111  T_perturb << std::flush; //show doesn't flush the buffer
1112 
1113  if ( debug_ ) {
1114  using namespace protocols::jd2;
1115  JobDistributor::get_instance()->job_outputter()->other_pose(JobDistributor::get_instance()->current_job(), pose, "perturbed_prerefullatom");
1116  }
1117  protocols::simple_moves::ReturnSidechainMover return_sidechains( saved_input_pose );
1118  return_sidechains.apply( pose );
1119 
1120  /////////////////////////////generate full repack&minimize mover//////////////////////////////
1122  TaskFactoryOP task_factory = new TaskFactory(*(interface_->get_late_factory())); //late factory = more rotamers
1123  task_factory->push_back( new core::pack::task::operation::RestrictToRepacking );
1124 
1126  pack_mover->task_factory( task_factory );
1127  pack_mover->score_function( interface_->get_fullatom_scorefunction() );
1128 
1129  //using protocols::simple_moves::MinMoverOP; //using protocols::simple_moves::MinMover;
1131  interface_->movemap_cen_all(), //even though this is fullatom; we do not yet want to minimize inside the anchor if we are using constraints
1132  interface_->get_fullatom_scorefunction(),
1133  min_type_,
1134  0.01,
1135  true /*use_nblist*/ );
1136 
1137  //definitely want sidechain minimization here
1140  protocols::simple_moves::TaskAwareMinMoverOP TAmin_mover_fa = new protocols::simple_moves::TaskAwareMinMover(min_mover_fa, task_factory);
1141  pack_mover->apply( pose );
1142  TAmin_mover_fa->apply( pose );
1143 
1144  //score the protein
1145  T_perturb << "fullatom score of perturbed, refullatomized, repacked/minimized PDB: "
1146  << (*(interface_->get_fullatom_scorefunction()))(pose) << std::endl;
1147  (*(interface_->get_fullatom_scorefunction())).show( T_perturb, pose );
1148  T_perturb << std::flush; //show doesn't flush the buffer
1149 
1150  clock_t stoptime = clock();
1151  T_perturb << "One perturb took " << ((double) stoptime - starttime )/CLOCKS_PER_SEC << " seconds" << std::endl;
1152  T_perturb << "perturb steps complete" << std::endl;
1153 
1154 }//AnchoredPerturbMover::apply
1155 
1156 
1159  return "AnchoredPerturbMover";
1160 }
1161 
1162 //option system replacement
1163 ///@brief debugging mode activates a bunch of extra output
1165 ///@brief do not perform CCD style closure (use KIC only)
1167 ///@brief do not perform KIC style closure (use CCD only)
1169 ///@brief use nonpivot torsion sampling for KIC?
1171 ///@brief MC temperature
1173 ///@brief number of MC cycles
1175 ///@brief do not use fragments?
1177 ///@brief what minimizer type to use?
1179 ///@brief show perturb result structure?
1181 
1182 ///@brief debugging mode activates a bunch of extra output
1184 ///@brief do not perform CCD style closure (use KIC only)
1185 void AnchoredPerturbMover::set_perturb_CCD_off(bool const perturb_CCD_off) { perturb_CCD_off_= perturb_CCD_off;}
1186 ///@brief do not perform KIC style closure (use CCD only)
1187 void AnchoredPerturbMover::set_perturb_KIC_off(bool const perturb_KIC_off) { perturb_KIC_off_= perturb_KIC_off;}
1188 ///@brief use nonpivot torsion sampling for KIC?
1189 void AnchoredPerturbMover::set_nonpivot_torsion_sampling(bool const nonpivot_torsion_sampling) { nonpivot_torsion_sampling_= nonpivot_torsion_sampling;}
1190 ///@brief MC temperature
1191 void AnchoredPerturbMover::set_perturb_temp(core::Real const perturb_temp) { perturb_temp_= perturb_temp;}
1192 ///@brief number of MC cycles
1193 void AnchoredPerturbMover::set_perturb_cycles(core::Size const perturb_cycles) { perturb_cycles_= perturb_cycles;}
1194 ///@brief do not use fragments?
1195 void AnchoredPerturbMover::set_no_frags(bool const no_frags) { no_frags_= no_frags;}
1196 ///@brief what minimizer type to use?
1197 void AnchoredPerturbMover::set_min_type(std::string const & min_type) { min_type_= min_type;}
1198 ///@brief show perturb result structure?
1199 void AnchoredPerturbMover::set_perturb_show(bool const perturb_show) { perturb_show_= perturb_show;}
1200 
1202 
1203  using namespace basic::options;
1204  using namespace basic::options::OptionKeys::AnchoredDesign;
1205 
1206  //bool debug_;
1207  debug_ = option[ debug ].value();
1208 
1209  //bool perturb_CCD_off_;
1210  perturb_CCD_off_ = option[ perturb_CCD_off ].value();
1211 
1212  //bool perturb_KIC_off_;
1213  perturb_KIC_off_ = option[ perturb_KIC_off ].value();
1214 
1215  ///@brief use nonpivot torsion sampling for KIC?
1216  nonpivot_torsion_sampling_ = option[ OptionKeys::loops::nonpivot_torsion_sampling ].value();
1217 
1218  //core::Real perturb_temp_;
1219  perturb_temp_ = option[ perturb_temp ].value();
1220 
1221  //core::Size perturb_cycles_;
1222  perturb_cycles_ = option[ perturb_cycles ].value();
1223 
1224  //bool no_frags_;
1225  no_frags_ = option[ no_frags ].value();
1226 
1227  //std::string min_type_;
1228  min_type_ = option[ OptionKeys::run::min_type ].value();
1229 
1230  //bool perturb_show_;
1231  perturb_show_ = option[ perturb_show ].value();
1232 
1233  return;
1234 }
1235 
1236 ///////////////////////////////////////////////////////////////////////////////////////////
1237 ///////////////////////AnchoredRefineMover/////////////////////////////////////////////////
1238 ///////////////////////////////////////////////////////////////////////////////////////////
1240  Mover(), interface_( interface_in )
1241 {
1242  protocols::moves::Mover::type( "AnchoredRefine" );
1243  read_options();
1244 }
1245 
1247 
1248 
1249 ///@details
1251 {
1252  clock_t starttime = clock();
1253  T_refine << "entering refine steps" << std::endl;
1254 
1255  //variables used for debugging output
1256  core::pose::PoseOP posecopy( NULL );
1257  if(debug_) posecopy = new core::pose::Pose(pose);
1258  int counter(1);
1259  std::stringstream outputfilename;
1260 
1261  //score the protein
1262  (*(interface_->get_fullatom_scorefunction()))(pose);
1263  T_refine << "fullatom score upon entering refine mode:" << std::endl;
1264  (*(interface_->get_fullatom_scorefunction())).show( T_refine, pose );
1265  T_refine << std::flush; //show doesn't flush the buffer
1266 
1267  //refinement steps:
1268  /*
1269  first, do a repack/minimize of the interface (handles bad rotamers coming in from perturb mode)
1270  for each loop
1271  small backbone movements (small and shear)
1272  CCD
1273  rotamer trials
1274  minimize
1275  monte carlo check
1276  every so often, do a repack/minimize instead of backbone perturbations
1277  */
1278 
1279  ///////////////////////////////////////////MC object////////////////////////////////
1280  //make the MC object ahead of time
1283  MonteCarloOP mc( new MonteCarlo(
1284  pose,
1285  *(interface_->get_fullatom_scorefunction()),
1286  refine_temp_ ) ); //temperature, default 0.8
1287 
1288  /////////////////////////////generate full repack mover//////////////////////////////
1290  pack_mover->task_factory( interface_->get_task_factory() );
1291  pack_mover->score_function( interface_->get_fullatom_scorefunction() );
1292 
1293  //////////////////////////////////generate minimizer mover/////////////////////////
1297  interface_->movemap_fa_all(),
1298  interface_->get_fullatom_scorefunction(),
1299  min_type_,
1300  0.01,
1301  true /*use_nblist*/ );
1302 
1305  protocols::simple_moves::TaskAwareMinMoverOP packing_TAmin_mover = new protocols::simple_moves::TaskAwareMinMover(packing_min_mover, interface_->get_task_factory());
1306 
1307  ////////////////////////////////////create repacking sequence///////////////////////////
1310  SequenceMoverOP repack_sequence = new SequenceMover(pack_mover, packing_TAmin_mover);
1311 
1312  //////////////////////////create refinement sequence////////////////////////////////
1313  //make the refine sequence mover. other movers are inserted into it (their handles go out of scope!)
1314  protocols::moves::SequenceMoverOP refine_sequence = new protocols::moves::SequenceMover;
1315  protocols::moves::SequenceMoverOP allloops_subsequence( new protocols::moves::SequenceMover() );
1317 
1318  //loop to add perturbing movers for each loop (this setup does each loop equally and sequentially)
1319  core::Size num_loops(interface_->num_loops());
1320  for( core::Size i(1); i <= num_loops; ++i ){
1321 
1322  ///////////////////////////generate backbone mover///////////////////////////////
1323  //as before, we might want CCD, ALC, or both
1324  //we might have terminal loops
1325 
1326  protocols::moves::SequenceMoverOP oneloop_subsequence( new protocols::moves::SequenceMover() );
1327  protocols::moves::MoverOP perturb_mover;
1329  //handles for clarity
1330  core::Size const loop_start(interface_->loop(i).start());
1331  core::Size const loop_end(interface_->loop(i).stop());
1332  bool const internal(!( pose.residue(loop_start).is_terminus() || pose.residue(loop_end).is_terminus() ));
1333  if( refine_CCD_off_ && refine_KIC_off_ ) utility_exit_with_message( "cannot pass both AnchoredDesign::refine_CCD_off AND AnchoredDesign::refine_KIC_off; this turns off both types of loop remodeling" );
1334 
1335  //option 3: kinematic; no perturbation or closure needed
1336  if( internal && !refine_KIC_off_){
1337  //make kinematic mover
1341  KinematicMoverOP kin_mover( new KinematicMover() );//temperature, default 0.8
1342  KinematicMoverCAP kin_mover_cap(*kin_mover);
1343  kin_mover->set_temperature( refine_temp_ );
1344 
1345  //set up kinematic mover - this is borrowed from loops_main.cc, perturb_one_loop_with_alc(), SVN 24219, #932-946
1346  kin_mover->set_vary_bondangles( false );
1347  kin_mover->set_sample_nonpivot_torsions( nonpivot_torsion_sampling_ );
1348  kin_mover->set_rama_check( true );
1349  kin_mover->set_idealize_loop_first( false );
1350 
1351  //make kinematic perturber
1354  VicinitySamplingKinematicPerturberOP TsamplingKP( new VicinitySamplingKinematicPerturber(kin_mover_cap));
1355  TsamplingKP->set_movemap(interface_->movemap_fa(i));
1356  //TsamplingKP->set_sample_vicinity( vicinity_sampling_ );
1357  TsamplingKP->set_degree_vicinity( vicinity_degree_ );
1358  kin_mover->set_perturber(TsamplingKP);
1359 
1362  KinematicWrapperOP kin_wrapper( new KinematicWrapper(kin_mover, interface_->loop(i)));
1363  kin_wrapper->respect_this_movemap(interface_->movemap_fa(i));
1364  oneloop_random->add_mover(kin_wrapper, 1);
1365  T_perturb << "creating KinematicWrapper with loop " << loop_start << " " << loop_end << std::endl;
1366  }//if using kinematic
1367 
1368  if (!internal || !refine_CCD_off_) { //termini and ccd loops
1369 
1370  core::Size nmoves(1);
1371  protocols::moves::MoverOP small_mover = new protocols::simple_moves::SmallMover(interface_->movemap_fa(i), 0.8, nmoves);
1372  protocols::moves::MoverOP shear_mover = new protocols::simple_moves::ShearMover(interface_->movemap_fa(i), 0.8, nmoves);
1373  T_refine << "creating Small & ShearMover for loop " << loop_start << " " << loop_end << std::endl;
1374 
1375  //generate "real" movers
1376  //this will do either a shear or small move
1378  smallshear_mover->add_mover(small_mover);
1379  smallshear_mover->add_mover(shear_mover);
1380 
1381  oneloop_subsequence->add_mover(smallshear_mover);
1382 
1383  //if not a terminal loop
1384  if (internal && !refine_CCD_off_) {
1387  MoverOP CCD_mover = new CcdLoopClosureMover(interface_->loop(i), interface_->movemap_fa_omegafixed(i));
1388  oneloop_subsequence->add_mover(CCD_mover);
1389  T_refine << "creating CCD-closure after perturbation for loop " << loop_start << " " << loop_end << std::endl;
1390 
1391  /*if(debug_){
1392  outputfilename.str(""); //clears stream
1393  outputfilename << "refine_smallmoved" << counter << ".pdb";
1394  small_mover->apply(*posecopy);
1395  posecopy->dump_pdb(outputfilename.str());
1396 
1397  outputfilename.str(""); //clears stream
1398  outputfilename << "refine_smallmoved_plus_CCD" << counter << ".pdb";
1399  debug_dump_pose(pose, posecopy, outputfilename.str(), CCD_mover);
1400 
1401  outputfilename.str(""); //clears stream
1402  outputfilename << "refine_shearmoved" << counter << ".pdb";
1403  shear_mover->apply(*posecopy);
1404  posecopy->dump_pdb(outputfilename.str());
1405 
1406  outputfilename.str(""); //clears stream
1407  outputfilename << "refine_shearmoved_plus_CCD" << counter << ".pdb";
1408  debug_dump_pose(pose, posecopy, outputfilename.str(), CCD_mover);
1409  }*/
1410  }//if needing CCD closure
1411  oneloop_random->add_mover(oneloop_subsequence, 1);
1412  }//if terminal or needing CCD closure
1413  ++counter;
1414  if(debug_) *posecopy = pose;
1415 
1416  allloops_subsequence->add_mover(oneloop_random); //keep track of all loops as a sequence
1417  backbone_mover->add_mover(oneloop_random, 1.0); //add to random mover with large weight
1418  } //end for loop over protein loops
1419 
1420  backbone_mover->add_mover(allloops_subsequence, 0.25); //run all loops combinatorially some small fraction of time
1421  //backbone_mover now randomly chooses one loop (equal probabilities) or all at once a small amount of the time
1422  refine_sequence->add_mover(backbone_mover);
1423 
1424  ////////////////////rotamer trials//////////////////////
1425  //rotamer trials work only for repacking, no design
1428  TaskFactoryOP rt_task_factory = new TaskFactory(*(interface_->get_task_factory())); //local copy so we can modify it
1429  rt_task_factory->push_back( new core::pack::task::operation::RestrictToRepacking );
1430 
1434  interface_->get_fullatom_scorefunction(),
1435  rt_task_factory,
1436  mc,
1437  0.01 /*energycut*/ ) );
1438 
1439  if(debug_) debug_dump_pose(pose, posecopy, "refine_rt.pdb", rt_mover);
1440  refine_sequence->add_mover(rt_mover);
1441 
1442  /////////////////////////minimizer mover/////////////////////////////////////////
1444  interface_->movemap_fa_all(),
1445  interface_->get_fullatom_scorefunction(),
1446  min_type_,
1447  0.01,
1448  true /*use_nblist*/ );
1449  refine_sequence->add_mover( min_mover );
1450 
1451  if(debug_){
1452  debug_dump_pose(pose, posecopy, "refine_min.pdb", ( packing_TAmin_mover ));
1453  debug_dump_pose(pose, posecopy, "refine_all.pdb", refine_sequence);
1454  dump_cutpoint_info(pose);
1455  }
1456 
1457  //////////////////cycle mover controls when backbone perturbations occur versus repacking///////////////
1458  //this mover should do backbone refinement first <many> times it is called, then repack, then repeat
1460  for(core::Size i = 1; i < refine_repack_cycles_; i++) refine_repack_cycle->add_mover(refine_sequence);
1461  refine_repack_cycle->add_mover(repack_sequence);
1462  //could swap so that repack_trial is first and remove its explicit apply() above
1463 
1464  ////////////////////////////////////Trial mover wraps sequence/////////////////////////////////////////
1465  protocols::moves::TrialMoverOP refine_master = new protocols::moves::TrialMover( refine_repack_cycle, mc );
1466 
1467  /////////////////////////wrap in a for loop output preference/////////////////////////////////
1468 
1469  core::Size const refine_latefactory = (refine_cycles_ -( refine_cycles_/3)); //magic number: final one third of cycles
1470  T_refine << " Current Low total cycles =" << refine_cycles_
1471  << ", second resfile at " << refine_latefactory << std::endl;
1472  for ( core::Size i = 1; i <= refine_cycles_; ++i ) {
1473 
1474  if ( i == refine_latefactory ) {
1475  pack_mover->task_factory(interface_->get_late_factory());
1476  //RT still needs restrict to repacking
1477  TaskFactoryOP rt_late_factory = new TaskFactory(*(interface_->get_late_factory()));
1478  rt_late_factory->push_back( new core::pack::task::operation::RestrictToRepacking );
1479  rt_mover->task_factory(rt_late_factory);
1480  }
1481 
1482  if ( i == refine_cycles_ ){
1483  repack_sequence->apply(pose);
1484  mc->boltzmann(pose);
1485  } else {
1486  refine_master->apply( pose );
1487  }
1488  T_refine << i << " " << mc->last_accepted_score() << " " << mc->lowest_score() << std::endl;
1489  }//end the exciting for loop
1490  mc->recover_low( pose );
1491 
1492  //score the protein
1493  (*(interface_->get_fullatom_scorefunction()))(pose);
1494  T_refine << "fullatom score exiting refine mode:" << std::endl;
1495  (*(interface_->get_fullatom_scorefunction())).show( T_refine, pose );
1496  T_perturb << std::flush; //show doesn't flush the buffer
1497 
1498  clock_t stoptime = clock();
1499  T_refine << "One refine took " << ((double) stoptime - starttime )/CLOCKS_PER_SEC << " seconds" << std::endl;
1500  T_refine << "refine steps complete" << std::endl;
1501 }//AnchoredRefineMover::apply()
1502 
1505  return "AnchoredRefineMover";
1506 }
1507 
1508 //option system replacement
1509 ///@brief debugging mode activates a bunch of extra output
1511 ///@brief do not perform CCD style closure (use KIC only)
1513 ///@brief do not perform KIC style closure (use CCD only)
1515 ///@brief use nonpivot torsion sampling for KIC?
1517 ///@brief KIC use vicinity sampling?
1519 ///@brief KIC vicinity sampling degrees
1521 ///@brief MC temperature
1523 ///@brief number of MC cycles
1525 ///@brief what minimizer type to use?
1527  ///@brief how many cycles between repack/design opportunities?
1529 
1530 ///@brief debugging mode activates a bunch of extra output
1532 ///@brief do not perform CCD style closure (use KIC only)
1533 void AnchoredRefineMover::set_refine_CCD_off(bool const refine_CCD_off) { refine_CCD_off_= refine_CCD_off;}
1534 ///@brief do not perform KIC style closure (use CCD only)
1535 void AnchoredRefineMover::set_refine_KIC_off(bool const refine_KIC_off) { refine_KIC_off_= refine_KIC_off;}
1536 ///@brief use nonpivot torsion sampling for KIC?
1537 void AnchoredRefineMover::set_nonpivot_torsion_sampling(bool const nonpivot_torsion_sampling) { nonpivot_torsion_sampling_= nonpivot_torsion_sampling;}
1538 ///@brief KIC use vicinity sampling?
1539 void AnchoredRefineMover::set_vicinity_sampling(bool const vicinity_sampling) { vicinity_sampling_= vicinity_sampling;}
1540 ///@brief KIC vicinity sampling degrees
1541 void AnchoredRefineMover::set_vicinity_degree(core::Size const vicinity_degree) { vicinity_degree_= vicinity_degree;}
1542 ///@brief MC temperature
1543 void AnchoredRefineMover::set_refine_temp(core::Real const refine_temp) { refine_temp_= refine_temp;}
1544 ///@brief number of MC cycles
1545 void AnchoredRefineMover::set_refine_cycles(core::Size const refine_cycles) { refine_cycles_= refine_cycles;}
1546 ///@brief what minimizer type to use?
1547 void AnchoredRefineMover::set_min_type(std::string const & min_type) { min_type_= min_type;}
1548 ///@brief how many cycles between repack/design opportunities?
1549 void AnchoredRefineMover::set_refine_repack_cycles(core::Size const refine_repack_cycles) { refine_repack_cycles_= refine_repack_cycles;}
1550 
1552 
1553  using namespace basic::options;
1554  using namespace basic::options::OptionKeys::AnchoredDesign;
1555 
1556  //bool debug_;
1557  debug_ = option[ debug ].value();
1558 
1559  //bool refine_CCD_off_;
1560  refine_CCD_off_ = option[ refine_CCD_off ].value();
1561 
1562  //bool refine_KIC_off_;
1563  refine_KIC_off_ = option[ refine_KIC_off ].value();
1564 
1565  /// bool nonpivot_torsion_sampling_;
1566  nonpivot_torsion_sampling_ = option[ OptionKeys::loops::nonpivot_torsion_sampling ].value();
1567 
1568  //bool vicinity_sampling_;
1569  vicinity_sampling_ = option[ OptionKeys::loops::vicinity_sampling ].value();
1570 
1571  //core::Real vicinity_degree_;
1572  vicinity_degree_ = option[ OptionKeys::loops::vicinity_degree ].value();
1573 
1574  //core::Real refine_temp_;
1575  refine_temp_ = option[ refine_temp ].value();
1576 
1577  //core::Size refine_cycles_;
1578  refine_cycles_ = option[ refine_cycles ].value();
1579 
1580  //std::string min_type_;
1581  min_type_ = option[ OptionKeys::run::min_type ].value();
1582 
1583  //core::Size refine_repack_cycles_;
1584  refine_repack_cycles_ = option[ refine_repack_cycles ].value();
1585 
1586  return;
1587 }
1588 
1589 }//AnchoredDesign
1590 }//protocols