Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
AnchorMoversData.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/AnchoredDesign/AnchorMoversData.cc
11 /// @brief AnchorMoversData methods implemented
12 /// @author Steven Lewis
13 
14 
15 // Unit Headers
18 
19 // Project Headers
20 // AUTO-REMOVED #include <core/fragment/FragID.hh> // REQUIRED FOR WINDOWS
21 #include <protocols/loops/Loop.hh>
22 #include <protocols/loops/Loops.hh>
23 
25 #include <core/id/TorsionID.hh> //used for movemap to set omega angle false
26 #include <core/id/types.hh> //used for movemap to set omega angle false
27 
28 #include <core/pose/Pose.hh>
29 // AUTO-REMOVED #include <core/pose/PDBPoseMap.hh>
30 // AUTO-REMOVED #include <core/pose/PDBInfo.hh>
32 
34 
36 
37 #include <core/id/AtomID.hh>
38 
45 
52 
54 #include <core/fragment/FragSet.hh>
55 #include <core/fragment/Frame.hh>
58 
59 // Utility Headers
60 #include <basic/Tracer.hh>
61 #include <core/types.hh>
62 #include <basic/options/option.hh>
63 #include <utility/exit.hh>
64 #include <numeric/random/random.hh>
65 
66 // C++ Headers
67 #include <string>
68 
69 // option key includes
70 #include <basic/options/keys/AnchoredDesign.OptionKeys.gen.hh>
71 #include <basic/options/keys/packing.OptionKeys.gen.hh>
72 #include <basic/options/keys/loops.OptionKeys.gen.hh>
73 #include <basic/options/keys/in.OptionKeys.gen.hh>
74 
75 #include <utility/vector1.hh>
76 
77 
78 using basic::T;
79 using basic::Error;
80 using basic::Warning;
81 
82 static basic::Tracer TR( "protocols.AnchoredDesign.AnchorMoversData" );
83 static numeric::random::RandomGenerator RG(10505);
84 
85 namespace protocols{
86 namespace anchored_design{
87 
88 std::string const EMPTY_STRING("");
89 core::Real const VDW_WEIGHT(2.0);
90 core::Real const CHAINBREAK_WEIGHT(10.0);
91 std::string const INTERFACE_CALC("AnchoredDesign_InterfaceNeighborDefinitionCalculator");
92 std::string const NEIGHBORHOOD_CALC("AnchoredDesign_NeighborhoodByDistanceCalculator");
93 
94 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
95 ////////////////////////////////AnchorMoversData//////////////////////////////////////////////////////////////////////
96 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
97 ///////////////////////////////////mechanicals (ctor, dtor)////////////////////////////////////////////////////////////
98 
99 ///@brief empty, useless ctor. You'll need to manually set all the data later. Why did you make me waste my time writing this ctor?
101  utility::pointer::ReferenceCount(),
102  anchor_( 0 ),
103  anchor_loop_index_( 0 ),
104  movemap_fa_all_( new core::kinematics::MoveMap() ),
105  movemap_cen_all_( new core::kinematics::MoveMap() ),
106  //loops_and_fa_mms_( ), //er, not really possible to initialize
107  //loops_and_cen_mms_( ),
108  //loops_( ),
109  fragset_( 0 ),
110  task_factory_( 0 ),
111  late_factory_( 0 ),
112  fullatom_scorefunction_( 0 ),
113  centroid_scorefunction_( 0 ),
114  centroid_scorefunction_min_( 0 ),
115  interface_calc_( INTERFACE_CALC ),
116  neighborhood_calc_( NEIGHBORHOOD_CALC ),
117  akash_dyepos_( 0 ),
118  unbound_mode_( false ),
119  anchor_via_constraints_( false ),
120  VDW_weight_( VDW_WEIGHT ),
121  chainbreak_weight_( CHAINBREAK_WEIGHT ),
122  allow_anchor_repack_( false ),
123  resfile_1_( EMPTY_STRING ),
124  resfile_2_( EMPTY_STRING ),
125  loop_file_( EMPTY_STRING ),
126  frag3_( EMPTY_STRING ),
127  no_frags_( false ),
128  anchor_noise_constraints_mode_( false ),
129  super_secret_fixed_interface_mode_( false )
130 {}
131 
132 ///@details constructor takes an anchor and loop object and sets up internals reasonably; options boolean is optionally optional. If you use this constructor, you will need to later manually give fragments to the AnchorMoversData object or use one of its fragments functions to determine what type of fragments to use.
135  protocols::loops::Loops const & loops,
136  bool const options) :
137  utility::pointer::ReferenceCount(),
138  anchor_(anchor), //redundant, given that set_loops_and_anchor takes care of it
139  anchor_loop_index_( 0 ),
140  movemap_fa_all_( new core::kinematics::MoveMap() ),
141  movemap_cen_all_( new core::kinematics::MoveMap() ),
142  //loops_and_fa_mms_( ), //er, not really possible to initialize
143  //loops_and_cen_mms_( ),
144  //loops_( ),
145  fragset_( 0 ),
146  task_factory_( 0 ),
147  late_factory_( 0 ),
148  fullatom_scorefunction_( 0 ),
149  centroid_scorefunction_( 0 ),
150  centroid_scorefunction_min_( 0 ),
151  interface_calc_( INTERFACE_CALC ),
152  neighborhood_calc_( NEIGHBORHOOD_CALC ),
153  akash_dyepos_( 0 ),
154  unbound_mode_( false ),
155  anchor_via_constraints_( false ),
156  VDW_weight_( VDW_WEIGHT ),
157  chainbreak_weight_( CHAINBREAK_WEIGHT ),
158  allow_anchor_repack_( false ),
159  resfile_1_( EMPTY_STRING ),
160  resfile_2_( EMPTY_STRING ),
161  loop_file_( EMPTY_STRING ),
162  frag3_( EMPTY_STRING ),
163  no_frags_( false ),
164  anchor_noise_constraints_mode_( false ),
165  super_secret_fixed_interface_mode_( false )
166 {
167  //TR << "loops/anchor ctor" << std::endl;
168 
169 
170  //read commandline options
171  if(options) read_options();
172 
173  //set up loops and anchor internal data
174  set_loops_and_anchor(anchor, loops);
175  //get other defaults set as necessary
177 
178 }
179 
180 ///@details use pose and option system to set up loops and create anchor, then call set_loops_and_anchor and set_unset_defaults to set up internal data to reasonable defaults, with or without option system help
182  utility::pointer::ReferenceCount(),
183  anchor_( 0 ),
184  anchor_loop_index_( 0 ),
185  movemap_fa_all_( new core::kinematics::MoveMap() ),
186  movemap_cen_all_( new core::kinematics::MoveMap() ),
187  //loops_and_fa_mms_( ), //er, not really possible to initialize
188  //loops_and_cen_mms_( ),
189  //loops_( ),
190  fragset_( 0 ),
191  task_factory_( 0 ),
192  late_factory_( 0 ),
193  fullatom_scorefunction_( 0 ),
194  centroid_scorefunction_( 0 ),
195  centroid_scorefunction_min_( 0 ),
196  interface_calc_( INTERFACE_CALC ),
197  neighborhood_calc_( NEIGHBORHOOD_CALC ),
198  akash_dyepos_( 0 ),
199  unbound_mode_( false ),
200  anchor_via_constraints_( false ),
201  VDW_weight_( VDW_WEIGHT ),
202  chainbreak_weight_( CHAINBREAK_WEIGHT ),
203  allow_anchor_repack_( false ),
204  resfile_1_( EMPTY_STRING ),
205  resfile_2_( EMPTY_STRING ),
206  loop_file_( EMPTY_STRING ),
207  frag3_( EMPTY_STRING ),
208  no_frags_( false ),
209  anchor_noise_constraints_mode_( false ),
210  super_secret_fixed_interface_mode_( false )
211 
212 {
213  //TR << "pose ctor" << std::endl;
214 
215  //read commandline options; you don't get a choice with this ctor, because we need the loops file and anchor spec
216  read_options();
217 
218  //set up loops and anchor internal data
219 
220  // read anchor file - automatically reads anchor file name from options system
222 
223  // read loops file
225  //we do not need to check if the anchor and loop are compatible here; pick_new_cutpoints will take care of it later
226 
227  //this will overwrite anchor_ and loops_ with modified versions of themselves, and fill in movemaps, etc
229 
230  //get other defaults set as necessary
232 
233  //handle fragments - can touch other data, thus needs to occur last
234  autogenerate_frags(pose);
235 
236 }
237 
239 
240 ///@brief copy ctor
242  utility::pointer::ReferenceCount(rhs),
243  interface_calc_( INTERFACE_CALC ), //const; must be initialized here
244  neighborhood_calc_( NEIGHBORHOOD_CALC )//const; must be initialized here
245 {
246  *this = rhs;
247 }
248 
249 ///@brief assignment operator
251 
252  //abort self-assignment
253  if (this == &rhs) return *this;
254 
255  //some data does not need to be copied; handled by set_loops_and_anchor below; required because loops_and_x_mms_ objects cannot be cloned
256  //anchor_ = ;
257  //anchor_loop_index_ = rhs.anchor_loop_index_;
258  //movemap_fa_all_ = rhs.movemap_fa_all()->clone();
259  //movemap_cen_all_ = rhs.movemap_cen_all()->clone();
260  //no way to copy for these next two objects; handled at end
261  //loops_and_fa_mms_ = rhs.loops_and_fa_mms_.clone();
262  //loops_and_cen_mms_ = rhs.loops_and_cen_mms_.clone();
263  //loops_ = rhs.loops(); //returns by value
264  fragset_ = rhs.get_frags()->clone();
273  VDW_weight_ = rhs.get_VDW_weight();
276  resfile_1_ = rhs.get_resfile_1();
277  resfile_2_ = rhs.get_resfile_2();
278  loop_file_ = rhs.get_loop_file();
279  frag3_ = rhs.get_frag3();
280  no_frags_ = rhs.get_no_frags();
283 
284  set_loops_and_anchor(rhs.anchor_, rhs.loops());
285 
286  return *this;
287 }
288 
290  return new AnchorMoversData(*this);
291 }
292 
293 ///@brief randomly reset loop cutpoints. Useful only when starting structure is well-closed. Best for MPI-style runs
295  TR << "checking/(re)setting loop cutpoints; loops become:" << std::endl;
296 
297  core::Size const numloop = num_loops();
298  for (core::Size i = 1; i <= numloop; ++i){
299  core::Size const loopstart(loop(i).start()), loopend(loop(i).stop()), loopcut(loop(i).cut());
300  if(reset_always || (loopcut < loopstart) || (loopcut > loopend) || ((anchor_->start() <= loopcut) && (anchor_->end() >= loopcut))){
301  core::Size cut(pick_new_cutpoint(loopstart, loopend));
302  loops_and_fa_mms_[ i ].key1().set_cut(cut);
303  loops_and_cen_mms_[ i ].key1().set_cut(cut);
304  }
305 
306  TR << loop(i) << std::endl;
307  }
308 
309 }
310 
311 ///@brief randomly reset just one cutpoint; used by pick_new_cutpoints
313  core::Size newcutpoint(0);
314  do{
315  newcutpoint = (loopstart) + int( RG.uniform()*(loopend-loopstart+1) );
316  } while( ((anchor_->start()) <= newcutpoint) && ((anchor_->end()) >= newcutpoint) ); //the cutpoint is in the anchor
317  return newcutpoint;
318 }
319 
320 ///////////////////set functions if defaults aren't acceptable//////////////////////
321 //set fragments object
323 
324 //set packertask factory
326 
327 //set fullatom scorefunction
329 { fullatom_scorefunction_ = in; }
330 
331 //set centroid scorefunction
333 { centroid_scorefunction_ = in; }
334 
335 ///@details set up kinematics' loops and anchors; these are combined because loop setup depends on anchor
338 {
339  anchor_ = anchor;
340 
341  //get loops and movemaps set up - most work is encoded in other functions
342  loops.sequential_order();
343  input_loops_into_tuples(loops);
344  locate_anchor_loop();
345  setup_movemaps();
346  loops_ = loops; //ordered
347 
348  return;
349 }
350 
351 /////////////////loops and movemap functions//////////////////////////////////////////////
352 //accessor for anchored loop
354 { return loops_and_fa_mms_[ anchor_loop_index_ ].key1(); } //ISSUE: WHY NOT USE CEN HERE? resolve w/ vectors?
355 
356 //access for movemap that covers all loops; centroid
358 
359 //access for movemap that covers all loops; fullatom may allow anchor movement w/constraints
361 
362 //accessor for a loop //ISSUE: WHY NOT USE CEN HERE? resolve w/ vectors?
364 { return loops_and_fa_mms_[ i ].key1(); }
365 
366 //accessor for omega-variable movemap (most movers); fullatom may allow anchor movement w/constraints
368 { return loops_and_fa_mms_[ i ].key2(); }
369 
370 //accessor for omega-fixed movemap (appropriate for CCD movers); fullatom may allow anchor movement w/constraints
372 { return loops_and_fa_mms_[ i ].key3(); }
373 
374 //accessor for omega-variable movemap (most movers); centroid
376 { return loops_and_cen_mms_[ i ].key2(); }
377 
378 //accessor for omega-fixed movemap (appropriate for CCD movers); centroid
380 { return loops_and_cen_mms_[ i ].key3(); }
381 
382 //accessor for loops object
384 { return loops_; }
385 
386 
387 /////////////////////////////anchor functions//////////////////////////////////////////////
388 ///@details access for anchor start
390 
391 ///@details access for anchor end
393 
394 ////////////////////////scfxn, packertask, fragments accessors//////////////////////////////
395 //access fragments object
397 { return fragset_; }
398 //access packertask factory
400 { return task_factory_; }
401 //access packertask factory
403 { return late_factory_; }
404 //access fullatom scorefunction
406 { return fullatom_scorefunction_; }
407 //access centroid scorefunction
409 { return centroid_scorefunction_; }
410 //access centroid scorefunction for minimization
412 { return centroid_scorefunction_min_; }
413 ///@details runs the member factory to create a task
415 { return task_factory_->create_task_and_apply_taskoperations( pose ); }
416 
417 
418 ////////////////////////private functions generate internal data from input and defaults///////////////
419 ///@details rearranges input loops data structure into the class's internal data structure
421 {
422  loops_and_fa_mms_.clear();
423  loops_and_cen_mms_.clear();
424  for( protocols::loops::Loops::const_iterator it=loops.begin(), it_end=loops.end(); it != it_end; ++it ){
425  //instantiate tuple
426  loops_and_fa_mms_.push_back( Loop_mm_tuple(
427  *it,
430  ) );
431 
432  loops_and_cen_mms_.push_back( Loop_mm_tuple(
433  *it,
436  ) );
437  }
438 }
439 
440 ///@details determines which loop contains the anchor (this loop may be treated differently)
442 {
443  core::Size const numloop = num_loops();
444  core::Size const anchorstart(anchor_->start()), anchorend(anchor_->end());
445  for (core::Size i = 1; i <= numloop; ++i){
446  core::Size const loopstart(loop(i).start()), loopend(loop(i).stop());
447  if ( (loopstart < anchorstart) && (loopend > anchorend) ){
448  TR << "anchor start/end " << anchorstart << "/" << anchorend
449  << " fits within loop start/end " << loopstart << "/" << loopend << std::endl;
450  anchor_loop_index_ = i;
451  return;
452  }// end if-anchor-is-in-this-loop
453  }//end iterate over all loops
454 
455  if(get_super_secret_fixed_interface_mode()) {
456  anchor_loop_index_ = 0; //I don't know what this will do, but it should cause bounds errors if something untoward happens (good except bad)
457  TR << "anchor start/end " << anchorstart << "/" << anchorend
458  << " not within a loop; appropriate for super_secret_fixed_interface_mode" << std::endl;
459  return;
460  }
461 
462  //if we did not return above
463  Error() << "Anchor does not reside completely within a loop. Anchor start and end: " << anchorstart
464  << " " << anchorend << std::endl;
465  utility_exit();
466 }
467 
468 ///@details sets all movemaps for the class - paired ones and single movemap_all_, also sets loop_or_notloop_
470 {
471  movemap_fa_all_->clear();
472  movemap_cen_all_->clear();
473  core::Size const numloop = num_loops();
474 
475  //for each loop, modify that pair's mm and modify movemap_all_
476  for (core::Size i = 1; i <= numloop; ++i){
477  core::Size loopstart(loop(i).start()), loopend(loop(i).stop());
478  movemap_fa(i)->clear();
479  movemap_fa_omegafixed(i)->clear();
480  movemap_cen(i)->clear();
481  movemap_cen_omegafixed(i)->clear();
482 
483  //set this loop's mm, and in movemap_all_
484  for (core::Size j = loopstart; j <= loopend; ++j){
485  set_movemap( movemap_fa( i ), j );
486  set_movemap( movemap_fa_omegafixed( i ), j, true );
487  set_movemap( movemap_fa_all_, j );
488 
489  set_movemap( movemap_cen( i ), j );
490  set_movemap( movemap_cen_omegafixed( i ), j, true );
491  set_movemap( movemap_cen_all_, j );
492  }
493 
494  }//for each loop
495 
496  if( !get_super_secret_fixed_interface_mode() ) {
497  fix_anchor( movemap_fa( anchor_loop_index_ ), false );
498  fix_anchor( movemap_fa_omegafixed( anchor_loop_index_ ), false );
499  fix_anchor( movemap_fa_all_, false );
500 
501  fix_anchor( movemap_cen( anchor_loop_index_ ), true );
502  fix_anchor( movemap_cen_omegafixed( anchor_loop_index_ ), true );
503  fix_anchor( movemap_cen_all_, true );
504  }
505 
506  return;
507 }
508 
510 {
511  //this if statement protects noncanonical dye residues; see AnchoredDesign application documentation.
512  if(seqpos == akash_dyepos_) return;
513  using namespace core::id;
514  movemap->set_bb(seqpos, true); //backbone mobile
515  if (omega) movemap->set( TorsionID(seqpos, BB, omega_torsion), false ); //fixes omega angle
516  movemap->set_chi(seqpos, true); // chi of loop residues
517  //movemap->set_jump(false); // call in fix_anchor (more efficient)
518 }
519 
521 {
522  //skip this function in unbound mode or super_secret_fixed_interface_mode_ or anchors_via_constraints mode
523  if( unbound_mode_ || get_super_secret_fixed_interface_mode() ) return;
524  if( anchor_via_constraints_ && !centroid ) { //if we have constraints, and this is NOT for the centroid phase...
525  movemap->set_jump(1, true); //magic number: the anchor-target jump is 1; TODO: make this a named variable
526  //do NOT re-fix the anchor residues
527  return;
528  }
529 
530  for (core::Size i = anchor_->start(); i <= anchor_->end(); ++i){
531  movemap->set_bb(i, false); //fix the backbones
532  movemap->set_chi(i, false); // and the chi
533  }
534 
535  using namespace core::id;
536  movemap->set( TorsionID(anchor_->start(), BB, phi_torsion), true);
537  movemap->set( TorsionID(anchor_->end(), BB, psi_torsion), true);
538  const bool omega(movemap->get(TorsionID(anchor_->end()+1, BB, omega_torsion)));//are omegas free in this mm?
539  movemap->set( TorsionID(anchor_->end(), BB, omega_torsion), omega);
540 
541  movemap->set_jump(false); //perhaps this call should be in set_movemap()?
542 }
543 
545 {
546  set_unset_scorefunctions();
547  set_unset_packertask_factory();
548 }
549 
551 {
552  using namespace core::scoring;
553 
554  //handle centroid scorefunction
555  centroid_scorefunction_ = new ScoreFunction;
556  centroid_scorefunction_->set_weight( env, 1.0 ); //no derivative
557  centroid_scorefunction_->set_weight( cbeta, 1.0 ); //no derivative
558  centroid_scorefunction_->set_weight( vdw, VDW_weight_ ); //defines eval_atom_derivative
559  centroid_scorefunction_->set_weight( pair, 1.0 ); //no derivative
560  centroid_scorefunction_->set_weight( cenpack, 1.0 ); //no derivative
561  centroid_scorefunction_->set_weight( rama, 1.0 ); //defines eval_dof_derivative
562  centroid_scorefunction_->set_weight( chainbreak, 2.0 ); //defines eval_atom_derivative
563  centroid_scorefunction_->set_weight( hbond_lr_bb, 1.0 );
564  centroid_scorefunction_->set_weight( hbond_sr_bb, 1.0 );
565  //DO NOT add constraints in centroid mode - unless all bb-bb constraints it will break due to csts using blind AtomIDs...
566  //core::scoring::constraints::add_constraints_from_cmdline_to_scorefxn( *centroid_scorefunction_ ); //protected if(option) internally
567  TR << "Using default centroid scorefunction\n" << *centroid_scorefunction_ << std::flush;
568 
569  //handle centroid minimization scorefunction
570  centroid_scorefunction_min_ = centroid_scorefunction_->clone();
571  centroid_scorefunction_->set_weight( env, 0. ); //no derivative
572  centroid_scorefunction_->set_weight( cbeta, 0. ); //no derivative
573  centroid_scorefunction_->set_weight( pair, 0. ); //no derivative
574  centroid_scorefunction_->set_weight( cenpack, 0. ); //no derivative
575 
576 
577  fullatom_scorefunction_ = getScoreFunction(); //this call is compatible with -correct; defaults to score12
578  fullatom_scorefunction_->set_weight( chainbreak, chainbreak_weight_ );
579  core::scoring::constraints::add_constraints_from_cmdline_to_scorefxn( *fullatom_scorefunction_ ); //protected if(option) internally
580  TR << "Using default fullatom scorefunction (STANDARD_WTS, SCORE12_PATCH plus chainbreak @ a lot)\n"
581  << *fullatom_scorefunction_ << std::flush;
582 
583  return;
584 }
585 
586 
588 {
589  using namespace core::pack::task;
590 
591  //set up interface-plus-neighbors-positions operation
592  core::Size const numloop = num_loops();
593  std::set< core::Size > loop_posns;
594  for (core::Size i = 1; i <= numloop; ++i){
595  core::Size loopstart(loop(i).start()), loopend(loop(i).stop());
596  for (core::Size j = loopstart; j <= loopend; ++j){
597  loop_posns.insert(j);
598  }//for each residue in loop
599  }//for each loop
600 
601  //std::string const interface_calc("AnchoredDesign_InterfaceNeighborDefinitionCalculator");
602  //std::string const neighborhood_calc("AnchoredDesign_NeighborhoodByDistanceCalculator");
603  //NOTE that these calculators ASSUME your interface is between chains 1 and 2, because most of the rest of AnchoredDesign carries the same assumption
604 
605  if( core::pose::metrics::CalculatorFactory::Instance().check_calculator_exists( interface_calc_ ) ){
606  Warning() << "In AnchoredDesign, calculator " << interface_calc_ << " already exists. "
607  << "Given the two-chain restriction, this is hopefully correct for your purposes" << std::endl;
608  } else {
610  }
611 
612  if( core::pose::metrics::CalculatorFactory::Instance().check_calculator_exists( neighborhood_calc_ ) ){
613  Warning() << "In AnchoredDesign, calculator " << neighborhood_calc_ << " already exists. If you have multiple instances of AnchoredDesign with different loops coexisting in the same program, this is going to cause problems, because you will have the wrong loop definitions for determining what residues to pack" << std::endl;
614  } else {
616  }
617 
618  //this is the constructor parameter for the calculator - pairs of calculators and calculations to perform
620  calcs_and_calcns.push_back(std::make_pair(interface_calc_, "interface_residues"));
621  calcs_and_calcns.push_back(std::make_pair(neighborhood_calc_, "neighbors"));
622 
624  operation::TaskOperationOP rbcop(new RestrictByCalculatorsOperation( calcs_and_calcns ));
625 
626  //command line operation
628 
629  //operation to protect anchor
631  if (!allow_anchor_repack_ && !get_super_secret_fixed_interface_mode()){
632  TR << "autogenerated TaskFactory will prevent repacking for anchor" << std::endl;
633  for( core::Size i(anchor_->start()); i<= anchor_->end(); ++i){
634  prop->include_residue(i);
635  }
636  }
637 
638  //'early' Factory
639  task_factory_ = new TaskFactory();
640  //resfile operation
641  if ( resfile_1_ != EMPTY_STRING ) {
643  rrop1->filename( resfile_1_ );
644  task_factory_->push_back( rrop1 );
645  }
646  task_factory_->push_back( initop );
647  task_factory_->push_back( rbcop );
648  if(!allow_anchor_repack_) task_factory_->push_back( prop );
649  TR << "Using default TaskFactory. Inits from command line and second resfile, then restricts "
650  << "to the loop/interface area" << std::endl;
651 
652  //'late' factory
653  if ( (resfile_2_ != EMPTY_STRING) ) {
654  late_factory_ = new TaskFactory();
656  rrop2->filename( resfile_2_ );//second resfile
657  late_factory_->push_back( rrop2 );
658 
659  late_factory_->push_back( initop );
660  late_factory_->push_back( rbcop );
661  if(!allow_anchor_repack_) late_factory_->push_back( prop );
662 
663  TR << "Using default late TaskFactory. Inits from command line and second resfile, then restricts "
664  << "to the loop/interface area" << std::endl;
665  }
666  else {
667  late_factory_ = task_factory_;
668  TR << "Not using separate late TaskFactory." << std::endl;
669  }
670  return;
671 }
672 
673 ///@details autogenerate_design_frags will use Andrew Ban's fragment picker to read the Vall and find fragments. It looks for fragments of loop secondary structure (for now, just 3mers.). This function is used in a design context and thus uses only secondary structure to define the fragments.
675 
676  core::Size const frags_length(3); //magic number: 3mer fragments!!
678 
679  std::string ss_string(frags_length, 'L');
681  list = core::fragment::picking_old::vall::pick_fragments_by_ss( ss_string, 4000, false ); //magic number: 4000 fragments
682 
683  core::Size const numloop = num_loops();
684  std::set< core::Size > loop_posns;
685  for (core::Size i = 1; i <= numloop; ++i){
686  core::Size loopstart(loop(i).start()), loopend(loop(i).stop());
687  for (core::Size j = loopstart; j <= loopend - frags_length+1; ++j){
688  if( !( (j >anchor_->start() - frags_length) && (j <= anchor_->end()) ) ){
689  TR << "adding frame, start at " << j << " go for " << frags_length << " to " << j+frags_length << std::endl;
691  frame = new core::fragment::Frame( j );
692  frame->add_fragment( list );
693  fragset->add( frame );
694  }//not in anchor
695  }//for each residue in loop
696  }//for each loop
697 
698  TR << "recovering memory?" << std::endl;
700 
701  set_frags(fragset);
702  return fragset;
703 }//autogenerate_design_frags
704 
705 ///@details autogenerate_constseq_frags will use Andrew Ban's fragment picker to read the Vall and find fragments. It looks for fragments of loop secondary structure and known, fixed sequence. The string argument is the whole pose sequence.
707 
708  core::Size const frags_length(3); //magic number: 3mer fragments!!
710 
711  std::string ss_string(frags_length, 'L');
713 
714  core::Size const numloop = num_loops();
715  std::set< core::Size > loop_posns;
716  for (core::Size i = 1; i <= numloop; ++i){
717  core::Size loopstart(loop(i).start()), loopend(loop(i).stop());
718  for (core::Size j = loopstart; j <= loopend - frags_length+1; ++j){
719  if( !( (j >anchor_->start() - frags_length) && (j <= anchor_->end()) ) ){
720  std::string const seqsubstr(seq, j-1, frags_length);
721  TR << "adding frame, start at " << j << " go for " << frags_length << " to " << j+frags_length << " seq " << seqsubstr << std::endl;
722  list = core::fragment::picking_old::vall::pick_fragments_by_ss_plus_aa( ss_string, seqsubstr, 200, false ); //magic number: 200 fragments per position (not duplicated - this will be like robetta server fragments)
723 
725  frame = new core::fragment::Frame( j );
726  frame->add_fragment( list );
727  fragset->add( frame );
728  }//not in anchor
729  }//for each residue in loop
730  }//for each loop
731 
732  TR << "recovering memory?" << std::endl;
734 
735  set_frags(fragset);
736  return fragset;
737 }//autogenerate_design_frags
738 
739 
740 ///@details autogenerate_frags will determine from this object's state what fragments to use, and generate fragments as needed. The logic was originally at the executeable level, src/apps/pilot/smlewis/AnchoredDesign.cc:116-136 SVN 40529
742 
744  bool const frags_file( !(frag3_ == EMPTY_STRING) );//basic::options::option[ basic::options::OptionKeys::in::file::frag3].user() );
745  //bool const no_frags( basic::options::option[ basic::options::OptionKeys::AnchoredDesign::no_frags ].value() );
746  if( frags_file && no_frags_ ){
747  utility_exit_with_message("you've specified a fragments file and requested no_frags - please choose only one");
748  } else if ( frags_file ){
749  TR << "reading from fragments file " << frag3_ << std::endl;
750  fragset3mer = new core::fragment::ConstantLengthFragSet( 3 );
751  fragset3mer->read_fragment_file( frag3_ );//basic::options::option[ basic::options::OptionKeys::in::file::frag3].value() );
752  set_frags( fragset3mer );
753  } else if ( !no_frags_ ){
754  //strange logic: are we designing or not? To determine, we must run a TaskFactory to get a Task and ask it!
755  if(get_task_factory()->create_task_and_apply_taskoperations(pose)->design_any()) {
756  TR << "creating sequence-generic loop fragments (LLLLL...)" << std::endl;
757  autogenerate_design_frags();
758  } else {
759  TR << "creating constant-sequence fragments for loops" << std::endl;
760  autogenerate_constseq_frags(pose.sequence());
761  }
762  } else { TR << "using no fragments" << std::endl; }
763  return;
764 }
765 
766 //////////////////////////////////////////////////////////////////////////////////////////////////
767 /////////////////////////////////////////option system replacement/////////////////////////////
768 ///@brief dye position used in dye modeling publication
769 void protocols::anchored_design::AnchorMoversData::set_akash_dyepos(core::Size const akash_dyepos){ akash_dyepos_ = akash_dyepos;}
770 ///@brief used for unbound mode
771 void protocols::anchored_design::AnchorMoversData::set_unbound_mode(bool unbound_mode){ unbound_mode_ = unbound_mode;}
772 ///@brief used to test anchoring via constraints
773 void protocols::anchored_design::AnchorMoversData::set_anchor_via_constraints(bool anchor_via_constraints){ anchor_via_constraints_ = anchor_via_constraints;}
774 ///@brief VDW weight in centroid scorefunction
776 ///@brief chainbreak weight in fullatom scorefunction
777 void protocols::anchored_design::AnchorMoversData::set_chainbreak_weight(core::Real chainbreak_weight){ chainbreak_weight_ = chainbreak_weight;}
778 ///@brief allow anchor to repack
779 void protocols::anchored_design::AnchorMoversData::set_allow_anchor_repack(bool allow_anchor_repack){ allow_anchor_repack_ = allow_anchor_repack;}
780 ///@brief resfile for design
781 void protocols::anchored_design::AnchorMoversData::set_resfile_1(std::string const & resfile_1){ resfile_1_ = resfile_1;}
782 ///@brief later-stage resfile if desired
783 void protocols::anchored_design::AnchorMoversData::set_resfile_2(std::string const & resfile_2){ resfile_2_ = resfile_2;}
784 ///@brief loop file
785 //void protocols::anchored_design::AnchorMoversData::set_loop_file(std::string const & loop_file){ loop_file_ = loop_file;}
786 ///@brief loop file
788 ///@brief do not use fragments?
789 void protocols::anchored_design::AnchorMoversData::set_no_frags(bool const no_frags) { no_frags_= no_frags;}
790 ///@brief special anchor_noise_constraints_mode
791 void protocols::anchored_design::AnchorMoversData::set_anchor_noise_constraints_mode(bool const anchor_noise_constraints_mode) { anchor_noise_constraints_mode_= anchor_noise_constraints_mode;}
792 ///@brief special super_secret_fixed_interface_mode
793 void protocols::anchored_design::AnchorMoversData::set_super_secret_fixed_interface_mode(bool const super_secret_fixed_interface_mode) { super_secret_fixed_interface_mode_= super_secret_fixed_interface_mode;}
794 
795 ///@brief dye position used in dye modeling publication
797 ///@brief used for unbound mode
799 ///@brief used to test anchoring via constraints
801 ///@brief VDW weight in centroid scorefunction
803 ///@brief chainbreak weight in fullatom scorefunction
805 ///@brief allow anchor to repack
807 ///@brief resfile for design
809 ///@brief later-stage resfile if desired
811 ///@brief loop file
813 ///@brief frag3 file
815 ///@brief do not use fragments?
817 ///@brief special anchor_noise_constraints_mode
818 bool protocols::anchored_design::AnchorMoversData::get_anchor_noise_constraints_mode() const { return anchor_noise_constraints_mode_;}
819 ///@brief special super_secret_fixed_interface_mode
820 bool protocols::anchored_design::AnchorMoversData::get_super_secret_fixed_interface_mode() const { return super_secret_fixed_interface_mode_;}
821 
823 
824  TR << "initializing from options system" << std::endl;
825 
826  using namespace basic::options;
827  using namespace basic::options::OptionKeys::AnchoredDesign;
828 
829  //core::Size akash_dyepos_;
830  if(option[akash::dyepos].user()) {
831  akash_dyepos_ = option[akash::dyepos].value();
832  } else {
833  akash_dyepos_ = 0;
834  }
835 
836  //bool unbound_mode_;
837  unbound_mode_ = option[ unbound_mode ].value();
838 
839  //bool anchor_via_constraints_;
840  anchor_via_constraints_ = option[ testing::anchor_via_constraints ].value();
841 
842  //core::Real VDW_weight_;
843  VDW_weight_ = option[testing::VDW_weight].value();
844 
845  //core::Real chainbreak_weight_;
846  chainbreak_weight_ = option[chainbreak_weight].value();
847 
848  //bool allow_anchor_repack_;
849  allow_anchor_repack_ = option[allow_anchor_repack].value();
850 
851  //std::string resfile_1_;
852  if(option[OptionKeys::packing::resfile].user()) {
853  resfile_1_ = option[OptionKeys::packing::resfile].value().at(1);
854  } else {
855  resfile_1_ = EMPTY_STRING; //empty string flag for don't use resfile
856  }
857 
858  //std::string resfile_2_;
859  if(option[OptionKeys::packing::resfile].user() && (option[ OptionKeys::packing::resfile ].value().size() > 1)) {
860  resfile_2_ = option[OptionKeys::packing::resfile].value().at(2);
861  } else {
862  resfile_2_ = EMPTY_STRING; //empty string flag for don't use resfile
863  }
864 
865  //std::string loop_file_;
866  if(option[OptionKeys::loops::loop_file].user()) {
867  loop_file_ = option[OptionKeys::loops::loop_file].value().at(1);
868  }
869 
870  //std::string frag3_;
871  if(option[OptionKeys::in::file::frag3].user()) {
872  frag3_ = option[OptionKeys::in::file::frag3].value();
873  }
874 
875  //bool no_frags_;
876  no_frags_ = option[ no_frags ].value();
877 
878  //bool anchor_noise_constraints_mode_;
879  anchor_noise_constraints_mode_ = option[ testing::anchor_noise_constraints_mode ].value();
880 
881  super_secret_fixed_interface_mode_ = option[ testing::super_secret_fixed_interface_mode ].value();
882 
883  return;
884 }
885 
886 ///@brief get string name for neighborhood_calc_
888 ///@brief get string name for interface_calc_
890 
891 ///@details This function automatically generates constraints for an anchor from and for the given pose. It is intended for use only with single-residue anchors. The constraints are between the residue CA and the four closest cross-chain CA. They are parabolic constraints with scores of 0.5 units at 1 Angstrom deviation.
893 {
894  //exclusion condition: can't use this mode with multi-residue anchor
895  if(anchor_start() != anchor_end())
896  utility_exit_with_message("You can only use one-residue anchors with anchor_noise_constraints_mode");
897 
898  //Calculate CA-CA distances between anchor residue and all other atoms
899  core::Size const anchor(anchor_start());
900  core::Size const CA(pose.residue_type(anchor).atom_index("CA"));
901  core::id::AtomID const anchor_ID(core::id::AtomID(CA, anchor));
902  core::Vector const & anchor_xyz(pose.xyz(anchor_ID));
903 
904  //we'll need to know which is the opposite chain (we are assuming there is only one)
905  core::Size const chain1end(pose.conformation().chain_end(1));
906  if( pose.conformation().num_chains() != 2 ) //2 is the value we expect
907  utility_exit_with_message("cannot use anchor_noise_constraints_mode with more than two chains");
908  core::Size const oppchain( anchor > chain1end ? 1 : 2);
909 
910  //Data object type to hold resid, distance pairs
911  typedef std::pair< core::Real, core::id::AtomID> dist_resid;
912  std::set< dist_resid > distances;
913 
914  //loop to generate distances
915  for(core::Size i(pose.conformation().chain_begin(oppchain)), end(pose.conformation().chain_end(oppchain)); i<=end; ++i){
916  //if the friend function version of distance worked, I bet I could fit this all on one line of code
917  core::id::AtomID const target_atomID(CA, i);
918  distances.insert(std::make_pair( anchor_xyz.distance(pose.xyz(target_atomID)), target_atomID) );
919  }
920 
921  //generate N constraints; add directly to pose
922  core::Size const this_many_constraints(4);
923  core::Real const sd(sqrt(0.5));
924  std::set< dist_resid >::const_iterator opp_CA(distances.begin());
925  for(core::Size i(1); i<=this_many_constraints; ++i, ++opp_CA){
926  using namespace core::scoring::constraints;
927 
928  HarmonicFuncOP anchor_func( new HarmonicFunc(opp_CA->first, sd));
929 
930  TR << "anchor_noise_constraints constraint, opp_CA, center, sd: " << opp_CA->second << " " << opp_CA->first << " " << sd << std::endl;
931 
932  pose.add_constraint(new AtomPairConstraint(anchor_ID, opp_CA->second, anchor_func));
933  //++opp_CA;
934  }
935 
936  //report constraints chosen
937  pose.constraint_set()->show_definition(TR, pose);
938 
939  //add constraints to cen and fa scorefunctions
940  fullatom_scorefunction_->set_weight( core::scoring::atom_pair_constraint, 1 );
941  centroid_scorefunction_->set_weight( core::scoring::atom_pair_constraint, 1 );
942  centroid_scorefunction_min_->set_weight( core::scoring::atom_pair_constraint, 1 );
943 
944  //free other widgets in AnchorMoversData to allow constraint freedom
945  movemap_fa_all_->set_jump(1, true);
946  movemap_cen_all_->set_jump(1, true);
947  core::Size const numloop = num_loops();
948  for (core::Size i = 1; i <= numloop; ++i){
949  movemap_fa(i)->set_jump(1, true);
950  movemap_fa_omegafixed(i)->set_jump(1, true);
951  movemap_cen(i)->set_jump(1, true);
952  movemap_cen_omegafixed(i)->set_jump(1, true);
953  }
954 
955  return;
956 }
957 
958 }//namespace anchored_design
959 }//namespace protocols