Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FoldTreeHybridize.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
11 /// @brief Align a random jump to template
12 /// @detailed
13 /// @author Yifan Song, David Kim
14 
20 
22 
23 #include <core/pose/Pose.hh>
24 #include <core/pose/Pose.fwd.hh>
25 #include <core/pose/PDBInfo.hh>
26 #include <core/pose/util.hh>
28 #include <core/sequence/util.hh>
29 
34 
37 
45 
46 #include <core/id/AtomID.hh>
47 #include <core/id/AtomID_Map.hh>
50 #include <core/fragment/Frame.hh>
52 #include <core/fragment/util.hh>
53 
54 // symmetry
61 
64 
71 
72 #include <protocols/loops/Loop.hh>
73 #include <protocols/loops/Loops.hh>
75 #include <protocols/loops/util.hh>
76 
77 #include <ObjexxFCL/format.hh>
78 #include <numeric/xyz.functions.hh>
79 #include <numeric/random/random.hh>
80 #include <numeric/random/random_permutation.hh>
81 #include <numeric/model_quality/rms.hh>
82 #include <numeric/model_quality/maxsub.hh>
83 
84 #include <basic/options/option.hh>
85 #include <basic/options/keys/OptionKeys.hh>
86 #include <basic/options/keys/in.OptionKeys.gen.hh>
87 #include <basic/options/keys/cm.OptionKeys.gen.hh>
88 #include <basic/options/keys/constraints.OptionKeys.gen.hh>
89 #include <basic/options/keys/rigid.OptionKeys.gen.hh>
90 #include <basic/options/keys/jumps.OptionKeys.gen.hh> // strand pairings
91 #include <basic/options/keys/evaluation.OptionKeys.gen.hh>
92 #include <basic/options/keys/abinitio.OptionKeys.gen.hh>
93 #include <basic/Tracer.hh>
94 
95 #include <numeric/random/DistributionSampler.hh>
96 #include <numeric/util.hh>
97 
98 // strand pairings
106 #include <core/scoring/rms_util.hh>
107 
108 #include <set>
109 #include <list>
110 
111 static numeric::random::RandomGenerator RG(42136);
112 static basic::Tracer TR( "protocols.hybridization.FoldTreeHybridize" );
113 
114 namespace protocols {
115 namespace hybridization {
116 
117 using namespace core;
118 using namespace chemical;
119 using namespace core::kinematics;
120 using namespace ObjexxFCL;
121 using namespace protocols::moves;
122 using namespace protocols::simple_moves;
123 using namespace protocols::loops;
124 using namespace numeric::model_quality;
125 using namespace id;
126 using namespace basic::options;
127 using namespace basic::options::OptionKeys;
128 
129 
131 foldtree_mover_()
132 {
133  init();
134 }
135 
137  core::Size const initial_template_index,
138  utility::vector1 < core::pose::PoseOP > const & template_poses,
139  utility::vector1 < core::Real > const & template_wts,
140  utility::vector1 < protocols::loops::Loops > const & template_chunks,
141  utility::vector1 < protocols::loops::Loops > const & template_contigs,
142  core::fragment::FragSetOP fragments_small_in,
143  core::fragment::FragSetOP fragments_big_in )
144 {
145  init();
146 
147  //initialize template structures
148  // note: for strand pairings, templates that represent the pairs will be added to this
149  // and templates with incorrect pairs may be removed if filter_templates option is used
150  initial_template_index_ = initial_template_index;
151  template_poses_ = template_poses;
152  template_wts_ = template_wts;
153  template_chunks_ = template_chunks;
154  template_contigs_ = template_contigs;
155 
156  // normalize weights
158 
159  // abinitio frags
160  frag_libs_small_.push_back(fragments_small_in);
161  frag_libs_big_.push_back(fragments_big_in);
164 }
165 
166 void
168  using namespace basic::options;
169  using namespace basic::options::OptionKeys;
170 
171  increase_cycles_ = option[cm::hybridize::stage1_increase_cycles]();
172  stage1_1_cycles_ = option[cm::hybridize::stage1_1_cycles]();
173  stage1_2_cycles_ = option[cm::hybridize::stage1_2_cycles]();
174  stage1_3_cycles_ = option[cm::hybridize::stage1_3_cycles]();
175  stage1_4_cycles_ = option[cm::hybridize::stage1_4_cycles]();
176  add_non_init_chunks_ = option[cm::hybridize::add_non_init_chunks]();
177  frag_weight_aligned_ = option[cm::hybridize::frag_weight_aligned]();
178  auto_frag_insertion_weight_ = option[cm::hybridize::auto_frag_insertion_weight]();
179  max_registry_shift_ = option[cm::hybridize::max_registry_shift]();
180 
184  top_n_big_frag_ = 25;
185  top_n_small_frag_ = 200;
186  domain_assembly_ = false;
187  add_hetatm_ = false;
188  hetatm_cst_weight_ = 10.;
189  // default scorefunction
191 
192  // strand pairings
193  pairings_file_ = "";
194  sheets_.push_back(1);
195  random_sheets_.push_back(1);
196  filter_templates_ = false;
197 
198  overlap_chainbreaks_ = option[ jumps::overlap_chainbreak ](); // default is true
199 
200  // evaluation
201  // native
202  if ( option[ in::file::native ].user() ) {
204  core::import_pose::pose_from_pdb( *native_, option[ in::file::native ]() );
205  } else if ( option[ evaluation::align_rmsd_target ].user() ) {
207  utility::vector1< std::string > const & align_rmsd_target( option[ evaluation::align_rmsd_target ]() );
208  core::import_pose::pose_from_pdb( *native_, align_rmsd_target[1] ); // just use the first one for now
209  }
210 
211 }
212 
213 void
215  // normalize weights
216  core::Real weight_sum = 0.0;
217  for (Size i=1; i<=template_poses_.size(); ++i) weight_sum += template_wts_[i];
218  for (Size i=1; i<=template_poses_.size(); ++i) template_wts_[i] /= weight_sum;
219 }
220 
221 void
223 {
224  chemical::ResidueTypeSet const& restype_set( pose.residue(1).residue_type_set() );
225 
226  for (Size iloop=1; iloop<=loops.num_loop(); ++iloop) {
227  for (Size ires=loops[iloop].start(); ires<=loops[iloop].stop(); ++ires) {
228 
229  // Create the new residue and replace it
230  conformation::ResidueOP new_res = conformation::ResidueFactory::create_residue(
231  restype_set.name_map("VBB"), pose.residue(ires),
232  pose.conformation());
233  // Make sure we retain as much info from the previous res as possible
235  *new_res, pose.conformation() );
236  pose.replace_residue(ires, *new_res, false );
237  //core::pose::add_variant_type_to_pose_residue(pose, "VIRTUAL_BB", ires);
238  }
239  }
240 }
241 
242 void
244 {
245  std::string sequence = core::sequence::read_fasta_file( option[ in::file::fasta ]()[1] )[1]->sequence();
246 
247  for (Size iloop=1; iloop<=loops.num_loop(); ++iloop) {
248  for (Size ires=loops[iloop].start(); ires<=loops[iloop].stop(); ++ires) {
249  utility::vector1< VariantType > variant_types = pose.residue_type(ires).variant_types();
250  MutateResidue mutate_mover(ires, sequence[ires-1]);
251  mutate_mover.apply(pose);
252  for (Size i_var = 1; i_var <=variant_types.size(); ++i_var) {
253  core::pose::add_variant_type_to_pose_residue(pose, variant_types[i_var], ires);
254  }
255  }
256  }
257 }
258 
259 
260 Real
262 {
263  core::Real gap_torr_0( 4.0);
264  core::Real gap_torr_1( 7.5);
265  core::Real gap_torr_2(11.0);
266  core::Real gap_torr_3(14.5);
267  core::Real gap_torr_4(18.0);
268  core::Real gap_torr_5(21.0);
269  core::Real gap_torr_6(24.5);
270  core::Real gap_torr_7(27.5);
271  core::Real gap_torr_8(31.0);
272 
273  switch (Seq_gap) {
274  case 0:
275  return gap_torr_0; break;
276  case 1:
277  return gap_torr_1; break;
278  case 2:
279  return gap_torr_2; break;
280  case 3:
281  return gap_torr_3; break;
282  case 4:
283  return gap_torr_4; break;
284  case 5:
285  return gap_torr_5; break;
286  case 6:
287  return gap_torr_6; break;
288  case 7:
289  return gap_torr_7; break;
290  case 8:
291  return gap_torr_8; break;
292  default:
293  return 9999.;
294  }
295  return 9999.;
296 }
297 
298 void FoldTreeHybridize::add_gap_constraints_to_pose(core::pose::Pose & pose, Loops const & chunks, int gap_edge_shift, Real stdev) {
299  using namespace ObjexxFCL::fmt;
300  for (Size i=1; i<chunks.num_loop(); ++i) {
301  int gap_start = chunks[i].stop() + gap_edge_shift;
302  int gap_stop = chunks[i+1].start() - gap_edge_shift;
303  int gap_size = gap_stop - gap_start - 1;
304  if (gap_size < 0) continue;
305  if (gap_size > 8) continue;
306  if (!pose.residue_type(gap_start).is_protein()) continue;
307  if (!pose.residue_type(gap_stop ).is_protein()) continue;
308  Size iatom = pose.residue_type(gap_start).atom_index("CA");
309  Size jatom = pose.residue_type(gap_stop ).atom_index("CA");
310 
311  TR << "Add constraint to residue " << I(4,gap_start) << " and residue " << I(4,gap_stop) << std::endl;
312  pose.add_constraint(
314  core::id::AtomID(iatom,gap_start),
315  core::id::AtomID(jatom,gap_stop),
316  new core::scoring::constraints::BoundFunc( 0, gap_distance(gap_size), stdev, "gap" ) )
317  );
318 
319  }
320 }
321 
322 void
324  // Add secondary structure information to the pose. Because the number of residues
325  // in the pose and secondary structure differ (because of virtual residues), we need
326  // to compute this quantity explicitly.
327  core::Size num_residues_nonvirt = get_num_residues_nonvirt(pose);
328 
329  bool ok = false;
330  if ( option[ OptionKeys::in::file::psipred_ss2 ].user() )
332  if (!ok) {
333  core::fragment::SecondaryStructureOP ss_def = new core::fragment::SecondaryStructure( *frag_libs_small_[1], num_residues_nonvirt, false );
334  for ( core::Size i = 1; i<= num_residues_nonvirt; ++i ) {
335  pose.set_secstruct( i, ss_def->secstruct(i) );
336  }
337  TR.Info << "Secondary structure from fragments: " << pose.secstruct() << std::endl;
338  } else {
339  TR.Info << "Secondary structure from psipred_ss2: " << pose.secstruct() << std::endl;
340  }
341 
342  // combine:
343  // (a) contigs in the current template
344 
345  core::Size nres = pose.total_residue();
346 
347  //symmetry
351  dynamic_cast<core::conformation::symmetry::SymmetricConformation &> ( pose.conformation()) );
352  symm_info = SymmConf.Symmetry_Info();
353  nres = symm_info->num_independent_residues();
354  }
355 
356  utility::vector1< bool > template_mask( nres, false );
358 
359  for (core::Size i = 1; i<=template_chunks_[initial_template_index_].num_loop(); ++i) {
360  Size seqpos_start_target = template_poses_[initial_template_index_]->pdb_info()->number(
361  template_chunks_[initial_template_index_][i].start());
362  my_chunks[i].set_start( seqpos_start_target );
363  Size seqpos_stop_target = template_poses_[initial_template_index_]->pdb_info()->number(
364  template_chunks_[initial_template_index_][i].stop());
365  my_chunks[i].set_stop( seqpos_stop_target );
366  for (Size j=seqpos_start_target; j<=seqpos_stop_target; ++j) template_mask[j] = true;
367  }
368 
369 
370 
371 
372  // strand pairings
373 
374  // keep track of strand pairs
375  strand_pairs_.clear();
376  std::set<core::Size> strand_pair_library_positions; // chunk positions from the strand pair library
377 
378  // add strand pairing chunks that are missing from the initial template
379  // this is mainly for the dynamic fold tree builder
380  // note: this adds to my_chunks
381  std::set<core::Size>::iterator pairings_iter;
382  for (pairings_iter = strand_pairings_template_indices_.begin(); pairings_iter != strand_pairings_template_indices_.end(); ++pairings_iter) {
383  Size seqpos_pairing_i = template_poses_[*pairings_iter]->pdb_info()->number(template_chunks_[*pairings_iter][1].start());
384  Size seqpos_pairing_j = template_poses_[*pairings_iter]->pdb_info()->number(template_chunks_[*pairings_iter][2].start());
385  strand_pairs_.push_back( std::pair< core::Size, core::Size >( seqpos_pairing_i, seqpos_pairing_j ) );
386  if (!template_mask[seqpos_pairing_i]) {
387  protocols::loops::Loop new_loop_i = template_chunks_[*pairings_iter][1];
388  new_loop_i.set_start( seqpos_pairing_i );
389  new_loop_i.set_stop( seqpos_pairing_i );
390  my_chunks.add_loop( new_loop_i );
391  strand_pair_library_positions.insert(seqpos_pairing_i);
392  template_mask[seqpos_pairing_i] = true;
393  }
394  if (!template_mask[seqpos_pairing_j]) {
395  protocols::loops::Loop new_loop_j = template_chunks_[*pairings_iter][2];
396  new_loop_j.set_start( seqpos_pairing_j );
397  new_loop_j.set_stop( seqpos_pairing_j );
398  my_chunks.add_loop( new_loop_j );
399  strand_pair_library_positions.insert(seqpos_pairing_j);
400  template_mask[seqpos_pairing_j] = true;
401  }
402  } // strand pairings
403 
404 
405  TR.Debug << "Chunks of initial template: " << initial_template_index_ << std::endl;
406  TR.Debug << template_chunks_[initial_template_index_] << std::endl;
407  TR.Debug << "Chunks from initial template: " << std::endl;
408  TR.Debug << my_chunks << std::endl;
409 
411  // (b) probabilistically sampled chunks from all other templates _outside_ these residues
413  for (core::Size itempl = 1; itempl<=template_chunks_.size(); ++itempl) {
414  if (itempl == initial_template_index_) continue;
415  for (core::Size icontig = 1; icontig<=template_chunks_[itempl].num_loop(); ++icontig) {
416  // remap
417  Size seqpos_start_target = template_poses_[itempl]->pdb_info()->number(template_chunks_[itempl][icontig].start());
418  Size seqpos_stop_target = template_poses_[itempl]->pdb_info()->number(template_chunks_[itempl][icontig].stop());
419 
420  bool uncovered = true;
421  for (Size j=seqpos_start_target; j<=seqpos_stop_target && uncovered ; ++j)
422  uncovered &= !template_mask[j];
423 
424  if (uncovered) {
425  protocols::loops::Loop new_loop = template_chunks_[itempl][icontig];
426  new_loop.set_start( seqpos_start_target );
427  new_loop.set_stop( seqpos_stop_target );
428  wted_insertions_to_consider.push_back( std::pair< core::Real, protocols::loops::Loop >( template_wts_[itempl] , new_loop ) );
429  }
430  }
431  }
432 
433  // (c) randomly shuffle, then add each with given prob
434  TR.Debug << "Chunks from all template: " << std::endl;
435  TR.Debug << my_chunks << std::endl;
436  std::random_shuffle ( wted_insertions_to_consider.begin(), wted_insertions_to_consider.end() );
437  for (Size i=1; i<=wted_insertions_to_consider.size(); ++i) {
438  // ensure the insert is still valid
439  bool uncovered = true;
440  for (Size j=wted_insertions_to_consider[i].second.start(); j<=wted_insertions_to_consider[i].second.stop() && uncovered ; ++j)
441  uncovered &= !template_mask[j];
442 
443  if (!uncovered) continue;
444 
445  core::Real selector = numeric::random::uniform();
446  if (domain_assembly_) selector = 0.; // always add additional domain if in domain assembly
447  TR << "Consider " << wted_insertions_to_consider[i].second.start() << "," << wted_insertions_to_consider[i].second.stop() << std::endl;
448  if (selector <= wted_insertions_to_consider[i].first) {
449  TR << " ====> taken!" << std::endl;
450  my_chunks.add_loop( wted_insertions_to_consider[i].second );
451  for (Size j=wted_insertions_to_consider[i].second.start(); j<=wted_insertions_to_consider[i].second.stop(); ++j) {
452  template_mask[j] = true;
453  }
454  }
455  }
456  }
457 
458  my_chunks.sequential_order();
459  TR << "Chunks used for foldtree setup: " << std::endl;
460  TR << my_chunks << std::endl;
461 
462  foldtree_mover_.initialize(pose, my_chunks, strand_pairs_, strand_pair_library_positions);
463  TR << pose.fold_tree() << std::endl;
464 }
465 
466 
469  int nres( pose.total_residue() ), nAtms = 0;
470  numeric::xyzVector<core::Real> massSum(0.,0.,0.), CoM;
471  for ( int i=1; i<= nres; ++i ) {
472  conformation::Residue const & rsd( pose.residue(i) );
473  if (rsd.aa() == core::chemical::aa_vrt) continue;
474 
475  for ( Size j=1; j<= rsd.nheavyatoms(); ++j ) {
476  conformation::Atom const & atom( rsd.atom(j) );
477  massSum += atom.xyz();
478  nAtms++;
479  }
480  }
481  CoM = massSum / (core::Real)nAtms;
482  return CoM;
483 }
484 
485 void
488  CoM = center_of_mass(pose);
489  numeric::xyzVector<Real> curr_pos = pose.residue(pose.total_residue()).xyz(1);
490  numeric::xyzVector<Real> translation = CoM - curr_pos;
491 
492  using namespace ObjexxFCL::fmt;
493  TR.Debug << F(8,3,translation.x()) << F(8,3,translation.y()) << F(8,3,translation.z()) << std::endl;
494 
495  // apply transformation
498  for (Size iatom = 1; iatom <= pose.residue_type(pose.total_residue()).natoms(); ++iatom) {
499  numeric::xyzVector<core::Real> atom_xyz = pose.xyz( core::id::AtomID(iatom,pose.total_residue()) );
500  ids.push_back(core::id::AtomID(iatom,pose.total_residue()));
501  positions.push_back(atom_xyz + translation);
502  }
503  pose.batch_set_xyz(ids,positions);
504 }
505 
506 
508  using namespace ObjexxFCL::fmt;
509  core::Size num_residues_nonvirt = get_num_residues_nonvirt(pose);
510 
511  utility::vector1< core::Real > residue_weights(num_residues_nonvirt, 0.0);
512  TR.Debug << "Fragment insertion positions and weights:" << std::endl;
513  for ( Size ires=1; ires<= num_residues_nonvirt; ++ires ) {
514  if (domain_assembly_) {
515  bool residue_in_template = false;
516  for (Size i_template=1; i_template<=template_poses_.size(); ++i_template) {
517  protocols::loops::Loops renumbered_template_chunks = renumber_with_pdb_info(
518  template_contigs_[i_template], template_poses_[i_template]);
519  if (renumbered_template_chunks.has(ires)) {
520  residue_in_template = true;
521  break;
522  }
523  }
524  if (! residue_in_template ) {
525  residue_weights[ires] = 1.0;
526  }
527  else {
528  residue_weights[ires] = frag_weight_aligned_;
529  }
530  }
531  else {
532  protocols::loops::Loops renumbered_template_chunks
534  template_contigs_[initial_template_index_], template_poses_[initial_template_index_]);
535 
536  if (! renumbered_template_chunks.has(ires) ) {
537  residue_weights[ires] = 1.0;
538  }
539  else {
540  residue_weights[ires] = frag_weight_aligned_;
541  }
542  }
543  TR.Debug << " " << ires << ": " << F(7,5,residue_weights[ires]) << std::endl;
544  }
545  // reset linker fragment insertion weights
546  if (domain_assembly_) {
547  for (Size i_template=1; i_template<=template_poses_.size(); ++i_template) {
548  int coverage_start = template_poses_[i_template]->pdb_info()->number(1);
549  int coverage_end = template_poses_[i_template]->pdb_info()->number(1);
550  for (Size ires = 1; ires <= template_poses_[i_template]->total_residue(); ++ires) {
551  if (template_poses_[i_template]->pdb_info()->number(ires) < coverage_start) {
552  coverage_start = template_poses_[i_template]->pdb_info()->number(ires);
553  }
554  if (template_poses_[i_template]->pdb_info()->number(ires) > coverage_end) {
555  coverage_end = template_poses_[i_template]->pdb_info()->number(ires);
556  }
557  }
558 
559  for (int shift = -5; shift<=5; ++shift) {
560  int ires = coverage_start + shift;
561  if (ires >= 1 && ires <= (int)num_residues_nonvirt) {
562  residue_weights[ires] = 1.;
563  TR.Debug << " " << ires << ": " << F(7,5,residue_weights[ires]) << std::endl;
564  }
565 
566  ires = coverage_end + shift;
567  if (ires >= 1 && ires <= (int)num_residues_nonvirt) {
568  residue_weights[ires] = 1.;
569  TR.Debug << " " << ires << ": " << F(7,5,residue_weights[ires]) << std::endl;
570  }
571  }
572  }
573  }
574  return residue_weights;
575 }
576 
578  std::set<core::Size>::iterator iter;
580  std::set< core::Size > unique;
581  for (core::Size i = 1; i<=jump_anchors.size();++i) unique.insert(jump_anchors[i]);
582  jump_anchors.clear();
583  // ignore strand pair residues
584  std::set<core::Size> strand_pair_residues = get_pairings_residues();
585  for (iter = unique.begin(); iter != unique.end(); ++iter) {
586  if (strand_pair_residues.count(*iter)) continue;
587  jump_anchors.push_back(*iter);
588  }
589  return jump_anchors;
590 }
591 
593  using namespace ObjexxFCL::fmt;
594  core::Size num_residues_nonvirt = get_num_residues_nonvirt(pose);
596  utility::vector1< core::Real > residue_weights_new( num_residues_nonvirt, 0.0 );
598  core::Size min_small_frag_len = 999999;
599  TR.Debug << "1mer fragment insertion positions and weights:" << std::endl;
600  for (core::Size i = 1; i<=frag_libs_small_.size(); ++i)
601  if (frag_libs_small_[i]->max_frag_length() < min_small_frag_len)
602  min_small_frag_len = frag_libs_small_[i]->max_frag_length();
603 
604  core::Size last_anchor = 0;
605  for (core::Size i = 1; i<=jump_anchors.size(); ++i) {
606  core::Size anchor_gap = jump_anchors[i]-last_anchor-1;
607  if (anchor_gap && anchor_gap < min_small_frag_len) {
608  for (core::Size ipos = last_anchor+1;ipos<jump_anchors[i];++ipos) {
609  residue_weights_new[ipos] = residue_weights[ipos];
610  TR.Debug << " " << ipos << ": " << F(7,5,residue_weights[ipos]) << std::endl;
611  }
612  }
613  last_anchor = jump_anchors[i];
614  }
615  core::Size anchor_gap = num_residues_nonvirt-last_anchor;
616  if (anchor_gap && anchor_gap < min_small_frag_len) {
617  for (core::Size ipos = last_anchor+1;ipos<=num_residues_nonvirt;++ipos) {
618  residue_weights_new[ipos] = residue_weights[ipos];
619  TR.Debug << " " << ipos << ": " << F(7,5,residue_weights[ipos]) << std::endl;
620  }
621  }
622  return residue_weights_new;
623 }
624 
626  using namespace ObjexxFCL::fmt;
627  core::Size num_residues_nonvirt = get_num_residues_nonvirt(pose);
629  utility::vector1< core::Real > residue_weights_new( num_residues_nonvirt, 0.0 );
631  core::Size min_big_frag_len = 999999;
632  TR.Debug << "Small fragment insertion positions and weights:" << std::endl;
633  for (core::Size i = 1; i<=frag_libs_big_.size(); ++i)
634  if (frag_libs_big_[i]->max_frag_length() < min_big_frag_len)
635  min_big_frag_len = frag_libs_big_[i]->max_frag_length();
636 
637  core::Size last_anchor = 0;
638  for (core::Size i = 1; i<=jump_anchors.size(); ++i) {
639  core::Size anchor_gap = jump_anchors[i]-last_anchor-1;
640  if (anchor_gap && anchor_gap < min_big_frag_len) {
641  for (core::Size ipos = last_anchor+1;ipos<jump_anchors[i];++ipos) {
642  residue_weights_new[ipos] = residue_weights[ipos];
643  TR.Debug << " " << ipos << ": " << F(7,5,residue_weights[ipos]) << std::endl;
644  }
645  }
646  last_anchor = jump_anchors[i];
647  }
648  core::Size anchor_gap = num_residues_nonvirt-last_anchor;
649  if (anchor_gap && anchor_gap < min_big_frag_len) {
650  for (core::Size ipos = last_anchor+1;ipos<=num_residues_nonvirt;++ipos) {
651  residue_weights_new[ipos] = residue_weights[ipos];
652  TR.Debug << " " << ipos << ": " << F(7,5,residue_weights[ipos]) << std::endl;
653  }
654  }
655  return residue_weights_new;
656 }
657 
659  foldtree_mover_.reset(pose);
660  /*
661  if (pose.total_residue() > orig_n_residue_) {
662  pose.conformation().delete_residue_range_slow(orig_n_residue_+1, pose.total_residue());
663  }
664  protocols::loops::remove_cutpoint_variants( pose );
665  pose.conformation().fold_tree( orig_ft_ );
666  */
667 }
668 
669 void
676  core::Real lincb_orig = scorefxn_->get_weight( core::scoring::linear_chainbreak );
677  core::Real cst_orig = scorefxn_->get_weight( core::scoring::atom_pair_constraint );
678 
679  score0->reset();
680  score0->set_weight( core::scoring::vdw, 0.1*scorefxn_->get_weight( core::scoring::vdw ) );
681 
682  score1->reset();
683  score2->set_weight( core::scoring::linear_chainbreak, 0.1*lincb_orig );
684  score1->set_weight( core::scoring::atom_pair_constraint, 0.1*cst_orig );
685  score1->set_weight( core::scoring::vdw, scorefxn_->get_weight( core::scoring::vdw ) );
686  score1->set_weight( core::scoring::env, scorefxn_->get_weight( core::scoring::env ) );
687  score1->set_weight( core::scoring::cen_env_smooth, scorefxn_->get_weight( core::scoring::cen_env_smooth ) );
688  score1->set_weight( core::scoring::pair, scorefxn_->get_weight( core::scoring::pair ) );
689  score1->set_weight( core::scoring::cen_pair_smooth, scorefxn_->get_weight( core::scoring::cen_pair_smooth ) );
690  score1->set_weight( core::scoring::hs_pair, scorefxn_->get_weight( core::scoring::hs_pair ) );
691  score1->set_weight( core::scoring::ss_pair, 0.3*scorefxn_->get_weight( core::scoring::ss_pair ) );
692  score1->set_weight( core::scoring::sheet, scorefxn_->get_weight( core::scoring::sheet ) );
693  //STRAND_STRAND_WEIGHTS 1 11
694  core::scoring::methods::EnergyMethodOptions score1_options(score1->energy_method_options());
695  score1_options.set_strand_strand_weights(1,11);
696  score1->set_energy_method_options(score1_options);
697 
698 
699  score2->reset();
700  score2->set_weight( core::scoring::linear_chainbreak, 0.25*lincb_orig );
701  score2->set_weight( core::scoring::atom_pair_constraint, 0.25*cst_orig );
702  score2->set_weight( core::scoring::vdw, scorefxn_->get_weight( core::scoring::vdw ) );
703  score2->set_weight( core::scoring::env, scorefxn_->get_weight( core::scoring::env ) );
704  score2->set_weight( core::scoring::cen_env_smooth, scorefxn_->get_weight( core::scoring::cen_env_smooth ) );
705  score2->set_weight( core::scoring::cbeta, 0.25*scorefxn_->get_weight( core::scoring::cbeta ) );
706  score2->set_weight( core::scoring::cbeta_smooth, 0.25*scorefxn_->get_weight( core::scoring::cbeta_smooth ) );
707  score2->set_weight( core::scoring::cenpack, 0.5*scorefxn_->get_weight( core::scoring::cenpack ) );
708  score2->set_weight( core::scoring::cenpack_smooth, 0.5*scorefxn_->get_weight( core::scoring::cenpack_smooth ) );
709  score2->set_weight( core::scoring::pair, scorefxn_->get_weight( core::scoring::pair ) );
710  score2->set_weight( core::scoring::cen_pair_smooth, scorefxn_->get_weight( core::scoring::cen_pair_smooth ) );
711  score2->set_weight( core::scoring::hs_pair, scorefxn_->get_weight( core::scoring::hs_pair ) );
712  score2->set_weight( core::scoring::ss_pair, 0.3*scorefxn_->get_weight( core::scoring::ss_pair ) );
713  score2->set_weight( core::scoring::sheet, scorefxn_->get_weight( core::scoring::sheet ) );
714  //STRAND_STRAND_WEIGHTS 1 6
715  core::scoring::methods::EnergyMethodOptions score2_options(score1->energy_method_options());
716  score2_options.set_strand_strand_weights(1,6);
717  score2->set_energy_method_options(score2_options);
718 
719  score5->reset();
720  score5->set_weight( core::scoring::linear_chainbreak, 0.25*lincb_orig );
721  score5->set_weight( core::scoring::atom_pair_constraint, 0.25*cst_orig );
722  score5->set_weight( core::scoring::vdw, scorefxn_->get_weight( core::scoring::vdw ) );
723  score5->set_weight( core::scoring::env, scorefxn_->get_weight( core::scoring::env ) );
724  score5->set_weight( core::scoring::cen_env_smooth, scorefxn_->get_weight( core::scoring::cen_env_smooth ) );
725  score5->set_weight( core::scoring::cbeta, 0.25*scorefxn_->get_weight( core::scoring::cbeta ) );
726  score5->set_weight( core::scoring::cbeta_smooth, 0.25*scorefxn_->get_weight( core::scoring::cbeta_smooth ) );
727  score5->set_weight( core::scoring::cenpack, 0.5*scorefxn_->get_weight( core::scoring::cenpack ) );
728  score5->set_weight( core::scoring::cenpack_smooth, 0.5*scorefxn_->get_weight( core::scoring::cenpack_smooth ) );
729  score5->set_weight( core::scoring::pair, scorefxn_->get_weight( core::scoring::pair ) );
730  score5->set_weight( core::scoring::cen_pair_smooth, scorefxn_->get_weight( core::scoring::cen_pair_smooth ) );
731  score5->set_weight( core::scoring::hs_pair, scorefxn_->get_weight( core::scoring::hs_pair ) );
732  score5->set_weight( core::scoring::ss_pair, 0.3*scorefxn_->get_weight( core::scoring::ss_pair ) );
733  score5->set_weight( core::scoring::sheet, scorefxn_->get_weight( core::scoring::sheet ) );
734  //STRAND_STRAND_WEIGHTS 1 11
735  core::scoring::methods::EnergyMethodOptions score5_options(score1->energy_method_options());
736  score5_options.set_strand_strand_weights(1,11);
737  score5->set_energy_method_options(score5_options);
738 
739  score3 = scorefxn_->clone();
740 }
741 
742 
743 
744 // start strand pairings methods
745 
746 void
748  if (pairings_file_.length()==0) return;
749 
750 // 1. read in the pairings file and get a jump sample (pairing jumps and fragments)
751 // A jump sample is a set of pairings from the pairing file that has either
752 // sheets or random sheets number of pairings.
753 // The code is from protocols/jumping.
754 
755  TR << "read pairings file: " << pairings_file_ << std::endl;
756 
758  read_pairing_list( pairings_file_, pairings );
759 
760  // get sheet-topology
761  // this code is taken from protocols/jumping and protocols/abinitio
762  core::fragment::SecondaryStructureOP ss_def = new core::fragment::SecondaryStructure( *frag_libs_small_[1], false ); // get SS from frags
764  if (sheets_.size()) {
765  jump_def = new protocols::jumping::SheetBuilder( ss_def, pairings, sheets_ );
766  } else {
767  jump_def = new protocols::jumping::RandomSheetBuilder( ss_def, pairings, random_sheets_ );
768  }
769  core::Size attempts( 10 );
770  do {
771  jump_sample_ = jump_def->create_jump_sample();
772  } while ( !jump_sample_.is_valid() && attempts-- );
773  if ( !jump_sample_.is_valid() ) {
774  utility_exit_with_message( "not able to get jump sample in HybridizeProtocol::add_strand_pairings()" );
775  }
776  TR << "jump_sample: " << jump_sample_ << std::endl; // debug
777 
778  // generate the jump fragments
780  movemap->set_bb( true );
781  movemap->set_jump( true );
782  jump_frags_ = jump_def->generate_jump_frags( jump_sample_, *movemap );
783 
784 // 2. identify templates with incorrect pairings
786  ObjexxFCL::FArray2D_int jumps = jump_sample_.jumps();
787  for ( core::Size i = 1; i <= jump_sample_.size(); ++i ) {
788  core::Size jumpres1 = jumps(1,i), jumpres2 = jumps(2,i);
789  core::scoring::dssp::Pairing pairing = jump_sample_.get_pairing( jumpres1, jumpres2 );
790  if (!pairing.Pos1() || !pairing.Pos2())
791  utility_exit_with_message( "not able to get pairing " + ObjexxFCL::string_of(jumpres1) + " " +
792  ObjexxFCL::string_of(jumpres2) + " from jump sample in HybridizeProtocol::add_strand_pairings()" );
793  pairings_to_add.push_back( pairing );
794  for (core::Size itempl = 1; itempl<=template_chunks_.size(); ++itempl) {
795  protocols::loops::Loops renumbered_template_chunks = renumber_with_pdb_info(
796  template_chunks_[itempl], template_poses_[itempl]);
797  core::scoring::dssp::StrandPairingSet strand_pairings( *template_poses_[itempl] );
798  if (renumbered_template_chunks.has(jumpres1) && renumbered_template_chunks.has(jumpres2)) {
799  // check template pose for correct pairing
800  if (!strand_pairings.has_pairing( pairing )) {
801  TR << "WARNING! template " << itempl << " is missing pairing: " << pairing << std::endl; // pleating may be different
803  } else {
804  TR << "template " << itempl << " has pairing: " << pairing << std::endl; // pleating may be different
805  }
806  }
807  }
808  }
809  // remove templates with incorrect pairings if desired
813  }
814 
815 // 3. add chunks from pairings (must do after filtering templates for correct indices)
816  for ( core::Size i = 1; i <= pairings_to_add.size(); ++i )
817  add_strand_pairing( pairings_to_add[i] );
818 
819 }
820 
821 
822 void
824  core::scoring::dssp::Pairing const & pairing
825 )
826 {
828 
829  // create a pose with the strand pairing
830  core::pose::PoseOP pairing_pose = new core::pose::Pose();
832  m.apply(*pairing_pose);
833  pairing_pose->fold_tree( jump_sample_.fold_tree() );
834  jump_mover->apply_at_all_positions( *pairing_pose );
835  ObjexxFCL::FArray2D_int jumps( 2, 1 );
836  jumps(1, 1) = 1;
837  jumps(2, 1) = 2;
838  ObjexxFCL::FArray1D_int cuts(1);
839  cuts(1) = 1;
840  core::kinematics::FoldTree pairing_fold_tree;
841  if (!pairing_fold_tree.tree_from_jumps_and_cuts( 2, 1, jumps, cuts, 1, true /* verbose */ )) {
842  TR << "WARNING! tree_from_jumps_and_cuts failed for pairing " << pairing << " so skipping it." << std::endl;
843  return;
844  }
845  utility::vector1< core::Size > pairing_positions;
846  pairing_positions.push_back(pairing.Pos1());
847  pairing_positions.push_back(pairing.Pos2());
848  core::pose::PoseOP trimmed_pairing_pose = new core::pose::Pose();
849  core::pose::create_subpose( *pairing_pose, pairing_positions, pairing_fold_tree, *trimmed_pairing_pose );
850  // add correct resnums to PDBInfo
851  utility::vector1< int > pdb_numbering;
852  pdb_numbering.push_back(pairing.Pos1());
853  pdb_numbering.push_back(pairing.Pos2());
854  core::pose::PDBInfoOP pdb_info( new core::pose::PDBInfo( trimmed_pairing_pose->total_residue() ) );
855  pdb_info->set_numbering( pdb_numbering );
856  pdb_info->set_chains( ' ' );
857  pdb_info->obsolete( false );
858  trimmed_pairing_pose->set_secstruct( 1, 'E' );
859  trimmed_pairing_pose->set_secstruct( 2, 'E' );
860  //std::string pairing_pdb = "pairing_" + ObjexxFCL::string_of(pairing.Pos1()) + "_" + ObjexxFCL::string_of(pairing.Pos2()) + ".pdb";
861  //trimmed_pairing_pose->dump_pdb(pairing_pdb); // debug, do this before setting pdb_info or it will seg fault
862  trimmed_pairing_pose->pdb_info( pdb_info );
863 
864  // add pairing as a template
865  protocols::loops::Loops contigs = protocols::loops::extract_continuous_chunks(*trimmed_pairing_pose, 1);
866  // add just the first residue chunk if there are no templates (if all templates were filtered out)
867  if (!template_poses_.size()) {
868  template_wts_.push_back( 0.0 ); // should not be used
869  template_poses_.push_back( trimmed_pairing_pose );
871  contig.push_back(contigs[1]);
872  template_chunks_.push_back(contig);
873  template_contigs_.push_back(contig);
874  TR << "Templates have been filtered so added first residue of pairing " << pairing << " as initial template " << template_poses_.size() << std::endl;
875  }
876  template_wts_.push_back( 0.0 ); // should not be used
877  template_poses_.push_back( trimmed_pairing_pose );
878  template_chunks_.push_back(contigs);
879  template_contigs_.push_back(contigs);
880  strand_pairings_template_indices_.insert( template_poses_.size() ); // keep track of which templates are pairings
881  TR << "Added pairing " << pairing << " as template " << template_poses_.size() << std::endl;
882 }
883 
885  if (!strand_pairings_template_indices_.size()) return;
886  using namespace core::kinematics;
887  kinematics::FoldTree const fold_tree = pose.fold_tree();
888  // we need to superimpose starting from the rooted chunks which are either from templates or if none exist, the first strand pair chunks
890  atom_names.push_back("CA");
891  atom_names.push_back("N");
892  atom_names.push_back("C");
893  atom_names.push_back("O");
894  std::set<core::Size>::iterator pairings_iter;
895 
896  // this loop should traverse the fold tree downstream starting from the root
897  for ( kinematics::FoldTree::const_iterator it = fold_tree.begin(), it_end = fold_tree.end(); it != it_end; ++it ) {
898  if (!it->is_jump() || it->start() == fold_tree.root()) continue;
899  for (pairings_iter = strand_pairings_template_indices_.begin(); pairings_iter != strand_pairings_template_indices_.end(); ++pairings_iter) {
900  core::Size resi_pdb = template_poses_[*pairings_iter]->pdb_info()->number(1);
901  core::Size resj_pdb = template_poses_[*pairings_iter]->pdb_info()->number(2);
902  // the pairing template pose index that represents this jump
903  if ( (resi_pdb == (core::Size)it->start() && resj_pdb == (core::Size)it->stop()) ||
904  (resj_pdb == (core::Size)it->start() && resi_pdb == (core::Size)it->stop())) {
907  // try to align to the initial template
910  core::Size template_resj = map_pdb_info_number( *template_poses_[initial_template_index_], resj_pdb );
911  if (template_resi && template_resj) {
912  // superimpose all atoms
913  for (core::Size i = 1; i<=atom_names.size();++i) {
914  core::id::AtomID const id1i( template_poses_[*pairings_iter]->residue(1).atom_index(atom_names[i]), 1 );
915  core::id::AtomID const id2i( template_poses_[initial_template_index_]->residue(template_resi).atom_index(atom_names[i]), template_resi );
916  atom_map[ id1i ] = id2i;
917  core::id::AtomID const id1j( template_poses_[*pairings_iter]->residue(2).atom_index(atom_names[i]), 2 );
918  core::id::AtomID const id2j( template_poses_[initial_template_index_]->residue(template_resj).atom_index(atom_names[i]), template_resj );
919  atom_map[ id1j ] = id2j;
920  }
921  TR << "Superimpose strand pair " << *pairings_iter << " (" << resi_pdb << " " << resj_pdb << ") at " << resi_pdb << " and " << resj_pdb << " to initial template " << initial_template_index_ << std::endl;
922  } else if (template_resi) {
923  // superimpose i strand atoms
924  for (core::Size i = 1; i<=atom_names.size();++i) {
925  core::id::AtomID const id1i( template_poses_[*pairings_iter]->residue(1).atom_index(atom_names[i]), 1 );
926  core::id::AtomID const id2i( template_poses_[initial_template_index_]->residue(template_resi).atom_index(atom_names[i]), template_resi );
927  atom_map[ id1i ] = id2i;
928  }
929  TR << "Superimpose strand pair " << *pairings_iter << " at " << resi_pdb << " to initial template " << initial_template_index_ << std::endl;
930  } else if (template_resj) {
931  // superimpose j strand atoms
932  for (core::Size i = 1; i<=atom_names.size();++i) {
933  core::id::AtomID const id1j( template_poses_[*pairings_iter]->residue(2).atom_index(atom_names[i]), 2 );
934  core::id::AtomID const id2j( template_poses_[initial_template_index_]->residue(template_resj).atom_index(atom_names[i]), template_resj );
935  atom_map[ id1j ] = id2j;
936  }
937  TR << "Superimpose strand pair " << *pairings_iter << " at " << resj_pdb << " to initial template " << initial_template_index_ << std::endl;
938  }
939  if (template_resi || template_resj) {
940  core::Real rms = core::scoring::superimpose_pose( *template_poses_[*pairings_iter], *template_poses_[initial_template_index_], atom_map );
941  TR << "rms: " << ObjexxFCL::fmt::F(8,3,rms) << std::endl;
942  continue;
943  }
944  }
945  // if we reach this point, try to align to upstream pairs
946  bool do_continue = false;
947  for ( kinematics::FoldTree::const_iterator iti = fold_tree.begin(), iti_end = fold_tree.end(); iti != iti_end; ++iti ) {
948  if (*it == *iti || !iti->is_jump() || iti->start() == fold_tree.root() || iti->stop() != it->start()) continue;
949  std::set<core::Size>::iterator pairings_iteri;
950  for (pairings_iteri = strand_pairings_template_indices_.begin(); pairings_iteri != strand_pairings_template_indices_.end(); ++pairings_iteri) {
951  core::Size resii_pdb = template_poses_[*pairings_iteri]->pdb_info()->number(1);
952  core::Size resji_pdb = template_poses_[*pairings_iteri]->pdb_info()->number(2);
953  if ((resii_pdb == (core::Size)iti->start() && resji_pdb == (core::Size)iti->stop()) ||
954  (resji_pdb == (core::Size)iti->start() && resii_pdb == (core::Size)iti->stop())) {
955  core::Size template_res = map_pdb_info_number( *template_poses_[*pairings_iteri], iti->stop() );
956  if (template_res) {
957  core::Size pair_res = map_pdb_info_number( *template_poses_[*pairings_iter], it->start() );
958  // superimpose strand atoms
959  for (core::Size j = 1; j<=atom_names.size();++j) {
960  core::id::AtomID const id1i( template_poses_[*pairings_iter]->residue(pair_res).atom_index(atom_names[j]), pair_res );
961  core::id::AtomID const id2i( template_poses_[*pairings_iteri]->residue(template_res).atom_index(atom_names[j]), template_res );
962  atom_map[ id1i ] = id2i;
963  }
964  TR << "Superimpose strand pair " << *pairings_iter << " at " << it->start() << " to pair " << *pairings_iteri << std::endl;
965  core::Real rms = core::scoring::superimpose_pose( *template_poses_[*pairings_iter], *template_poses_[*pairings_iteri], atom_map );
966  TR << "rms: " << ObjexxFCL::fmt::F(8,3,rms) << std::endl;
967  do_continue = true;
968  }
969  }
970  }
971  }
972  if (do_continue) continue;
973  // if we reach this point, try to align to any non-strand pair template
974  utility::vector1< core::Size > candidate_templates;
975  for (core::Size i=1; i<=template_poses_.size(); ++i) {
977  if ( map_pdb_info_number( *template_poses_[i], resi_pdb ) || map_pdb_info_number( *template_poses_[i], resj_pdb ) )
978  candidate_templates.push_back(i);
979  }
980  if (candidate_templates.size()) {
982  std::random_shuffle ( candidate_templates.begin(), candidate_templates.end() );
983  for (it=candidate_templates.begin(); it!=candidate_templates.end(); ++it) {
984  core::Size template_resi = map_pdb_info_number( *template_poses_[*it], resi_pdb );
985  core::Size template_resj = map_pdb_info_number( *template_poses_[*it], resj_pdb );
986  if (template_resi && template_resj) {
987  // superimpose all atoms
988  for (core::Size i = 1; i<=atom_names.size();++i) {
989  core::id::AtomID const id1i( template_poses_[*pairings_iter]->residue(1).atom_index(atom_names[i]), 1 );
990  core::id::AtomID const id2i( template_poses_[*it]->residue(template_resi).atom_index(atom_names[i]), template_resi );
991  atom_map[ id1i ] = id2i;
992  core::id::AtomID const id1j( template_poses_[*pairings_iter]->residue(2).atom_index(atom_names[i]), 2 );
993  core::id::AtomID const id2j( template_poses_[*it]->residue(template_resj).atom_index(atom_names[i]), template_resj );
994  atom_map[ id1j ] = id2j;
995  }
996  } else if (template_resi) {
997  // superimpose i strand atoms
998  for (core::Size i = 1; i<=atom_names.size();++i) {
999  core::id::AtomID const id1i( template_poses_[*pairings_iter]->residue(1).atom_index(atom_names[i]), 1 );
1000  core::id::AtomID const id2i( template_poses_[*it]->residue(template_resi).atom_index(atom_names[i]), template_resi );
1001  atom_map[ id1i ] = id2i;
1002  }
1003  } else if (template_resj) {
1004  // superimpose j strand atoms
1005  for (core::Size i = 1; i<=atom_names.size();++i) {
1006  core::id::AtomID const id1j( template_poses_[*pairings_iter]->residue(2).atom_index(atom_names[i]), 2 );
1007  core::id::AtomID const id2j( template_poses_[*it]->residue(template_resj).atom_index(atom_names[i]), template_resj );
1008  atom_map[ id1j ] = id2j;
1009  }
1010  }
1011  if (template_resi || template_resj) {
1012  TR << "Superimpose strand pair " << *pairings_iter << " to random template " << *it << std::endl;
1013  core::Real rms = core::scoring::superimpose_pose( *template_poses_[*pairings_iter], *template_poses_[*it], atom_map );
1014  TR << "rms: " << ObjexxFCL::fmt::F(8,3,rms) << std::endl;
1015  do_continue = true;
1016  break;
1017  }
1018  }
1019  }
1020  if (do_continue) continue;
1021  TR << "Cannot superimpose strand pairing " << *pairings_iter << " to a template so treating it as a floating pair" << std::endl;
1022  floating_pairs_.insert(*pairings_iter);
1023  }
1024  }
1025  }
1026 }
1027 
1029  core::Size mapped = 0;
1030  for (core::Size i=1; i<=pose.total_residue(); ++i) {
1031  if (pose.pdb_info()->number(i) == (int)pdb_res) {
1032  mapped = i;
1033  break;
1034  }
1035  }
1036  return mapped;
1037 }
1038 
1039 void FoldTreeHybridize::filter_templates(std::set< core::Size > const & templates_to_remove) {
1040  if (templates_to_remove.size() == 0) return;
1041 
1042  utility::vector1 < core::pose::PoseOP > template_poses_filtered;
1043  utility::vector1 < core::Real > template_wts_filtered;
1044  utility::vector1 < protocols::loops::Loops > template_chunks_filtered;
1045  utility::vector1 < protocols::loops::Loops > template_contigs_filtered;
1046  for (core::Size i=1; i<=template_poses_.size(); ++i) {
1047  if (templates_to_remove.count(i)) {
1048  if (i == initial_template_index_) {
1049  initial_template_index_ = 1; // default to 1
1050  TR << "filter_templates: removing initial template: " << i << std::endl;
1051  } else {
1052  TR << "filter_templates: removing template: " << i << std::endl;
1053  }
1054  continue;
1055  }
1056  template_poses_filtered.push_back(template_poses_[i]);
1057  template_wts_filtered.push_back(template_wts_[i]);
1058  template_chunks_filtered.push_back(template_chunks_[i]);
1059  template_contigs_filtered.push_back(template_contigs_[i]);
1060  }
1061  if (!template_poses_filtered.size())
1062  TR << "Warning! all templates were removed." << std::endl;
1063  template_poses_ = template_poses_filtered;
1064  template_wts_ = template_wts_filtered;
1065  template_chunks_ = template_chunks_filtered;
1066  template_contigs_ = template_contigs_filtered;
1068 }
1069 
1071  assert( jump_frags_ );
1073  movemap->set_bb( true );
1074  movemap->set_jump( true );
1076  jump_mover->type( "JumpMoves" );
1077  jump_mover->set_check_ss( false ); // this doesn't make sense with jump fragments
1078  jump_mover->enable_end_bias_check( false ); //no sense for discontinuous fragments
1079  return jump_mover;
1080 }
1081 
1083  std::set<core::Size> strand_pair_residues;
1084  for (core::Size i = 1; i<=strand_pairs_.size();++i) {
1085  strand_pair_residues.insert(strand_pairs_[i].first);
1086  strand_pair_residues.insert(strand_pairs_[i].second);
1087  }
1088  return strand_pair_residues;
1089 }
1090 
1091 
1092 // end of strand pairings methods
1093 
1094 // convergence checker from ClassicAbinitio
1095 /// @brief (helper) functor class which keeps track of old pose for the
1096 /// convergence check in stage3 cycles
1097 /// @detail
1098 /// Similar to Classic Abinitio's convergence check but checks moves
1099 /// with big fragments for 3 angstrom rmsd convergence and for small
1100 /// fragments, 1.5 angstrom rmsd convergence. It checks after 200 cycles
1101 /// compared to 100 used in ClassicAbinitio
1104 
1106 public:
1107  hConvergenceCheck() : bInit_( false ), ct_( 0 ) {}
1108  void reset() { ct_ = 0; bInit_ = false; residue_selection_big_frags_.clear(); residue_selection_small_frags_.clear(); }
1110  trials_ = trin;
1111  runtime_assert( trials_->keep_stats_type() < moves::no_stats );
1112  last_move_ = 0;
1113  }
1114  void set_residue_selection_big_frags( std::list< core::Size > const & residue_selection ) {
1115  residue_selection_big_frags_ = residue_selection;
1116  }
1117  void set_residue_selection_small_frags( std::list< core::Size > const & residue_selection ) {
1118  residue_selection_small_frags_ = residue_selection;
1119  }
1120  virtual bool operator() ( const core::pose::Pose & pose );
1121 private:
1123  bool bInit_;
1125  std::list< core::Size > residue_selection_big_frags_;
1126  std::list< core::Size > residue_selection_small_frags_;
1129 };
1130 
1131 // keep going --> return true
1133  if ( !bInit_ ) {
1134  bInit_ = true;
1135  TR.Trace << "hConvergenceCheck residue_selection_small_frags size: " << residue_selection_small_frags_.size() << std::endl;
1136  TR.Trace << "hConvergenceCheck residue_selection_big_frags size: " << residue_selection_big_frags_.size() << std::endl;
1137  very_old_pose_ = pose;
1138  return true;
1139  }
1140  runtime_assert( trials_ );
1141  TR.Trace << "TrialCounter in hConvergenceCheck: " << trials_->num_accepts() << std::endl;
1142  if ( numeric::mod(trials_->num_accepts(),200) != 0 ) return true;
1143  if ( (Size) trials_->num_accepts() <= last_move_ ) return true;
1144  last_move_ = trials_->num_accepts();
1145  core::Real converge_rms_small = (residue_selection_small_frags_.size()) ?
1146  core::scoring::CA_rmsd( very_old_pose_, pose, residue_selection_small_frags_ ) : 0.0;
1147  core::Real converge_rms_big = (residue_selection_big_frags_.size()) ?
1148  core::scoring::CA_rmsd( very_old_pose_, pose, residue_selection_big_frags_ ) : 0.0;
1149  very_old_pose_ = pose;
1150  if ( converge_rms_big >= 3.0 || converge_rms_small >= 1.5 || (!converge_rms_small && !converge_rms_big)) {
1151  TR.Trace << "hConvergenceCheck continue, converge_rms_big: " << converge_rms_big << " converge_rms_small: " << converge_rms_small << std::endl;
1152  return true;
1153  }
1154  // if we get here thing is converged stop the While-Loop
1155  TR.Info << "stop cycles due to convergence, converge_rms_big: " << converge_rms_big << " converge_rms_small: " << converge_rms_small << std::endl;
1156  return false;
1157 }
1158 
1159 
1160 
1161 void
1163 
1164  // save target sequence
1165  target_sequence_ = pose.sequence();
1166 
1167  // strand pairings - include chunks from pairings
1168  // this will add pairings templates and may remove templates that are missing strand pairings if filter_templates option is used
1170 
1171  setup_foldtree(pose); // easier said than done!
1172 
1173  // strand pairings - superimpose pairings to templates to place them in the same coordinate frame
1175 
1176  bool has_strand_pairings = (strand_pairings_template_indices_.size()) ? true : false;
1177 
1178  // setup constraints
1179  // note: ignore pairings residues (strand pairings templates) for auto generated constraints
1181  if (add_hetatm_)
1183 
1184  // Initialize the structure
1185  bool use_random_template = false;
1186  ChunkTrialMover initialize_chunk_mover(template_poses_, template_chunks_, ss_chunks_pose_, use_random_template, all_chunks);
1187  initialize_chunk_mover.set_template(initial_template_index_);
1188  initialize_chunk_mover.apply(pose);
1189  // strand pairings
1190  if (has_strand_pairings) {
1191  // apply strand pairing jumps to place floating pairs
1193  jump_mover->apply_at_all_positions( pose );
1194  // insert strand pairing template chunks (to place template pairs)
1195  for (std::set<core::Size>::iterator pairings_iter = strand_pairings_template_indices_.begin(); pairings_iter != strand_pairings_template_indices_.end(); ++pairings_iter) {
1196  if (floating_pairs_.count(*pairings_iter)) continue;
1197  initialize_chunk_mover.set_template(*pairings_iter);
1198  initialize_chunk_mover.apply(pose);
1199  }
1200  }
1201 
1202  translate_virt_to_CoM(pose);
1203 
1204  use_random_template = true;
1205  Size max_registry_shift = max_registry_shift_;
1206  ChunkTrialMoverOP random_sample_chunk_mover(
1207  new ChunkTrialMover(template_poses_, template_chunks_, ss_chunks_pose_, use_random_template, random_chunk, max_registry_shift) );
1208 
1209  // ignore strand pair templates, they will be sampled by a jump mover
1210  random_sample_chunk_mover->set_templates_to_ignore(strand_pairings_template_indices_);
1211 
1212  utility::vector1< core::Real > residue_weights_1mer_frags( get_residue_weights_for_1mers(pose) );
1213  utility::vector1< core::Real > residue_weights_small_frags( get_residue_weights_for_small_frags(pose) );
1215 
1217 
1218  // ab initio ramping up of weights
1219  // set up scorefunctions
1220  core::scoring::ScoreFunctionOP score0=scorefxn_->clone(),
1221  score1=scorefxn_->clone(),
1222  score2=scorefxn_->clone(),
1223  score5=scorefxn_->clone(),
1224  score3=scorefxn_->clone();
1225  setup_scorefunctions( score0, score1, score2, score5, score3 );
1226 
1227  // set montecarlo temp
1228  core::Real temp = 2.0;
1229 
1230  // set up movers
1231  // Stage 1-3: chunks + big + small (at positions skipped by big) + 1mer (at positions skipped by small) frags + strand pair jumps if given
1232  RandomMoverOP random_chunk_and_frag_mover( new RandomMover() );
1233  // Stage 4: chunks + small + 1mer (at positions skipped by small) frags + strand pair jumps if given
1234  RandomMoverOP random_chunk_and_small_frag_mover( new RandomMover() );
1235  // Stage 4 smooth moves: chunks + small + 1mer (at positions skipped by small) frags + strand pair jumps if given
1236  RandomMoverOP random_chunk_and_small_frag_smooth_mover( new RandomMover() );
1237 
1238  WeightedFragmentTrialMoverOP frag_1mer_mover( new WeightedFragmentTrialMover( frag_libs_1mer_, residue_weights_1mer_frags, jump_anchors, top_n_big_frag_) );
1239  WeightedFragmentTrialMoverOP small_frag_gaps_mover( new WeightedFragmentTrialMover( frag_libs_small_, residue_weights_small_frags, jump_anchors, top_n_big_frag_) );
1240  WeightedFragmentTrialMoverOP top_big_frag_mover( new WeightedFragmentTrialMover( frag_libs_big_, residue_weights, jump_anchors, top_n_big_frag_) );
1241  WeightedFragmentTrialMoverOP small_frag_mover( new WeightedFragmentTrialMover( frag_libs_small_, residue_weights, jump_anchors, 0) );
1242  WeightedFragmentSmoothTrialMoverOP small_frag_smooth_mover( new WeightedFragmentSmoothTrialMover( frag_libs_small_, residue_weights, jump_anchors, 0, new GunnCost) );
1243 
1244  // automatically re-weight the fragment insertions if desired
1245  auto_frag_insertion_weight(frag_1mer_mover, small_frag_gaps_mover, top_big_frag_mover);
1246 
1248  if ( total_frag_insertion_weight < 1. ) {
1249  random_chunk_and_frag_mover->add_mover(random_sample_chunk_mover, 1.-total_frag_insertion_weight);
1250  random_chunk_and_small_frag_mover->add_mover(random_sample_chunk_mover, 1.-total_frag_insertion_weight);
1251  random_chunk_and_small_frag_smooth_mover->add_mover(random_sample_chunk_mover, 1.-total_frag_insertion_weight);
1252  }
1253  bool do_frag_inserts = false;
1254  if ( total_frag_insertion_weight > 0. ) {
1255  core::Real sum_weight = 0.;
1256  for ( Size ires=1; ires<= residue_weights.size(); ++ires ) sum_weight += residue_weights[ires];
1257  if (sum_weight > 1e-6) do_frag_inserts = true;
1258  }
1259  if (do_frag_inserts) {
1260  // use similar default fraction of fragment to jump moves as in KinematicAbinitio.cc
1261  core::Real jump_move_fraction = 1.0/(core::Real)(option[ jumps::invrate_jump_move ]+1.);
1262 
1263  // 1mers fragment insertions where small and big fragments are not allowed (small gaps between small chunks)
1264  if (frag_1mer_insertion_weight_ > 0.) {
1265  if (has_strand_pairings) {
1266  core::Real jump_insertion_weight = frag_1mer_insertion_weight_*jump_move_fraction;
1267  random_chunk_and_frag_mover->add_mover(frag_1mer_mover, frag_1mer_insertion_weight_-jump_insertion_weight);
1268  // strand pair jump insertions
1270  random_chunk_and_frag_mover->add_mover(jump_mover, jump_insertion_weight);
1271  } else {
1272  random_chunk_and_frag_mover->add_mover(frag_1mer_mover, frag_1mer_insertion_weight_);
1273  }
1274  }
1275 
1276  // small fragment insertions where big fragments are not allowed (where big fragments cover jump_anchors)
1277  if (small_frag_insertion_weight_ > 0.) {
1278  if (has_strand_pairings) {
1279  core::Real jump_insertion_weight = small_frag_insertion_weight_*jump_move_fraction;
1280  random_chunk_and_frag_mover->add_mover(small_frag_gaps_mover, small_frag_insertion_weight_-jump_insertion_weight);
1281  // strand pair jump insertions
1283  random_chunk_and_frag_mover->add_mover(jump_mover, jump_insertion_weight);
1284  } else {
1285  random_chunk_and_frag_mover->add_mover(small_frag_gaps_mover, small_frag_insertion_weight_);
1286  }
1287  }
1288 
1289  // big fragment and strand pairing jump insertions
1290  if (big_frag_insertion_weight_ > 0.) {
1291  if (has_strand_pairings) {
1292  core::Real jump_insertion_weight = big_frag_insertion_weight_*jump_move_fraction;
1293  random_chunk_and_frag_mover->add_mover(top_big_frag_mover, big_frag_insertion_weight_-jump_insertion_weight);
1294  // strand pair jump insertions
1296  random_chunk_and_frag_mover->add_mover(jump_mover, jump_insertion_weight);
1297  } else {
1298  random_chunk_and_frag_mover->add_mover(top_big_frag_mover, big_frag_insertion_weight_);
1299  }
1300  }
1301 
1302  // small fragment insertions for stage 4
1304  if (has_strand_pairings) {
1305  core::Real jump_insertion_weight = (small_frag_insertion_weight_+big_frag_insertion_weight_)*jump_move_fraction;
1306  random_chunk_and_small_frag_mover->add_mover(small_frag_mover, small_frag_insertion_weight_+big_frag_insertion_weight_-jump_insertion_weight);
1307  random_chunk_and_small_frag_smooth_mover->add_mover(small_frag_smooth_mover, small_frag_insertion_weight_+big_frag_insertion_weight_-jump_insertion_weight);
1308  // strand pair jump insertions
1310  random_chunk_and_small_frag_mover->add_mover(jump_mover, jump_insertion_weight);
1311  random_chunk_and_small_frag_smooth_mover->add_mover(jump_mover, jump_insertion_weight);
1312  } else {
1313  random_chunk_and_small_frag_mover->add_mover(small_frag_mover, small_frag_insertion_weight_+big_frag_insertion_weight_);
1314  random_chunk_and_small_frag_smooth_mover->add_mover(small_frag_smooth_mover, small_frag_insertion_weight_+big_frag_insertion_weight_);
1315  }
1316  }
1317 
1318  // 1mer fragment insertions for stage 4
1319  if (frag_1mer_insertion_weight_ > 0.) {
1320  if (has_strand_pairings) {
1321  core::Real jump_insertion_weight = frag_1mer_insertion_weight_*jump_move_fraction;
1322  random_chunk_and_small_frag_mover->add_mover(frag_1mer_mover, frag_1mer_insertion_weight_-jump_insertion_weight);
1323  random_chunk_and_small_frag_smooth_mover->add_mover(frag_1mer_mover, frag_1mer_insertion_weight_-jump_insertion_weight);
1324  // strand pair jump insertions
1326  random_chunk_and_small_frag_mover->add_mover(jump_mover, jump_insertion_weight);
1327  random_chunk_and_small_frag_smooth_mover->add_mover(jump_mover, jump_insertion_weight);
1328  } else {
1329  random_chunk_and_small_frag_mover->add_mover(frag_1mer_mover, frag_1mer_insertion_weight_);
1330  random_chunk_and_small_frag_smooth_mover->add_mover(frag_1mer_mover, frag_1mer_insertion_weight_);
1331  }
1332  }
1333  }
1334 
1335  // determine the number of cycles
1340 
1341  // For stages 1-4 use the same ramping of chainbreaks as in KinematicAbinitio without close_chbrk_
1342  // may want to look into using the constraints/jump sequence separation logic as in KinematicAbinitio
1343 
1344  // stage 1
1345  // fragment moves to get rid of extended chains (should we include chunk moves?)
1346  // this version: up to 2000 cycles until torsions are replaced
1347  // casp10 version: 2000 cycles
1348  if (do_frag_inserts) {
1349  TR.Info << "\n===================================================================\n";
1350  TR.Info << " Stage 1 \n";
1351  TR.Info << " Folding with score0 for max of " << stage1_max_cycles << std::endl;
1352  using namespace ObjexxFCL::fmt;
1353  AllResiduesChanged done( pose, residue_weights, jump_anchors );
1354  protocols::moves::MonteCarloOP mc1 = new protocols::moves::MonteCarlo( pose, *score0, temp );
1355  mc1->set_autotemp( false, temp );
1356  (*score0)(pose);
1357  bool all_res_changed = false;
1358  for (core::Size i=1; i<=stage1_max_cycles; ++i) {
1359  random_chunk_and_frag_mover->apply(pose);
1360  (*score0)(pose);
1361  mc1->boltzmann(pose, "RandomMover");
1362  if ( done(pose) ) {
1363  TR.Info << "Stage 1: Replaced extended chains after " << i << " cycles." << std::endl;
1364  all_res_changed = true;
1365  break;
1366  }
1367  }
1368  if (!all_res_changed) {
1369  TR.Warning << "Stage 1: Warning: extended chain may still remain after " << stage1_max_cycles << " cycles!" << std::endl;
1370  done.show_unmoved( pose, TR.Warning );
1371  }
1372  mc1->show_scores();
1373  mc1->show_counters();
1374  mc1->recover_low(pose);
1375  mc1->reset( pose );
1376  }
1377 
1378  // evaluation
1380  core::Real gdtmm = 0.0;
1381  if (native_ && native_->total_residue()) {
1382  gdtmm = get_gdtmm(*native_, pose, native_aln);
1383  core::pose::setPoseExtraScores( pose, "GDTMM_after_stage1_1", gdtmm);
1384  TR << "GDTMM_after_stage1_1" << ObjexxFCL::fmt::F(8,3,gdtmm) << std::endl;
1385  }
1386 
1387  // stage 2
1388  // fragment and chunk insertion moves with score1
1389  // this version: 2000 cycles with autotemp
1390  // casp10 version: 2000 cycles
1391  {
1392  TR.Info << "\n===================================================================\n";
1393  TR.Info << " Stage 2 \n";
1394  TR.Info << " Folding with score1 for " << stage2_max_cycles << std::endl;
1395 
1396  // ramp chainbreak weight as in KinematicAbinitio
1397  Real const setting( 0.25 / 3 * option[ jumps::increase_chainbreak ] );
1398  TR.Debug << scoring::name_from_score_type(scoring::linear_chainbreak) << " " << setting << std::endl;
1399  score1->set_weight(scoring::linear_chainbreak, setting);
1400 
1401  protocols::moves::MonteCarloOP mc2 = new protocols::moves::MonteCarlo( pose, *score1, temp );
1402  mc2->set_autotemp( true, temp );
1403  mc2->set_temperature( temp ); // temperature might have changed due to autotemp..
1404  mc2->reset( pose );
1405  (*score1)(pose);
1406  moves::TrialMoverOP stage2_trials = new moves::TrialMover( random_chunk_and_frag_mover, mc2 );
1407  stage2_trials->keep_stats_type( moves::accept_reject );
1408  moves::RepeatMover( stage2_trials, stage2_max_cycles ).apply( pose );
1409 
1410  mc2->show_scores();
1411  mc2->show_counters();
1412  mc2->recover_low(pose);
1413  mc2->reset( pose );
1414  }
1415 
1416 
1417  // evaluation
1418  if (native_ && native_->total_residue()) {
1419  gdtmm = get_gdtmm(*native_, pose, native_aln);
1420  core::pose::setPoseExtraScores( pose, "GDTMM_after_stage1_2", gdtmm);
1421  TR << "GDTMM_after_stage1_2" << ObjexxFCL::fmt::F(8,3,gdtmm) << std::endl;
1422  }
1423 
1424  // stage 3
1425  // fragment and chunk insertion moves with alternating score 2 and 5
1426  // (ClassicAbinitio uses 2000 cycles for each inner iteration)
1427  // this version: up to 2000 cycles with autotemp, convergence checking, and ramped chainbreak score
1428  // casp10 version: 200 cycles
1429  {
1430  TR.Info << "\n===================================================================\n";
1431  TR.Info << " Stage 3 \n";
1432  TR.Info << " Folding with score2 and score5 for " << stage3_max_cycles <<std::endl;
1433  hConvergenceCheckOP convergence_checker ( NULL );
1434  if ( !option[ abinitio::skip_convergence_check ] ) {
1435  convergence_checker = new hConvergenceCheck;
1436  std::list< core::Size > residue_selection_big_frags;
1437  std::list< core::Size > residue_selection_small_frags;
1438  for (core::Size i = 1; i<=residue_weights.size(); ++i) {
1439  if ( residue_weights[i] > 0.0 &&
1440  pose.residue(i).is_protein() &&
1441  pose.residue(i).has("CA") ) residue_selection_big_frags.push_back(i);
1442  }
1443  for (core::Size i = 1; i<=residue_weights_small_frags.size(); ++i) {
1444  if ( residue_weights_small_frags[i] > 0.0 &&
1445  pose.residue(i).is_protein() &&
1446  pose.residue(i).has("CA") ) residue_selection_small_frags.push_back(i);
1447  }
1448  convergence_checker->set_residue_selection_big_frags(residue_selection_big_frags);
1449  convergence_checker->set_residue_selection_small_frags(residue_selection_small_frags);
1450  }
1451 
1452  for (int nmacro=1; nmacro<=10; ++nmacro) {
1453 
1454  // ramp chainbreak weight as in KinematicAbinitio
1455  Real chbrk_weight_stage_3a = 0;
1456  Real chbrk_weight_stage_3b = 0;
1457  Real progress( 1.0* nmacro/10 );
1458  Real const fact( progress * 1.0/3 * option[ jumps::increase_chainbreak ]);
1459  chbrk_weight_stage_3a = 2.5 * fact;
1460  chbrk_weight_stage_3b = 0.5 * fact;
1461  TR.Debug << scoring::name_from_score_type(scoring::linear_chainbreak) << " " << chbrk_weight_stage_3a << std::endl;
1462  score2->set_weight(scoring::linear_chainbreak, chbrk_weight_stage_3a);
1463  TR.Debug << scoring::name_from_score_type(scoring::linear_chainbreak) << " " << chbrk_weight_stage_3b << std::endl;
1464  score5->set_weight(scoring::linear_chainbreak, chbrk_weight_stage_3b);
1465 
1466  protocols::moves::MonteCarloOP mc3 = new protocols::moves::MonteCarlo( pose, *score2, temp );
1467  moves::TrialMoverOP stage3_trials = new moves::TrialMover( random_chunk_and_frag_mover, mc3 );
1468  stage3_trials->keep_stats_type( moves::accept_reject );
1469 
1470  if ( numeric::mod( nmacro, 2 ) != 0 || nmacro > 6 ) {
1471  TR.Info << "Stage 3 select score2..." << std::endl;
1472  mc3->recover_low(pose);
1473  mc3->score_function( *score2 );
1474  mc3->set_autotemp( true, temp );
1475  mc3->set_temperature( temp );
1476  mc3->reset( pose );
1477  (*score2)( pose );
1478  } else {
1479  TR.Info << "Stage 3 select score5..." << std::endl;
1480  mc3->recover_low(pose);
1481  mc3->score_function( *score5 );
1482  mc3->set_autotemp( true, temp );
1483  mc3->set_temperature( temp );
1484  mc3->reset( pose );
1485  (*score5)( pose );
1486  }
1487 
1488  TR.Info << "Stage 3 loop iteration " << nmacro << std::endl;
1489  if ( convergence_checker ) {
1490  convergence_checker->set_trials( stage3_trials );
1491  moves::WhileMover( stage3_trials, stage3_max_cycles, convergence_checker ).apply( pose );
1492  } else {
1493  moves::RepeatMover( stage3_trials, stage3_max_cycles ).apply( pose );
1494  }
1495  TR.Debug << "finished" << std::endl;
1496  mc3->show_scores();
1497  mc3->show_counters();
1498  mc3->recover_low(pose);
1499  mc3->reset( pose );
1500  }
1501  }
1502 
1503  // evaluation
1504  if (native_ && native_->total_residue()) {
1505  gdtmm = get_gdtmm(*native_, pose, native_aln);
1506  core::pose::setPoseExtraScores( pose, "GDTMM_after_stage1_3", gdtmm);
1507  TR << "GDTMM_after_stage1_3" << ObjexxFCL::fmt::F(8,3,gdtmm) << std::endl;
1508  }
1509 
1510  {
1511  // stage 4 -- ramp up chainbreak
1512  // this version: 3 steps, 4000 cycles (only small fragments and last 2 steps smooth moves)
1513  // casp10 version: 4 steps, 500 cycles
1514  TR.Info << "\n===================================================================\n";
1515  TR.Info << " Stage 4 \n";
1516  TR.Info << " Folding with score3 for " << stage4_max_cycles <<std::endl;
1517  for (int nmacro=1; nmacro<=3; ++nmacro) {
1518 
1519  // ramp chainbreak weight as in KinematicAbinitio
1520  Real progress( 1.0* nmacro/3 );
1521  Real const setting( ( 1.5*progress+2.5 ) * ( 1.0/3) * option[ jumps::increase_chainbreak ]);
1522  TR.Debug << scoring::name_from_score_type(scoring::linear_chainbreak) << " " << setting << std::endl;
1523  score3->set_weight( core::scoring::linear_chainbreak, setting );
1524  if (overlap_chainbreaks_) {
1525  TR.Debug << scoring::name_from_score_type(scoring::overlap_chainbreak) << " " << progress << std::endl;
1526  score3->set_weight( core::scoring::overlap_chainbreak, progress );
1527  }
1528 
1529  protocols::moves::MonteCarloOP mc4 = new protocols::moves::MonteCarlo( pose, *score3, temp );
1530  mc4->set_autotemp( true, temp );
1531  mc4->set_temperature( temp );
1532  mc4->reset( pose );
1533  (*score3)( pose );
1534  moves::TrialMoverOP stage4_trials;
1535  if ( nmacro == 1 ) {
1536  TR.Info << "Stage 4 loop iteration " << nmacro << ": small fragments trials" << std::endl;
1537  stage4_trials = new moves::TrialMover( random_chunk_and_small_frag_mover, mc4 );
1538  } else {
1539  TR.Info << "Stage 4 loop iteration " << nmacro << ": small fragments smooth trials" << std::endl;
1540  stage4_trials = new moves::TrialMover(random_chunk_and_small_frag_smooth_mover, mc4);
1541  }
1542  moves::RepeatMover( stage4_trials, stage4_max_cycles ).apply(pose);
1543  TR.Debug << "finished" << std::endl;
1544  mc4->show_scores();
1545  mc4->show_counters();
1546  mc4->recover_low(pose);
1547  mc4->reset( pose );
1548  }
1549  }
1550 
1551  // evaluation
1552  if (native_ && native_->total_residue()) {
1553  gdtmm = get_gdtmm(*native_, pose, native_aln);
1554  core::pose::setPoseExtraScores( pose, "GDTMM_after_stage1_4", gdtmm);
1555  TR << "GDTMM_after_stage1_4" << ObjexxFCL::fmt::F(8,3,gdtmm) << std::endl;
1556  }
1557 
1558  pose.remove_constraints();
1560 
1561  for (Size ires=1; ires<=pose.total_residue(); ++ires) {
1562  using namespace ObjexxFCL::fmt;
1563  TR.Debug << "Chunk trial counter:" << I(4,ires) << I(8, random_sample_chunk_mover->trial_counter(ires)) << std::endl;
1564  }
1565 }
1566 
1568  WeightedFragmentTrialMoverOP & frag_1mer_trial_mover,
1569  WeightedFragmentTrialMoverOP & small_frag_trial_mover,
1570  WeightedFragmentTrialMoverOP & big_frag_trial_mover
1571 ) {
1572  using namespace ObjexxFCL::fmt;
1573  if (!auto_frag_insertion_weight_) return;
1574  core::Size frag_1mer_n_frags = frag_1mer_trial_mover->get_nr_frags();
1575  if (!frag_1mer_n_frags) frag_1mer_n_frags = top_n_small_frag_;
1576  core::Size small_n_frags = small_frag_trial_mover->get_nr_frags();
1577  if (!small_n_frags) small_n_frags = top_n_small_frag_;
1578  core::Size big_n_frags = big_frag_trial_mover->get_nr_frags();
1579  if (!big_n_frags) big_n_frags = top_n_big_frag_;
1580  core::Size template_pos_coverage = 0;
1581  for (core::Size i = 1; i<=template_chunks_.size(); ++i) {
1582  if (strand_pairings_template_indices_.count(i)) continue;
1583  template_pos_coverage += template_chunks_[i].num_loop();
1584  }
1585  core::Size frag_1mer_pos_coverage = frag_1mer_trial_mover->get_total_frames()*frag_1mer_n_frags;
1586  core::Size small_frag_pos_coverage = small_frag_trial_mover->get_total_frames()*small_n_frags;
1587  core::Size big_frag_pos_coverage = big_frag_trial_mover->get_total_frames()*big_n_frags;
1588  core::Real sum = (core::Real)(frag_1mer_pos_coverage+small_frag_pos_coverage+big_frag_pos_coverage+template_pos_coverage);
1589  frag_1mer_insertion_weight_ = (core::Real)frag_1mer_pos_coverage/sum;
1590  small_frag_insertion_weight_ = (core::Real)small_frag_pos_coverage/sum;
1591  big_frag_insertion_weight_ = (core::Real)big_frag_pos_coverage/sum;
1592  TR.Info << "auto_frag_insertion_weight for 1mer fragments: " << F(7,5,frag_1mer_insertion_weight_) << " " << frag_1mer_pos_coverage << std::endl;
1593  TR.Info << "auto_frag_insertion_weight for small fragments: " << F(7,5,small_frag_insertion_weight_) << " " << small_frag_pos_coverage << std::endl;
1594  TR.Info << "auto_frag_insertion_weight for big fragments: " << F(7,5,big_frag_insertion_weight_) << " " << big_frag_pos_coverage << std::endl;
1595  TR.Info << "auto_frag_insertion_weight for template chunks: " <<
1596  F(7,5,1.0-frag_1mer_insertion_weight_-big_frag_insertion_weight_-small_frag_insertion_weight_) << " " << template_pos_coverage << std::endl;
1597 }
1598 
1600 {
1601  return "FoldTreeHybridize";
1602 }
1603 
1604 } // hybridization
1605 } // protocols
1606