Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RemodelMover.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/forge/remodel/RemodelMover.cc
11 /// @brief
12 /// @author Possu Huang (possu@u.washington.edu)
13 /// @author Yih-En Andrew Ban (yab@u.washington.edu)
14 
15 // unit headers
20 
21 // package headers
32 // AUTO-REMOVED #include <core/pack/pack_rotamers.hh>
33 #include <basic/options/keys/enzdes.OptionKeys.gen.hh>
34 #include <basic/options/keys/packing.OptionKeys.gen.hh>
35 #include <basic/options/keys/remodel.OptionKeys.gen.hh>
36 #include <basic/options/keys/constraints.OptionKeys.gen.hh>
37 #include <basic/options/keys/run.OptionKeys.gen.hh>
38 #include <basic/options/keys/out.OptionKeys.gen.hh>
39 // AUTO-REMOVED #include <core/conformation/symmetry/util.hh>
40 // AUTO-REMOVED #include <core/pose/symmetry/util.hh>
44 #include <basic/options/keys/symmetry.OptionKeys.gen.hh>
45 
46 // project headers
47 #include <core/chemical/AA.hh>
49 
50 // AUTO-REMOVED #include <core/io/pdb/file_data.hh>
51 #include <core/pose/PDBInfo.hh>
54 #include <core/pose/Remarks.hh>
63 
64 #include <core/pose/Pose.hh>
65 #include <core/pose/util.hh> // for pdbinfo
67 #include <core/scoring/Energies.hh>
69 // AUTO-REMOVED #include <core/scoring/constraints/Constraint.hh>
70 #include <protocols/simple_moves/symmetry/SetupNCSMover.hh> //dihedral constraint
71 #include <basic/MetricValue.hh>
72 #include <basic/Tracer.hh>
78 // AUTO-REMOVED #include <protocols/simple_moves/PackRotamersMover.hh>
79 // AUTO-REMOVED #include <protocols/toolbox/pose_manipulation.hh>
84 // AUTO-REMOVED #include <protocols/toolbox/task_operations/PreventChainFromRepackingOperation.hh>
85 // AUTO-REMOVED #include <protocols/forge/remodel/RemodelConstraintGenerator.hh>
89 
90 #ifdef GL_GRAPHICS
92 #endif
93 
94 // AUTO-REMOVED #include <protocols/moves/PyMolMover.hh>
95 
96 // Parser headers
98 #include <utility/tag/Tag.hh>
99 
100 //test
101 // AUTO-REMOVED #include <protocols/protein_interface_design/movers/DockAndRetrieveSidechains.hh>
102 // AUTO-REMOVED #include <protocols/simple_moves/ReturnSidechainMover.hh>
103 // AUTO-REMOVED #include <protocols/simple_moves/SwitchResidueTypeSetMover.hh>
104 
105 // C++ headers
106 #include <utility>
107 
111 #include <utility/vector0.hh>
112 #include <utility/vector1.hh>
113 
114 //Auto Headers
116 
117 
118 namespace protocols {
119 namespace forge {
120 namespace remodel {
121 
122 
123 static basic::Tracer TR( "protocols.forge.remodel.RemodelMover" );
124 
125 //parser
128 {
130 }
131 
134  return new RemodelMover;
135 }
136 
139 {
140  return "RemodelMover";
141 }
142 
143 
144 /// @brief default constructor
146  Super( "RemodelMover" ),
147 // use_fullmer_( false ),
148 // use_sequence_bias_( false ),
149  max_linear_chainbreak_( basic::options::option[basic::options::OptionKeys::remodel::RemodelLoopMover::max_linear_chainbreak]),
150 // max_linear_chainbreak_( 0.15 ),
151  //centroid_loop_mover_str_( "quick_ccd" ),
152  centroid_loop_mover_str_( "RemodelLoopMover" ),
153  redesign_loop_neighborhood_( false ),
154  dr_cycles_( basic::options::option[basic::options::OptionKeys::remodel::dr_cycles] ),
155  centroid_sfx_( core::scoring::ScoreFunctionFactory::create_score_function( basic::options::option[basic::options::OptionKeys::remodel::cen_sfxn] )),
156  fullatom_sfx_( core::scoring::ScoreFunctionFactory::create_score_function( core::scoring::STANDARD_WTS, core::scoring::SCORE12_PATCH ) )
157 {
159  if (basic::options::option[basic::options::OptionKeys::packing::soft_rep_design]){
160  TR << "SWITCHING FULLATOM FUNCITON TO SOFT_REP_DESIGN" << std::endl;
162  }
163 }
164 
165 void
167 {
168  using namespace basic::options;
169  using namespace core::scoring;
170 
171  //set optional weights
172  if ( option[OptionKeys::remodel::vdw].user() ){
173  centroid_sfx_-> set_weight(vdw, option[OptionKeys::remodel::vdw]);
174  TR << "USER OVERWRITE VDW: " << option[OptionKeys::remodel::vdw] << std::endl;
175  }
176 
177  if ( option[OptionKeys::remodel::rama].user() ){
178  centroid_sfx_-> set_weight(rama, option[OptionKeys::remodel::rama]);
179  TR << "USER OVERWRITE RAMA: " << option[OptionKeys::remodel::rama] << std::endl;
180  }
181 
182  if ( option[OptionKeys::remodel::cbeta].user() ){
183  centroid_sfx_-> set_weight(cbeta, option[OptionKeys::remodel::cbeta]);
184  TR << "USER OVERWRITE CBETA: " << option[OptionKeys::remodel::cbeta] << std::endl;
185  }
186 
187  if ( option[OptionKeys::remodel::cenpack].user() ){
188  centroid_sfx_-> set_weight(cenpack, option[OptionKeys::remodel::cenpack]);
189  TR << "USER OVERWRITE CENPACK: " << option[OptionKeys::remodel::cenpack] << std::endl;
190  }
191 
192  if ( option[OptionKeys::remodel::hb_lrbb].user() ){
193  centroid_sfx_-> set_weight(hbond_lr_bb, option[OptionKeys::remodel::hb_lrbb]);
194  TR << "USER OVERWRITE HB_LRBB: " << option[OptionKeys::remodel::hb_lrbb] << std::endl;
195  }
196 
197  if ( option[OptionKeys::remodel::hb_srbb].user() ){
198  centroid_sfx_-> set_weight(hbond_sr_bb, option[OptionKeys::remodel::hb_srbb]);
199  TR << "USER OVERWRITE HB_SRBB: " << option[OptionKeys::remodel::hb_srbb] << std::endl;
200  }
201  if ( option[OptionKeys::remodel::rg].user() ){
202  centroid_sfx_-> set_weight(rg, option[OptionKeys::remodel::rg]);
203  TR << "USER OVERWRITE RG: " << option[OptionKeys::remodel::rg] << std::endl;
204  }
205 
206  if ( option[OptionKeys::remodel::rsigma].user() ){
207  centroid_sfx_-> set_weight(rsigma, option[OptionKeys::remodel::rsigma]);
208  TR << "USER OVERWRITE RSIGMA: " << option[OptionKeys::remodel::rsigma] << std::endl;
209  }
210  if ( option[OptionKeys::remodel::ss_pair].user() ){
211  centroid_sfx_-> set_weight(ss_pair, option[OptionKeys::remodel::ss_pair]);
212  TR << "USER OVERWRITE SSPAIR: " << option[OptionKeys::remodel::ss_pair] << std::endl;
213  }
214 
215 }
216 
217 
218 /// @brief copy constructor
220  //utility::pointer::ReferenceCount(),
221  Super( rval ),
222  //manager_( rval.manager_ ),
223  design_info_( rval.design_info_ ),
224  //use_fullmer_( rval.use_fullmer_ ),
225  //use_sequence_bias_( rval.use_sequence_bias_ ),
229  //resfile_( rval.resfile_ ),
230  dr_cycles_( rval.dr_cycles_ ),
231  centroid_sfx_( rval.centroid_sfx_->clone() ),
232  fullatom_sfx_( rval.fullatom_sfx_->clone() ),
233  blueprint_( rval.blueprint_ )
234 {
235  if ( rval.vlb_.get() ) {
236  vlb_ = new VarLengthBuild( *rval.vlb_ );
237  }
238 }
239 
240 
241 /// @brief default destructor
243 
244 
245 /// @brief clone for parser
247  return new RemodelMover( *this );
248 }
249 
250 
251 /// @brief fresh instance for parser
253  return new RemodelMover();
254 }
255 
256 
257 /// @brief clone this object
259  return new RemodelMover( *this );
260 }
261 
262 
263 /// @brief create this type of object
265  return new RemodelMover();
266 }
267 
268 /// @brief the centroid level score function, default "remodel_cen"
270  return *centroid_sfx_;
271 }
272 
273 
274 /// @brief the full-atom level score function, default score12
276  return *fullatom_sfx_;
277 }
278 
279 
280 /// @brief add instruction to the manager of this RemodelMover (no copy)
281 /// @param[in] bi BuildInstruction
282 /// @param[in] aa_during_design_refine The allowed amino acid sequence
283 /// during design. Only applicable to BuildInstructions like
284 /// SegmentRebuild and SegmentInsert. Make sure the length of this
285 /// string matches up properly. Default empty string.
286 /*void RemodelMover::add_instruction(
287  BuildInstructionOP bi,
288  String const & aa_during_design_refine
289 )
290 {
291  manager_.add( bi );
292  if ( !aa_during_design_refine.empty() ) {
293  design_info_.push_back( std::make_pair( bi->original_interval(), aa_during_design_refine ) );
294  }
295 
296  // additional instruction means we'll need a new re-init the VLB, so
297  // go ahead and drop the existing one
298  vlb_ = 0;
299 }
300 */
301 
302 /// @brief create directed dependency between two instructions
303 /*
304 void RemodelMover::create_directed_dependency(
305  BuildInstructionOP u,
306  BuildInstructionOP v
307 )
308 {
309  manager_.create_directed_dependency( u, v );
310 }
311 */
312 
313 /// @brief set the centroid level score function
315  centroid_sfx_ = sfx.clone();
316 }
317 
318 
319 /// @brief set the centroid level score function
321  centroid_sfx_ = sfx->clone();
322 }
323 
324 
325 /// @brief set the full-atom level score function
327  fullatom_sfx_ = sfx.clone();
328 }
329 
330 
331 /// @brief set the full-atom level score function
333  fullatom_sfx_ = sfx->clone();
334 }
335 
336 
337 /// @brief apply defined moves to given Pose
338 void RemodelMover::apply( Pose & pose ) {
340  using basic::MetricValue;
347  using namespace core::scoring;
348  using namespace protocols::simple_filters;
349  using namespace basic::options;
350  using namespace core::scoring::constraints;
351 
352 #if defined GL_GRAPHICS
354 #endif
355 
356  //store the starting pose for KIC confirmation RMSD calculation
357  native_pose_ = pose;
358 
359  // assign secondary structure
360  Dssp dssp( pose );
361 
364  // read blueprint
365 
366  //TR << "blueprint value 0 is " << blueprint_ << std::endl;
367 
368  if (blueprint_ == "") {
369  //TR << "blueprint value 1 is " << blueprint_ << std::endl;
370  blueprint_ = option[basic::options::OptionKeys::remodel::blueprint]();
371  //TR << "blueprint value 2 is " << blueprint_ << std::endl;
372  }
373 
374  remodel_data.getLoopsToBuildFromFile(blueprint_);
375 
376  TR << pose.total_residue() << std::endl;
377  ObjexxFCL::FArray1D_char dsspSS( pose.total_residue() );
378  dssp.dssp_reduced(dsspSS);
379  TR << "input PDB dssp assignment:" << std::endl;
380 
381  for (Size i = 1; i<= pose.total_residue(); i++){
382  TR << dsspSS(i);
383  }
384  TR << std::endl;
385 
386  remodel_data.updateWithDsspAssignment( dsspSS );
387  dssp.insert_ss_into_pose( pose );
388 
389 
390  // insertion
391  if (option[OptionKeys::remodel::domainFusion::insert_segment_from_pdb].user()){
392  TR << "INSERT SEGMENT FROM PDB" << std::endl;
393  remodel_data.collectInsertionPose();
394  }
395 
396  // score the pose first
398  (*sfx)( pose );
399 
400  working_model.workingSetGen( pose, remodel_data );
401 
402  remodel_data_ = remodel_data; // will use the movemap for natro definition later
403  working_model_=working_model;
404 
405 
406 /* test PyMol viewer */
407  if ( option[ OptionKeys::run::show_simulation_in_pymol ].user() &&
408  option[ OptionKeys::run::show_simulation_in_pymol ]() == true ){
409  // moves::AddPyMolObserver( pose, false, core::Real( 0.50 ) );
410  }
411 
412 
413 
414 /*
415 // DEBUG
416  std::set<core::Size> up = working_model.manager.undefined_positions();
417  for ( std::set<core::Size>::iterator i = up.begin(); i!=up.end(); i++){
418  TR << *i << std::endl;
419  }
420  std::set<core::Size> uup = working_model.manager.union_of_intervals_containing_undefined_positions();
421  for ( std::set<core::Size>::iterator i = uup.begin(); i!=uup.end(); i++){
422  TR << *i << " UUP" << std::endl;
423  }
424  */
425 
426  if (basic::options::option[basic::options::OptionKeys::remodel::repeat_structure].user()) {
427  //for cases involve jxn, need to make pose longer so manager won't complain
428  //about missing residues
429 
430  //this is pre modify, so simply extend to 2x blueprint length,
431  //with extensions, the pose will go beyond the correct length. need to fix
432  //that after modify. Residues beyond first copy+ jxn doesn't really matter
433  if (pose.total_residue() < 2*remodel_data.sequence.length()){ //just making sure it's shorter before grow, input pose can be longer
434  Size len_diff = (2*remodel_data_.sequence.length()) - pose.total_residue();
435  // append a tail of the same length
436  for (Size i = 1; i<= len_diff; ++i){
437  core::chemical::ResidueTypeSet const & rsd_set = (pose.residue(1).residue_type_set());
441  pose.set_omega(pose.total_residue()-1,180);
442  }
443  }
444  }
445 
446 
447 //
448 // Pose testArc;
449 // testArc = pose;
450 if (working_model.manager.size()!= 0){
451  if (!basic::options::option[basic::options::OptionKeys::remodel::bypass_fragments]){
452  working_model.manager.modify(pose);
453  }else{
454  working_model.manager.dummy_modify(pose.total_residue());
455  }
456 // protocols::forge::methods::restore_residues(working_model.manager.original2modified(), testArc, pose);
457 // pose.dump_pdb("testArcRestore.pdb");
458  //testArc=pose;
459  manager_ = working_model.manager;
461  pose,
462  true , // fix chain
463  true, // start_from_existing_numbering
464  false, // keep_insertion_code
465  false // rotate_chain_id
466  );
467 
468 }
469 
470 //finally recheck length to ensure blueprint compliance
471 if (basic::options::option[basic::options::OptionKeys::remodel::repeat_structure].user()) {
472  Size max_pdb_index = remodel_data_.blueprint.size()*2;
473  while (pose.total_residue() >= max_pdb_index){
475  }
476 
477  if ( pose.total_residue() < (remodel_data_.sequence.length()*2) ) {
478  Size len_diff = (2*remodel_data_.sequence.length()) - pose.total_residue();
479  // append a tail of the same length
480  for (Size i = 1; i<= len_diff; ++i){
481  core::chemical::ResidueTypeSet const & rsd_set = (pose.residue(1).residue_type_set());
485  pose.set_omega(pose.total_residue()-1,180);
486  }
487  }
488 
489 }
490 
491 
492 
493 
494 /*
495  up = working_model.manager.undefined_positions();
496  for ( std::set<core::Size>::iterator i = up.begin(); i!=up.end(); i++){
497  TR << *i << std::endl;
498  }
499  uup = working_model.manager.union_of_intervals_containing_undefined_positions();
500  for ( std::set<core::Size>::iterator i = uup.begin(); i!=uup.end(); i++){
501  TR << *i << " UUP2" << std::endl;
502  }
503 */
504 // manager_.dummy_modify(testArc.n_residue());
505 // core::util::switch_to_residue_type_set( pose, core::chemical::CENTROID, true);
506 // core::util::switch_to_residue_type_set( pose, core::chemical::FA_STANDARD, true);
507 // protocols::forge::methods::restore_residues(manager_.original2modified(), testArc, pose);
508 // pose.dump_pdb("testArcRestore2.pdb");
509 // protocols::forge::methods::restore_residues(manager_.original2modified(), testArc, pose);
510 // pose.update_residue_neighbors();
511 // pose.dump_pdb("testArcRestore3.pdb");
512  //testArc.dump_pdb("testArcRestoreSrc3.pdb");
513  //protocols::simple_moves::SwitchResidueTypeSetMover to_all_atom( core::chemical::FA_STANDARD);
514  //protocols::simple_moves::ReturnSidechainMover recover_sidechains( testArc);
515  //to_all_atom.apply(pose);
516  //recover_sidechains.apply(pose);
517  //pose.dump_pdb("MoverREstore.pdb");
518 
519  //initialize symmetry
520  if ( option[ OptionKeys::symmetry::symmetry_definition ].user() ) {
522  pre_mover.apply( pose );
523  // Remodel assumes chain ID is ' '
524  core::pose::PDBInfoOP pdb_info ( pose.pdb_info() );
525  for ( Size i=1; i<= pdb_info->nres(); ++i ){
526  pdb_info->chain(i,' ');
527  }
528  pose.pdb_info( pdb_info );
529  }
530 
531  Size i = basic::options::option[basic::options::OptionKeys::remodel::num_trajectory]();
532  Size num_traj = i; //need this for checkpointing math
533  Size prev_checkpoint = 0;
534 
535  RemodelAccumulator accumulator(working_model);
536 
537  if (option[OptionKeys::remodel::checkpoint]){
538  prev_checkpoint = accumulator.recover_checkpoint();
539  if (prev_checkpoint >= i){
540  i = 0;
541  } else {
542  i = i - prev_checkpoint;
543  }
544  }
545  if (working_model.manager.size() != 0){
546  // setup calculators
547  CalculatorFactory::Instance().remove_calculator( neighborhood_calc_name() );
548  CalculatorFactory::Instance().register_calculator(
550  new NeighborhoodByDistanceCalculator( manager_.union_of_intervals_containing_undefined_positions() )
551  );
552 }
553 /*
554  up = working_model.manager.undefined_positions();
555  for ( std::set<core::Size>::iterator i = up.begin(); i!=up.end(); i++){
556  TR << *i << std::endl;
557  }
558  uup = working_model.manager.union_of_intervals_containing_undefined_positions();
559  for ( std::set<core::Size>::iterator i = uup.begin(); i!=uup.end(); i++){
560  TR << *i << " UUP2" << std::endl;
561  }
562 
563 */
564  if (basic::options::option[ OptionKeys::remodel::repeat_structure].user()){
565  //turning on the res_type_linking constraint weight for designs
569 
570  //fullatom_sfx_->set_weight( core::scoring::fa_dun, 0);
571 // fullatom_sfx_->set_weight( core::scoring::fa_sol, 0);
572 // fullatom_sfx_->set_weight( core::scoring::fa_pair, 0);
573 // fullatom_sfx_->set_weight( core::scoring::hbond_sc, 0);
574 // fullatom_sfx_->set_weight( core::scoring::hbond_sc, 0);
575 // fullatom_sfx_->set_weight( core::scoring::fa_intra_rep, 0);
576 // fullatom_sfx_->set_weight( core::scoring::rama, 0);
577 // fullatom_sfx_->set_weight( core::scoring::hbond_bb_sc, 0);
578 // fullatom_sfx_->set_weight( core::scoring::p_aa_pp, 0);
579 // fullatom_sfx_->set_weight( core::scoring::ref, 10);
580 
581  }
582 
583  RemodelDesignMover designMover(remodel_data, working_model, fullatom_sfx_);
584 
585  Size repeat_number = basic::options::option[ OptionKeys::remodel::repeat_structure];
586 //rerooting tree
587  if (option[ OptionKeys::remodel::repeat_structure].user() && pose.total_residue() == remodel_data.blueprint.size()*repeat_number) {
589  f.reorder(working_model.safe_root_);
590  pose.fold_tree(f);
591  TR << "rerooting tree: " << pose.fold_tree() << std::endl;
592  }
593 
594  while ( i > 0){
595 
596  //cache the modified pose first for REPEAT
597  Pose cached_modified_pose( pose );
598 
599  // do centroid build
600  TR << "BUILD CYCLE REMAINING " << i << std::endl;
601  core::kinematics::FoldTree originalTree = pose.fold_tree();
602 TR << "ORIGINAL TREE: " << pose.fold_tree() << std::endl;
603  if (working_model.manager.size() != 0){
604  if ( !centroid_build( pose, working_model.manager ) ) { // build failed
606  i--;
607  continue;
608  //return;
609  }
610  }
611 
612  if (option[ OptionKeys::remodel::repeat_structure].user()) {
613  //should fold this pose to match just the first segment of a repeat, and that will be used for next round of building
614  for (Size res = 1; res <= cached_modified_pose.n_residue(); res++){
615  cached_modified_pose.set_phi(res, pose.phi(res));
616  cached_modified_pose.set_psi(res, pose.psi(res));
617  cached_modified_pose.set_omega(res, pose.omega(res));
618  }
619  }
620 
622  pose,
623  true , // fix chain
624  true, // start_from_existing_numbering
625  false, // keep_insertion_code
626  false // rotate_chain_id
627  );
628 
629  //test
630  //pose.dump_pdb("check.pdb");
631 /*
632  //extract the constraint currently in Pose for later Recycling
633  ConstraintSetOP cst_set_post_built;
634  if (basic::options::option[ OptionKeys::remodel::repeat_structure].user()){
635 
636  // at this stage it should hold generic cstfile and res_type_linking
637  // constraints
638  cst_set_post_built = new ConstraintSet( *pose.constraint_set());
639  }
640 */
641 
642  designMover.set_state("stage");
643 
644  //handle constraints as soon as centroid is done. If applying sidechain
645  //constraints, replace residue to the right AA right away.
646  if ( basic::options::option[basic::options::OptionKeys::enzdes::cstfile].user() ){
647 
648  RemodelEnzdesCstModuleOP cstOP = new RemodelEnzdesCstModule(remodel_data);
649 
650  //RemodelEnzdesCstModule cst(remodel_data);
651  //safety
652  pose.remove_constraints();
653  //wipe out cst_cache
654  protocols::toolbox::match_enzdes_util::get_enzdes_observer( pose ) -> set_cst_cache( NULL );
655  //wipe out observer too
657 
658  //cstOP->remove_constraints_from_pose(pose,true /*keep covalent*/, false /*fail if missing*/);
659 
660  cstOP->use_all_blocks();
661  cstOP->apply(pose);
662  cstOP->enable_constraint_scoreterms(fullatom_sfx_);
663  designMover.scorefunction(fullatom_sfx_);
664  }
665 
666  if (basic::options::option[ OptionKeys::constraints::cst_file ].user()){
667  //safety
668  pose.remove_constraints();
669 
671  constraint->apply( pose );
672 
675  designMover.scorefunction(fullatom_sfx_);
676  }
677 
678 
679 
680  if (basic::options::option[OptionKeys::remodel::build_disulf].user()){
681  utility::vector1<std::pair <Size, Size> > disulf_partners;
682  bool disulfPass = false;
683  disulfPass = designMover.find_disulfides_in_the_neighborhood(pose, disulf_partners);
684  if (disulfPass != true){
685  i--; //for now control disulf with num_trajectory flag, too.
686  continue;
687  }
688 
689  for (utility::vector1<std::pair<Size,Size> >::iterator itr = disulf_partners.begin(); itr != disulf_partners.end(); itr++){
690  Pose disulf_copy_pose = pose;
692  single_disulf.push_back(*itr);
693 
695 
696  combined_mm->import(remodel_data_.natro_movemap_);
697  combined_mm->import( manager_.movemap() );
698 
699  designMover.make_disulfide(disulf_copy_pose, single_disulf, combined_mm);
700  designMover.apply(disulf_copy_pose);
701  //for now, accept all disulf build, as it is hard enough to do
702  //already. Accept instead of cst filter?
703  //accumulator.apply(disulf_copy_pose);
704  if ( basic::options::option[basic::options::OptionKeys::enzdes::cstfile].user() ||
705  basic::options::option[ OptionKeys::constraints::cst_file ].user()
706  )
707  {
708  ScoreTypeFilter const pose_constraint( fullatom_sfx_, atom_pair_constraint, 10 );
709  bool CScore(pose_constraint.apply( disulf_copy_pose ));
710  if (!CScore){ // if didn't pass, rebuild
711  continue;
712  }
713  else {
714  accumulator.apply(disulf_copy_pose);
715  }
716  } else {
717  accumulator.apply(disulf_copy_pose);
718  }
719  }
720  }
721  else {
722 
723  if (option[ OptionKeys::remodel::cen_minimize]) {
724 
725  //cache current foldTree;
726  core::kinematics::FoldTree cenFT = pose.fold_tree();
727  pose.fold_tree(originalTree);
728 
730  //pose.dump_pdb("pretest.pdb");
731 
732  cmmop->import(remodel_data_.natro_movemap_);
733  cmmop->import( manager_.movemap() );
734 
735  for (Size i = 1; i<= pose.total_residue(); ++i){
736  std::cout << "bb at " << i << " " << cmmop->get_bb(i) << std::endl;
737  }
738 
739  //adding angles and bonds dof
740  // cmmop->set(core::id::THETA, true);
741  // cmmop->set(core::id::D, true);
742 
743  for(Size i = 1; i <= pose.n_residue(); i++) {
744  for(Size j = 1; j <= pose.residue(i).nheavyatoms(); j++) {
745  if (cmmop->get_bb(i) == 1){
746  cmmop->set(core::id::DOF_ID(core::id::AtomID(j,i),core::id::THETA),true);
747  cmmop->set(core::id::DOF_ID(core::id::AtomID(j,i),core::id::D),true);
748  }
749  }
750  }
751 
752 
753  //core::scoring::ScoreFunctionOP cen_min_sfxn = core::scoring::ScoreFunctionFactory::create_score_function("score4_smooth");
754 
755  TR << "centroid minimizing" << std::endl;
756  Pose archived_pose = pose;
757 
758  // flip residue type set for centroid minimize
760 
762 
763  if (basic::options::option[ OptionKeys::remodel::repeat_structure].user()){
764  //Dihedral (NCS) Constraints, need to be updated each mutation cycle for sidechain symmetry
765 
766  Size repeat_number = basic::options::option[ OptionKeys::remodel::repeat_structure];
767  Size segment_length = (pose.n_residue())/repeat_number;
768 
769 
770  for (Size rep = 1; rep < repeat_number-1; rep++){ // from 1 since first segment don't need self-linking
771  std::stringstream templateRangeSS;
772  templateRangeSS << "2-" << segment_length+1; // offset by one to work around the termini
773  std::stringstream targetSS;
774  targetSS << 1+(segment_length*rep)+1 << "-" << segment_length + (segment_length*rep)+1;
775  TR << "NCS " << templateRangeSS.str() << " " << targetSS.str() << std::endl;
776  setup_ncs.add_group(templateRangeSS.str(), targetSS.str());
777  }
778 
779  for (Size rep = 1; rep < repeat_number-1; rep++){ // from 1 since first segment don't need self-linking
780  std::stringstream templateRangeSS;
781  templateRangeSS << "3-" << segment_length+2; // offset by one to work around the termini
782  std::stringstream targetSS;
783  targetSS << 1+(segment_length*rep)+2 << "-" << segment_length + (segment_length*rep)+2;
784  TR << "NCS " << templateRangeSS.str() << " " << targetSS.str() << std::endl;
785  setup_ncs.add_group(templateRangeSS.str(), targetSS.str());
786  }
787 
788 
789  std::stringstream templateRangeSS;
790  //take care of the terminal repeat, since the numbers are offset.
791  templateRangeSS << "2-" << segment_length-1; // offset by one to work around the termini
792  std::stringstream targetSS;
793  targetSS << 1+(segment_length*(repeat_number-1))+1 << "-" << segment_length + (segment_length*(repeat_number-1))-1;
794  TR << "NCS " << templateRangeSS.str() << " " << targetSS.str() << std::endl;
795  setup_ncs.add_group(templateRangeSS.str(), targetSS.str());
796  setup_ncs.apply(pose);
797 
798  }
799 
800  //sfx->show(TR, pose);
801  //TR << std::endl;
802 
805  //enable cartesian bond terms
809  centroid_sfx_->set_weight(core::scoring::omega, 0.2 );
810 
811  //only use smooth hb if either of the term is used in centroid build level
812  if (centroid_sfx_->get_weight(core::scoring::hbond_lr_bb) > 0 || centroid_sfx_->get_weight(core::scoring::hbond_sr_bb) > 0 ){
813  centroid_sfx_->set_weight( core::scoring::cen_hb, 2.0);
814  }
815  /*
816  if (centroid_sfx_->get_weight(core::scoring::env) > 0 ){
817  centroid_sfx_->set_weight( core::scoring::cen_env_smooth, centroid_sfx_->get_weight(core::scoring::env));
818  centroid_sfx_->set_weight( core::scoring::env, 0.0);
819  }*/
820 
821  //simple_moves::MinMoverOP minMover = new simple_moves::MinMover( cmmop , centroid_sfx_, "dfpmin_armijo", 0.01, true);
822  simple_moves::MinMoverOP minMover = new simple_moves::MinMover( cmmop , centroid_sfx_, "lbfgs_armijo", 0.01, true);
823  TR << "cen_minimize pose foldtree: " << pose.fold_tree() << std::endl;
824  minMover->apply(pose);
825 
826  //reset cen_hb to 0
827  centroid_sfx_->set_weight( core::scoring::cen_hb, 0.0);
828  //switch back the foldtree
829  //pose.fold_tree(cenFT);
830 
831  // flip residue type set back, for repeat builds, currently don't do
832  // restore_sidechain, as they should all be redesigned. MAY NEED TO
833  // CHANGE
835  //protocols::forge::methods::restore_residues( manager_.original2modified(), archived_pose , pose );
836  //pose.dump_pdb("test.pdb");
837 
838  }
839 
840  designMover.apply(pose);
841 
842  if ( basic::options::option[basic::options::OptionKeys::enzdes::cstfile].user() ||
843  basic::options::option[ OptionKeys::constraints::cst_file ].user()
844  ){
845  ScoreTypeFilter const pose_constraint( fullatom_sfx_, atom_pair_constraint, option[ OptionKeys::remodel::cstfilter]() );
846  bool CScore(pose_constraint.apply( pose ));
847  if (!CScore){ // if didn't pass, rebuild
848  continue;
849  }
850  else {
851  accumulator.apply(pose);
852  }
853  } else {
854  accumulator.apply(pose);
855  }
856  }
857 
858  if (option[OptionKeys::remodel::checkpoint]){
859  // debug:
860  TR << "writing chkpnt at step " << num_traj-i+prev_checkpoint << std::endl;
861  accumulator.write_checkpoint(num_traj-i-prev_checkpoint);
862  }
863  //restore foldtree
864  if (option[ OptionKeys::remodel::repeat_structure].user()) {
865  //reset the pose to monomer
866  pose = cached_modified_pose;
867 
868  } else {
869  pose.fold_tree(originalTree);
870  }
871  i--;
872  }
873 /* DONT USE THIS FOR NOW...
874  if (get_last_move_status() == FAIL_RETRY){
875  return;
876  }
877 */
878  //take the lowest member and the cluster center
879  //accumulator.shrink_cluster();
880  std::vector<core::pose::PoseOP> results;
881  if (accumulator.cluster_switch()){
882  results = accumulator.clustered_best_poses();
883  //results = accumulator.clustered_top_poses(option[OptionKeys::remodel::collect_clustered_top]);
884  }
885  else {
886  results = accumulator.contents_in_pose_store();
887  }
888 
889  //seriously refine the poses
890  Size filecount = 1;
891  core::Real current_score = 100000;
892 
893  TR << "clustered poses count: " << results.size() << std::endl;
894  for(std::vector<core::pose::PoseOP>::iterator it = results.begin(), end= results.end(); it!= end; it++){
895  bool bypass_refinement = basic::options::option[basic::options::OptionKeys::remodel::quick_and_dirty].user();
896  if (working_model.manager.size() == 0 ) bypass_refinement = true;
897  if ( !bypass_refinement ){
898 
899  // std::stringstream SS1;
900  // SS1 << "pre-ref_" << filecount << ".pdb";
901  // (*(*it)).dump_scored_pdb(SS1.str(), *fullatom_sfx_);
902 
903  TR << "aggressively refine" << std::endl;
904  if (basic::options::option[basic::options::OptionKeys::remodel::use_pose_relax]){
905  if (!design_refine_seq_relax(*(*it), designMover)){
906  TR << "WARNING: DESIGN REFINE SEQ RELAX FAILED!! (one should never see this)" << std::endl;
907  continue;
908  }
909  }else {
910  if (! design_refine(*(*it), designMover)){
911  TR << "WARNING: DESIGN REFINE FAILED TO CLOSE STRUCTURE!!" << std::endl;
912  continue;
913  }
914  }
915  } else // simple design
916  {
917  designMover.set_state("finish");
918  designMover.apply(*(*it));
919 
920  }
921 
922  if ( basic::options::option[basic::options::OptionKeys::remodel::run_confirmation].user()){
923  if (!confirm_sequence(*(*it))){
924  TR << "WARNING: STRUCTURE DID NOT PASS KIC CONFIRMATION!!" << std::endl;
925  continue;
926  }
927  }
928 
929  std::stringstream SS;
930  std::string prefix = basic::options::option[basic::options::OptionKeys::out::prefix];
931  if (!prefix.empty()){
932  SS << prefix << "_" << filecount << ".pdb";
933  }
934  else {
935  SS << filecount << ".pdb";
936  }
937 
938  //this is to make sure that the final scoring is done with SCORE12
940 
941  (*(*it)).dump_scored_pdb(SS.str(), *scorefxn);
942 
943  ScoreTypeFilter const pose_total_score( scorefxn, total_score, 100 );
944  core::Real score(pose_total_score.compute( *(*it) ));
945  if (score <= current_score) {
946  current_score = score ;
947  pose = *(*it) ;
948  }
949 
950  filecount++;
951  }
952 
953  // update PDBinfo
954  pose.pdb_info( new core::pose::PDBInfo( pose ));
955 
956 
957  // setup calculators
958  CalculatorFactory::Instance().remove_calculator( neighborhood_calc_name() );
959  CalculatorFactory::Instance().register_calculator(
961  new NeighborhoodByDistanceCalculator( manager_.union_of_intervals_containing_undefined_positions() )
962  );
963 
964 
965 /*
966  // do design-refine iteration
967  if ( dr_cycles_ > 0 ) {
968 
969  if ( !design_refine( pose ) ) { // design-refine failed
970  set_last_move_status( FAIL_RETRY );
971  return;
972  }
973 
974  }
975 */
976  // if we've gotten to this point, then the structure has been
977  // built properly
979 
980  // setup the PoseMetricCalculators and add them to the evaluators in the
981  // JobOutputter
982  CalculatorFactory::Instance().remove_calculator( loops_buns_polar_calc_name() );
983  CalculatorFactory::Instance().remove_calculator( neighborhood_buns_polar_calc_name() );
984 
985  CalculatorFactory::Instance().register_calculator(
987  new BuriedUnsatisfiedPolarsCalculator(
988  "default",
989  "default",
991  )
992  );
993 
994  MetricValue< std::set< Size > > loops_neighborhood;
995  pose.metric( neighborhood_calc_name(), "neighbors", loops_neighborhood );
996  CalculatorFactory::Instance().register_calculator(
998  new BuriedUnsatisfiedPolarsCalculator(
999  "default",
1000  "default",
1001  loops_neighborhood.value()
1002  )
1003  );
1004 }
1005 
1008  return "RemodelMover";
1009 }
1010 
1012  Pose & pose,
1014 ) {
1015  manager_ = manager;
1016  if (basic::options::option[basic::options::OptionKeys::remodel::bypass_fragments]){
1017  TR << "-=BYPASSING FRAGMENT BUILD (REFINE ONLY) =-" << std::endl;
1018  return true;
1019  }
1020  if (centroid_build( pose )){
1021  //update external manager
1022  //manager = manager_;
1023  return true;
1024  }
1025  else {
1026  return false;
1027  }
1028 }
1029 
1030 
1031 
1032 /// @brief run the centroid level build stage
1033 /// @return true if loop closed, false otherwise
1035  Pose & pose
1036 ) {
1041  using namespace basic::options;
1043 
1046  //using protocols::toolbox::pose_manipulation::construct_poly_uniq_restype_pose;
1047  using namespace protocols::forge::components;
1048 
1049  // safety, clear the energies object
1050  pose.energies().clear();
1051 
1052  // make backup Pose for transferring sidechains
1053  Pose archive_pose = pose;
1054  Pose modified_archive_pose = archive_pose;
1055  //manager_.modify( modified_archive_pose );
1056 
1057  // ensure modified_archive_pose is completely full-atom, otherwise mismatch
1058  // will occur when restoring sidechains at the end of the procedure
1059  bool mod_ap_is_full_atom = true;
1060  for ( Size i = 1, ie = modified_archive_pose.n_residue(); mod_ap_is_full_atom && i != ie; ++i ) {
1061  mod_ap_is_full_atom &= ( modified_archive_pose.residue( i ).residue_type_set().name() == core::chemical::FA_STANDARD );
1062  }
1063 
1064  if ( !mod_ap_is_full_atom ) {
1066  }
1067 /*
1068  // flip to poly-ala-gly-pro-disulf pose, only in the rebuilt segment
1069  utility::vector1< Size > protein_residues;
1070  for (std::set<Size>::iterator it=rebuild.begin(), end=rebuild.end(); it != end; it++){
1071  //for ( Size i = 1, ie = pose.n_residue(); i <= ie; ++i ) {
1072  if ( pose.residue( *it ).is_protein() ) {
1073  protein_residues.push_back( *it );
1074  TR<< "turning these to ala: " << *it << std::endl;
1075  }
1076  }
1077  TR << "default building restype: " << "ALA" << std::endl;
1078  construct_poly_uniq_restype_pose( pose, protein_residues, core::chemical::ChemicalManager::get_instance()->residue_type_set( core::chemical::FA_STANDARD )->name_map("ALA"), true, true, true );
1079 */
1080  // run VLB to build the new section, if no segments have been added/deleted
1081  // we use the same VLB so that fragment caching works properly
1082  if ( !vlb_.get() ) {
1084  }
1085  if (!working_model_.abego.empty()){
1086  //the following block simply packages the string to feed to vlb
1088  for (Size i = 0; i < working_model_.abego.length(); i++){
1089  std::string buffer;
1090  buffer.push_back(working_model_.abego[i]);
1091  abego_vec.push_back(buffer);
1092  }
1093  vlb_->set_abego(abego_vec);
1094  }
1095 
1096  vlb_->scorefunction( centroid_sfx_ );
1098  vlb_->use_fullmer( option[OptionKeys::remodel::use_same_length_fragments] );
1099  vlb_->max_linear_chainbreak( max_linear_chainbreak_ );
1100  vlb_->loop_mover_str( centroid_loop_mover_str_ );
1101  vlb_->restart_mode(true);
1102  vlb_->new_secondary_structure_override(working_model_.ss);
1103  if ( option[OptionKeys::remodel::use_blueprint_sequence] ) {
1104  if (option[ OptionKeys::remodel::repeat_structure].user()) {
1105  Size copies = option[ OptionKeys::remodel::repeat_structure];
1106  String rep_seq = remodel_data_.sequence;
1107  while (copies > 1){
1108  rep_seq.append(remodel_data_.sequence);
1109  copies--;
1110  }
1111  vlb_->new_sequence_override( rep_seq );
1112  }
1113  else vlb_->new_sequence_override( remodel_data_.sequence );
1114  }
1115 
1116 
1117  vlb_->apply( pose );
1118 
1119  if ( vlb_->get_last_move_status() == MS_SUCCESS ) {
1120 
1121  // record the used manager w/ all mapping info
1122  // manager_ = vlb_->manager();
1123 
1124  // safety, clear all the energies before restoring full-atom residues and
1125  // scoring
1126  pose.energies().clear();
1127  if (option[ OptionKeys::remodel::repeat_structure].user()) {
1128  //this part really needs work.... currently doesn't allow growing a loop
1129  //in regional repeat building. This section is used in de novo rebuild
1130  //cases where the monomer pose is extended, so to restore the sidechain,
1131  //the source of the sidechains has to be extended too in de novo cases.
1132  //but with refining an existing repeat pose, no need to extend
1133  if (modified_archive_pose.total_residue() == pose.total_residue()){ //dangerous, assuming no further length change
1134  //do nothing.
1135  } else { // if there's mismatch, assuming restoration source need extension... dangerous.
1136  using namespace protocols::loops;
1138  std::set< Interval > loop_intervals = manager_.intervals_containing_undefined_positions();
1139  LoopsOP loops = new Loops( intervals_to_loops( loop_intervals.begin(), loop_intervals.end() ) );
1140  RemodelLoopMover RLM(loops);
1142  Pose bufferPose(modified_archive_pose);
1143  //due to code change, modified_archive_pose would always be 2x length now
1144  RLM.repeat_generation_with_additional_residue( bufferPose, modified_archive_pose );
1145  }
1146  }
1147 
1148 
1149 
1150  // Swap back original sidechains. At the moment this is a two step process
1151  // in case any sidechains from SegmentInsert and the like that aren't in the
1152  // original archive pose need to be transferred.
1153  restore_residues( modified_archive_pose, pose );
1154 
1155  // since pose is setup modified in RemodelMover, only one step will do
1156  //restore_residues( manager_.original2modified(), archive_pose, pose );
1157  // go ahead and score w/ full-atom here; we do this in case there are no
1158  // design-refine cycles -- it's useful to have e.g. rama in the output
1159  (*fullatom_sfx_)( pose );
1160 
1161  if (option[ OptionKeys::remodel::repeat_structure].user()) {
1162  //return the modified pose to original state, otherwise it keeps growing.
1163  modified_archive_pose = archive_pose;
1164  }
1165 
1166  return true; // loop closed
1167 
1168  } else {
1169 
1170  pose = archive_pose;
1171 
1172  }
1173  return false; // false if loop not closed
1174 }
1175 
1177  Pose & pose,
1178  RemodelDesignMover & designMover
1179 )
1180 {
1190  using namespace protocols::loops;
1195  using namespace core::scoring::constraints;
1196  using namespace basic::options;
1197 
1198 
1203 
1205 
1206  // collect new regions/positions
1207  std::set< Interval > loop_intervals = manager_.intervals_containing_undefined_positions();
1208  Original2Modified original2modified_interval_endpoints = manager_.original2modified_interval_endpoints();
1209 
1210  // collect loops
1211  Loops loops = intervals_to_loops( loop_intervals.begin(), loop_intervals.end() );
1212 
1213  if (basic::options::option[ OptionKeys::remodel::repeat_structure].user()){
1214  //do nothing
1215  } else {
1217  }
1218 
1219  // safety, clear the energies object
1220  pose.energies().clear();
1221 
1222 // for refinement, always use standard repulsive
1224 //turning on weights
1225  sfx->set_weight(core::scoring::coordinate_constraint, 1.0 );
1226  sfx->set_weight(core::scoring::atom_pair_constraint, 1.0 );
1227  sfx->set_weight(core::scoring::angle_constraint, 1.0 );
1228  sfx->set_weight(core::scoring::dihedral_constraint, 10.0 ); // 1.0 originally
1229  sfx->set_weight(core::scoring::res_type_constraint, 1.0);
1230  sfx->set_weight(core::scoring::res_type_linking_constraint, 1.0);
1231  protocols::relax::FastRelax relaxMover(sfx);
1232 
1233 
1234  ConstraintSetOP cst_set_post_built;
1235  if (basic::options::option[ OptionKeys::remodel::repeat_structure].user()){
1236 
1237  // at this stage it should hold generic cstfile and res_type_linking
1238  // constraints
1239  cst_set_post_built = new ConstraintSet( *pose.constraint_set() );
1240  }
1241 
1243  if (basic::options::option[ OptionKeys::remodel::repeat_structure].user()){
1244  //Dihedral (NCS) Constraints, need to be updated each mutation cycle for sidechain symmetry
1245 
1246  Size repeat_number = basic::options::option[ OptionKeys::remodel::repeat_structure];
1247  Size segment_length = (pose.n_residue())/repeat_number;
1248 
1249 
1250  for (Size rep = 1; rep < repeat_number-1; rep++){ // from 1 since first segment don't need self-linking
1251  std::stringstream templateRangeSS;
1252  templateRangeSS << "2-" << segment_length+1; // offset by one to work around the termini
1253  std::stringstream targetSS;
1254  targetSS << 1+(segment_length*rep)+1 << "-" << segment_length + (segment_length*rep)+1;
1255  TR << "NCS " << templateRangeSS.str() << " " << targetSS.str() << std::endl;
1256  setup_ncs.add_group(templateRangeSS.str(), targetSS.str());
1257  }
1258 
1259  for (Size rep = 1; rep < repeat_number-1; rep++){ // from 1 since first segment don't need self-linking
1260  std::stringstream templateRangeSS;
1261  templateRangeSS << "3-" << segment_length+2; // offset by one to work around the termini
1262  std::stringstream targetSS;
1263  targetSS << 1+(segment_length*rep)+2 << "-" << segment_length + (segment_length*rep)+2;
1264  TR << "NCS " << templateRangeSS.str() << " " << targetSS.str() << std::endl;
1265  setup_ncs.add_group(templateRangeSS.str(), targetSS.str());
1266  }
1267 
1268 
1269  std::stringstream templateRangeSS;
1270  //take care of the terminal repeat, since the numbers are offset.
1271  templateRangeSS << "2-" << segment_length-1; // offset by one to work around the termini
1272  std::stringstream targetSS;
1273  targetSS << 1+(segment_length*(repeat_number-1))+1 << "-" << segment_length + (segment_length*(repeat_number-1))-1;
1274  TR << "NCS " << templateRangeSS.str() << " " << targetSS.str() << std::endl;
1275  setup_ncs.add_group(templateRangeSS.str(), targetSS.str());
1276 
1277  }
1278 
1279  // run design-refine cycle
1280  for ( Size i = 0; i < dr_cycles_; ++i ) {
1281 
1282 
1283  designMover.set_state("finish");
1284  designMover.apply(pose);
1285 
1286  //update dihedral constraint for repeat structures
1287  if (basic::options::option[ OptionKeys::remodel::repeat_structure].user()){
1288  setup_ncs.apply(pose);
1289 
1290  //total hack (for now), see if the restypeset fails when initialized
1291  //twice.
1292  if (option[OptionKeys::remodel::RemodelLoopMover::cyclic_peptide].user()){
1294  }
1295 
1296  sfx->show(TR, pose);
1297  TR << std::endl;
1298  }
1299 
1300  relaxMover.apply(pose);
1301 
1302  //reset constraints without NCS
1303  pose.constraint_set(cst_set_post_built);
1304  sfx->show(TR, pose);
1305  TR << std::endl;
1306  }
1307 
1308 
1309 //turning off weights
1310  sfx->set_weight(core::scoring::coordinate_constraint, 0.0 );
1311  sfx->set_weight(core::scoring::atom_pair_constraint, 0.0 );
1312  sfx->set_weight(core::scoring::angle_constraint, 0.0 );
1313  sfx->set_weight(core::scoring::dihedral_constraint, 0.0 );
1314  sfx->set_weight(core::scoring::res_type_constraint, 0.0);
1315  sfx->set_weight(core::scoring::res_type_linking_constraint, 0.0);
1316 
1317  (*sfx)( pose );
1318 
1319  return true;
1320 }
1321 
1322 /// @brief run the design-refine stage
1323 /// @return currently always true
1325  Pose & pose,
1326  RemodelDesignMover & designMover
1327 )
1328 {
1333  using namespace core::pack::task::operation;
1334  using namespace protocols::toolbox::task_operations;
1340  using namespace protocols::loops;
1345 
1350 
1352 
1353  // collect new regions/positions
1354  std::set< Interval > loop_intervals = manager_.intervals_containing_undefined_positions();
1355  Original2Modified original2modified_interval_endpoints = manager_.original2modified_interval_endpoints();
1356 
1357  // collect loops
1358  LoopsOP loops = new Loops( intervals_to_loops( loop_intervals.begin(), loop_intervals.end() ) );
1359 
1360  // refine Mover used doesn't setup a fold tree, so do it here
1361  //FoldTree loop_ft = protocols::forge::methods::fold_tree_from_loops( pose, loops );
1362  FoldTree loop_ft;
1363  protocols::loops::fold_tree_from_loops( pose, *loops, loop_ft, true /*term cut*/);
1364 
1365  // save original fold tree
1366  FoldTree original_ft = pose.fold_tree();
1367 
1368  // define the score function
1369  //ScoreFunctionOP sfx = fullatom_sfx_->clone();
1370 //for refinement always use hard repulsive
1372 
1373 //turning on weights, for paranoya
1374  sfx->set_weight(core::scoring::atom_pair_constraint, 1.0 );
1375  sfx->set_weight(core::scoring::dihedral_constraint, 10.0 ); // 1.0 originally
1376 
1377  // setup the refine TaskFactory
1378  TaskFactoryOP refine_tf = generic_taskfactory();
1379  refine_tf->push_back( new RestrictToNeighborhoodOperation( neighborhood_calc_name() ) );
1380  refine_tf->push_back( new RestrictToRepacking() );
1381 
1382  // safety, clear the energies object
1383  pose.energies().clear();
1384 
1385  // run design-refine cycle
1386  for ( Size i = 0; i < dr_cycles_; ++i ) {
1387 
1388  // design the new section
1389  // PackRotamersMover design( sfx );
1390  // design.task_factory( design_tf );
1391  // design.apply( pose );
1392  designMover.set_state("finish");
1393  designMover.apply(pose);
1394 
1395  // set loop topology
1396  pose.fold_tree( loop_ft );
1397 
1398  if (!basic::options::option[basic::options::OptionKeys::remodel::swap_refine_confirm_protocols].user()){
1399  // refine the new section
1400  LoopMover_Refine_CCD refine( loops, sfx );
1402 
1403  ////// fix dna
1404  for ( Size i=1; i<=pose.total_residue() ; ++i ) {
1405 // if( pose.aa( i ) == core::chemical::na_ade or pose.aa( i ) == core::chemical::na_gua or pose.aa( i ) == core::chemical::na_cyt or pose.aa( i ) == core::chemical::na_thy ) {
1406  if( pose.residue( i ).is_DNA()) {
1407  TR << "NATRO movemap setup: turning off DNA bb and chi move for refinement stage" << std::endl;
1408  remodel_data_.natro_movemap_.set_bb( i, false );
1409  remodel_data_.natro_movemap_.set_chi( i, false );
1410  }
1411  }
1412  ////// end fix dna
1413 
1414  combined_mm->import(remodel_data_.natro_movemap_);
1415  combined_mm->import( manager_.movemap() );
1416 
1417  //modify task to accept NATRO definition
1418  utility::vector1<core::Size> natroPositions;
1419  for (Size i = 1; i<= pose.total_residue(); i++){
1420  if (remodel_data_.natro_movemap_.get_chi(i) == 0){
1421  natroPositions.push_back(i);
1422  }
1423  }
1425  natroRes->residue_indices( natroPositions );
1426  natroRes->op( new PreventRepackingRLT );
1427  refine_tf->push_back( natroRes );
1428 
1429  refine.false_movemap( combined_mm );
1430  refine.set_task_factory( refine_tf );
1431  refine.apply( pose );
1432  }
1433  else {
1435  KIC.apply(pose);
1436  }
1437 
1438  // remove cutpoint variants -- shouldn't this happen at the end
1439  // of the refine Mover?
1440  remove_cutpoint_variants( pose );
1441 
1442  //debug
1443 // std::stringstream SS;
1444 // SS << "RefineStage" << i << ".pdb";
1445 // pose.dump_pdb(SS.str());
1446  }
1447 
1448 //turning off weights, for paranoya
1449  sfx->set_weight(core::scoring::atom_pair_constraint, 0.0 );
1450  sfx->set_weight(core::scoring::dihedral_constraint, 0.0 ); // 1.0 originally
1451 
1452  // must score one last time since we've removed variants and set
1453  // new topology, otherwise component energies not correct for
1454  // e.g. structure output
1455  (*sfx)( pose );
1456 
1457 
1458  // evaluate all chainbreaks using linear chainbreak
1459  bool cbreaks_pass = true;
1460  for ( Loops::const_iterator l = loops->begin(), le = loops->end(); l != le && cbreaks_pass; ++l ) {
1461  if ( l->cut() > 0 ) {
1462  Real const c = linear_chainbreak( pose, l->cut() );
1463  TR << "design_refine: final chainbreak = " << c << " at " << l->cut() << std::endl;
1464  cbreaks_pass = c <= max_linear_chainbreak_;
1465  }
1466  }
1467  // set original topology
1468  pose.fold_tree( original_ft );
1469 
1470  return cbreaks_pass;
1471  //return true; //FOR NOW!! change me back!
1472 }
1473 
1476  using namespace protocols::loops;
1477  using namespace protocols::forge::methods;
1481 
1482  core::pose::Pose archive_pose = pose; //for rmsd
1483 
1484  std::set< Interval > loop_intervals = manager_.intervals_containing_undefined_positions();
1485  //pose.dump_pdb("pre_KICpose.pdb");
1486 
1487  // collect loops
1488  LoopsOP confirmation_loops = new Loops( intervals_to_confirmation_loops( loop_intervals.begin(), loop_intervals.end(), pose.total_residue() ) );
1489 
1490  // refine Mover used doesn't setup a fold tree, so do it here
1491  FoldTree loop_ft;
1492  protocols::loops::fold_tree_from_loops( pose, *confirmation_loops, loop_ft, true );
1493  TR << "confirmation loops tree" << loop_ft << std::endl;
1494 
1495  // save original fold tree
1496  FoldTree original_ft = pose.fold_tree();
1497  // switch over to new tree
1498  pose.fold_tree(loop_ft);
1499 
1500  //LoopMover_Refine_KIC KIC(confirmation_loops);
1501 
1502  TR << "fold tree entering confirmation: " << pose.fold_tree() << std::endl;
1503 
1504  //KIC.apply(pose);
1505 
1506  if (basic::options::option[basic::options::OptionKeys::remodel::swap_refine_confirm_protocols].user()){
1507  TR << "REFINE USING CCD" << std::endl;
1508  // refine the new section
1509  // setup the refine TaskFactory
1510  //
1511  // protocols::forge::remodel::RemodelLoopMover scramble_mover(confirmation_loops);
1512  // scramble_mover.randomize_stage(pose);
1513 
1514  TaskFactoryOP refine_tf = generic_taskfactory();
1515  refine_tf->push_back( new RestrictToNeighborhoodOperation( neighborhood_calc_name() ) );
1516  refine_tf->push_back( new RestrictToRepacking() );
1517 
1518  loop_mover::refine::LoopMover_Refine_CCD refine( confirmation_loops, fullatom_sfx_ );
1520 
1521  ////// fix dna
1522  for ( Size i=1; i<=pose.total_residue() ; ++i ) {
1523 // if( pose.aa( i ) == core::chemical::na_ade or pose.aa( i ) == core::chemical::na_gua or pose.aa( i ) == core::chemical::na_cyt or pose.aa( i ) == core::chemical::na_thy ) {
1524  if( pose.residue( i ).is_DNA()) {
1525  TR << "NATRO movemap setup: turning off DNA bb and chi move for refinement stage" << std::endl;
1526  remodel_data_.natro_movemap_.set_bb( i, false );
1527  remodel_data_.natro_movemap_.set_chi( i, false );
1528  }
1529  }
1530  ////// end fix dna
1531 
1532  combined_mm->import(remodel_data_.natro_movemap_);
1533  combined_mm->import( manager_.movemap() );
1534 
1535  refine.false_movemap( combined_mm );
1536  refine.set_task_factory( refine_tf );
1537  refine.apply( pose );
1538  }
1539  else {
1540  TR << "REFINE USING KIC" << std::endl;
1541  loop_mover::refine::LoopMover_Refine_KIC KIC(confirmation_loops);
1542  KIC.apply(pose);
1543  }
1544 
1545  //reset to original foldtree
1546  pose.fold_tree(original_ft);
1547 
1548  //pose.dump_pdb("post_KICpose.pdb");
1549 
1550  //rmsd_calculation:
1551 
1552  core::Real sum_sd = 0;
1553  core::Real sum_sd_native = 0;
1554  core::Real sum_sd_archive2native=0;
1555  core::Size atom_count = 0;
1556 
1557  for ( Loops::iterator it = confirmation_loops->v_begin(), end = confirmation_loops->v_end(); it!=end; it++) {
1558  for (core::Size i = it->start(); i <= it->stop(); ++i){
1559  core::Real dist_squared = (pose.residue(i).xyz( "CA" ) - archive_pose.residue(i).xyz( "CA" ) ).length_squared();
1560  core::Real dist_squared_native = (pose.residue(i).xyz( "CA" ) - native_pose_.residue(i).xyz( "CA" ) ).length_squared();
1561  core::Real dist_squared_archive2native = (archive_pose.residue(i).xyz( "CA" ) - native_pose_.residue(i).xyz( "CA" ) ).length_squared();
1562  sum_sd = sum_sd + dist_squared;
1563  sum_sd_native = sum_sd_native + dist_squared_native;
1564  sum_sd_archive2native = sum_sd_archive2native + dist_squared_archive2native;
1565  atom_count++;
1566  if(false){
1567  std::cout << " Backbone atom= " << "CA res: " << i << " dist_squared= " << dist_squared << std::endl;
1568  std::cout << " Backbone atom= " << "CA res: " << i << " dist_squared_native= " << dist_squared_native << std::endl;
1569  std::cout << " Backbone atom= " << "CA res: " << i << " dist_squared_archive2native= " << dist_squared_archive2native << std::endl;
1570  }
1571  }
1572  }
1573  sum_sd = sum_sd/atom_count;
1574  sum_sd_native = sum_sd_native/atom_count;
1575  sum_sd_archive2native = sum_sd_archive2native/atom_count;
1576 
1577  core::Real rmsd = sqrt(sum_sd);
1578  core::Real rmsd_native = sqrt(sum_sd_native);
1579  core::Real rmsd_archive2native = sqrt(sum_sd_archive2native);
1580 
1581  core::pose::PDBInfoOP temp_pdbinfo = pose.pdb_info();
1582 
1583  core::pose::RemarkInfo remark;
1584  remark.value = "KIC confirmation RMSD: " + utility::to_string(rmsd) + " to native RMSD: " + utility::to_string(rmsd_native) ;
1585  temp_pdbinfo->remarks().push_back( remark );
1586 
1587  remark.value = " ARCHIVE2NATIVE RMSD: " + utility::to_string(rmsd_archive2native);
1588 
1589  temp_pdbinfo->remarks().push_back( remark );
1590 
1591  pose.pdb_info(temp_pdbinfo);
1592 
1593  TR << "RMSD of KIC confirmation: " << rmsd << std::endl;
1594  TR << "RMSD of KIC confirmation to native: " << rmsd_native << std::endl;
1595  TR << "RMSD of ARCHIVE to NATIVE: " << rmsd_archive2native << std::endl;
1596 
1597  //currently the confirmation stage is not setup as filter so always return
1598  //true
1599  if (rmsd <= 1){
1600  return true;
1601  }
1602  else {
1603  return true; //for now CHANGE IT BACK!!
1604  }
1605 }
1606 
1607 
1608 /// @brief return a TaskFactory useable as a starting point for either
1609 /// design or refinement
1618 
1619  TaskFactoryOP tf = new TaskFactory();
1620 
1621  tf->push_back( new InitializeFromCommandline() ); // also inits -ex options
1622  tf->push_back( new IncludeCurrent() ); // enforce keeping of input sidechains
1623  tf->push_back( new NoRepackDisulfides() );
1624  if (!basic::options::option[basic::options::OptionKeys::remodel::design::allow_rare_aro_chi].user()){
1625  tf->push_back( new LimitAromaChi2Operation() );
1626  }
1627 
1628  // load resfile op only if requested
1629 /* if ( !resfile_.empty() ) {
1630  ReadResfileOP rrf = new ReadResfile();
1631  rrf->filename( resfile_ );
1632  tf->push_back( rrf );
1633  }
1634 */
1635  return tf;
1636 }
1637 
1638 
1639 /// @brief process a continuous design string, adding appropriate operations
1640 /// to the TaskFactory
1642  Interval const & original_interval,
1643  String const & design_str,
1644  Original2Modified const & original2modified_interval_endpoints,
1645  TaskFactoryOP design_tf
1646 )
1647 {
1649 
1651 
1652  Size const offset = original2modified_interval_endpoints.find( original_interval.left )->second;
1653  for ( Size i = 0, ie = design_str.length(); i < ie; ++i ) {
1654  utility::vector1< bool > allowed_aa_types( 20, false );
1655 
1656  switch ( design_str.at( i ) ) {
1657  case 's': // surface case, no CFWY
1658  allowed_aa_types = allowed_surface_aa();
1659  break;
1660  case '.': // protocol default design
1661  continue;
1662  default: // regular case, single aa type
1663  allowed_aa_types[ aa_from_oneletter_code( design_str.at( i ) ) ] = true;
1664  break;
1665  }
1666 
1667  design_tf->push_back( new RestrictAbsentCanonicalAAS( i + offset, allowed_aa_types ) );
1668  }
1669 }
1670 
1671 
1672 /// @brief process a design string containing an insert, adding appropriate
1673 /// operations to the TaskFactory
1675  Interval const & original_interval,
1676  String const & design_str,
1677  Original2Modified const & original2modified_interval_endpoints,
1678  TaskFactoryOP design_tf
1679 )
1680 {
1686 
1688 
1689  char const insert_char = SegmentInsert::insertion_char();
1690 
1691  // Figure out the number of residues in each section.
1692  Interval const interval(
1693  original2modified_interval_endpoints.find( original_interval.left )->second,
1694  original2modified_interval_endpoints.find( original_interval.right )->second
1695  );
1696 
1697  Size const insert_char_idx = design_str.find( insert_char );
1698  Size const left_nres = insert_char_idx;
1699  Size const right_nres = design_str.size() - left_nres - 1;
1700  Size const insert_nres = interval.length() - left_nres - right_nres;
1701 
1702  // Make setup easy by building a new design string to expand the
1703  // insertion character into a series of the insertion character
1704  // the size of the insert.
1705  String aa = design_str;
1706  aa.replace( insert_char_idx, 1, insert_nres, insert_char );
1707 
1708  // setup TaskOperations
1710 
1711  Size const left_offset = interval.left;
1712  for ( Size i = 0, ie = aa.size(); i < ie; ++i ) {
1713  utility::vector1< bool > allowed_aa_types( 20, false );
1714 
1715  if ( aa.at( i ) == insert_char ) { // repack only
1716  repack_op->include_residue( i + left_offset );
1717  continue;
1718  } else if ( aa.at( i ) == 's' ) { // surface case, no CFWY
1719  allowed_aa_types = allowed_surface_aa();
1720  } else if ( aa.at( i ) == '.' ) { // protocol default design
1721  continue;
1722  } else { // regular case, single aa type
1723  allowed_aa_types[ aa_from_oneletter_code( aa.at( i ) ) ] = true;
1724  }
1725 
1726  design_tf->push_back( new RestrictAbsentCanonicalAAS( i + left_offset, allowed_aa_types ) );
1727  }
1728 
1729  design_tf->push_back( repack_op );
1730 }
1731 
1732 
1733 /// @brief return a boolean vector specifying allowed a.a. when designing
1734 /// on the surface
1737 
1738  static String surface_aa = "ADEGHIKLMNPQRSTV";
1739  static utility::vector1< bool > v( 20, false );
1740 
1741  for ( Size i = 0, ie = surface_aa.length(); i < ie; ++i ) {
1742  v[ aa_from_oneletter_code( surface_aa.at( i ) ) ] = true;
1743  }
1744 
1745  return v;
1746 }
1747 
1748 /// @brief parse xml
1749 void
1751  utility::tag::TagPtr const tag,
1752  DataMap & /*data*/,
1753  Filters_map const & /*filters*/,
1754  Movers_map const & /*movers*/,
1755  Pose const & /*pose*/ )
1756 {
1757  if( tag->hasOption("blueprint") ) {
1758  blueprint_ = tag->getOption<std::string>( "blueprint" );
1759  }
1760 }
1761 
1762 
1763 
1764 } // namespace remodel
1765 } // namespace forge
1766 } // namespace protocols