Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
IterativeBase.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 // This file is part of the Rosetta software suite and is made available under license.
5 // The Rosetta software is developed by the contributing members of the Rosetta Commons consortium.
6 // (C) 199x-2009 Rosetta Commons participating institutions and developers.
7 // For more information, see http://www.rosettacommons.org/.
8 
9 /// @file IterativeAbrelax
10 /// @brief iterative protocol starting with abinitio and getting progressively more concerned with full-atom relaxed structures
11 /// @detailed
12 ///
13 ///
14 /// @author Oliver Lange
15 
16 // Unit Headers
19 
20 
21 // Package Headers
24 
25 // to test broker setup-file
30 #include <basic/options/keys/broker.OptionKeys.gen.hh>
31 
32 // Project Headers
33 #include <core/types.hh>
34 #include <core/pose/Pose.hh>
35 #include <core/pose/util.hh>
36 // AUTO-REMOVED #include <core/io/pdb/pose_io.hh>
37 #include <core/scoring/Energies.hh>
42 
45 
48 #include <core/fragment/util.hh>
49 
50 
52 
53 #ifdef WIN32
54 #include <core/fragment/FragID.hh>
56 #endif
57 
58 #include <core/sequence/util.hh>
60 
63 
67 
68 
69 // AUTO-REMOVED #include <core/scoring/constraints/util.hh>
70 
77 #include <protocols/loops/util.hh>
78 #include <protocols/loops/Loop.hh>
80 #include <basic/Tracer.hh>
81 #include <basic/MemTracer.hh>
82 
86 
87 
89 // ObjexxFCL Headers
90 
91 // Utility headers
92 #include <utility/io/izstream.hh>
93 #include <utility/io/ozstream.hh>
94 #include <utility/file/FileName.hh>
95 #include <utility/file/file_sys_util.hh>
96 #include <numeric/random/random.hh>
97 #include <utility/DereferenceIterator.hh>
98 
99 // Option Headers
100 #include <basic/options/keys/abinitio.OptionKeys.gen.hh>
101 #include <basic/options/keys/constraints.OptionKeys.gen.hh>
102 #include <basic/options/keys/jumps.OptionKeys.gen.hh>
103 #include <basic/options/keys/in.OptionKeys.gen.hh>
104 #include <basic/options/keys/run.OptionKeys.gen.hh>
105 #include <basic/options/keys/cluster.OptionKeys.gen.hh>
106 #include <basic/options/keys/score.OptionKeys.gen.hh>
107 // Third-party Headers
108 #include <boost/functional/hash.hpp>
109 
110 //// C++ headers
111 #include <cstdlib>
112 #include <string>
113 // AUTO-REMOVED #include <ctime>
114 // AUTO-REMOVED #include <iterator>
115 #include <vector>
116 
117 // Utility headers
118 #include <basic/options/option_macros.hh>
119 #include <numeric/random/random_permutation.hh>
120 
124 #include <utility/vector0.hh>
125 #include <utility/vector1.hh>
126 
127 static basic::Tracer tr("protocols.iterative");
128 using basic::mem_tr;
129 
130 static numeric::random::RandomGenerator RG(428342); // <- Magic number, do not change
131 
132 using core::Real;
133 using namespace core;
134 using namespace basic;
135 using namespace basic::options;
136 using namespace basic::options::OptionKeys;
137 
138 OPT_2GRP_KEY( File, iterative, enumerate, broker )
139 OPT_2GRP_KEY( Integer, iterative, enumerate, Naccept )
140 OPT_2GRP_KEY( Boolean, iterative, enumerate, skip_half )
141 //OPT_1GRP_KEY( Real, iterative, turnover_rate )
142 OPT_1GRP_KEY( Integer, iterative, rmsf_nstruct )
143 OPT_1GRP_KEY( File, iterative, cen_score )
144 OPT_1GRP_KEY( File, iterative, cen_score_patch )
145 
146 OPT_1GRP_KEY( File, iterative, fa_score )
147 OPT_1GRP_KEY( File, iterative, fa_score_patch )
148 OPT_1GRP_KEY( Real, iterative, chainbreak_evaluator_weight )
149 OPT_1GRP_KEY( IntegerVector, iterative, max_nstruct )
150 OPT_1GRP_KEY( Real, iterative, perturb_resampling )
151 OPT_1GRP_KEY( Boolean, iterative, mix_frags )
152 OPT_1GRP_KEY( Real, iterative, min_core_fraction_to_score )
153 OPT_1GRP_KEY( RealVector, iterative, min_diversity )
154 OPT_1GRP_KEY( RealVector, iterative, accept_ratio )
155 OPT_1GRP_KEY( Boolean, iterative, copy_pool_for_convergence_check )
156 OPT_1GRP_KEY( Real, iterative, safety_hatch_scorecut )
157 OPT_1GRP_KEY( Boolean, iterative, scored_ss_core )
158 OPT_1GRP_KEY( File, iterative, force_scored_region )
159 OPT_1GRP_KEY( Boolean, iterative, cluster )
160 OPT_1GRP_KEY( File, iterative, fix_core )
161 OPT_1GRP_KEY( Real, iterative, cenpool_noesy_cst_weight )
162 OPT_1GRP_KEY( String, iterative, chemicalshift_column )
163 OPT_1GRP_KEY( Real, iterative, cenpool_chemicalshift_weight )
164 OPT_1GRP_KEY( Real, iterative, centroid_before_quickrelax_weight )
165 OPT_1GRP_KEY( Real, iterative, fullatom_after_quickrelax_weight )
166 OPT_1GRP_KEY( Integer, iterative, limit_decoys_for_noe_assign )
167 OPT_1GRP_KEY( Boolean, iterative, centroid_quickrelax )
168 OPT_1GRP_KEY( String, iterative, super_quick_relax_protocol )
169 OPT_1GRP_KEY( String, iterative, super_quick_relax_patch )
170 OPT_1GRP_KEY( Integer, iterative, skip_redundant_constraints )
171 OPT_1GRP_KEY( String, iterative, initial_noe_auto_assign_csts )
172 OPT_1GRP_KEY( Integer, iterative, delay_noesy_reassign )
173 OPT_1GRP_KEY( String, iterative, auto_assign_scheme )
174 OPT_1GRP_KEY( Real, iterative, dcut )
175 OPT_1GRP_KEY( String, iterative, initial_beta_topology )
176 OPT_1GRP_KEY( Integer, iterative, recompute_beta_Naccept )
177 OPT_1GRP_KEY( String, iterative, flags_fullatom )
178 OPT_1GRP_KEY( Boolean, iterative, force_topology_resampling )
179 OPT_2GRP_KEY( Boolean, iterative, normalize, sampling )
180 OPT_1GRP_KEY( Boolean, iterative, update_noesy_filter_cst )
181 OPT_1GRP_KEY( Boolean, iterative, never_update_noesy_filter_cst )
182 
183 OPT_1GRP_KEY( Boolean, iterative, split_autoNOE_restraints )
184 OPT_1GRP_KEY( Real, iterative, randomize_elimination_candidates )
185 
186 OPT_1GRP_KEY( File, iterative, refine_auto_noe_flags )
187 OPT_1GRP_KEY( FileVector, iterative, staged_auto_noe_flags )
188 
189 std::string const NOESY_CST_FILE_NAME("noe_auto_assign.cst");
190 
191 bool protocols::abinitio::IterativeBase::options_registered_( false );
192 
193 
194 //Mike: when you want to remove these Macros... leave them at least here as comment - since they provide documentation
195 void protocols::abinitio::IterativeBase::register_options() {
196  if ( !options_registered_ ) {
199  OPT( in::file::silent );
200  OPT( cluster::limit_cluster_size );
201  OPT( cluster::limit_clusters );
202  OPT( cluster::limit_total_structures );
203 
204  NEW_OPT( iterative::enumerate::Naccept, "use enumerated pairings until Naccept decoys were added to archive", 5000 );
205  NEW_OPT( iterative::enumerate::broker, "broker-file for enumerated_pairings", "" );
206  NEW_OPT( iterative::enumerate::skip_half, "run half of the batches without enumerated pairings -- even before Naccept is reached", false );
207  // NEW_OPT( iterative::turnover_rate, "exchange of X percent of archive before new batch is started", 0.1 );
208  NEW_OPT( iterative::accept_ratio, "switch to new stage if accept_ratio is lower than", 0.2 );
209  NEW_OPT( iterative::rmsf_nstruct, "how many structures of pool used for computations of cores", 30 );
210  NEW_OPT( iterative::cen_score, "energy function for centroid pool", "score3" );
211  NEW_OPT( iterative::cen_score_patch, "patch of centroi_pool energy function", "NOPATCH" );
212  NEW_OPT( iterative::fa_score, "energy function for centroid pool", "score12_full" );
213  NEW_OPT( iterative::fa_score_patch, "patch of centroi_pool energy function", "NOPATCH" );
214  NEW_OPT( iterative::max_nstruct, "give maximum numbers of structures generated for a given stage before switch -- 0 for infinite, -1 for skip stage", 0);
215 
216  NEW_OPT( iterative::mix_frags, "mix frags with original fragset", false );
217  NEW_OPT( iterative::perturb_resampling, "perturb resample_stage2 start structures by this amount", 0.0 );
218  NEW_OPT( iterative::min_core_fraction_to_score, "use core (2, 3, 4A) for discriminiation if more than X% of residues", 2.0); //>1 == off
219  NEW_OPT( iterative::min_diversity, "don't accept structures that are closer than X to one of the pool", 1.5 );
220  NEW_OPT( iterative::copy_pool_for_convergence_check, "make a copy of the pool for each batch that uses the convergence check", true );
221  NEW_OPT( iterative::chainbreak_evaluator_weight, "weight for selection in pool...", 1.0 );
222 
223  NEW_OPT( iterative::safety_hatch_scorecut, "in CEN2FULLATOM state use structures for innput that are below scorecut in individual batches", 0.1);
224  NEW_OPT( iterative::scored_ss_core, "selecte structures based on score restricted to the selected residues based on secondary structure", false );
225  NEW_OPT( iterative::force_scored_region, "as scored_ss_core, but residues for scoring are provided manually", "" );
226 
227  NEW_OPT( iterative::cluster, "cluster archive with min_diversity_limit before each batch creation", false );
228 
229  NEW_OPT( iterative::fix_core, "RIGID file for RigidChunkClaimer to fix residues in stage 1-3", "" );
230 
231  NEW_OPT( iterative::cenpool_noesy_cst_weight, "weight to apply to centroid pool for noesy-autoassigned constraints", 1);
232  NEW_OPT( iterative::cenpool_chemicalshift_weight, "weight to apply to chemical shifts in centroid pool rescoring", 5 );
233  NEW_OPT( iterative::chemicalshift_column, "column name of the ChemicalShiftEvaluator used for chemical shift rescoring -- allows to have inactive shifts in score", "chem_shift" );
234  NEW_OPT( iterative::super_quick_relax_protocol, "provide a sequence file for super quick relax ", "none" );
235  NEW_OPT( iterative::super_quick_relax_patch, "provide a patch file for use during super quick relax ", "none" );
236  NEW_OPT( iterative::centroid_before_quickrelax_weight, "add the centroid score of the decoy before it went into the <super_quick_relax> with this weight " , 1.0 );
237  NEW_OPT( iterative::fullatom_after_quickrelax_weight, "add the centroid score of the decoy before it went into the <super_quick_relax> with this weight " , 0.0 );
238  NEW_OPT( iterative::limit_decoys_for_noe_assign, "only use X first decoys for NOE assigment... ", 30 );
239  NEW_OPT( iterative::centroid_quickrelax, "run a quick relax on centroid structures... ", false );
240  NEW_OPT( iterative::skip_redundant_constraints, "skip constranits that have similar constraints within 1=same residue 2=neighbours (0=inactive)", 0 );
241 
242  NEW_OPT( iterative::delay_noesy_reassign, "start reassigning NOE restraints after X structures have been generated", 500 );
243  NEW_OPT( iterative::initial_noe_auto_assign_csts, "initial nopool assignment of NOESY data.... ", "../initial_assignment/noe_auto_assign.cst" );
244  NEW_OPT( iterative::auto_assign_scheme,"select CONST, ADAPT1, ... ","CONST");
245  NEW_OPT( iterative::dcut,"in ADAPT1 what dcut should be chosen",7);
246  NEW_OPT( iterative::initial_beta_topology,"start with this file as beta.top in stage3","" );
247  NEW_OPT( iterative::force_topology_resampling,"if strand-fraction is low topology sampling is usually skipped. Override this with this flags", false );
248  NEW_OPT( iterative::recompute_beta_Naccept, "recompute beta-topology after minimum of Naccept structures -- if no initial_beta_topology always recompute", 2000 );
249  NEW_OPT( iterative::flags_fullatom, "point to flag-file to read flags for fullatom-refinement and loop-closing specify e.g., as ../flags_fullatom ","");
250  NEW_OPT( iterative::normalize::sampling,
251  "dynamically determined score-variation will be used for patching the sampling stage scores", false );
252  NEW_OPT( iterative::update_noesy_filter_cst, "update noesy filter restraints (used for pool selection) as often as possible", false );
253  NEW_OPT( iterative::never_update_noesy_filter_cst, "never update noesy filter restraints (used for pool selection) not even once for fullatom stage", false );
254  NEW_OPT( iterative::refine_auto_noe_flags, "file with extra flags to modify NOESY-Module behavior in refinement phase (stage5+ )", "" );
255 
256  NEW_OPT8( iterative::staged_auto_noe_flags, "files with extra flags for each RASREC stage, say NONE for no option file", "NONE", "NONE", "NONE", "NONE", "NONE", "NONE", "NONE", "NONE" );
257 
258  NEW_OPT( iterative::split_autoNOE_restraints, "split the generated restraints into HI and MED accuracy class and use restraint combination only on the 2nd class", false );
259  NEW_OPT( iterative::randomize_elimination_candidates, "put the elimination candidates into extra restraint file and only randomly activate them", 0 );
260 
261 
262 
263  options_registered_ = true;
264  }
265 }
266 
267 #define OBSOLETE(key) \
268  if ( option[ key ].user() ) { \
269  tr.Warning << "WARNING: Option "<< #key<< " is deprecated!" << std::endl; \
270  }
271 
273  using namespace basic::options;
274  using namespace basic::options::OptionKeys;
275  // if ( option[ iterative::copy_pool_for_convergence_check ].user() ) {
276  // tr.Warning << "WARNING: Option -iterative::copy_pool_for_convergence_check is deprecated!" << std::endl;
277  // }
278  OBSOLETE(iterative::copy_pool_for_convergence_check);
279  OBSOLETE(iterative::fix_core);
280  OBSOLETE(iterative::enumerate::Naccept);
281  OBSOLETE(iterative::min_core_fraction_to_score);
282  OBSOLETE(iterative::force_scored_region);
283  OBSOLETE(iterative::scored_ss_core);
284 
285  OBSOLETE( iterative::perturb_resampling);
286 
287  OBSOLETE( iterative::chainbreak_evaluator_weight);
288 
289  //OBSOLETE( iterative::safety_hatch_scorecut);
290  OBSOLETE( iterative::cluster);
291 
292 
293 //OBSOLETE( iterative::cenpool_chemicalshift_weight);
294 //OBSOLETE( iterative::chemicalshift_column);
295 //OBSOLETE( iterative::super_quick_relax_protocol);
296 //OBSOLETE( iterative::centroid_before_quickrelax_weight);
297 //OBSOLETE( iterative::fullatom_after_quickrelax_weight);
298 //OBSOLETE( iterative::limit_decoys_for_noe_assign);
299 //OBSOLETE( iterative::centroid_quickrelax);
300 
301 //noesy
302 //OBSOLETE( iterative::skip_redundant_constraints);
303 //OBSOLETE( iterative::cenpool_noesy_cst_weight);
304 //OBSOLETE( iterative::delay_noesy_reassign);
305 //OBSOLETE( iterative::initial_noe_auto_assign_csts);
306 //OBSOLETE( iterative::auto_assign_scheme);
307 //OBSOLETE( iterative::dcut);
308 
309 //OBSOLETE( iterative::initial_beta_topology);
310 //OBSOLETE( iterative::force_topology_resampling);
311 //OBSOLETE( iterative::recompute_beta_Naccept);
312 
313 //OBSOLETE( iterative::flags_fullatom);
314 //OBSOLETE( iterative::normalize::sampling);
315 
316 }
317 
318 namespace protocols {
319 namespace abinitio {
320 
321 static numeric::random::RandomGenerator RG(42089); // <- rg needed for CEN2FULLATOM_NON_POOL_DECOYS
322 
323 using namespace jd2::archive;
324 
325 
326 void fix_chainbreak_patch( scoring::ScoreFunctionOP scorefxn, std::string const& patch_name ) {
327  //constraints are done via patches
328  bool chainbreaks_in_patch( scorefxn->get_weight( scoring::linear_chainbreak ) > 0.0 );
329  core::Real extra_chainbreak_weight( basic::options::option[ basic::options::OptionKeys::jumps::increase_chainbreak ] );
330  if ( !chainbreaks_in_patch ) { //if chainbreak is not patched .. set it
331  core::Real lin_wgt( 4.0/3.0 * extra_chainbreak_weight );
332  core::Real overlap_wgt( 1.0 * extra_chainbreak_weight );
333  core::Real quad_wgt( 1.0 * extra_chainbreak_weight );
334  tr.Info << "no chainbreaks specified in " << patch_name << ",..."
335  << " set chainbreaks to " << lin_wgt << " and "
336  << overlap_wgt <<" for linear- and overlap-chainbreak, respectively" << std::endl;
337  scorefxn->set_weight( scoring::chainbreak, quad_wgt );
338  scorefxn->set_weight( scoring::linear_chainbreak, lin_wgt );
339  scorefxn->set_weight( scoring::overlap_chainbreak, overlap_wgt );
340  }
341 }
342 
344  /// determine if we have enough strands to do jumping...
345  bool bDoBetaJumping(true);
346  using namespace core::fragment;
347  FragSetOP frags_s = FragmentIO( option[ OptionKeys::abinitio::number_3mer_frags ]() ).read_data( option[ in::file::frag3 ] );
348  core::fragment::SecondaryStructure ss_def( *frags_s, true /*no JustUseCentralResidue */ );
349  Size ct_E( 0 );
350  Size ct_H( 0 );
351  for ( Size i=1; i<=ss_def.total_residue(); ++i ) {
352  if ( ss_def.strand_fraction( i ) > 0.7 ) ++ct_E;
353  if ( ss_def.helix_fraction( i ) > 0.7 ) ++ct_H;
354  }
355  mem_tr << "fragments loaded for ss-prediction" << std::endl;
356  //less than 15% strands and less than 40 residues in total and we skip jumping...
357  bDoBetaJumping = true;
358  if ( ct_E < 0.1*ct_H && ct_E < 40 ) {
359  tr.Info << "skip beta-jumping since mostly alpha-helical protein" << std::endl;
360  tr.Info << "only " << (ct_E*1.0)/(ss_def.total_residue()*1.0)*100 << "% of residues display significant strand-character" << std::endl;
361  tr.Info << "whereas " << (ct_H*1.0)/(ss_def.total_residue()*1.0)*100 << "% of residues display significant helix-character" << std::endl;
362  bDoBetaJumping = false;
363  }
364  if ( !bDoBetaJumping && option[ OptionKeys::iterative::force_topology_resampling ]() ) {
365  tr.Info << "force-topology-resampling despite low beta-sheet content due to flag -force_topology_resampling" << std::endl;
366  bDoBetaJumping = true;
367  }
368  return bDoBetaJumping;
369 }
370 
371 
372 IterativeBase::IterativeBase(std::string name_in )
373  : Parent(),
374 
375  stage_( ENUMERATION ),
376  finish_stage_( LAST_CENTROID_START ),
377  first_batch_this_stage_ ( 1 ),
378  first_fullatom_batch_( 100000 ),
379  // min_structures_for_accept_statistics_( 500 ),
380 
381  bEnumeratedLastTime_( false ),
382 
383  last_accepted_decoys_in_idle_( 0 ),
384 
385  reference_pose_( NULL ),
386 
387  cen_score_( option[ iterative::cen_score ]() ),
388  cen_score_patch_( option[ iterative::cen_score_patch ]() ),
389 
390  fa_score_( option[ iterative::fa_score ]() ),
391  fa_score_patch_( option[ iterative::fa_score_patch ]() ),
392  noesy_assign_float_cycle_( 1.0 ), //changed OCT 20th 2010 ... start only in generation 3 of STAGE2_RESAMPLE with cyana-cycle 2
393  first_noesy_cst_file_( "n/a" ),
394  first_noesy_fa_cst_file_ ("n/a" ),
395  current_noesy_sampling_file_( "n/a" ),
396  bCombineNoesyCst_( true ),
397  super_quick_relax_of_centroids_( option[ iterative::centroid_quickrelax ]() ),
398  use_dynamic_weights_for_sampling_( option[ iterative::normalize::sampling ]() ),
399  delay_noesy_reassign_( option[ iterative::delay_noesy_reassign ]() ),
400  rdc_data_( NULL ),
401  cst_data_( NULL ),
402  cst_fa_data_( NULL ),
403  vanilla_options_( basic::options::option )
404 {
407  basic::show_time_on_cerr = true;
408 
409  using namespace ObjexxFCL;
410  mem_tr << "IterativeBase CStor-Start" << std::endl;
411  //changes for debug mode
412  if ( option[ run::test_cycles ] || option[ run::dry_run ] ) {
414  // min_structures_for_accept_statistics_ = 20;
415  }
416 
417  //name is e.g., centroid_pool or fullatom_pool
418  set_name( name_in );
419 
420 // --- setup stage-steering parameters
421  // maximum of sampled structures per stage
422  max_nstruct_list_ = option[ iterative::max_nstruct ]();
423  if ( max_nstruct_list_.size() != ( FINISHED-1 ) ) {
424  throw EXCN_Archive("wrong number "+string_of( max_nstruct_list_.size() )
425  +" of values for max_nstruct -- needs exactly "+string_of( FINISHED - 1 )+" values.");
426  }
427  max_nstruct_list_.push_back( 0 ); //for FINISH_STAGE
428 
429  // min cluster radius for diversification
430  min_diversity_list_ = option[ iterative::min_diversity ]();
431  if ( min_diversity_list_.size() != ( FINISHED-1 ) ) {
432  throw EXCN_Archive("wrong number "+string_of( min_diversity_list_.size() )
433  +" of values for min_diversity -- needs exactly "+string_of( FINISHED - 1 )+" values.");
434  }
435  min_diversity_list_.push_back( 0 ); //for FINISH_STAGE
436 
437  // accept ratio to end stage
438  target_accept_ratio_ = option[ iterative::accept_ratio ]();
439  if ( target_accept_ratio_.size() != ( FINISHED-1 ) ) {
440  throw EXCN_Archive("wrong number "+string_of( target_accept_ratio_.size() )
441  +" of values for accept_ratio -- needs exactly "+string_of( FINISHED - 1 )+" values.");
442  }
443  target_accept_ratio_.push_back( 1 ); //for FINISH_STAGE
444 
445  /// -- setup native pose
446  if ( option[ in::file::native ].user() ) {
447  core::pose::PoseOP native_pose = new core::pose::Pose;
448  core::import_pose::pose_from_pdb( *native_pose, option[ in::file::native ]() );
449  reference_pose_ = native_pose;
450  mem_tr << "setup native pose" << std::endl;
451  }
452 
453  /// --- setup sequence
454  if ( option[ in::file::fasta ].user() ) {
455  target_sequence_ = core::sequence::read_fasta_file( option[ in::file::fasta ]()[1] )[1]->sequence();
456  if ( reference_pose_ ) {
457  if ( reference_pose_->sequence()!=target_sequence_ ) {
458  std::string msg("target sequence and sequence of native pose -in:file:native are inconsistent! ");
459  msg+="\nNATIVE: "+reference_pose_->sequence();
460  msg+="\nFASTA : "+target_sequence_;
461  utility_exit_with_message(msg);
462  }
463  }
464  } else {
465  if ( reference_pose_ ) {
466  target_sequence_ = reference_pose_->sequence();
467  } else {
468  throw EXCN_Archive("need either fasta-sequence (-in:file:fasta) or native structure ( -in:file:native )");
469  }
470  }
471 
472  if ( tr.Trace.visible() ) {
473  if ( reference_pose_ ) reference_pose_->dump_pdb("reference_pose_in_IterativeBase.pdb");
474  tr.Trace << "target_sequence_:\n " << target_sequence_ << std::endl;
475  }
476 }
477 
480  // --- setup scorefxn
483  tr.Info << "create Archive Scorefunction with: "
484  << option[ iterative::cen_score]() << " "
485  << option[ iterative::cen_score_patch ]() << std::endl;
486 
487  mem_tr << "setup cen-scorefxn" << std::endl;
488 
489  //manually set the chainbreaks if user has forgotten to specify them ...
490  fix_chainbreak_patch( scorefxn, cen_score_patch() );
491 
492  set_scorefxn( scorefxn );
494  set_weight( "atom_pair_constraint", 0 ); //this is now done via FILTER mechanism of ConstraintClaimer only !
495  scorefxn->set_weight( scoring::atom_pair_constraint, 0 );
496 
497  // --- setup pool-evaluation
498  if ( evaluate_local() ) {
499  set_weight( "score", 1.0 );
500  //setup constraint-evaluation for filter-cst from the ConstraintClaimers ( -broker:setup )
501  ///@brief set scorefxn used for evaluation
503  // set_weight( "prefa_clean_score3", option[ iterative::centroid_before_quickrelax_weight ]() );
504  add_evaluation( new simple_filters::RDC_Evaluator("rdc"), scorefxn->get_weight( scoring::rdc ) );
505  scorefxn->set_weight( scoring::rdc, 0 );
506  } else {
507  set_weight( "score", 0.0 ); //don't use score that comes back --- but the score_final thing
508  set_weight( "score_final", 1.0 );
509  set_weight( "rdc_filt", scorefxn->get_weight( scoring::rdc ) );
510  scorefxn->set_weight( scoring::rdc, 0 );
511  }
512  set_scorefxn( scorefxn );
513  //will setup autoNOE module if cmd-line options activated -- might set super_quick_relax_of_centroids_ to true.
514  setup_autoNOE();
515 
516  // setup chemical shift rescoring -- this is done on worker side, here we pick up the column and give it a weight
517  if ( option[ iterative::cenpool_chemicalshift_weight ].user() ) {
518  chemshift_column_ = option[ iterative::chemicalshift_column ]();
519  set_weight( option[ iterative::chemicalshift_column ](), option[ iterative::cenpool_chemicalshift_weight ]() );
521  }
522 
524  if ( !bDoBetaJumping_ ) {
526  }
527 
528  //if we use super-quick-relax mode setup appropriate score-evaluation
529  //and put a 0-Scorefunction into the Archive (as the scores are computed on worker side)
530  //keep this at end of constructor since other setup-routines can change this boolean value
532  set_weight( "prefa_clean_score3", option[ iterative::centroid_before_quickrelax_weight ]() );
533  set_weight( "score_fa", option[ iterative::fullatom_after_quickrelax_weight ]() );
534 
535  // --- setup scorefxn a NULL scorefxn since we cannot evaluate a centroid score anymore (could do that by changing residue_type_set...)
537  set_scorefxn( scorefxn );
538  set_weight( "score", 0 );
539  }
540 
541  //start stage-end controller
543  mem_tr << "IterativeBase CStor-End" << std::endl;
544 }
545 
547 
548 ///@details ready for new batch .... if queue is empty batch will be generated any way, but otherwise we only generate if this yields true.
549 /// logic here: new batch at beginning, but only if we are in startup phase ( not a reload of a full archive )
550 /// otherwise make new batch if sufficiently many structures have been accepted since last batch
551 // bool IterativeBase::ready_for_batch() const {
552 // if ( !bStartedInitBatch_ && decoys().size() <= nstruct() ) return true;
553 // if ( decoys().size() >= nstruct() && accepts_since_last_batch() > nstruct_accept_before_rerun_ && proposed_since_last_batch() > min_structures_for_accept_statistics_ ) return true;
554 // return false;
555 // }
556 
559  basic::show_time( tr, "compute_cores/rescore: start..." );
561  compute_cores();
562  rescore();
563  basic::show_time( tr, "compute_cores/rescore: done..." );
564  //if we take out the compute_cores() we should still trigger a rescore() to get the new score-variations...
565  }
566 
567  using namespace basic::options;
568  using namespace basic::options::OptionKeys;
569 
570  //if we are in remote-evaluation mode we want to switch the noesy-filter restraints once after stage3
571  if ( !evaluate_local()
572  && option[ iterative::update_noesy_filter_cst ]()
576  && decoys().begin() != decoys().end()
577  ) {
578  basic::show_time( tr, "non-local scoring replace noesy_filter constraints: start..." );
581  basic::show_time( tr, "non-local scoring replace noesy_filter constraints: done! ");
582  }
583 }
584 /// ----------------- stage control ----------------------
585 // ---> outsource to extra class ? --- might be reused by other protocols
586 ///@brief batch is expired ?
587 bool IterativeBase::still_interested( Batch const& batch ) const {
588  return Parent::still_interested( batch ) && batch.id() >= first_batch_this_stage_;
589 }
590 
591 //after reading new structures we test for energy-saturation
593  basic::show_time( tr, "read structures into "+name()+"..." );
594  Parent::read_structures( sfd, batch );
596  basic::show_time( tr, "done reading into "+name() );
597 }
598 
599 ///@brief are we ready to switch to next stage ?
601  //switch to next stage ? want to have some significance to this ratio --- hence at least 1000 proposals
602  tr.Info << "current accept ratio: " << current_acceptance_ratio() << " this is "
603  << ( current_acceptance_ratio() < target_accept_ratio() ? "" : "not" )
604  << " lower than " << target_accept_ratio()
605  << "\n"
606  << proposed_since_last_batch() << " proposed decoys since last batch "
607  << std::endl;
608 
609  int last_stage_N( 0 );
610  if ( stage_ > 1 ) last_stage_N = max_nstruct_list_[ stage_ - 1 ];
611  if ( max_nstruct_list_[ stage_ ] && ( (int) total_proposed() - last_stage_N ) > max_nstruct_list_[ stage_ ] ) {
612  tr.Info << "maximum number of " << max_nstruct_list_[ stage_ ]
613  << " decoys for stage " << stage_ << " is reached...switching!" << std::endl;
614  increment_stage();
615  }
616 
618  increment_stage();
619  }
620 }
621 
622 ///@brief got to next stage
624  if ( stage_ >= finish_stage_ ) return;
625  save_to_file( "_stage" + ObjexxFCL::string_of( stage_ ) );
626 
627  //save current number of structures:
628  max_nstruct_list_[ stage_ ] = total_proposed(); //used in test_for_stage_end to no how-many new structures since last stage
629 
630  //switch to next possible stage
631  stage_ = IterationStage( 1 + (int) stage_ );
632  while ( (( max_nstruct_list_[ stage_ ] < 0 ) || ( !bDoBetaJumping_ && stage_ == NOESY_PHASEII_TOPO )) && stage_ < finish_stage_ ) {
633  stage_ = IterationStage( 1 + (int) stage_ );
634  }
635  if ( !manager_ptr() ) {
636  tr.Info << "start with stage " << stage_ << std::endl;
637  return;
638  }
639  tr.Info << "manager_ptr() " << manager_ptr() << " logical " << !manager_ptr() << std::endl;
640  tr.Info << "switched to stage: " << stage_ << std::endl;
641 
642  //safe status and reset counters
644  save_to_file();
646  manager().cancel_batches_previous_to( manager().last_batch_id(), true /*allow reading of decoys already in production*/ );
647 
648  //if we are not doing enumeration anymore we don't need fragments.
649  using namespace core::fragment;
650  if ( stage_ >= PURE_TOPO_RESAMPLING ) FragmentIO().clean_frag_cache();
651 
652 }
653 
654 /// ------------------------ end stage control
655 ///@detail rescore and sort archive
657  Parent::rescore();
658  if ( hedge_archive_ ) {
659  hedge_archive_->set_evaluators( evaluators(), weights() );
660  hedge_archive_->set_weights( weights() );
661  hedge_archive_->set_scorefxn( scorefxn().clone() );
662  hedge_archive_->rescore();
663  }
664 }
665 
666 
668  if ( !evaluate_local() ) return;
669  if ( !hedge_archive_ ) {
670  hedge_archive_ = new HedgeArchive( name()+"_hedge" );
671  hedge_archive_->initialize();
672  hedge_archive_->set_evaluators( evaluators(), weights() );
673  }
674  hedge_archive_->add_evaluated_structure( evaluated_decoy, batch );
675 }
676 
677 ///@brief overload to check for pool_convergence data in incoming decoys
679  core::io::silent::SilentStructOP evaluated_decoy = evaluate_silent_struct( from_batch );
680  if ( decoys().size() == 0 ) {
681  first_batch_this_stage_ = batch.id();
682  }
683 
684  if ( stage_ < CEN2FULLATOM || ( stage_ == CEN2FULLATOM && batch.id() < first_batch_this_stage_ ) ) {
685  select_score( evaluated_decoy ); //make sure that _archive_select_score_ is there
686  collect_hedge_structures( evaluated_decoy, batch );
687  }
688  //comes without pool-convergence ? nothing to do
689  if ( !from_batch->has_energy( "pool_converged_tag" ) || min_diversity_list_[ stage() ] == 0 ) {
690  return Parent::add_evaluated_structure( evaluated_decoy, batch );
691  }
692 
693  //okay, let's look at the rmsd to closest structure
694  runtime_assert( from_batch->has_energy( "pool_converged_rmsd" ) );
695  Real const rmsd_to_pool( from_batch->get_energy( "pool_converged_rmsd" ) );
696 
697  if ( rmsd_to_pool > min_diversity_list_[ stage() ] ) { //structure is sufficiently different -- add via score
698  return Parent::add_evaluated_structure( evaluated_decoy, batch );
699  } else { //structure is close in RMSD to one of archive
700  std::string const tag( from_batch->get_string_value( "pool_converged_tag" ) );
701 
702  //find the pool-structure that is redundant with new decoy
703  SilentStructs::iterator it;
704  for ( it = decoys().begin(); it != decoys().end(); ++it ) {
705  if ( (*it)->decoy_tag() == tag ) break;
706  }
707 
708  if ( it == decoys().end() ) {
709  //can't find tag ... (might be that we are close to a centroid structure and now add to fullatom pool ).
710  // might be that we have swapped away the original structure
711  return Parent::add_evaluated_structure( evaluated_decoy, batch );
712  }
713 
714  //improved score ?
715  if ( it != decoys().end() ) {
716  core::Real const new_score=select_score( evaluated_decoy );
717  core::Real const old_score=select_score( *it );
718  core::Real const check_score=(*it)->get_energy( "_archive_select_score_" );
719  if ( new_score < old_score ) {
720  core::Real const min_score=select_score( decoys().front() );
721  core::Real const max_score=select_score( decoys().back() );
722  core::Real const delta_max=max_score-min_score;
723  core::Real const delta_score=new_score-old_score;
724  tr.Debug << "swap " << evaluated_decoy->decoy_tag() << " for " << (*it)->decoy_tag()
725  << " new-score " << new_score << " check: " << check_score
726  << " score-improvement: " << delta_score
727  << " at spread of " << delta_max
728  << " ratio " << delta_score/delta_max << std::endl;
729  if ( delta_score/delta_max < -0.05 ) {
730  decoys().erase( it );
731  return Parent::add_evaluated_structure( evaluated_decoy, batch );
732  } else {
733  tr.Debug << "swap declined because score-improvement below 5% of total spread" << std::endl;
734  return false;
735  }
736  } // new_score < old_score
737  }//improve score block
738 
739  tr.Trace << "decoy " << evaluated_decoy->decoy_tag() << " with original tag " << evaluated_decoy->get_comment( "tag_in_file" )
740  << " declined because of min_diversity: rmsd is " << rmsd_to_pool
741  << " limit: " << min_diversity_list_[ stage() ]
742  << std::endl;
743 
744  return false; //declined ... either tag not found or score not improved...
745  }
746  return false; //should never get here
747 }
748 
749 
750 
751 ///@details generate new batch...
752 /// type of batch depends on stage_. we switch to next stage based on some convergence criteria:
753 /// right now it is how many decoys were accepted from last batch.. if this number drops sufficiently ---> next stage...
754 /// (maybe need to put a safeguard in here: ratio small but at least XXX decoys proposed since last batch... )
755 ///
757  //OBSOLET cluster();
758  basic::show_time( tr, "generate_batch" );
759  //initialize batch
760  mem_tr << "IterativeBase::start_new_batch " << std::endl;
761  {
762  Batch& batch( manager().start_new_batch() );
763  mem_tr << "IterativeBase::generate_batch " << stage_ << " " << batch.batch() << std::endl;
764  tr.Info << "\ngenerate batch from " <<name() << " " << batch.batch() << std::endl;
765 
766  //want intermediate structures from abinitio runs
767  batch.set_intermediate_structs();
768 
769  // --- run some of the gen_X methods to generate the type of run we want
770  gen_noe_assignments( batch );
771 
772  // first 2 stages: enumerate pairings
773  if ( (int) stage_ < (int) PURE_TOPO_RESAMPLING ) gen_enumerate_pairings( batch );
774 
775  // beta-sheet-topologies
776  if ( stage_ == TOPO_RESAMPLING || stage_ == PURE_TOPO_RESAMPLING || stage_ == NOESY_PHASEII_TOPO ) gen_resample_topologies( batch );
777 
778  // reuse fragments and restart from stage2 structures
780  gen_resample_stage2( batch );
781  }
782 
783  if ( stage_ >= STAGE2_RESAMPLING ) {
784  gen_resample_fragments( batch );
785  }
786 
787  bool result_is_fullatom = false;
788  // close loops - fullatom relax
789  if ( stage_ == CEN2FULLATOM ) {
790  gen_cen2fullatom( batch );
791  // gen_resample_fragments( batch );
792  batch.set_intermediate_structs( false ); //otherwise the intermediate (centroid) structures will be scored by score_13_envhb
793  result_is_fullatom = true;
794  }
795  mem_tr.Debug << "before evaluation output" << std::endl;
796  //finalize batch
797  gen_evaluation_output( batch, result_is_fullatom );
798  gen_dynamic_patches( batch );
799  mem_tr.Debug << "evaluation output" << std::endl;
800 
801  basic::show_time( tr, "finalize batch..." );
802  test_broker_settings( batch );
803  manager().finalize_batch( batch );
804  basic::show_time( tr, "finalized batch" );
805 
806  tr.Info << std::endl;
807  // don't want to reset counters too often... if we run out of steam the QUEUE EMPTY pathway will make sure that we do more runs
808 
809  mem_tr << "IterativeBase::generated_batch " << std::endl;
810  //now it is best time to do this... JobQueue is definitely filled up....
811  reassign_noesy_data( batch );
812  }
813  //add extra batch if we have "safety_hatch"
814  ///SWITCHED THIS OFF TEMPORARILY !!!
815  // std::cerr << "saftey hatch is switched off due to maintainence reasons" << std::endl;
816  if ( stage_ == CEN2FULLATOM && option [ iterative::safety_hatch_scorecut ].user() ) {
817  basic::show_time( tr, "generate safety_hatch" );
818  mem_tr.Debug << "make safety hatch..." << std::endl;
819  Batch& harvest_batch( manager().start_new_batch() );
820  tr.Info << "starting harvest batch at same time as normal cen2fullatom batch" << std::endl;
821  gen_cen2fullatom_non_pool_decoys( harvest_batch );
822 
823  // add NOESY autoassign constraints
824  gen_noe_assignments( harvest_batch );
825 
826  harvest_batch.set_intermediate_structs( false ); //otherwise the intermediate (centroid) structures will be scored by score_13_envhb
827  gen_evaluation_output( harvest_batch, true /*fullatom*/ );
828  gen_dynamic_patches( harvest_batch );
829  basic::show_time( tr, "finalize safety_hatch... ");
830  test_broker_settings( harvest_batch );
831  manager().finalize_batch( harvest_batch );
832  basic::show_time( tr, "finalized safety_hatch" );
833  }
834 }
835 
836 /// ============================================================================
837 /// ----------- methods to make new batches ------------
838 /// ----- each method should only "append" to broker and flags -----
839 /// ============================================================================
840 
841 
842 void IterativeBase::do_dynamic_patching( jd2::archive::Batch& batch, utility::io::ozstream& flags, std::string score, utility::options::FileVectorOptionKey const& key ) const {
843  if ( ! option[ key ].user() ) return; //if this wasn't patched it doesn't require dynamic balancing...
844 
845  core::Real var_score(0); //can't change score so keep this as reference
846  if ( get_weight("score")>0.001 ) {
847  var_score = score_variation("score");
848  } else if ( get_weight("prefa_clean_score3") > 0.001 ) {
849  var_score = score_variation("prefa_clean_score3");
850  } else {
851  runtime_assert(false); //should find either score or prefa_clean_score3
852  }
853 
854  typedef std::map< scoring::ScoreType, std::string > ScoreTypeMap;
855  ScoreTypeMap dynamic_scores;
856  dynamic_scores[ scoring::rdc ] ="rdc";
857  dynamic_scores[ scoring::atom_pair_constraint ] ="atom_pair_constraint";
858 
859  //get patched scorefxn
861  std::ostringstream patches;
862  bool have_patch( false );
863  for ( ScoreTypeMap::const_iterator it = dynamic_scores.begin(); it != dynamic_scores.end(); ++it ) {
864  if ( scorefxn->get_weight( it->first ) > 0.00001 ) {
865  core::Real var_rel;
866  if ( it->second == "atom_pair_constraint" ) {
867  core::Real var_sum( 0 ); core::Size ct_cst( 0 );
868  WeightMap const& variations( score_variations() );
869  for ( WeightMap::const_iterator vit = variations.begin(); vit != variations.end(); ++vit ) {
870  if ( vit->first.find( "filter_cst" ) != std::string::npos ) {
871  var_sum += vit->second;
872  ++ct_cst;
873  }
874  }
875  runtime_assert( ct_cst );
876  var_sum /= ct_cst;
877  var_rel=var_sum/var_score;
878  } else { //not a atom_pair_constraint
879  var_rel=score_variation( it->second );
880  var_rel/=var_score;
881  }
882  core::Real patch = scorefxn->get_weight( it->first )/var_rel;
883  patches << it->second << " = " << patch << std::endl;
884  have_patch = true;
885  } //has positive weight in patched scorefunction
886  }
887  if ( have_patch ) {
888  std::string patch_file ( batch.dir()+"/dynamic_abinitio_"+score+".patch" );
889  utility::io::ozstream patch_fd( patch_file );
890  patch_fd << patches.str() << std::endl;
891  tr.Info << "dynamic patching: write to flag-file " << key.id() << " " << patch_file << std::endl;
892  flags << "-" << key.id() << " " << patch_file << std::endl;
893  // std::cerr << "dynamic patching for " << key.id() << std::endl;
894  }
895 }
896 
898  if ( !use_dynamic_weights_for_sampling_ ) return;
899 
900  utility::io::ozstream flags( batch.flag_file(), std::ios::app );
901  do_dynamic_patching( batch, flags, "score0", OptionKeys::abinitio::stage1_patch );
902  do_dynamic_patching( batch, flags, "score1", OptionKeys::abinitio::stage2_patch );
903  do_dynamic_patching( batch, flags, "score2", OptionKeys::abinitio::stage3a_patch );
904  do_dynamic_patching( batch, flags, "score5", OptionKeys::abinitio::stage3b_patch );
905  do_dynamic_patching( batch, flags, "score3", OptionKeys::abinitio::stage4_patch );
906  do_dynamic_patching( batch, flags, "score12", OptionKeys::score::patch );
907 }
908 
909 
910 void IterativeBase::gen_evaluation_output( Batch& batch, bool fullatom ) {
911  tr.Info << "gen_evaluation_output in " << name() << std::endl;
912  utility::io::ozstream flags( batch.flag_file(), std::ios::app );
913  flags << "-evaluation:jump_nr" << std::endl; //add JumpNrEvaluator
914 
915  //add score evaluator
916  if ( !fullatom && !super_quick_relax_of_centroids_ ) { //centroid
917  // the standard 'score_final' score column
918  flags << "-evaluation:extra_score " << option[ iterative::cen_score]() << std::endl
919  << "-evaluation:extra_score_column _final" << std::endl;
920  flags << "-evaluation:extra_score_patch " << option[ iterative::cen_score_patch ]() << std::endl;
921  } else { //fullatom
923  //obtain 'empty' score for 'score_final' and put normal fullatom score into 'score_fa'
924  flags << "-evaluation:extra_score " << "empty " << option[ iterative::fa_score]() << std::endl
925  << "-evaluation:extra_score_column _final _fa" << std::endl;
926  flags << "-evaluation:extra_score_patch " << option[ iterative::fa_score_patch ]() << " NOPATCH " << std::endl;
927  } else {
928  //score-final standard fullatom mode
929  flags << "-evaluation:extra_score " << option[ iterative::fa_score]() << std::endl
930  << "-evaluation:extra_score_column _final" << std::endl;
931  flags << "-evaluation:extra_score_patch " << option[ iterative::fa_score_patch ]() << std::endl;
932  }
933  }
934  flags << "-evaluation:built_in_rdc rdc_filt" << std::endl;
935 
936  //setup relax sequence protocol for super-quick relax
938  if ( !fullatom ) {
939  if ( option[ iterative::super_quick_relax_protocol ].user() ) {
940  flags<< "-relax:sequence_file " << option[ iterative::super_quick_relax_protocol ]() << std::endl;
941  } else {
942  utility::io::ozstream sequence_file( batch.dir()+"/super_quick_relax.txt" );
943  sequence_file << "ramp_repack_min 0.02 0.01" << std::endl;
944  sequence_file << "ramp_repack_min 0.250 0.01" << std::endl;
945  sequence_file << "ramp_repack_min 0.550 0.01" << std::endl;
946  sequence_file << "ramp_repack_min 1 0.00001" << std::endl;
947  sequence_file << "accept_to_best" << std::endl;
948  flags << "-relax:sequence_file " << batch.dir()+"/super_quick_relax.txt" << std::endl;
949  }
950  flags << "-relax:sequence" << std::endl;
951  flags << "-out:user_tag centroid" << std::endl;
952  // utility::io::ozstream patch_file( batch.dir()+"/super_quick_relax.patch" );
953  // patch_file << "atom_pair_constraint = 0.1" << std::endl;
954  // patch_file << "rdc = 0.1" << std::endl;
955  if ( option[ iterative::super_quick_relax_patch ].user() ) {
956  flags << "-score:patch " << option[ iterative::super_quick_relax_patch ]() << std::endl;
957  }
958  } else { //!fullatom
959  flags << "-out:user_tag fullatom" << std::endl;
960  }
961  } //end super-quick relax
962 
963  //NOESY FILTER Restraints
966 
967  flags << "-evaluation::constraints " << ( fullatom ? first_noesy_fa_cst_file_ : first_noesy_cst_file_ ) << std::endl;
968  flags << "-evaluation::constraints_column " << ( evaluate_local() ? "noesy_autoassign_cst_worker" : "noesy_autoassign_cst" ) << std::endl;
969  }
970 
971  //compute pool_convergence_XXX ?
972  if ( min_diversity_list_[ stage() ] > 0 ) {
973  gen_diversity_pool( batch, fullatom );
974  } //setup of min-divergence pool
975 } //gen_evaluation
976 
977 
979 
980  utility::io::ozstream flags( batch.flag_file(), std::ios::app );
981 
982  //copy pool to '<batch>/pool.in'
984  for ( SilentStructs::const_iterator it = decoys().begin(); it != decoys().end(); ++it ) {
985  sfd.add_structure( *it ); //not a copy, only adds OP to sfd
986  }
987  sfd.write_all( batch.dir()+"/pool.in" );
988 
989  //empty pool -- write empty file for score-column consistency
990  if ( sfd.size() == 0 ) {
991  // write a pool anyway so that we have the tags in the returning structures and don't mess
992  // up the columns in the pool decoys.out file... not crucial but makes post-analysis with scripts easier.
993  utility::io::ozstream empty_pool_file( batch.dir()+"/pool.in" );
994  empty_pool_file << "REMARK no structure in pool " << std::endl;
995  }
996 
997  //setup flags for min-divergence-pool: ----------------
998 
999  //common flags
1000  flags << "-mc:known_structures " << batch.dir() << "/pool.in" << std::endl;
1001  flags << "-mc:max_rmsd_against_known_structures " << std::max( 0.0, min_diversity_list_[ stage() ] - 0.25 ) << std::endl;
1002 
1003  //exclude residues from RMSD that are flexible anyhow
1004  if ( basic::options::option[ basic::options::OptionKeys::in::replonly_residues ].user() ) {
1005  flags << "-mc:excluded_residues_from_rmsd ";
1006  utility::vector1<Size> replonly_rsd = basic::options::option[ basic::options::OptionKeys::in::replonly_residues ]();
1007  for ( utility::vector1<Size>::const_iterator it = replonly_rsd.begin(); it != replonly_rsd.end(); ++it ) {
1008  flags << " "<< *it;
1009  }
1010  flags << std::endl;
1011  }
1012 }
1013 ///@brief in the comp. modelling protocol the topo-resampling stage might also contain a RigidChunkClaimer...
1014 /// provide start-structures for this as -in:file:silent
1016  // OBSOLETE
1017 // batch.set_has_silent_in();
1018 // io::silent::SilentFileData sfd;
1019 // for ( SilentStructs::const_iterator it = decoys().begin(); it != decoys().end(); ++it ) {
1020 // sfd.add_structure( *it ); //not a copy, only adds OP to sfd
1021 // }
1022 // sfd.write_all( batch.silent_in() );
1023 
1024 // utility::io::ozstream broker( batch.broker_file(), std::ios::app );
1025 // broker << "\nUSE_INPUT_POSE\n" << std::endl;
1026 // broker << "CLAIMER RigidChunkClaimer" << std::endl
1027 // << "REGION_FILE " << option[ iterative::fix_core ]() << std::endl
1028 // << "END_CLAIMER" << std::endl;
1029 
1030 // //compute nstruct such that we get the usual amount of total structures
1031 // batch.nstruct() = std::max( 1, int( 1.0*batch.nstruct() / ( 1.0*decoys().size() ) ) );
1032 }
1033 
1034 //creation of the random-ss samplign stage
1036 
1037  //after Naccept accepted structures stop doing the enumerated pairing.
1038  //sounds OBSOLETE TO ME: if ( (int) total_accepts() > option[ iterative::enumerate::Naccept ]() ) return;
1039 
1040  //skip every second time (standard setting in flag-lib: Apr 2012)
1041  if ( option[ iterative::enumerate::skip_half ]() && bEnumeratedLastTime_ ) {
1042  bEnumeratedLastTime_ = false;
1043  return;
1044  }
1045  bEnumeratedLastTime_ = true;
1046 
1047  tr.Info << "enumerate pairings\n ";
1048  utility::io::ozstream broker( batch.broker_file(), std::ios::app );
1049  runtime_assert( broker.good() );
1050 
1051  //look for an explicit broker file for enumeration stage...
1052  if ( option[ iterative::enumerate::broker ].user() ) {
1053  utility::io::izstream enum_broker( option[ iterative::enumerate::broker ]() );
1054  if ( !enum_broker.good() ) throw ( utility::excn::EXCN_FileNotFound
1055  ( "-iterative::enumerate::broker: File "
1056  +std::string( option[ iterative::enumerate::broker ]())+" not found! ") );
1057  std::string line;
1058  while ( getline( enum_broker, line ) ) broker << line << std::endl;
1059  } else {
1060  //no explicit enumerate file is given -- generate enumeration automatically from ss-content of fragments
1061  std::string frag_ss_file( batch.dir() + "psipred_ss2.dat" );
1062  std::string pairings_file( batch.dir() + "pairings_guess.dat" );
1063 
1064  using namespace core::fragment;
1065  FragSetOP frags_s = FragmentIO(
1066  option[ OptionKeys::abinitio::number_3mer_frags ]()
1067  ).read_data( option[ in::file::frag3 ] );
1068  guess_pairings_from_secondary_structure( *frags_s, pairings_file, frag_ss_file );
1069  broker << "CLAIMER TemplateJumpClaimer\n"
1070  << "RANDOM_SHEETS 2\n"
1071  << "SS_INFO " << frag_ss_file << "\n"
1072  << "PAIRING_FILE " << pairings_file << "\n"
1073  << "END_CLAIMER" << std::endl;
1074  } //else (not enumerate::broker)
1075 }
1076 
1077 ///@brief figure out beta-sheet topologies from pooled decoys and run with jumping
1079  if ( !bDoBetaJumping_ ) return;
1080  tr.Info << "resample topologies\n";
1081 
1082 
1083  utility::io::ozstream broker( batch.broker_file(), std::ios::app );
1084  broker << "\nCLAIMER TemplateJumpClaimer \n"
1085  << "NO_USE_INPUT_POSE\n"
1086  << "topol_file "<< batch.dir() << "beta.top\n"
1087  << "END_CLAIMER\n\n" << std::endl;
1088  broker.close();
1089 
1090  //read beta-topology from start file -fix_topol --- use this file for first recompute_beta_Naccept decoys
1091  if ( option[ iterative::initial_beta_topology ].user() &&
1092  (int) total_accepts() < option[ iterative::recompute_beta_Naccept ]() ) {
1093  //copy file to batch.dir() + "beta.top"
1094  std::string input( option[ iterative::initial_beta_topology ]() );
1095 
1096  utility::io::izstream beta_input( input );
1097  if( beta_input.good() ) {
1098  std::string line;
1099  utility::io::ozstream beta_batch( batch.dir()+"beta.top" );
1100  while ( getline( beta_input, line ) ) beta_batch << line << std::endl;
1101  } else {
1102  utility_exit_with_message("topology_file "+input+" not found. supply file or remove option -iterative::initial_beta_topology");
1103  }
1104  } else { //generate beta-topology from decoys
1106  utility::io::ozstream file( batch.dir() + "beta.top" );
1107  file << *beta_topol << std::endl;
1108  }
1109 }
1110 
1111 ///@brief restart runs from stage2-structures that correspond to those in the pool
1113  tr.Info << "resample_stage2 \n";
1114  mem_tr << "IterativeBase::gen_resample_stage2 start" << std::endl;
1115  SilentStructVector start_decoys;
1116 
1117  //collect to decoys() the corresponding stage2 decoys and store in start_decoys
1118  collect_alternative_decoys( decoys(), "decoys_stage2.out", start_decoys );
1119 
1120 
1121 // typedef std::map< std::string, utility::vector1< std::string > > SourceFiles;
1122 // typedef std::map< std::string, utility::vector1< core::io::silent::SilentStructOP > > AlternativeDecoys;
1123 
1124 // SourceFiles sources;
1125 // AlternativeDecoys alternative_decoys;
1126 // Size ct_in( 0 );
1127 
1128 // //to find the stage2 structures collect first all tags for a specific file
1129 // for ( const_decoy_iterator it = decoys().begin(); it != decoys().end(); ++it ) {
1130 // runtime_assert( (*it)->has_comment( TAG_IN_FILE ) );
1131 // std::string tag( (*it)->get_comment( TAG_IN_FILE ) );
1132 // utility::file::FileName file( (*it)->get_comment( SOURCE_FILE ) );
1133 // std::string stage2_file( file.path()+file.base() + "_stage2." + file.ext() );
1134 
1135 // //creates map <filename> <list of tags>
1136 // sources[ stage2_file ].push_back( tag );
1137 // alternative_decoys[ stage2_file ].push_back( (*it) );
1138 // ++ct_in;
1139 // }
1140 
1141 // //read selected structures from each file
1142 // Size ct_read( 0 );
1143 // io::silent::SilentStructOPs start_decoys;
1144 // for ( SourceFiles::const_iterator it = sources.begin(); it != sources.end(); ++it ) {
1145 // /// it->first is filename, it->second are all tags collected for this file
1146 // io::silent::SilentFileData sfd;
1147 // try { //read structures
1148 // sfd._read_file( it->first, it->second, true /*throw exceptions */ );
1149 // if ( sfd.size() != it->second.size() ) {
1150 // tr.Warning << "[WARNING] multiple decoys with same tag detected in file " << it->first << std::endl;
1151 // }
1152 // copy( sfd.begin(), sfd.end(), std::back_inserter( start_decoys ) );
1153 // ct_read += sfd.size();
1154 // } catch ( utility::excn::EXCN_IO& excn ) { //ERROR
1155 // tr.Warning << "[WARNING] Problem reading silent-file " << it->first << " for " << it->second.size() << " structures " << std::endl;
1156 // excn.show( tr.Warning );
1157 // tr.Warning << std::endl;
1158 // tr.Warning << "use the respective structures in the pool as starting structure instead" << std::endl;
1159 // copy( alternative_decoys[ it->first ].begin(), alternative_decoys[ it->first ].end(), std::back_inserter( start_decoys ) );
1160 // ct_read += alternative_decoys[ it->first ].size();
1161 // }
1162 // }
1163 
1164 // tr.Debug << "structures from pool" << ct_in << " structure retrieved from stage2-files "
1165 // << ct_read << " start structs: " << start_decoys.size() << std::endl;
1166 // if ( start_decoys.size() != decoys().size() ) {
1167 // tr.Warning << "[WARNING] why do we have a different number of decoys in pool and start_decoys ? " << std::endl;
1168 // }
1169 
1170  ///write flags and broker-file
1171  if ( start_decoys.size() ) {
1172  numeric::random::random_permutation( start_decoys, RG ); //permute to get rid of high fluctuation in acceptance rate
1173  batch.set_has_silent_in();
1175  for ( SilentStructVector::const_iterator
1176  it = start_decoys.begin(); it != start_decoys.end(); ++it ) {
1177  sfd.add_structure( **it );
1178  }
1179  sfd.write_all( batch.silent_in() );
1180 
1181  //make broker file for RESTART calculations
1182  utility::io::ozstream broker( batch.broker_file(), std::ios::app );
1183  broker << "\nUSE_INPUT_POSE\n"
1184  << "CLAIMER StartStructClaimer\n"
1185  << "PERTURB " << option[ iterative::perturb_resampling ] << std::endl
1186  << "END_CLAIMER\n\n"
1187  << "CLAIMER JumpClaimer\n"
1188  << "END_CLAIMER\n\n" << std::endl;
1189 
1190  //skip stage 1
1191  utility::io::ozstream flags( batch.flag_file(), std::ios::app );
1192  flags << "-abinitio:skip_stages 1 " << std::endl;
1193  flags << "-out:no_nstruct_label" << std::endl;
1194  flags << "-out:suffix " << "_b" << std::setfill('0') << std::setw(4) << batch.id() << std::endl;
1195  } else {
1196  tr.Warning << "[WARNING] no stage2 decoys found ! " << std::endl;
1197  }
1198 
1199  //compute nstruct such that we get the usual amount of total structures
1200  batch.nstruct() = std::max( 1, int( 1.0*batch.nstruct() / ( 1.0*start_decoys.size() ) ) );
1201  mem_tr << "IterativeBase::gen_resample_stage2 end" << std::endl;
1202 }
1203 
1204 
1206  using namespace core::fragment;
1207  ConstantLengthFragSet frags_9mer( 9 ); //steal good old 9mers
1208  ConstantLengthFragSet frags_3mer( 3 ); //steal good old 9mers
1209  mem_tr << "IterativeBase::gen_resample_fragments start" << std::endl;
1210 
1211  Size ct( 1 );
1212  Size const max_frags( 500 );
1213  if ( option[ iterative::mix_frags ]() ) {
1214  FragSetOP frags_l = FragmentIO(
1215  option[ OptionKeys::abinitio::number_9mer_frags ]()
1216  ).read_data( option[ in::file::frag9 ] );
1217  FragSetOP frags_s = FragmentIO(
1218  option[ OptionKeys::abinitio::number_3mer_frags ]()
1219  ).read_data( option[ in::file::frag3 ] );
1220  frags_9mer.add( *frags_l );//assuming we really have read 9mers and 3mers.
1221  frags_3mer.add( *frags_s );
1222  }
1223  for ( const_decoy_iterator it = decoys().begin(); it != decoys().end() && ct <= max_frags; ++it, ++ct ) {
1224  pose::Pose pose;
1225  std::string tag;// = it->decoy_tag();
1226  (*it)->fill_pose( pose );
1227  steal_constant_length_frag_set_from_pose( pose, frags_9mer );
1228  steal_constant_length_frag_set_from_pose( pose, frags_3mer );
1229  }
1230  std::string file_9mer( batch.dir() + "frags_9mer.dat" ); //using here gzipped files causes weird seg-fault on BG/P
1231  std::string file_3mer( batch.dir() + "frags_3mer.dat" );
1232  FragmentIO().write_data( file_9mer, frags_9mer );
1233  FragmentIO().write_data( file_3mer, frags_3mer );
1234 
1235  utility::io::ozstream flags( batch.flag_file(), std::ios::app );
1236  flags << "-frag3 " << file_3mer << std::endl
1237  << "-frag9 " << file_9mer << std::endl
1238  << "-abinitio:number_3mer_frags 0" << std::endl
1239  << "-abinitio:number_9mer_frags 0" << std::endl;
1240 
1241  mem_tr << "IterativeBase::gen_resample_fragments end" << std::endl;
1242 }
1243 
1245  std::string const& current,
1246  bool fullatom
1247 ) {
1248  current_noesy_sampling_file_ = current;
1249  if ( first_noesy_cst_file_ == "n/a" ) {
1252  } else {
1254  }
1255  }
1256  if ( fullatom && first_noesy_fa_cst_file_ == "n/a" ) {
1257  if ( option[ iterative::never_update_noesy_filter_cst ]() ) {
1259  } else {
1261  }
1262  }
1263  tr.Info << "update_noesy_filter_files for " << name() << std::endl;
1264  tr.Info << "STATUS now: ";
1265  save_status( tr.Info );
1266  tr.Info << std::endl;
1267 }
1268 
1269 //generate ConstraintClaimer files for NOE restraints
1271  tr.Info << "gen_noe_assignments in " << name() << std::endl;
1273  bool bCombine( bCombineNoesyCst_ );
1274  mem_tr << "IterativeBase::gen_noe_assignments start" << std::endl;
1275 
1276  /* OBSOLETED by update_noesy_filter_files
1277  //if just started IterativeFullatom we are in a new instance and the first_noesy_cst_file and
1278  // the current_noesy_sampling_file_ are not set .. go through backward through past batches and take first (i.e., youngest) file.
1279  if ( batch.id() > 1 && stage() > CEN2FULLATOM && first_noesy_cst_file_ == "n/a" ) {
1280  tr.Info << "Figure out current NOESY CST File by going backwards from " << batch.id() << std::endl;
1281  for ( Size back = batch.id() - 1; back >= 1; --back ) {
1282  Batch last_batch( back );
1283  runtime_assert( last_batch.id() < batch.id() );
1284  current_noesy_sampling_file_ = last_batch.dir()+"/"+NOESY_CST_FILE_NAME;
1285  if ( utility::file::file_exists( current_noesy_sampling_file_ ) ) break;
1286  current_noesy_sampling_file_ = option[ iterative::initial_noe_auto_assign_csts ]();
1287  }
1288  // if ( option[ iterative::update_noesy_filter_cst ]() ) {
1289  first_noesy_cst_file_ = current_noesy_sampling_file_+".filter";
1290  first_noesy_fa_cst_file_ = current_noesy_sampling_file_+".filter";
1291  //} else {
1292  //first_noesy_cst_file_ = option[ iterative::initial_noe_auto_assign_csts ]()+".filter";
1293  //first_noesy_fa_cst_file_ = option[ iterative::initial_noe_auto_assign_csts ]()+".filter";
1294  //}
1295  }
1296  */
1297  //
1299  std::string best_cst_file( cst_file + ".good");
1300  std::string cst_centroid_file( cst_file + ".centroid");
1301  std::string best_cst_centroid_file( best_cst_file + ".centroid");
1302 
1303  //make broker files with FULL-ATOM and CENTROID CLaimers
1304  utility::io::ozstream broker( batch.broker_file(), std::ios::app );
1305  bool bSplitted( option[ iterative::split_autoNOE_restraints ]() );
1306 
1307  std::string drop_candidates( cst_file + ".drop" );
1308  std::string drop_candidates_centroid( drop_candidates + ".centroid" );
1309 
1310  using namespace utility::file; //for file_exists
1311  bool bRandomRestraints( option[ iterative::randomize_elimination_candidates ] > 0.0 && file_exists( drop_candidates ) );
1312 
1313 
1314  if ( stage() >= CEN2FULLATOM ) { //don't add fa constraints in early stages... slows down super-quick relax to much...
1315  if ( bSplitted ) {
1316  broker << "\nCLAIMER ConstraintClaimer \n"
1317  << "CST_FILE " << best_cst_file << "\n"
1318  << "NO_CENTROID\n"
1319  << "FULLATOM\n"
1320  << "SKIP_REDUNDANT "<<option[ iterative::skip_redundant_constraints ]() << "\n";
1321  broker << "COMBINE_RATIO 1" << std::endl;
1322  broker << "END_CLAIMER\n" << std::endl;
1323  }
1324  broker << "\nCLAIMER ConstraintClaimer \n"
1325  << "CST_FILE " << cst_file << "\n"
1326  << "NO_CENTROID\n"
1327  << "FULLATOM\n"
1328  << "SKIP_REDUNDANT "<<option[ iterative::skip_redundant_constraints ]() << "\n";
1329  if ( bCombine || bSplitted ) {
1330  broker << "COMBINE_RATIO " << option[ basic::options::OptionKeys::constraints::combine ]() << std::endl;
1331  }
1332  broker << "END_CLAIMER\n" << std::endl;
1333  if ( bRandomRestraints ) {
1334  broker << "\nCLAIMER ConstraintClaimer \n"
1335  << "CST_FILE " << drop_candidates << "\n"
1336  << "NO_CENTROID\n"
1337  << "FULLATOM\n"
1338  << "DROP_RANDOM_RATE " << option[ iterative::randomize_elimination_candidates ]() << "\n"
1339  << "SKIP_REDUNDANT "<<option[ iterative::skip_redundant_constraints ]() << "\n";
1340  if ( bCombine || bSplitted ) {
1341  broker << "COMBINE_RATIO " << option[ basic::options::OptionKeys::constraints::combine ]() << std::endl;
1342  }
1343  broker << "END_CLAIMER\n" << std::endl;
1344  } //bRandom
1345  }
1346  // if ( bCombine ) broker << "COMBINE_RATIO " << basic::options::option[ basic::options::OptionKeys::constraints::combine ]() << "\n";
1347  if ( bSplitted ) {
1348  broker << "\nCLAIMER ConstraintClaimer \n"
1349  << "CST_FILE " << best_cst_centroid_file << "\n"
1350  << "CENTROID\n"
1351  << "SKIP_REDUNDANT "<<option[ iterative::skip_redundant_constraints ]() << "\n";
1352  broker << "COMBINE_RATIO 1" << std::endl;
1353  broker << "END_CLAIMER\n" << std::endl;
1354  }
1355  broker << "\nCLAIMER ConstraintClaimer \n"
1356  << "CST_FILE " << cst_centroid_file << "\n"
1357  << "CENTROID\n"
1358  << "SKIP_REDUNDANT "<<option[ iterative::skip_redundant_constraints ]() << "\n";
1359  if ( bCombine || bSplitted ) {
1360  broker << "COMBINE_RATIO " << option[ basic::options::OptionKeys::constraints::combine ]() << std::endl;
1361  }
1362  broker << "END_CLAIMER\n" << std::endl;
1363 
1364  if ( bRandomRestraints ) {
1365  broker << "\nCLAIMER ConstraintClaimer \n"
1366  << "CST_FILE " << drop_candidates_centroid << "\n"
1367  << "CENTROID\n"
1368  << "DROP_RANDOM_RATE " << option[ iterative::randomize_elimination_candidates ]() << "\n"
1369  << "SKIP_REDUNDANT "<<option[ iterative::skip_redundant_constraints ]() << "\n";
1370  if ( bCombine || bSplitted ) {
1371  broker << "COMBINE_RATIO " << option[ basic::options::OptionKeys::constraints::combine ]() << std::endl;
1372  }
1373  broker << "END_CLAIMER\n" << std::endl;
1374  } //bRandom
1375 
1376  mem_tr << "IterativeBase::gen_noe_assignments end" << std::endl;
1377 }
1378 
1379 
1381  utility::io::ozstream broker( batch.broker_file(), std::ios::app );
1382  broker << "\nUSE_INPUT_POSE\n"
1383  << "CLAIMER StartStructClaimer\n"
1384  << "END_CLAIMER\n\n"
1385  << "CLAIMER JumpClaimer\n"
1386  << "END_CLAIMER\n\n" << std::endl;
1387 
1388 
1389  utility::io::ozstream flags( batch.flag_file(), std::ios::app );
1390  flags << "-abinitio::skip_stages 1 2 3 4" << std::endl;
1391 
1392  add_fullatom_flags( batch );
1393  io::silent::SilentStructOPs start_decoys;
1394  std::copy( decoys().begin(), decoys().end(), std::back_inserter( start_decoys ) );
1395 
1396  if ( start_decoys.size() ) {
1397  batch.set_has_silent_in();
1399  for ( core::io::silent::SilentStructOPs::const_iterator
1400  it = start_decoys.begin(); it != start_decoys.end(); ++it ) {
1401  sfd.add_structure( **it );
1402  }
1403  sfd.write_all( batch.silent_in() );
1404  }
1405 
1406  batch.nstruct() = std::max( 1, int( 1.0*batch.nstruct() / ( 1.0*start_decoys.size() ) ) );
1407 
1408 }
1409 
1410 
1412  Batch const& batch,
1413  core::io::silent::SilentStructOPs& start_decoys,
1414  Real score_cut_per_batch
1415 ) {
1416  using namespace core::io::silent;
1417 
1418  //count total decoys
1419  Size total( 0 );
1420  for ( ArchiveManager::BatchList::const_iterator it = manager().batches().begin(); it != manager().batches().end(); ++it ) {
1421  if ( it->id() >= first_fullatom_batch_ ) break;
1422  if ( !it->has_silent_in() ) continue;
1423  total += it->decoys_returned();
1424  tr.Debug << "harvest old decoys for safety hatch: batch " << it->id() << " " << it->decoys_returned() << " " << total << std::endl;
1425  }
1426  basic::show_time( tr, "generate safety_hatch: counted total decoys" );
1427 
1428 
1429  for ( ArchiveManager::BatchList::const_iterator it = manager().batches().begin(); it != manager().batches().end(); ++it ) {
1430  Real percentage_per_batch( 1.0*batch.nstruct() / (1.0*total) );
1431  if ( it->id() >= first_fullatom_batch_ ) break;
1432  if ( !it->has_silent_in() ) continue; //usually only the resampling decoys are interesting...
1433  if ( !it->decoys_returned() ) continue; //avoid looking for empty files
1434  // it->silent_out();
1435  basic::show_time( tr, "generate safety_hatch: access batch "+it->batch() );
1436  SilentFileData sfd;
1437  std::list< std::pair< core::Real, SilentStructOP > > score_cut_decoys;
1438  Size ct( 0 );
1439  tr.Debug << "read and score decoys in " << it->silent_out() << "..." << std::endl;
1440  sfd.read_file( it->silent_out() );
1441  for ( SilentFileData::iterator sit=sfd.begin(), esit=sfd.end(); sit!=esit; ++sit ) {
1442  std::string tag = sit->decoy_tag();
1443  sit->set_decoy_tag( "harvest_"+batch.batch()+"_"+ObjexxFCL::lead_zero_string_of( ++ct, 6 ) );
1444 
1445  //note this does nothing but return *it, if b_evaluate_incoming_decoys_ is false
1446  //Solve this by having another Archive that is once and only once filled with decoys from all relevant batches.
1447  //This can already be done when the batches are being made. the only difference is that the rule for acceptance is different..
1448  //the archive has no upper-size limit and always takes the bestX% of all structures.
1449  //it has to be maintained with updates of evaluators and such together with the main-archive.
1450  //but one could also choose to *not* update evaluators to have a more different (more hedging approach. )
1451  //this should probably be renamed into hedging !!!
1452  core::io::silent::SilentStructOP pss = *sit;//cannot afford this ever: evaluate_silent_struct( *sit );
1453  score_cut_decoys.push_back( std::make_pair( select_score( pss ), pss ) );
1454  }
1455  score_cut_decoys.sort();
1456  tr.Debug << "select " << percentage_per_batch*100 << "% from batch from the lowest scoring " << score_cut_per_batch*100 << "% of structures" << std::endl;
1457  basic::show_time( tr, "generate safety_hatch: collected decoys batch "+it->batch() );
1458  // if we have less structures below score cut than what we want to harvest,.... take them all
1459  while ( score_cut_per_batch < percentage_per_batch ) {
1460  Size ind_max( static_cast< Size > ( score_cut_decoys.size()*score_cut_per_batch ) );
1461  for ( std::list< std::pair< core::Real, core::io::silent::SilentStructOP > >::const_iterator sit = score_cut_decoys.begin();
1462  sit != score_cut_decoys.end(); ++sit ) {
1463  start_decoys.push_back( sit->second );
1464  if ( --ind_max <= 1 ) break;
1465  }
1466  percentage_per_batch-=score_cut_per_batch;
1467  }
1468  basic::show_time( tr, "generate safety_hatch: generated start_decoys batch "+it->batch());
1469  // for the remaining structures we want to harvest, they clearly will be less than what the score-cut yields... choose randomly...
1470  if ( percentage_per_batch > 0.01 ) {
1471  Size ind_max( static_cast< Size > ( score_cut_decoys.size()*score_cut_per_batch ) );
1472  for ( std::list< std::pair< core::Real, core::io::silent::SilentStructOP > >::const_iterator sit = score_cut_decoys.begin();
1473  sit != score_cut_decoys.end(); ++sit ) {
1474  if ( RG.uniform() < ( percentage_per_batch / score_cut_per_batch ) ) {
1475  start_decoys.push_back( sit->second );
1476  }
1477  if ( --ind_max <= 1 ) break;
1478  }
1479  }
1480  }
1481  basic::show_time( tr, "generate safety_hatch: done collecting");
1482 }
1483 
1485  using namespace core::io::silent;
1486  utility::io::ozstream broker( batch.broker_file(), std::ios::app );
1487  broker << "\nUSE_INPUT_POSE\n"
1488  << "CLAIMER StartStructClaimer\n"
1489  << "END_CLAIMER\n\n"
1490  << "CLAIMER JumpClaimer\n"
1491  << "END_CLAIMER\n\n" << std::endl;
1492 
1493 
1494  utility::io::ozstream flags( batch.flag_file(), std::ios::app );
1495  flags << "-abinitio::skip_stages 1 2 3 4" << std::endl;
1496  add_fullatom_flags( batch );
1497 
1498 
1499  //now go thru batches and select percentage_per_batch structures randomly from the pool created by score_cut_per_batch...
1500  //use score_final for this ? or can we use EvaluatedArchive methods to get a reasonable score ???
1501  //ACHTUNG: need also to know final centroid batch id...
1502  SilentStructOPs start_decoys;
1503  Real score_cut_per_batch( option[ OptionKeys::iterative::safety_hatch_scorecut ] );
1504  if ( !hedge_archive_ ) {
1505  collect_hedgeing_decoys_from_batches( batch, start_decoys, score_cut_per_batch );
1506  } else {
1507  hedge_archive_->collect( batch, start_decoys );
1508  }
1509 
1510  if ( start_decoys.size() ) {
1511  batch.set_has_silent_in();
1513  Size ct( 0 );
1514  for ( core::io::silent::SilentStructOPs::const_iterator
1515  it = start_decoys.begin(); it != start_decoys.end(); ++it ) {
1516  if ( ++ct > batch.nstruct() ) break;
1517  sfd.add_structure( **it );
1518  }
1519  sfd.write_all( batch.silent_in() );
1520  }
1521  basic::show_time( tr, "generate safety_hatch: done writing");
1522  batch.nstruct() = std::max( 1, int( 1.0*batch.nstruct() / ( 1.0*start_decoys.size() ) ) );
1523 
1524 }
1525 
1526 /// -----------------------------------------------------------------------------
1527 /// END gen_xxx ( batch ) methods
1528 /// ==============================================================================
1529 
1532  Size const n_decoys( option[ iterative::limit_decoys_for_noe_assign ] );
1533  if ( batch.id() == 1 || ( total_proposed() < delay_noesy_reassign_ && stage() < CEN2FULLATOM )
1534  || ( stage() >= CEN2FULLATOM && total_proposed() < 2*n_decoys ) ) return; //don't do this at very beginning
1535  //this takes a while... make sure that backedup version of archive is up-to-date
1536  manager().save_archive();
1537 
1538  mem_tr << "IterativeBase reassign_noesy_data start" << std::endl;
1539 
1540  SilentStructs calibration_decoys;
1541 
1542  std::ostringstream hash_string;
1543  hash_string << "NO_POOL " << std::endl;
1544 
1545  //get the calibration subset of decoys...
1546  if ( decoys().size() < n_decoys && decoys().size() < nstruct() ) {
1547  calibration_decoys = decoys();
1548  hash_string << "ONLY "<< decoys().size() << std::endl;
1549  } else {
1550  Size ct2 ( 1 );
1551  for ( SilentStructs::const_iterator it = decoys().begin(); it != decoys().end() && ct2 <= n_decoys; ++ct2, ++it ) {
1552  calibration_decoys.push_back( *it );
1553  hash_string << (*it)->decoy_tag() << std::endl; //create hash-string out of decoy tags
1554  }
1555  }
1556 
1557  //check if the low-energy decoy-tags have changed via their hash-string
1558  size_t hash_val( hasher( hash_string.str() ) );
1559  if ( hash_val == noesy_assign_hash_ ) {
1560  tr.Info << "do not create new noesy assignment since low-energy structures have not changed..." << std::endl;
1561  return; // don't do anything
1562  }
1563  noesy_assign_hash_ = hash_val;
1564 
1565 
1566  //manipulate params if we have some "SCHEME"
1567 
1568  bool use_hardwired_phaseII_params( false );
1569  option=vanilla_options_;
1570  std::string const& option_file( option[ iterative::staged_auto_noe_flags ][ stage() ] );
1571  if ( option_file != "NONE" ) {
1572  tr.Info << "Loading Auto-NOE options for stage " << stage() << " from @" << option_file << std::endl;
1574  if ( !file_exists( option_file ) ) {
1575  utility_exit_with_message( "couldn't find flag-file "+option_file );
1576  }
1577  option.load_options_from_file( option_file );
1578  } else {
1579  tr.Info << "No stage specific Auto-NOE option file found for stage" << stage() << std::endl;
1580  if ( stage() > STAGE2_RESAMPLING ) {
1581  if ( option[ iterative::refine_auto_noe_flags ].user() ) {
1583  if ( !file_exists( option[ iterative::refine_auto_noe_flags ]() ) ) {
1584  utility_exit_with_message( "couldn't find flag-file "+std::string(option[ iterative::refine_auto_noe_flags ]()) );
1585  }
1586 
1587  basic::options::option.load_options_from_file( option[ iterative::refine_auto_noe_flags ] );
1588  } else {
1589  use_hardwired_phaseII_params = true;
1590  }
1591  }
1592  }
1593 
1594  noesy_assign::PeakAssignmentParameters::reset(); //re-read cmd-line options
1596 
1597  if ( use_hardwired_phaseII_params ) {
1598  tr.Info << "Use hardwired phaseII params for NoesyModule " << std::endl;
1599  params.set_cycle( 7 );
1600  params.use_local_distviol_ = true;
1601  }
1602 
1603  std::string scheme( option[ iterative::auto_assign_scheme ]() );
1604  if ( scheme == "CONST" ) {
1605  tr.Info << " reassign NOESY data with cmd-line settings " << std::endl;
1607  } else if ( scheme == "ADAPT1" ) {
1608  tr.Info << " ADAPT1 scheme selected for NOESY data: " << std::endl;
1609  tr.Info << "stage1-3: cycle7 - nodistViol - combine-cst " << std::endl;
1610  tr.Info << "stage4: cycle7 - [dcut = -iterative:dcut ] - do not combine " << std::endl;
1611  if ( stage() < STAGE2_RESAMPLING ) {
1612  params.dcut_ = -1;
1613  bCombineNoesyCst_ = true;
1614  } else {
1615  params.dcut_ = option[ iterative::dcut ]();
1616  bCombineNoesyCst_ = false;
1617  }
1618  } else {
1619  utility_exit_with_message("unknown auto_assign_scheme for NOESY data: choose ADAPT1 or CONST" + scheme);
1620  }
1621 
1622  //initialize noesy-module
1623  if ( !noesy_module_ ) {
1625  } else {
1626  noesy_module_->reset();
1627  }
1628 
1629  //dump params on tracer and in README file
1630  params.show_on_tracer();
1631  {
1632  utility::io::ozstream param_out( batch.dir()+"/README_noe_auto_assign", std::ios::app );
1633  params.show( param_out );
1634  }
1635 
1636  //assign corss-peaks using the calibration decoys
1637  noesy_module_->assign(
1638  utility::DereferenceIterator< SilentStructs >( calibration_decoys.begin() ),
1639  utility::DereferenceIterator< SilentStructs >( calibration_decoys.end() )
1640  );
1641  using namespace basic::options;
1642  using namespace basic::options::OptionKeys;
1643 
1644  //make constraints
1645  core::pose::Pose aPose; //make a pose to make constraint-files
1647  aPose,
1649  *( chemical::ChemicalManager::get_instance()->residue_type_set( core::chemical::FA_STANDARD ))
1650  );
1651  std::string cst_file( batch.dir()+"/"+NOESY_CST_FILE_NAME ); //cst-file names
1652  std::string cst_centroid_file( cst_file + ".centroid");
1653  std::string best_cst_file( cst_file + ".good");
1654  std::string best_cst_centroid_file( best_cst_file + ".centroid");
1655 
1656  if ( reference_pose_ ) {
1657  noesy_module_->add_dist_viol_to_assignments( *reference_pose_ );
1658  }
1659  bool bSplitted( option[ iterative::split_autoNOE_restraints ] );
1660  bool bRandomRestraints( option[ iterative::randomize_elimination_candidates ] > 0.0 );
1661  if ( bSplitted ) {
1662  noesy_module_->generate_constraint_files( aPose, best_cst_file, best_cst_centroid_file, 5, 0, 2 ); //generate constraints
1663  noesy_module_->generate_constraint_files( aPose, cst_file, cst_centroid_file, 5, 3, 4 ); //generate constraints
1664  } else {
1665  noesy_module_->generate_constraint_files( aPose, cst_file, cst_centroid_file, 5, 0, 5, !bRandomRestraints ); //generate constraints
1666  }
1667  noesy_module_->generate_constraint_files( aPose, cst_file+".filter", cst_file+".filter.centroid", 2, 0, 5 );
1668 
1669  std::string drop_candidates( cst_file + ".drop" );
1670  std::string drop_candidates_centroid( drop_candidates + ".centroid" );
1671 
1672  if ( bRandomRestraints ) {
1673  noesy_module_->generate_constraint_files( aPose, drop_candidates, drop_candidates_centroid, 5, 0, 5, !bRandomRestraints, true );
1674  }
1675 
1676  //write NOE_out.dat
1677  noesy_module_->write_assignments( batch.dir()+"/NOE_out.dat" );
1678 
1679  //remember current cst-file
1680  current_noesy_sampling_file_ = cst_file;
1681 
1682  //switch out filter constraints --- if evaluate-local() otherwise we do this only once ( triggered from idle() )
1683  if ( evaluate_local() && option[ iterative::update_noesy_filter_cst ]() ) { //change filter restraints if we are local-evaluators
1685  new topology_broker::ConstraintClaimer( current_noesy_sampling_file_+".filter", "noesy_autoassign_cst" );
1686  cst->set_combine_ratio( bCombineNoesyCst_ ? 2 : 1 );
1687  cst->set_fullatom( true );
1688  cst->set_centroid( false );
1689  cst->set_skip_redundant( option[ iterative::skip_redundant_constraints ]() );
1690  cst->set_filter_weight( get_weight( "noesy_autoassign_cst" )/overall_cstfilter_weight_ );
1691  add_evaluation( new topology_broker::ConstraintEvaluatorWrapper( cst->tag(), cst ), cst->filter_weight()*overall_cstfilter_weight_ );
1692  rescore(); //rescore now, since we probably have more time now, when later when the decoys are arriving...
1693  }
1694  basic::prof_show();
1695  mem_tr << "IterativeBase reassign_noesy_data end" << std::endl;
1696 }
1697 
1698 
1699 
1701  core::fragment::FragSet const& frags,
1702  std::string const& out_pairings_file,
1703  std::string const& out_frag_ss_file
1704 ) const {
1705  core::fragment::SecondaryStructure ss_def( frags, true /*no JustUseCentralResidue */ );
1706  utility::io::ozstream out_ss( out_frag_ss_file );
1707  ss_def.write_psipred_ss2( out_ss, target_sequence() ); // << ss_def << std::endl;
1708 
1709  loops::Loops strands;
1710  int last_sheet_pos=-1;
1711  int new_sheet_start=0;
1712 
1713  //find all sheets longer than 3 residues and put them into "strands"
1714  for ( int pos=1; pos <= (int) ss_def.total_residue(); pos++ ) {
1715  if ( ss_def.sheet_fraction( pos ) >= 0.7 ) {
1716  if ( pos - 1 != last_sheet_pos ) {
1717  if ( new_sheet_start > 0 && (last_sheet_pos - new_sheet_start >= 3 )) {
1718  strands.push_back( new_sheet_start, last_sheet_pos );
1719  }
1720  new_sheet_start = pos;
1721  }
1722  last_sheet_pos = pos;
1723  }
1724  }
1725  // last detected strand is still not pushed into "strands"
1726  if ( new_sheet_start > 0 && (last_sheet_pos - new_sheet_start >= 3 ) ) {
1727  strands.push_back( new_sheet_start, last_sheet_pos );
1728  }
1729  tr.Debug << "secondary structure in current fragset reveals following beta-strands: " << std::endl << strands;
1730 
1731  //create pairings between all possible strand pairings
1732  utility::io::ozstream os(out_pairings_file);
1733  for ( Size i1 = 1; i1 <= strands.size(); i1++ ) {
1734  for ( Size i2 = i1+1; i2 <= strands.size(); i2++ ) {
1735  for ( Size pos1=strands[i1].start(); pos1<=strands[i1].stop(); pos1++ ) {
1736  for ( Size pos2=strands[i2].start(); pos2<=strands[i2].stop(); pos2++ ) {
1737  if ( pos2-pos1 > 25 ) {
1738  os << pos1 << " " << pos2 << " A 1" << std::endl;
1739  os << pos1 << " " << pos2 << " A 2" << std::endl;
1740  os << pos1 << " " << pos2 << " P 1" << std::endl;
1741  os << pos1 << " " << pos2 << " P 2" << std::endl;
1742  }
1743  }
1744  }
1745  }
1746  }
1747 }
1748 
1749 
1750 //this is called for non-local evaluation to switch-out the filter restraints once after stage3.
1751 //this causes cancelling of batches and other shit, that is the reason why called rarely/once
1752 //is not called if switching is deactivated
1754  tr.Info << "replacing NOE filter constraints" << std::endl;
1755  //are we full-atom ?
1756  pose::Pose pose;
1757  (*decoys().begin())->fill_pose( pose );
1758  bool const fullatom( pose.is_fullatom() );
1760 
1761  // this needs work in EvaluatedArchive to make sure the right constraint files are used...
1763  std::string const cst_file( fullatom ? first_noesy_fa_cst_file_ : first_noesy_cst_file_ );
1764  Real weight( get_weight( "noesy_autoassign_cst" )/overall_cstfilter_weight_ );
1766  new topology_broker::ConstraintClaimer( cst_file, "noesy_autoassign_cst" );
1767  cst->set_combine_ratio( 2 );
1768  cst->set_fullatom( true );
1769  cst->set_centroid( false );
1770  cst->set_skip_redundant( option[ OptionKeys::iterative::skip_redundant_constraints ]() );
1771  cst->set_filter_weight( weight );
1772  add_evaluation( new topology_broker::ConstraintEvaluatorWrapper( cst->tag(), cst ), cst->filter_weight()*overall_cstfilter_weight_ );
1773  }
1775 }
1776 
1777 //this is called for non-local evaluation to switch filter-restraints
1779  if ( evaluate_local() ) return;
1780 
1781  //cancel all running batches...
1782  manager().cancel_batches_previous_to( manager().last_batch_id(), false /*don't allow reading of old decoys...*/ );
1783 
1784  //make sure that archive gets re-evaluated...
1785  set_evaluate_local( true );//set this temporarily
1786 
1787  core::scoring::ScoreFunctionOP scfxn( NULL );
1788  std::string score_name;
1789  std::string score_patch;
1790 
1791  //check fullatom:
1792  core::pose::Pose a_pose;
1793  (*decoys().begin())->fill_pose( a_pose );
1794  bool const fullatom( a_pose.is_fullatom() );
1795 
1796  if ( !fullatom ) {
1797  score_name=option[ iterative::cen_score]();
1798  score_patch=option[ iterative::cen_score_patch ]();
1799  } else {
1800  score_name=option[ iterative::fa_score ]();
1801  score_patch=option[ iterative::fa_score_patch ]();
1802  }
1803 
1804  if ( score_patch != "NOPATCH" ) {
1805  scfxn = core::scoring::ScoreFunctionFactory::create_score_function( score_name, score_patch );
1806  } else {
1808  }
1809 
1810  bool chainbreaks_in_patch( scfxn->get_weight( scoring::linear_chainbreak ) > 0.0 );
1811  core::Real extra_chainbreak_weight( basic::options::option[ basic::options::OptionKeys::jumps::increase_chainbreak ] );
1812  if ( !chainbreaks_in_patch ) { //if chainbreak is not patched .. set it
1813  core::Real lin_wgt( 4.0/3.0 * extra_chainbreak_weight );
1814  core::Real overlap_wgt( 1.0 * extra_chainbreak_weight );
1815  core::Real quad_wgt( 1.0 * extra_chainbreak_weight );
1816  tr.Info << "no chainbreaks specified in " << score_patch << ",..."
1817  << " set chainbreaks to " << lin_wgt << " and "
1818  << overlap_wgt <<" for linear- and overlap-chainbreak, respectively" << std::endl;
1819  scfxn->set_weight( scoring::chainbreak, quad_wgt );
1820  scfxn->set_weight( scoring::linear_chainbreak, lin_wgt );
1821  scfxn->set_weight( scoring::overlap_chainbreak, overlap_wgt );
1822  }
1823 
1825  std::string score_patch=option[ iterative::fa_score_patch ]();
1826  if ( score_patch != "NOPATCH" ) {
1827  scfxn = core::scoring::ScoreFunctionFactory::create_score_function( "empty", score_patch );
1828  } else {
1830  }
1831  // cannot compute this from fullatom-pose... keep energy term around in rescore...
1832  // std::string cen_score = option[ iterative::cen_score ]();
1833  // core::scoring::ScoreFunctionOP cen_scfxn( NULL );
1834  // cen_scfxn = core::scoring::ScoreFunctionFactory::create_score_function( cen_score );
1835  // add_evaluation( new evaluation::TruncatedScoreEvaluator( "prefa_centroid_score", selection, cen_scfxn, true /*fullname*/ ), 1.0 );
1836 
1837  std::string fa_score = option[ iterative::fa_score ]();
1838  core::scoring::ScoreFunctionOP fa_scfxn( NULL );
1840  add_evaluation( new simple_filters::ScoreEvaluator( "score_fa", fa_scfxn, true /*fullname*/ ), option[ iterative::fullatom_after_quickrelax_weight ]() );
1841  }
1842 
1843  set_scorefxn( scfxn );
1844  add_evaluation( new simple_filters::ScoreEvaluator( "_final", scfxn ), 1.0 );
1845  rescore();
1846  save_to_file();
1847  set_scorefxn( NULL );
1848  remove_evaluation("score_final");
1849  set_weight("score_final",1.0); // need this for further scoring
1850  //can only get here, if the mode is evaluate_local == false, then its setting to true was only temporarily
1851  set_evaluate_local( false );//have set this above to true, it was temporarily
1852 }
1853 
1855  if ( first_fullatom_batch_ > batch.id() ) first_fullatom_batch_ = batch.id();
1856  utility::io::ozstream flags( batch.flag_file(), std::ios::app );
1857  //these are many.... should there be some input file ?
1858  // flags << "@../flags_fullatom" << std::endl;
1859  if ( !option[ iterative::flags_fullatom ].user() ) {
1860  utility_exit_with_message( "option -iterative:flags_fullatom is required !!! ");
1861  }
1862  flags << "@"<< option[ iterative::flags_fullatom ]() << std::endl;
1863 
1864  if ( option[ constraints::cst_fa_file ].user() ) {
1865  utility::io::ozstream broker( batch.broker_file(), std::ios::app );
1866  broker << "\nCLAIMER ConstraintClaimer \n"
1867  << "CMD_FLAG\n"
1868  << "FULLATOM\n"
1869  << "NO_CENTROID\n";
1870  broker << "END_CLAIMER\n"
1871  << std::endl;
1872  }
1873  if ( option[ constraints::cst_file ].user() ) {
1874  utility::io::ozstream broker( batch.broker_file(), std::ios::app );
1875  broker << "\nCLAIMER ConstraintClaimer \n"
1876  << "CMD_FLAG\n"
1877  // << "FULLATOM\n"
1878  // if ( option[ constraints::cst_fa_file ].user() ) {
1879  << "CENTROID \n"
1880  << "END_CLAIMER\n"
1881  << std::endl;
1882  }
1883 }
1884 
1885 /// ============================================================================
1886 /// ----------- methods to compute stuff from archive ------------
1887 /// ----------- these may be called from idle() ------------
1888 /// ============================================================================
1889 
1891  using namespace ObjexxFCL;
1892  PairingStatisticsOP beta_topol;
1893 
1894  //use -jumps::max_strand_gap_allowed 10 -jumps:contact_score 0.2
1895  if ( !option[ jumps::max_strand_gap_allowed ].user() ) {
1896  option[ jumps::max_strand_gap_allowed ].def( 10 );
1897  }
1898  if ( !option[ jumps::contact_score ].user() ) {
1899  option[ jumps::contact_score ].def( 0.2 );
1900  }
1901 
1902  beta_topol = new PairingStatistics;
1903  PairingStatistics::ModelFreq model_freq;
1904  core::Size ct( 1 );
1905  for ( const_decoy_iterator it = decoys().begin(); it != decoys().end(); ++it, ++ct ) {
1906  pose::Pose pose;
1907  std::string tag;// = it->decoy_tag();
1908  (*it)->fill_pose( pose );
1909 
1910  // get strand pairings
1911  core::scoring::dssp::StrandPairingSet strand_pairings( pose );
1912 
1913  tag = right_string_of( ct, 4, '0');
1914  beta_topol->add_topology( strand_pairings, tag );
1915  model_freq[ tag.substr(0, 4) ] += 1;
1916 
1917  } // for decoys
1918  // set score terms
1919  beta_topol->compute_model_weights( model_freq );
1920  return beta_topol;
1921 }
1922 
1923 
1925  ObjexxFCL::FArray1D_double weights( eval.n_atoms(), 1.0 );
1926  eval.superimpose();
1927  eval.wRMSD( cutoff, 0.00001, weights );
1928 
1929  utility::vector1< Real > result;
1930  eval.rmsf( result );
1931 
1932  rigid.clear();
1933  for ( Size i=1; i<=result.size(); ++i ) {
1934  if ( result[ i ] < cutoff ) rigid.add_loop( loops::Loop( i, i ), 5 );
1935  }
1936  tr.Debug << "make rigid with cutoff " << cutoff << " " << std::endl << rigid << std::endl;
1937 }
1938 
1939 
1941  tr.Info << "compute converged regions " << std::endl;
1942  basic::DynamicProfileThis prof_here("ARCHIVE_COMPUTE_CONVERGED_REGIONS");
1943  core::Size const opt_nstruct( option[ iterative::rmsf_nstruct ]() );
1944  core::Size const nstruct( std::min( int( opt_nstruct ), int( decoys().size() ) ));
1945 
1946  if ( nstruct==0 ) return;
1948  eval.reserve( nstruct );
1949  //Size nres( (*decoys().begin())->nres() );
1950  // Size ct( 1 );
1951  //for ( const_decoy_iterator iss = decoys().begin(); iss != decoys().end(); ++iss, ++ct ) {
1952  // if ( ct > nstruct ) break;
1953  // pose::Pose pose;
1954  // (*iss)->fill_pose( pose );
1955  // eval.push_back( pose );
1956  // nres = pose.total_residue();
1957  // }
1959  eval.push_back_CA_xyz_from_silent_file( nstruct, decoy_iterator( decoys().begin() ), decoy_iterator( decoys().end() ), false );
1960 
1961  loops::Loops old_core15 = core15_;
1962  loops::Loops old_core2 = core2_;
1963  loops::Loops old_core3 = core3_;
1964  loops::Loops old_core4 = core4_;
1965 
1966  get_core( eval, 1.5, core15_ );
1967  get_core( eval, 2, core2_ );
1968  get_core( eval, 3, core3_ );
1969  get_core( eval, 4, core4_ );
1970 
1971  if ( old_core15 != core15_ ) add_core_evaluator( core15_, "_core15" );
1972  if ( old_core2 != core2_ ) add_core_evaluator( core2_, "_core2" );
1973  if ( old_core3 != core3_ ) add_core_evaluator( core3_, "_core3" );
1974  if ( old_core4 != core4_ ) add_core_evaluator( core4_, "_core4" );
1975  tr.Info << "finished computing converged regions" << std::endl;
1976 }
1977 
1979  utility::vector1< Size> selection;
1980  core.get_residues( selection );
1982  core.write_loops_to_file( name()+"/"+core_tag+".gen.rigid", "RIGID" ); //so we have them for other evaluations
1983 }
1984 
1985 void IterativeBase::restore_status( std::istream& is ) {
1986  Parent::restore_status( is );
1987  if ( evaluate_local() ) {
1988  hedge_archive_ = new HedgeArchive( name()+"_hedge" );
1989  hedge_archive_->restore_from_file();
1990  }
1991  int bla; std::string tag;
1992  is >> tag >> bla;
1993  runtime_assert( tag == "IterationStage:" );
1994  stage_ = IterationStage( bla );
1995  tr.Info << "restored iteration stage: " << stage_ << std::endl;
1996  is >> tag >> bla;
1997  runtime_assert( tag == "first_batch_this_stage:");
1999  is >> tag >> bla;
2000  runtime_assert( tag == "first_fullatom_batch:" );
2001  first_fullatom_batch_ = bla;
2002  compute_cores();
2003  is >> tag;
2004  if ( is.good() && tag == "SCORED_CORE:" ) {
2005  //OBSOLETE TAG: read anyway for backward compatibility
2008  loops::SerializedLoopList loops = reader.read_pose_numbered_loops_file( is, name()+"STATUS file", false /*no strict checking */ );
2009  tr.Warning << "WARNING: found obsolete tag SCORE_CORE in status file" << std::endl;
2010  }
2011  is >> tag;
2012  if ( is.good() && tag == "NOESY_CYCLE:" ) {
2014  }
2015  is >> tag;
2016  if ( is.good() && tag == "NOESY_FIRST_CST:" ) {
2017  is >> first_noesy_cst_file_;
2018  }
2019  is >> tag;
2020  if ( is.good() && tag == "NOESY_FIRST_FA_CST:" ) {
2022  }
2023  is >> tag;
2024  if ( is.good() && tag == "NOESY_CURRENT_CST:" ) {
2026  }
2028  if ( evaluate_local() && current_noesy_sampling_file_ != "n/a" ) { //change filter restraints if we are local-evaluators
2030  new topology_broker::ConstraintClaimer( current_noesy_sampling_file_+".filter", "noesy_autoassign_cst" );
2031  cst->set_combine_ratio( bCombineNoesyCst_ ? 2 : 1 );
2032  cst->set_fullatom( true );
2033  cst->set_centroid( false );
2034  cst->set_skip_redundant( option[ iterative::skip_redundant_constraints ]() );
2035  cst->set_filter_weight( get_weight( "noesy_autoassign_cst" )/overall_cstfilter_weight_ );
2036  add_evaluation( new topology_broker::ConstraintEvaluatorWrapper( cst->tag(), cst ), cst->filter_weight()*overall_cstfilter_weight_ );
2037  }
2038  bCombineNoesyCst_ = stage() < STAGE2_RESAMPLING; //will be overwritten in next reassign NOESY... take guess until then...
2039 }
2040 
2041 void IterativeBase::save_status( std::ostream& os ) const {
2042  Parent::save_status( os );
2043  if ( hedge_archive_ ) hedge_archive_->save_to_file();
2044  os << "IterationStage: " << stage_;
2045  os << " first_batch_this_stage: " << first_batch_this_stage_;
2046  os << " first_fullatom_batch: " << first_fullatom_batch_;
2047  os << std::endl;
2048  os << "NOESY_CYCLE: " << noesy_assign_float_cycle_ << std::endl;
2049  os << "NOESY_FIRST_CST: " << first_noesy_cst_file_ << std::endl;
2050  os << "NOESY_FIRST_FA_CST: " << first_noesy_fa_cst_file_ << std::endl;
2051  os << "NOESY_CURRENT_CST: " << current_noesy_sampling_file_ << std::endl;
2052 }
2053 
2054 
2058 }
2059 
2060 
2062  ///OBSOLET
2063 // using namespace protocols::cluster;
2064 // // using namespace basic::options::OptionKeys;
2065 // using namespace basic::options::OptionKeys::cluster;
2066 // using namespace basic::options;
2067 // using namespace toolbox;
2068 
2069 // //jump out if inactive
2070 // if ( !option[ iterative::cluster ]() ) return;
2071 // if ( decoys().size() < 50 ) return;
2072 // if ( min_diversity_list_[ stage() ] == 0 ) return;
2073 
2074 // mem_tr << "IterativeBase cluster-start" << std::endl;
2075 
2076 // SilentStructs kept_decoys;
2077 // toolbox::ClusterOptions cluster_opts( false /*don't change tags to c.XXX.NNN */ );
2078 // cluster_opts.cluster_radius = min_diversity_list_[ stage() ];
2079 // cluster_opts.keep_center = false; /* keep the lowest energy structures -- not interested in the most central structure */
2080 
2081 // //read CA coords into DecoySetEvaluation
2082 // DecoySetEvaluation CA_set;
2083 // CA_set.push_back_CA_xyz_from_silent_file( decoys().size(),
2084 // utility::DereferenceIterator< SilentStructs >( decoys().begin() ),
2085 // utility::DereferenceIterator< SilentStructs >( decoys().end() ),
2086 // false /*don't store plain energies */
2087 // );
2088 
2089 // //we have our special score... so need to gather this information
2090 // utility::vector1< core::Real > all_energies;
2091 // all_energies.reserve( decoys().size() );
2092 // for ( SilentStructs::const_iterator it = decoys().begin(); it != decoys().end(); ++it ) {
2093 // all_energies.push_back( select_score( *it ) );
2094 // }
2095 // CA_set.set_all_energies( all_energies );
2096 
2097 // //now do the clustering
2098 // toolbox::cluster_silent_structs( CA_set,
2099 // utility::DereferenceIterator< SilentStructs >( decoys().begin() ),
2100 // utility::DereferenceIterator< SilentStructs >( decoys().end() ),
2101 // kept_decoys,
2102 // cluster_opts
2103 // );
2104 
2105 // //how many were removed ?
2106 // Size n_removed = decoys().size() - kept_decoys.size();
2107 // tr.Info << "removed " << n_removed << " structures. " << kept_decoys.size() << " structures remaining after clustering " << std::endl;
2108 // decoys()=kept_decoys;
2109 // count_removed_structures( n_removed );
2110 
2111 // //finally...
2112 // mem_tr << "IterativeBase cluster-end" << std::endl;
2113 }
2114 
2115 
2116 
2117 ///@detail before we can apply score-fxn we have to add extra data: RDC, NOES, (not supported yet: PCS, ... )
2118 void IterativeBase::score( pose::Pose & pose ) const {
2119  //to speed up things we cache the RDC data in the archive
2120  if ( basic::options::option[ basic::options::OptionKeys::in::file::rdc ].user() ) {
2123  }
2124  Parent::score( pose );
2125 }
2126 
2127 
2128 /// Helper functions
2129 
2130 void IterativeBase::collect_alternative_decoys( SilentStructs primary_decoys, std::string alternative_decoy_file, SilentStructVector& output_decoys ) {
2131 
2132  tr.Info << "resample_stage2 \n";
2133  typedef std::map< std::string, utility::vector1< std::string > > SourceFiles;
2134  typedef std::map< std::string, utility::vector1< core::io::silent::SilentStructOP > > AlternativeDecoys;
2135 
2136  SourceFiles sources;
2137  AlternativeDecoys alternative_decoys;
2138  Size ct_in( 0 );
2139 
2140  //to find the stage2 structures collect first all tags for a specific file
2141  for ( const_decoy_iterator it = primary_decoys.begin(); it != primary_decoys.end(); ++it ) {
2142  runtime_assert( (*it)->has_comment( TAG_IN_FILE ) );
2143  std::string tag( (*it)->get_comment( TAG_IN_FILE ) );
2144  utility::file::FileName file( (*it)->get_comment( SOURCE_FILE ) );
2145  std::string stage2_file( file.path()+"/"+alternative_decoy_file );
2146 
2147  //creates map <filename> <list of tags>
2148  sources[ stage2_file ].push_back( tag );
2149  alternative_decoys[ stage2_file ].push_back( (*it) );
2150  ++ct_in;
2151  }
2152 
2153  //read selected structures from each file
2154  Size ct_read( 0 );
2155 
2156  for ( SourceFiles::const_iterator it = sources.begin(); it != sources.end(); ++it ) {
2157  /// it->first is filename, it->second are all tags collected for this file
2159  try { //read structures
2160  sfd._read_file( it->first, it->second, true /*throw exceptions */ );
2161  if ( sfd.size() > it->second.size() ) {
2162  tr.Warning << "[WARNING] multiple decoys with same tag detected in file " << it->first << std::endl;
2163  }
2164  //copy( sfd.begin(), sfd.end(), std::back_inserter( output_decoys ) );
2165  for ( core::io::silent::SilentFileData::iterator sit = sfd.begin(); sit != sfd.end(); ++sit ) {
2166  std::string batch_prefix( it->first );
2167  batch_prefix='f'+batch_prefix.substr(9,3);
2168  sit->set_decoy_tag( batch_prefix+"_"+sit->decoy_tag() );
2169  output_decoys.push_back( *sit );
2170  }
2171  ct_read += sfd.size();
2172  } catch ( utility::excn::EXCN_IO& excn ) { //ERROR
2173  tr.Warning << "[WARNING] Problem reading silent-file " << it->first << " for " << it->second.size() << " structures " << std::endl;
2174  excn.show( tr.Warning );
2175  tr.Warning << std::endl;
2176  tr.Warning << "use the respective structures in the pool as starting structure instead" << std::endl;
2177  copy( alternative_decoys[ it->first ].begin(), alternative_decoys[ it->first ].end(), std::back_inserter( output_decoys ) );
2178  ct_read += alternative_decoys[ it->first ].size();
2179  }
2180  }
2181 
2182  tr.Debug << "structures from pool" << ct_in << " structure retrieved from " << alternative_decoy_file << "-files "
2183  << ct_read << " start structs: " << output_decoys.size() << std::endl;
2184  if ( output_decoys.size() != primary_decoys.size() ) {
2185  tr.Warning << "[WARNING] why do we have a different number of decoys in pool and start_decoys ? " << std::endl;
2186  }
2187 }
2188 
2189 void
2191  tr.Debug << "test broker settings...." << std::endl;
2192  OptionCollection vanilla_options( option );
2193  option.load_options_from_file( batch.flag_file() );
2194  try {
2196  topology_broker::add_cmdline_claims( *topology_broker );
2197  tr.Debug << "setting of broker::setup " << std::endl;
2198  utility::vector1< std::string > files( option[ OptionKeys::broker::setup ]() );
2199  std::copy( files.begin(), files.end(), std::ostream_iterator<std::string>( tr.Debug, " "));
2200  tr.Debug << std::endl;
2201  } catch ( utility::excn::EXCN_Exception &excn ) { // clean up options and rethrow
2202  utility_exit_with_message( "[ERROR] problems with broker setup in "+batch.all_broker_files()+" aborting... ");
2203  tr.Error << "[ERROR] problems with broker setup in " << batch.all_broker_files() << " aborting... " << std::endl;
2204  // excn.show( tr.Error );
2205  option = vanilla_options;
2206  throw ( EXCN_Archive( batch.all_broker_files() + " contains errors: " + excn.msg() ) );
2207  }
2208  option = vanilla_options;
2209 }
2210 
2211 
2212 ///@detail load decoys into archive from -archive:input_pool or so
2214  //make bogus batch that contains init-file
2215 
2216  //if non-local evaluation we need to add score_final to decoys --- switch temporarily to local evaluation
2217  bool b_old_eval_state( evaluate_local() );
2218  if ( !b_old_eval_state ) {
2219  tr.Debug << "switch to local evaluation for reading of initial pool" << std::endl;
2220  set_evaluate_local( true );//set this temporarily
2222  }
2223 
2224  //read decoys and evaluate
2226 
2227  //switch back to non-local evaluation if applicable
2228  if ( !b_old_eval_state ) {
2229  remove_evaluation( "score_final" );
2230  set_weight( "score_final", 1.0 );
2231  set_evaluate_local( b_old_eval_state );
2232  }
2233 }
2234 
2235 
2236 //setup filter-cst from broker-setup:
2238  using namespace topology_broker;
2239  tr.Info << "setup filter-cst module in IterativeBase"<<std::endl;
2240  TopologyBrokerOP topology_broker = new TopologyBroker();
2241  add_cmdline_claims( *topology_broker, false );
2242  tr.Trace << "topology_broker is initiailized with " << topology_broker->num_claimers() << " claimers "<< std::endl;
2243  core::Size ct( 1 );
2244  for ( TopologyBroker::const_iterator it = topology_broker->begin();
2245  it != topology_broker->end(); ++it, ++ct ) {
2246  tr.Trace << "found claimer of type " << (*it)->type() << "trying to cast now..."<< std::endl;
2247  ConstraintClaimerCOP cst_claimer = dynamic_cast< ConstraintClaimer* >( (*it).get() );
2248  if ( cst_claimer ) {
2249  tr.Info << "found cst-claimer with filter_name " << cst_claimer->filter_name()
2250  << " filter_weight " << cst_claimer->filter_weight() << std::endl;
2251  if ( cst_claimer->filter_weight() < 0.01 ) continue;
2252  std::string name( cst_claimer->filter_name() );
2253  core::Real weight( cst_claimer->filter_weight() );
2254  if ( !name.size() ) {
2255  name = "filter_cst_"+ObjexxFCL::lead_zero_string_of( ct, 2 );
2256  } else {
2257  name = "filter_cst_"+name+"_"+ObjexxFCL::lead_zero_string_of( ct, 2 );;
2258  }
2259  add_evaluation( new ConstraintEvaluatorWrapper( name, cst_claimer ), weight*overall_weight );
2260  }//if cst_claimer
2261  } // for claimer
2262 }
2263 
2266 
2267  tr.Debug << "setup autoNOE module in IterativeBase"<<std::endl;
2269  current_noesy_sampling_file_ = option[ iterative::initial_noe_auto_assign_csts ]();
2272  utility_exit_with_message( "couldn't find initial NOESY-autoassign file "+current_noesy_sampling_file_ );
2273  }
2274 
2275  //another cst set for filtering
2276  set_weight( "noesy_autoassign_cst", option[ iterative::cenpool_noesy_cst_weight ]()*overall_cstfilter_weight_ );
2277 
2278  //use restraints combination -- this might be switched off later when convergence is better
2279  bCombineNoesyCst_ = true;
2280 
2281  //add full-atom restraints as Evaluator (since a full-atom structure is sent back after relax)
2282  if ( evaluate_local() ) {
2283  tr.Debug << "cool we have local-scoring active"<<std::endl;
2285  new topology_broker::ConstraintClaimer( current_noesy_sampling_file_+".filter", "noesy_autoassign_cst" );
2286  cst->set_combine_ratio( bCombineNoesyCst_ ? 2 : 1 );
2287  cst->set_fullatom( true );
2288  cst->set_centroid( false );
2289  cst->set_filter_weight( option[ iterative::cenpool_noesy_cst_weight ]() );
2290  add_evaluation( new topology_broker::ConstraintEvaluatorWrapper( cst->tag(), cst ), cst->filter_weight()*overall_cstfilter_weight_ );
2291  }
2292 
2293  //hash-string of the low30 decoy-tags to quickly determine if a new AutoNOE run should be done.
2294  std::ostringstream hash_string;
2295  hash_string << "NO_POOL " << std::endl;
2296  noesy_assign_hash_ = hasher( hash_string.str() );
2297 }
2298 
2299 } //abinitio
2300 } //protocols