Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
AbrelaxApplication.cc
Go to the documentation of this file.
1 // -*- mode:c++;tab-width:2;indent-tabs-mode:t;show-trailing-whitespace:t;rm-trailing-spaces:t -*-
2 // vi: set ts=2 noet:
3 //
4 // (c) Copyright Rosetta Commons Member Institutions
5 // (c) This file is part of the Rosetta software suite and is made available under license.
6 // (c) The Rosetta software is developed by the contributing members of the Rosetta Commons.
7 // (c) For more information, see http://www.rosettacommons.org. Questions about this can be
8 // (c) addressed to University of Washington UW TechTransfer, email: license@u.washington.edu.
9 
10 /// @brief Application level code for relax-type protocols
11 /// @detailed
12 ///
13 /// use AbrelaxApplication in the following way:
14 ///
15 /// AbrelaxApplication::register_options();
16 /// core::init
17 /// AbrelaxAppliaction my_app;
18 /// my_app.add_evaluation( new MySpecialEvaluator );
19 /// ...
20 /// my_app.run();
21 ///
22 /// ---------------------------------------
23 /// control flow:
24 /// the run method calls
25 /// setup()
26 /// and then either fold() or rerun() (depending on option -rerun )
27 ///
28 /// each decoy is evaluated by process_decoy() and results are written to the score-file (if specified) or
29 /// to the silent_output file ( if applicable ).
30 /// the score file is a silent-file without structural data ( just SCORE lines )
31 ///
32 /// rerun(): run thru structures in in:file:silent and call process_decoy for each
33 /// fold(): produce structures with an Abinitio-type protocol and call process_decoy
34 ///
35 /// options specific to AbrelaxApplication can be found by using -help at the command-line.
36 /// if you add new options please follow the scheme in the static method register options
37 ///
38 /// the behaviour of AbrelaxApplication is controlled by comman-line-options. Refer to -help (usage) and the code
39 ///
40 /// information that is not always present is stored as xxxOP, and the NULL-pointer is interpreted that the respective
41 /// behaviour is not present. (i.e., native_pose_ is either pointing to the native pose (-native) or to NULL.
42 /// when you use such pointers ask if they are non-NULL.
43 ///
44 ///
45 ///
46 /// @author Oliver Lange
47 /// @author Christopher Miles (cmiles@uw.edu)
48 
49 // keep these headers first for compilation with Visual Studio C++
50 #include <utility/io/izstream.hh>
53 
54 // Unit Headers
57 #include <protocols/loops/util.hh>
58 #include <protocols/loops/Loops.hh>
59 #include <protocols/loops/Loop.hh>
62 
63 #if defined(WIN32) || defined(__CYGWIN__)
64  #include <ctime>
65 #endif
66 
67 // Package Headers
68 #include <core/kinematics/util.hh>
97 #include <basic/datacache/BasicDataCache.hh>
99 // AUTO-REMOVED #include <core/scoring/SS_Killhairpins_Info.fwd.hh>
101 
102 // Project Headers
103 #include <core/types.hh>
105 #include <core/pose/Pose.hh>
107 #include <core/pose/util.hh>
108 #include <basic/MetricValue.hh>
109 #include <basic/options/option.hh>
110 #include <basic/options/keys/abinitio.OptionKeys.gen.hh>
111 #include <basic/options/keys/constraints.OptionKeys.gen.hh>
112 // AUTO-REMOVED #include <basic/options/keys/evaluation.OptionKeys.gen.hh>
113 #include <basic/options/keys/filters.OptionKeys.gen.hh>
114 #include <basic/options/keys/frags.OptionKeys.gen.hh>
115 #include <basic/options/keys/in.OptionKeys.gen.hh>
116 #include <basic/options/keys/jumps.OptionKeys.gen.hh>
117 #include <basic/options/keys/loopfcst.OptionKeys.gen.hh>
118 #include <basic/options/keys/loops.OptionKeys.gen.hh>
119 #include <basic/options/keys/out.OptionKeys.gen.hh>
120 #include <basic/options/keys/run.OptionKeys.gen.hh>
121 #include <basic/options/keys/templates.OptionKeys.gen.hh>
122 #include <basic/options/keys/relax.OptionKeys.gen.hh>
123 #include <basic/options/keys/score.OptionKeys.gen.hh>
126 #include <core/fragment/util.hh>
130 #include <core/scoring/Energies.hh>
137 // AUTO-REMOVED #include <core/io/pdb/pose_io.hh>
142 #include <core/scoring/ScoreType.hh>
147 #include <core/sequence/util.hh>
148 #include <core/sequence/Sequence.hh>
155 // AUTO-REMOVED #include <protocols/evaluation/ChemicalShiftEvaluator.hh>
169 
170 //numeric headers
171 #include <numeric/random/random.hh>
172 
173 // Utility headers
174 #include <utility/string_util.hh>
175 #include <utility/vector1.hh>
176 #include <basic/Tracer.hh>
177 #include <utility/io/util.hh>
178 #include <utility/exit.hh>
179 
180 // C++ headers
181 #include <cstdlib>
182 // AUTO-REMOVED #include <iterator>
183 #include <string>
184 #include <utility>
185 #include <vector>
186 
187 #include <core/fragment/FragData.hh>
188 #include <core/fragment/Frame.hh>
199 #include <protocols/relax/util.hh>
200 #include <utility/vector0.hh>
201 #include <ObjexxFCL/format.hh>
202 
203 //Auto using namespaces
204 namespace ObjexxFCL { } using namespace ObjexxFCL; // AUTO USING NS
205 namespace ObjexxFCL { namespace fmt { } } using namespace ObjexxFCL::fmt; // AUTO USING NS
206 
207 static basic::Tracer tr("protocols.abinitio.AbrelaxApplication");
208 static numeric::random::RandomGenerator RG(423464); // <- Magic number, do not change it!
209 
210 ////////////////////////////////////////////////////////////////////////////////////////////////////
211 ///@details registering of options that are relevant for AbrelaxApplication
213  using namespace basic::options;
214  using namespace basic::options::OptionKeys;
215 
216  /// options from the main Option file that are relevant in this context ( and should appear in -help output )
217  option.add_relevant( in::file::native );
218  option.add_relevant( in::file::silent ); // input silent file
219  option.add_relevant( in::file::frag3 );
220  option.add_relevant( in::file::frag9 );
221  option.add_relevant( in::file::fasta );
222  option.add_relevant( in::file::native_exclude_res ); // list for residues to exclude
223 
224  option.add_relevant( out::file::silent );
225  option.add_relevant( out::nstruct );
226 
227  option.add_relevant( run::proc_id );
228  option.add_relevant( run::nproc );
229  option.add_relevant( run::condor );
230 
231  option.add_relevant( OptionKeys::abinitio::fastrelax );
232  option.add_relevant( OptionKeys::abinitio::relax );
233  option.add_relevant( OptionKeys::abinitio::multifastrelax );
234  option.add_relevant( OptionKeys::abinitio::relax_with_jumps );
235  option.add_relevant( OptionKeys::abinitio::use_filters );
236  option.add_relevant( OptionKeys::abinitio::detect_disulfide_before_relax );
237  option.add_relevant( OptionKeys::abinitio::debug );
238  option.add_relevant( OptionKeys::abinitio::number_3mer_frags );
239  option.add_relevant( OptionKeys::abinitio::number_9mer_frags );
240  option.add_relevant( OptionKeys::abinitio::process_store );
241  option.add_relevant( OptionKeys::abinitio::fix_residues_to_native );
242  option.add_relevant( OptionKeys::abinitio::return_full_atom );
243  option.add_relevant( OptionKeys::abinitio::rerun );
244  option.add_relevant( OptionKeys::abinitio::jdist_rerun );
245 
246  // starting conditions
247  option.add_relevant( OptionKeys::abinitio::start_native );
248  option.add_relevant( OptionKeys::abinitio::perturb );
249  option.add_relevant( OptionKeys::abinitio::close_loops );
250 
251  // evaluation
252  option.add_relevant( OptionKeys::abinitio::rmsd_residues );
253  option.add_relevant( OptionKeys::abinitio::bGDT );
254  option.add_relevant( OptionKeys::run::no_prof_info_in_silentout );
255 
256  // use fragments from native structure
257  option.add_relevant( OptionKeys::abinitio::steal_3mers );
258  option.add_relevant( OptionKeys::abinitio::steal_9mers );
259  option.add_relevant( OptionKeys::abinitio::dump_frags );
260  option.add_relevant( OptionKeys::abinitio::no_write_failures );
261 
262  option.add_relevant( loopfcst::use_general_protocol );
263  option.add_relevant( loopfcst::coord_cst_weight );
264  option.add_relevant( loopfcst::coord_cst_all_atom );
265  option.add_relevant( loopfcst::coord_cst_weight_array );
266  option.add_relevant( loopfcst::dump_coord_cst_weight_array );
267 
268  option.add_relevant( OptionKeys::in::file::pca );
269  option.add_relevant( OptionKeys::out::sf );
270 
271  // jumping
272  option.add_relevant( jumps::fix_jumps );
273  option.add_relevant( jumps::jump_lib );
274  option.add_relevant( jumps::fix_chainbreak );
275  option.add_relevant( jumps::pairing_file );
276  option.add_relevant( jumps::sheets );
277  option.add_relevant( jumps::random_sheets );
278  option.add_relevant( jumps::evaluate );
279  option.add_relevant( jumps::extra_frags_for_ss );
280  option.add_relevant( jumps::loop_definition_from_file );
281  option.add_relevant( jumps::no_chainbreak_in_relax );
282  option.add_relevant( jumps::residue_pair_jump_file );
283  option.add_relevant( jumps::topology_file );
284 
285  //loop closure
286  option.add_relevant( OptionKeys::loops::loop_file );
287  option.add_relevant( OptionKeys::loops::alternative_closure_protocol );
288  option.add_relevant( OptionKeys::loops::short_frag_cycles );
289  option.add_relevant( OptionKeys::loops::scored_frag_cycles );
290  option.add_relevant( OptionKeys::loops::debug_loop_closure );
291  option.add_relevant( OptionKeys::loops::non_ideal_loop_closing );
292  option.add_relevant( OptionKeys::loops::chainbreak_max_accept );
293  option.add_relevant( OptionKeys::loops::extended );
294 
295  // constraints
296  option.add_relevant( constraints::cst_file );
297  option.add_relevant( constraints::forest_file );
298  option.add_relevant( constraints::compute_total_dist_cst );
299  option.add_relevant( constraints::no_linearize_bounded );
300  option.add_relevant( constraints::dump_cst_set );
301  option.add_relevant( constraints::no_cst_in_relax );
302  option.add_relevant( constraints::evaluate_max_seq_sep );
303  option.add_relevant( constraints::cull_with_native );
304  option.add_relevant( constraints::named );
305  option.add_relevant( constraints::epr_distance );
306  option.add_relevant( constraints::viol );
307  option.add_relevant( constraints::viol_level );
308  option.add_relevant( constraints::viol_type );
309 
310  // homologs
311  option.add_relevant( templates::config );
312  option.add_relevant( templates::pairings );
313 
314  // large default number means all frags are used if this option is not specified
315  option.add_relevant( templates::min_nr_large_frags );
316  option.add_relevant( templates::min_nr_small_frags );
317 
318  option.add_relevant( templates::nr_large_copies );
319  option.add_relevant( templates::nr_small_copies );
320  option.add_relevant( templates::vary_frag_size );
321  option.add_relevant( templates::fix_aligned_residues );
322  option.add_relevant( templates::fix_margin );
323  option.add_relevant( templates::fix_frag_file );
324  option.add_relevant( templates::no_pick_fragments );
325  option.add_relevant( templates::pick_multiple_sizes );
326  option.add_relevant( templates::strand_constraint );
327  option.add_relevant( frags::nr_large_copies );
328  option.add_relevant( frags::annotate );
329  option.add_relevant( in::file::tags );
330 
331  // this adds all relevant options from the protocols
332  // ClassicAbinitio, FoldConstraints, JumpingFoldConstraints
337 
338  // here we should have
339  // ClassicRelax::register_options();
340  // FastRelax::register_options(); etc.
341  #ifdef BOINC
342  std::cerr << "Registered extra options." << std::endl; std::cerr.flush();
343  #endif
344 }
345 
346 namespace protocols {
347 namespace abinitio {
348 
349 using core::Size;
350 using namespace core;
351 using namespace protocols;
352 using namespace fragment;
353 using namespace abinitio;
354 using namespace jumping;
355 using namespace evaluation;
356 using namespace basic::options;
357 //using namespace basic::options::OptionKeys;
358 
359 // little helper classes for evaluation of generated decoys:
360 ////////////////////////////////////////////////////////////////////////////////////////////////////
361 // evaluates the PCA
362 class PcaEvaluator : public PoseEvaluator {
363 public:
364  PcaEvaluator ( PCA_OP pca ) : pca_( pca ) {}
365  virtual void apply( pose::Pose& pose, std::string tag, io::silent::SilentStruct &pss ) const;
366  core::Size size() const { return 2; };
367  std::string name( core::Size ) const { return "pca1"; };
368 private:
369  PCA_OP pca_;
370 };
371 
372 ////////////////////////////////////////////////////////////////////////////////////////////////////
373 // evaluates the violations of atom-pairconstraints always with the full weight and full sequence separation
374  using namespace core::scoring::constraints; // has to be core, now that protocols::scoring is visible
375 class ShowViolation : public PoseEvaluator {
376 public:
377  ShowViolation( ) : constraints_( NULL ) {}
378  virtual void apply( pose::Pose& pose, std::string tag, io::silent::SilentStruct &pss ) const;
379  core::Size size() const { return 1; };
380  std::string name( core::Size ) const { return "viol"; };
381 private:
382  mutable ConstraintSetOP constraints_;
383 };
384 
385 ////////////////////////////////////////////////////////////////////////////////////////////////////
387 public:
388  ComputeTotalDistCst( ) : constraints_( NULL ) {};
389  virtual void apply( pose::Pose& pose, std::string tag, io::silent::SilentStruct &pss ) const;
390  core::Size size() const { return 1; };
391  std::string name( core::Size ) const { return "total"; };
392 private:
393  mutable ConstraintSetOP constraints_;
394 };
395 
396 ////////////////////////////////////////////////////////////////////////////////////////////////////
397 ///@detail c'stor - nothing special
398 AbrelaxApplication::AbrelaxApplication() :
399  silent_score_file_( NULL ),
400  native_pose_( NULL ),
401  pca_( NULL ),
402  bRelax_ ( false ),
403  cstset_( NULL ),
404  jump_def_ ( NULL ),
405  templates_( NULL ),
406  fragset_large_( NULL ),
407  fragset_small_top25_( NULL ),
408  fragset_small_( NULL ),
409  evaluator_ ( new MetaPoseEvaluator ),
410  abrelax_checkpoints_( "Abrelax" )
411 {}
412 
414 
415 /// @details Shallow copy to mimic the pre 9/8/09 compiler-generated version of this
416 /// method. If you add new
418  silent_score_file_( src.silent_score_file_ ),
419  native_pose_( src.native_pose_ ),
420  loops_in_( src.loops_in_ ),
421  pca_( src.pca_ ),
422  bRelax_( src.bRelax_ ),
423  sequence_( src.sequence_ ),
424  cstset_( src.cstset_ ),
425  membrane_jumps_( src.membrane_jumps_ ),
426  jump_def_ ( src.jump_def_ ),
427  ss_def_( src.ss_def_ ),
428  templates_( src.templates_ ),
429  fragset_large_( src.fragset_large_ ),
430  fragset_small_top25_( src.fragset_small_top25_ ),
431  fragset_small_( src.fragset_small_ ),
432  fragset_templates_( src.fragset_templates_ ),
433  evaluator_( src.evaluator_ ),
434  abrelax_checkpoints_( src.abrelax_checkpoints_ )
435 {}
436 
437 ////////////////////////////////////////////////////////////////////////////////////////////////////
438 ///@detail add a PoseEvaluator derived instance for decoy-processing
440  evaluator_->add_evaluation( eval );
441 }
442 ////////////////////////////////////////////////////////////////////////////////////////////////////
443 ///@details setup of Application data that is used for both, fold() and run()
444 /// this is mainly stuff for scoring and evaluation ( process_decoys(), evaluator_ )
446  using namespace basic::options::OptionKeys;
447 
448  if ( option[ constraints::no_linearize_bounded ] ) {
449  tr.Info << "use fully harmonic potential for BOUNDED " << std::endl;
450  ConstraintIO::get_func_factory().add_type("BOUNDED", new BoundFunc(0,0,0,1000,"dummy") );
451  }
452  if ( option[ constraints::named ] ) {
453  tr.Info << "use named constraints in AtomPairConstraint to avoid problems with cutpoint-variants " << std::endl;
456  }
457 
459  silent_score_file_-> set_filename( std::string( option[ out::sf ]() ) );
460 
461  // read native pose
462  if ( option[ in::file::native ].user() ) {
463  native_pose_ = new pose::Pose;
464  core::import_pose::pose_from_pdb( *native_pose_, option[ in::file::native ]() );
465 
467 
468 #ifdef BOINC_GRAPHICS
469  // set native for graphics
470  boinc::Boinc::set_graphics_native_pose( *native_pose_ );
471 #endif
472 
473  // allow sloppy matches here, because sometimes the Centroid residue set doesn't have all the residue variants
474  // that the fullatom set has.
475  core::util::switch_to_residue_type_set( *native_pose_, chemical::CENTROID, true ); //so that in do_rerun the native pose is the same as the other poses
476  }
477 
478  // specify sequence -- from fasta file or native_pose
479  if ( option[ in::file::fasta ].user() ) {
480  sequence_ = core::sequence::read_fasta_file( option[ in::file::fasta ]()[1] )[1]->sequence();
481  tr.Info << "read fasta sequence: " << sequence_.size() << " residues\n" << sequence_ << std::endl;
482  } else if ( native_pose_ ) {
483  sequence_ = native_pose_->sequence();
484  tr.Info << "take sequence from native : " << sequence_ << std::endl;
485  } else if ( !option[ OptionKeys::abinitio::rerun ]() && !option[ OptionKeys::abinitio::jdist_rerun ]() ) { // if we rerun we don't need sequence or native or anything...
486  utility_exit_with_message(
487  "Error: can't read sequence! Use -in::file::fasta sequence.fasta or -in::file::native native.pdb!"
488  );
489  }
490 
491  std::string native_tag = "";
492 
493  // run with homolog info? -- needed for setup_fragments, and rerun keep it upfront
494  setup_templates();
495 
496  //add command-line evaluator stuff
498 
504 
505  if ( option[ constraints::viol ]() ) add_evaluation( new ShowViolation );
506  if ( option[ constraints::compute_total_dist_cst ] ) add_evaluation( new ComputeTotalDistCst );
507  // read PCA info
508  if ( option[ OptionKeys::in::file::pca ].user() ) {
509  pca_ = new PCA;
510  pca_->read_eigvec_file( option[ OptionKeys::in::file::pca ](), *native_pose_, 2 );
511  add_evaluation( new PcaEvaluator( pca_ ) );
512  }
513 }
514 
515 ////////////////////////////////////////////////////////////////////////////////////////////////////
516 bool AbrelaxApplication::close_loops( pose::Pose &pose, core::scoring::ScoreFunctionOP scorefxn, std::string const& tag /*for checkpoints*/ ) {
517  if ( !fragset_small_ ) {
518  setup_fragments();
519  }
520  runtime_assert( !pose.is_fullatom() );
521  (*scorefxn)( pose ); // just to check that we can do this --
522 
523  using namespace basic::options::OptionKeys;
524  if ( option[ OptionKeys::loops::debug_loop_closure ]() ) pose.dump_pdb(tag+"_pre_closure.pdb");
525 
526  bool success( false );
527 
528  // Did we already close the loops successfully ?
529  if ( (success=abrelax_checkpoints_.recover_checkpoint( pose, tag, "close_loops", false /*fullatom*/, true /*foldtree*/))) {
530  abrelax_checkpoints_.debug( tag, "close_loops", (*scorefxn)(pose), (core::Real) true );
531  return true;
532 
533  } else {
534  // No ? Have we already tried but failed ?
535  if ( abrelax_checkpoints_.recover_checkpoint( pose, tag, "close_loops_failure", false /*fullatom*/, true /*foldtree*/)) {
536  abrelax_checkpoints_.debug( tag, "close_loops", (*scorefxn)(pose), (core::Real) false );
537  return false;
538  }
539 
540  // Oh - we've not tried at all yet - let's go then!
541  // make a MoveMap ... could be coming from somewhere else, though
543  movemap->set_bb( true );
544 
545  // a weird bug occurs if we make a copy of a copy of the pose and set the new fold-tree
546  // the behaviour is very different from setting the same fold-tree into the copy of the pose
549 
550  if ( option[ OptionKeys::loops::alternative_closure_protocol ]() ) {
551  closure_protocol =
553  }
554 
555  // set options here if you like
556  closure_protocol->set_native_pose( native_pose_ );
557  closure_protocol->scored_frag_cycle_ratio( option[ OptionKeys::loops::scored_frag_cycles ]() );
558  closure_protocol->short_frag_cycle_ratio( option[ OptionKeys::loops::short_frag_cycles ]() );
559 
560  //for debugging:
561  closure_protocol->set_evaluation( evaluator_ );
562  if ( option[ OptionKeys::abinitio::debug ] ) {
563  closure_protocol->keep_fragments();
564  }
565 
566  bool bIdeal( !option[ OptionKeys::loops::non_ideal_loop_closing ]() );
567  closure_protocol->set_bIdealLoopClosing( bIdeal );
568 
569  ProtocolOP debug_output = new Protocol;
570  debug_output->set_evaluation( evaluator_ );
571 
572  success = true;
573 
574  try {
575  jumping::close_chainbreaks( closure_protocol, pose, abrelax_checkpoints_, tag, kinematics::FoldTree() );
576  if ( option[ OptionKeys::loops::debug_loop_closure ]() ) pose.dump_pdb(tag+"_post_closure.pdb");
577  } catch ( loops::EXCN_Loop_not_closed& excn ) {
578  success = false;
579  }
580 
581  if ( success && option[ OptionKeys::loops::idealize_after_loop_close ]() ) {
583  idealizer.fast( false );
584  pose.constraint_set( NULL );
585  idealizer.apply( pose );
586  bIdeal = true;
587  }
588 
589  if ( !bIdeal ) option[ basic::options::OptionKeys::out::file::silent_struct_type ].def( "binary");
590  // to know this we'd have to catch the Exception EXCN_Loop_not_closed
591  if ( success ) abrelax_checkpoints_.checkpoint( pose, tag, "close_loops", true /*foldtree*/ );
592  else abrelax_checkpoints_.checkpoint( pose, tag, "close_loops_failure", true /*foldtree*/ );
593 
594  abrelax_checkpoints_.debug( tag, "close_loops", (*scorefxn)(pose), (core::Real) success );
595  }
596  return success;
597 }
598 ////////////////////////////////////////////////////////////////////////////////////////////////////
599 ///@detail run all evaluations on the decoy from this function
600 /// if you want these evaluations also available during internal stages of the protocols -->
601 /// put them into a PoseEvaluator and use add_evaluation in setup()
602 /// otherwise you can also use "manual" code right here in process_decoy --> this will only appear in final
603 /// silent_out and silent_score - files.
605  pose::Pose &pose,
606  core::scoring::ScoreFunction const& scorefxn,
607  std::string tag,
608  io::silent::SilentStruct &pss ) const
609 {
610  using namespace basic::options::OptionKeys;
611  // would like to put the following two also in an PoseEvaluator
612  // ScoreEvaluator
613  // StructureDumper
614  if ( option[ OptionKeys::abinitio::clear_pose_cache ]() ) {
615  tr.Debug << "\n******************************************************** \n"
616  << " CLEAR POSE CACHE \n"
617  << "***********************************************************" << std::endl;
618  pose.data().clear();
619  }
620 
621  scorefxn( pose );
622  pss.fill_struct( pose, tag );
623  // run PoseEvaluators
624  evaluator_->apply( pose, tag, pss );
625  if ( option[ jumps::evaluate ]() ) {
626  if ( !native_pose_ ) utility_exit_with_message(" to evaluate jumps you need to specify a native structure ");
628  native_pose_->fold_tree( pose.fold_tree() );
629  for ( Size nj = 1; nj<= pose.num_jump(); ++nj ) {
631  }
632  eval_jumps.apply( pose, tag, pss );
633  }
634 
635 } // process_decoy
636 ////////////////////////////////////////////////////////////////////////////////////////////////////
637 //mjo commenting out 'pose' because it is unused and causes a warning
639  using namespace basic::options::OptionKeys;
640  if ( option[ constraints::forest_file ].user() ) {
641  tr.Info << "read ConstraintForest... : " << std::endl;
642  utility_exit_with_message( "ConstraintForest needs to be revived!" );
643  }
644 }
645 ////////////////////////////////////////////////////////////////////////////////////////////////////
646 ///@detail read constraints file (once) and constraints_set to the pose (each call)
648  using namespace core::scoring::constraints;
649  using namespace basic::options::OptionKeys;
650 
651  bool bFirst( !cstset_ );
652  if ( bFirst ) {
653  if ( option[ constraints::cst_file ].user() ) {
654  // reads and sets constraints
656  }
657  }
658 
659  if ( bFirst && templates_ ) {
660  if ( !cstset_ ) cstset_ = new ConstraintSet;
661  templates_->add_target_constraints( cstset_, pose );
662  if ( option[ templates::strand_constraint ] ) {
663  ConstraintCOPs my_strand_cst;
664  if ( templates_ ) {
665  my_strand_cst = StrandConstraints( templates_->strand_pairing_stats() ).build_constraints( pose );
666  } else if ( option[ jumps::topology_file ].user() ) {
667  utility::io::izstream is( option[ jumps::topology_file ] );
668  if ( is.good() ) {
670  is >> *ps;
671  tr.Info << *ps << std::endl;
672  my_strand_cst = StrandConstraints( *ps ).build_constraints( pose );
673  } else {
674  utility_exit_with_message(" did not find topology_file: " + std::string( option[ jumps::topology_file ]() ) );
675  }
676  } else {
677  utility_exit_with_message(" strand_constraint nees a topology info: either via templates or -topology_file ");
678  }
679  cstset_->add_constraints( my_strand_cst );
680  add_evaluation( new constraints_additional::ConstraintEvaluator( "strand", my_strand_cst ) );
681 
682  if ( native_pose_ ) {//just a temporary hack to test the StrandConstraint
683  pose::Pose test_pose = *native_pose_;
684  test_pose.add_constraints( my_strand_cst );
685 
686  if ( option[ constraints::dump_cst_set ].user() ) {
687  tr.Info << "dump strand constraints to file..." << std::endl;
688  utility::io::ozstream dump_cst( "STRAND_CST_DUMP" );
689  test_pose.constraint_set()->show_definition( dump_cst, test_pose );
690  }
691 
694  cst_score( test_pose );
695  tr.Info << " native pose yields this score for the StrandConstraints: " << cst_score( test_pose ) << std::endl;
696  cst_score.show( tr, test_pose );
697  test_pose.constraint_set()->show_violations( tr , test_pose, 120);
698  }
699  }
700  }
701 
702  if ( option[ constraints::cull_with_native ].user() && native_pose_ ) {
703  tr.Warning << "************************************************************************************\n"
704  << "********************* CULL CONSTRAINTS WITH NATIVE STRUCTURE *********************\n"
705  << "************************************************************************************\n" << std::endl;
706  ConstraintCOPs filtered;
707  core::scoring::constraints::cull_violators( cstset_->get_all_constraints(),
708  filtered, *native_pose_, option[ constraints::cull_with_native ]() );
710  cstset_->add_constraints( filtered );
711  }
712 
713  pose.constraint_set( cstset_ );
714 
715  if ( option[ constraints::dump_cst_set ].user() ) {
716  tr.Info << "dump constraints to file..." << std::endl;
717  utility::io::ozstream dump_cst( option[ constraints::dump_cst_set ]() );
718  cstset_->show_definition( dump_cst, pose );
719  }
720 
721  if ( option[ constraints::evaluate_max_seq_sep ].user() ) {
722  Size const neval ( option[ constraints::evaluate_max_seq_sep ]().size() );
723  for ( Size i = 1; i<= neval; i++ ) {
724  Size const seq_sep( option[ constraints::evaluate_max_seq_sep ]()[ i ] );
725  add_evaluation( new constraints_additional::ConstraintEvaluator( "seq_sep_"+utility::to_string( seq_sep) , *cstset_, 1, seq_sep ) );
726  }
727  }
728 
729 } // add_constraints( pose::Pose & pose )
730 
731 ////////////////////////////////////////////////////////////////////////////////////////////////////
733 public:
735  core::fragment::FragSetCOP fragset_large,
737  ) : ClassicAbinitio( fragset_large, fragset_large, movemap ) {};
738 
740  : ClassicAbinitio( brute_move_large, brute_move_large, brute_move_large, 1 /*dummy*/ ) {};
741 
742  virtual void apply( core::pose::Pose &pose );
743 };
744 
746  prepare_stage1( pose );
747  do_stage1_cycles( pose );
748 }
749 ////////////////////////////////////////////////////////////////////////////////////////////////////
751  using namespace basic::options::OptionKeys;
752  if ( option[ templates::fix_frag_file ].user() ) {
753  FrameList fix_frames;
754  fragment::FragmentIO().read_data( option[ templates::fix_frag_file ](), fix_frames );
755  Size const frame_id ( static_cast< int >( RG.uniform() * fix_frames.size() ) + 1 );
756  FrameOP frame( fix_frames[ frame_id ] );
757  Size const frag_id ( static_cast< int >( RG.uniform() * frame->nr_frags() ) + 1 );
758  frame->apply( frag_id, pose );
759 
760  std::ofstream out( "big_frags.log", std::ios_base::out | std::ios_base::app );
761  out << tag << " " << RJ(10,frame->start()) << RJ( 10, frame->stop() ) << RJ( 10, frag_id ) << std::endl;
762 
763  movemap->set_bb( true );
764  Size const npadding( option[ OptionKeys::templates::fix_margin ] );
765  for ( Size pos = frame->start() + npadding; pos<=frame->end() - npadding; ++pos ) {
766  movemap->set_bb( pos, false );
767  }
768  }
769 }
770 
771 ////////////////////////////////////////////////////////////////////////////////////////////////////
772 ///@detail loop over structures in silent-input file
773 /// small trick is used to also have native structure in the set of analysis:
774 /// it is added to the collection of silent_file-structures manually
775 /// TODO we need to do something about difference between fullatom and centroid input!
777  using namespace core;
778  using namespace io::silent;
779  using namespace pose;
780  using namespace basic::options::OptionKeys;
781 
782  core::io::silent::SilentFileDataOP outsfd( NULL );
783  if ( option[ out::file::silent ].user() ) {
784  outsfd = new core::io::silent::SilentFileData();
785  }
786 
787  core::scoring::ScoreFunctionOP scorefxn( NULL );
788  if ( option[ in::file::silent ].user() ) {
789  //read silent file for input
790  SilentFileData sfd;
791  sfd.read_file( *(option [ in::file::silent ]().begin()) );
792 
793  // run thru all structures
794  Size ct ( 0 );
795  for ( SilentFileData::iterator it=sfd.begin(), eit=sfd.end(); it!=eit; ++it ) {
796  Pose pose;
797  std::string tag = it->decoy_tag();
798  if ( option[ in::file::tags ].user() == 0 || std::find( option[ in::file::tags ]().begin(), option[ in::file::tags ]().end(), tag ) != option[ in::file::tags ]().end() ) {
799  if ( option[ in::file::fullatom ].user() ) {
800  it->fill_pose( pose,
801  option[ in::file::fullatom ] ?
802  *(chemical::ChemicalManager::get_instance()->residue_type_set( chemical::FA_STANDARD )) :
803  *(chemical::ChemicalManager::get_instance()->residue_type_set( chemical::CENTROID ) ));
804  } else {
805  it->fill_pose( pose );
806  }
807 
808  add_constraints( pose );
809  scorefxn = generate_scorefxn( pose.is_fullatom() );
810  //screen output
811  if ( sfd.size() < 10 || option[ constraints::viol ]() ) {
812  tr.Info << tag << " " << std::endl;
813  } else {
814  if ( (ct++ % 50) == 0 ) {
815  std::cout << ".";
816  std::cout.flush();
817  }
818  }
819 
820  // set score terms
821  scorefxn->set_weight( core::scoring::linear_chainbreak, 1.0 );
822  scorefxn->set_weight( core::scoring::overlap_chainbreak, 1.0 );
823 
824  if ( option[ OptionKeys::abinitio::close_loops ] ) {
825  add_evaluation( new simple_filters::RmsdEvaluator( new pose::Pose( pose ), std::string("closure"), option[ OptionKeys::abinitio::bGDT ]() ) );
826  close_loops( pose, scorefxn, tag );
827  }
828 
829  basic::MetricValue<core::Size> mr;
830  pose.metric("clashes","total",mr);
831  tr.Info << "Total clashes " << mr.value() << std::endl;
832 
833  bool passes_filters = check_filters( pose );
834  if( !passes_filters ) {
835  tag = "F_"+tag.substr(2);
836  }
837 
838  SilentStructOP ss = io::silent::SilentStructFactory::get_instance()->get_silent_struct_out();
839  process_decoy( pose, *scorefxn, tag, *ss );
840  // write this to score-file if applicable
841  if ( outsfd ) outsfd->add_structure( ss );
842 
843  //remove closure-rmsd
844  if ( option[ OptionKeys::abinitio::close_loops ] ) {
845  evaluator_->pop_back();
846  }
847  }
848  }
849  }
850 
851  // add native structure to the list
852  if ( native_pose_ ) {
853  SilentStructOP ss = io::silent::SilentStructFactory::get_instance()->get_silent_struct_out();
855  scorefxn = generate_scorefxn( false /*full_atom*/ );
856  scorefxn->set_weight( core::scoring::linear_chainbreak, 1.0 );
857  scorefxn->set_weight( core::scoring::overlap_chainbreak, 1.0 );
858 
859  if ( option[ OptionKeys::abinitio::close_loops ] ) { //otherwise the column (needed for non-native decoys) doesn't show up in score-file
860  add_evaluation( new simple_filters::RmsdEvaluator( new pose::Pose( *native_pose_ ), std::string("closure"), option[ OptionKeys::abinitio::bGDT ]() ) );
861  }
862 
863  process_decoy( *native_pose_, *scorefxn, "NATIVE", *ss );
864  // write this to score-file if applicable
865  if ( silent_score_file_ ) {
866  silent_score_file_ -> write_silent_struct( *ss, silent_score_file_->filename(), true /* bWriteScoresOnly */ );
867  }
868 
869  if ( outsfd ) outsfd->add_structure( ss );
870  if ( option[ OptionKeys::abinitio::close_loops ] ) evaluator_->pop_back();
871  }
872 
873  if ( silent_score_file_ && outsfd ) {
874  outsfd->write_all( silent_score_file_->filename(), true /* bWriteScoresOnly */ );
875  }
876 
877  if ( outsfd ) outsfd->write_all( option[ out::file::silent ]() );
878 }
879 
880 ////////////////////////////////////////////////////////////////////////////////////////////////////
881 ///@detail loop over structures in silent-input file
882 /// small trick is used to also have native structure in the set of analysis:
883 /// it is added to the collection of silent_file-structures manually
884 /// TODO we need to do something about difference between fullatom and centroid input!
886  using namespace core;
887  using namespace io::silent;
888  using namespace pose;
889  using namespace basic::options::OptionKeys;
890 
894 
895  //read silent file for input
896  bRelax_ = option[ OptionKeys::abinitio::relax ]() ||
897  option[ OptionKeys::abinitio::fastrelax ]();
898 
899  // setup profiling
900  evaluation::TimeEvaluatorOP run_time( NULL );
901  if ( !option[ OptionKeys::run::no_prof_info_in_silentout ] ) {
902  add_evaluation( run_time = new evaluation::TimeEvaluator ); //just don't use this in integration tests!
903  }
904 
906 
907  // get input tags
908  SilentFileData sfd;
909  typedef utility::vector1< std::string > TagList;
910  TagList input_tags;
911  //WRONG -- these tags are the ones in file --- while after "read_file" tags might be renamed use .tags() after reading
912  // input_tags = sfd.read_tags_fast( *(option [ in::file::silent ]().begin()) );
913 
914  // read silent data
915  sfd.read_file( *(option [ in::file::silent ]().begin()) );
916  input_tags = sfd.tags();
917  // determine nstruct
918  int const nstruct = std::max( 1, option [ out::nstruct ]() );
919 
920  // create jobs
921  typedef utility::vector1< BasicJobOP > JobList;
922  JobList input_jobs;
923  for ( TagList::const_iterator it = input_tags.begin(), eit = input_tags.end(); it!=eit; ++it ) {
924  BasicJobOP job = new BasicJob( *it, "rerun", nstruct);
925  input_jobs.push_back( job );
926  }
927 
928  // setup JobDistributor
929  PlainSilentFileJobDistributor jobdist( input_jobs );
930  if ( option[ run::proc_id ].user() ) {
931  int const procid ( option[ run::proc_id ] + ( option[ run::condor ] ? 1 : 0 ) );
932  if ( procid > option[ run::nproc ] ) {
933  utility_exit_with_message("procid to large " + ObjexxFCL::string_of( procid ) + " run only " + ObjexxFCL::string_of( option[ run::nproc ] ) + " processes");
934  }
935  jobdist.set_proc_id( procid, option[ run::nproc ] );
936  }
937  jobdist.startup(); //this will overwrite proc_id settings with mpi_rank if MPI is present.
938 
939  // production loop
940  bool bEndrun = false;
941  BasicJobOP curr_job;
942  int curr_nstruct;
943  while ( jobdist.next_job(curr_job, curr_nstruct) && !bEndrun ) {
944  if ( run_time ) run_time->reset(); //reset clock of TimeEvaluator
945  tr.Info << "Starting " << jobdist.get_current_output_tag() << " ..." << std::endl;
946  tr.Info << "read " << curr_job->input_tag() << "..." << std::endl;
947  Pose pose;
948 
949  sfd.get_structure( curr_job->input_tag() ).fill_pose( pose );
950  set_ss_from_phipsi( pose );
951 
952  //mjo TODO: verify that the disulfides are correct coming out of fill_pose() and then delete this code
953  // Fix disulfides if a file is given
954  if ( basic::options::option[ basic::options::OptionKeys::in::fix_disulf ].user() ) {
956  core::io::raw_data::DisulfideFile ds_file( basic::options::option[ basic::options::OptionKeys::in::fix_disulf ]() );
957  ds_file.disulfides( disulfides, pose);
958  pose.conformation().fix_disulfides( disulfides );
959  }
960 
961  loops_in_.verify_against( pose );
962 
963  if ( bRelax_ ) { //always add all f@@#$ columns so we never-ever have a column mismatch....
964  tr.Info << "relax is active... add stupid extra score terms " << std::endl;
966  }
967 
968  std::string tag = jobdist.get_current_output_tag();
969  if( option[ OptionKeys::loops::random_grow_loops_by ].user() ){
970  loops_in_.grow_all_loops( pose, option[ OptionKeys::loops::random_grow_loops_by ]() );
971  tr.Info << "Enlarged loops: " << std::endl;
972  tr.Info << loops_in_ << std::endl;
973  };
974 
975  add_constraints( pose ); // needs to come before scorefxn setup to know if constraints are present
976  core::scoring::ScoreFunctionOP centroid_scorefxn( generate_scorefxn( false /*fullatom*/ ) );
977  core::scoring::ScoreFunctionOP fullatom_scorefxn( generate_scorefxn( true /*fullatom*/ ) ); // this is the score12 standard score function ?! )
978 
979  centroid_scorefxn->set_weight( core::scoring::linear_chainbreak, 1.0 );
980  centroid_scorefxn->set_weight( core::scoring::overlap_chainbreak, 1.0 );
981 
982  if ( loops_in_.size() ) {
984  loops::Loops rigid( loops_in_.invert( pose.total_residue() ) );
985  loops::fix_with_coord_cst( rigid, pose, option[ loopfcst::coord_cst_all_atom ], vecs );
986  }
987 
988  if ( option[ jumps::no_chainbreak_in_relax ] ) {
989  fullatom_scorefxn->set_weight( core::scoring::linear_chainbreak, 0.0 );
990  fullatom_scorefxn->set_weight( core::scoring::overlap_chainbreak, 0.0 );
991  }
992  // set score function for processing/relaxing stage
993 
994  tr.Info << tag << " " << std::endl;
995  if ( option [ OptionKeys::abinitio::debug ] ) {
996  //this functionality is needed for the iterative protocol to have a restart structure with the same tag as the final structure
998  std::string silent_file = option[ basic::options::OptionKeys::out::file::silent ]() + "_" + "before_loops";
999 
1000  io::silent::SilentStructOP pss = io::silent::SilentStructFactory::get_instance()->get_silent_struct_out();
1001  process_decoy( pose, pose.is_fullatom() ? *fullatom_scorefxn : *centroid_scorefxn, jobdist.get_current_output_tag(), *pss );
1002  outsfd.write_silent_struct( *pss, silent_file );
1003  }
1004 
1005  bool loop_closure_failed( false );
1006  if ( option[ OptionKeys::abinitio::close_loops ] ) {
1007  add_evaluation( new simple_filters::RmsdEvaluator( new pose::Pose( pose ), std::string("closure"), option[ OptionKeys::abinitio::bGDT ]() ) );
1008  loop_closure_failed = !close_loops( pose, centroid_scorefxn, tag );
1009  }
1010 
1011  bool passes_filters = check_filters( pose );
1012  // run relax if applicable
1013  // don't relax if we failed filters or loop_closing, or if option[ relax_with_jumps ] is true
1014  bool bCanRelax = passes_filters && ( !loop_closure_failed || option[ OptionKeys::abinitio::relax_with_jumps ]() );
1015  if ( bRelax_ ) {
1016  if ( !pose.is_fullatom() ) {
1017  Pose const centroid_pose ( pose );
1019  pose.constraint_set( pose.constraint_set()->remapped_clone( centroid_pose, pose ) );
1020  }
1021 
1022  if ( bCanRelax ) {
1023  tr.Info << "relax is active... add stupid extra score terms " << std::endl;
1025  relax( pose, fullatom_scorefxn, jobdist.get_current_output_tag() );
1026  } else { //cannot relax
1027  //need proper atom set to score with full-atom
1028  (*fullatom_scorefxn)( pose );
1029  if ( option[ basic::options::OptionKeys::abinitio::fastrelax ]() ) {
1030  } else {
1031  relax::ClassicRelax().setPoseExtraScores( pose ); // ClassicRelax adds four columns
1032  }
1033  }
1034  } // if ( bRelax_ )
1035 
1036  // process decoy if this hasn't happened yet
1037  // analyze result
1038  std::string output_tag = jobdist.get_current_output_tag();
1039  if ( !passes_filters && loop_closure_failed ) {
1040  output_tag = "X_"+output_tag.substr(2);
1041  } else if( loop_closure_failed ) {
1042  output_tag = "C_"+output_tag.substr(2);
1043  } else if( !passes_filters ) {
1044  output_tag = "F_"+output_tag.substr(2);
1045  }
1046 
1047  SilentStructOP pss = io::silent::SilentStructFactory::get_instance()->get_silent_struct_out();
1048  process_decoy( pose, pose.is_fullatom() ? *fullatom_scorefxn : *centroid_scorefxn, output_tag, *pss );
1049  // write this to score-file if applicable
1050  if ( silent_score_file_ ) {
1051  silent_score_file_ -> write_silent_struct( *pss, silent_score_file_->filename(), true /* bWriteScoresOnly */ );
1052  }
1053 
1054  // write to silent file
1055  jobdist.dump_silent( curr_nstruct, *pss );
1056 
1057  //remove closure-rmsd
1058  if ( option[ OptionKeys::abinitio::close_loops ] ) {
1059  evaluator_->pop_back();
1060  }
1061 
1062  } // end of production loop
1063  jobdist.shutdown();
1064 }
1065 
1066 ////////////////////////////////////////////////////////////////////////////////////////////////////
1067 ///@detail called by setup_fold() if option[ start_native ] is active
1068 /// the routine defines a fragment of the length of the structure
1069 /// steals the fragment from the native and applies it to the decoy
1070 /// native needs to be idealized!
1072  // requires that the sequences match at the beginning (1..nmatch_res) -- > use sequence alignment later
1073  tr.Info << " *** use native structure as starting template -- NEEDS TO BE IDEALIZED !!! *** \n";
1074  copy_structure( extended_pose, *native_pose_ );
1075 }
1076 
1077 ////////////////////////////////////////////////////////////////////////////////////////////////////
1078 void AbrelaxApplication::copy_structure( core::pose::Pose & extended_pose, core::pose::Pose & desired_pose ) const {
1079  // requires that the sequences match at the beginning (1..nmatch_res) -- > use sequence alignment later
1080  tr.Info << " *** use native structure as starting template -- NEEDS TO BE IDEALIZED !!! *** \n";
1081  // determine length of segment to copy from native
1082  Size seg_len = std::min(extended_pose.total_residue(), desired_pose.total_residue() );
1083  // chu workaround when folding with ligand/metal
1084  Size protein_len = 0;
1085  for ( Size i = 1; i <= seg_len; ++i ) {
1086  if( extended_pose.residue(i).is_protein() && desired_pose.residue(i).is_protein() ) {
1087  protein_len ++;
1088  }
1089  }
1090  seg_len = protein_len;
1091  fragment::Frame long_frame(1, seg_len);
1092 
1093  //create apropriate length FragData object
1094  FragData frag( new BBTorsionSRFD, seg_len );
1095 
1096  // get torsion angles from native pose
1097  frag.steal( desired_pose, long_frame );
1098 
1099  // apply native torsions to extended structue
1100  frag.apply( extended_pose, long_frame );
1101 }
1102 
1103 ////////////////////////////////////////////////////////////////////////////////////////////////////
1104 ///@detail called by setup_fold(): setup the decoy pose with correct target sequence and extended structure
1105 ///
1106 void AbrelaxApplication::generate_extended_pose( core::pose::Pose &extended_pose, std::string const& sequence ) const {
1108  extended_pose,
1109  sequence,
1110  *( chemical::ChemicalManager::get_instance()->residue_type_set( chemical::CENTROID ))
1111  );
1112 
1113  // Fix disulfides if a file is given
1114  if ( basic::options::option[ basic::options::OptionKeys::in::fix_disulf ].user() ) {
1116  core::io::raw_data::DisulfideFile ds_file( basic::options::option[ basic::options::OptionKeys::in::fix_disulf ]() );
1117  ds_file.disulfides( disulfides, extended_pose);
1118  extended_pose.conformation().fix_disulfides( disulfides );
1119  }
1120 
1121  // make extended chain
1122  for ( Size pos = 1; pos <= extended_pose.total_residue(); pos++ ) {
1123  if ( ! extended_pose.residue(pos).is_protein() ) continue;
1124  extended_pose.set_phi( pos, -150 );
1125  extended_pose.set_psi( pos, 150);
1126  extended_pose.set_omega( pos, 180 );
1127  }
1128 
1129 #ifdef BOINC_GRAPHICS
1130  // attach boinc graphics pose observer
1131  protocols::boinc::Boinc::attach_graphics_current_pose_observer( extended_pose );
1132 #endif
1133 }
1134 
1135 ////////////////////////////////////////////////////////////////////////////////////////////////////
1136 ///@detail called by setup_fold(): read fragment libraries, I strongly suggest to use different options than A and B
1137 /// if option[ steal ] fragments from the native structure are added to the set.
1138 /// native structure needs to be idealized for this!
1139 void AbrelaxApplication::setup_fragments() {// FragSetOP& fragsetA, FragSetOP& fragsetB ) const {
1140  using namespace basic::options;
1141  using namespace basic::options::OptionKeys;
1142 
1143  std::string frag_large_file, frag_small_file;
1144  if (option[ in::file::fragA ].user()) {
1145  frag_large_file = option[ in::file::fragA ]();
1146  } else {
1147  frag_large_file = option[ in::file::frag9 ]();
1148  }
1149 
1150  if (option[ in::file::fragB ].user()) {
1151  frag_small_file = option[ in::file::fragB ]();
1152  } else {
1153  frag_small_file = option[ in::file::frag3 ]();
1154  }
1155 
1156  fragset_large_ = FragmentIO(
1157  option[ OptionKeys::abinitio::number_9mer_frags ](),
1158  option[ OptionKeys::frags::nr_large_copies ](),
1159  option[ OptionKeys::frags::annotate ]()
1160  ).read_data( frag_large_file );
1161 
1162  if(option[OptionKeys::abinitio::membrane]) { //bw stupied way of get top25 frags for 3mer.
1163  fragset_small_top25_ = FragmentIO(
1164  option[ OptionKeys::abinitio::number_9mer_frags ],
1165  1, //nr_copies
1166  option[ OptionKeys::frags::annotate ]
1167  ).read_data( frag_small_file );
1168  }
1169  fragset_small_ = FragmentIO(
1170  option[ OptionKeys::abinitio::number_3mer_frags ],
1171  1, //nr_copies
1172  option[ OptionKeys::frags::annotate ]
1173  ).read_data( frag_small_file );
1174 
1175  if ( templates_ && !option[ templates::no_pick_fragments ]() ) {
1176  if ( option[ templates::vary_frag_size ] ) {
1177  fragset_templates_ = new OrderedFragSet;
1178  templates_->pick_large_frags( *fragset_templates_, new BBTorsionSRFD, option[ templates::nr_large_copies ] );
1179  tr.Info << " merge template frags with standard library " << std::endl;
1182  *fragset_large_,
1183  option[ templates::min_nr_large_frags ],
1184  true /* random selection of fill frags */
1185  );
1186  } else { // use old-way of picking:
1187  //pick torsion fragments fragset_large
1188  tr.Info << "pick large fragments as 9mers " << std::endl;
1189  if ( option[ templates::min_nr_large_frags ].user() ) {
1190  Size const min_nr_frags( option[ templates::min_nr_large_frags ] );
1191  Size const nr_large_copies( option[ templates::nr_large_copies ] );
1192  fragset_large_ = templates_->pick_frags(
1194  new FragData( new BBTorsionSRFD, fragset_large_->max_frag_length() ),
1195  min_nr_frags,
1196  nr_large_copies );
1197  } else {
1198  Size nr = templates_->pick_frags( *fragset_large_, new FragData( new BBTorsionSRFD, fragset_large_->max_frag_length() ) );
1199  tr.Info << nr << " " << fragset_large_->max_frag_length() << "mer fragments picked from homolog structures" << std::endl;
1200  }
1201  if ( option[ templates::pick_multiple_sizes ] ) {
1202  Size nr = templates_->pick_frags(
1203  *fragset_large_,
1204  new FragData( new BBTorsionSRFD, 18 )
1205  );
1206  tr.Info << nr << " 18mer fragments picked from homolog structures" << std::endl;
1207  nr = templates_->pick_frags(
1208  *fragset_large_,
1209  new FragData( new BBTorsionSRFD, 24 )
1210  );
1211  tr.Info << nr << " 27mer fragments picked from homolog structures" << std::endl;
1212  }
1213  } // !vary_frag_size
1214 
1215  if ( option[ templates::min_nr_small_frags ].user() ) {
1216  Size const min_nr_frags( option[ templates::min_nr_small_frags ] );
1217  Size const nr_small_copies( option[ templates::nr_small_copies ] );
1218  fragset_small_ = templates_->pick_frags(
1220  new FragData( new BBTorsionSRFD, fragset_small_->max_frag_length() ),
1221  min_nr_frags,
1222  nr_small_copies );
1223  } else {
1224  //pick torsion fragments fragset_small
1225  Size nr2 = templates_->pick_frags( *fragset_small_, new FragData( new BBTorsionSRFD, fragset_small_->max_frag_length() ) );
1226  tr.Info << nr2 << " " << fragset_small_->max_frag_length() << "mer fragments picked from homolog structures" << std::endl;
1227  }
1228  } // templates && !templates:no_pick_fragments
1229 
1230  if ( native_pose_ && ( option[ OptionKeys::abinitio::steal_3mers ]() || option[ OptionKeys::abinitio::steal_9mers ]() )) {
1231  tr.Info << " stealing fragments from native pose: ATTENTION: native pose has to be IDEALIZED!!! " << std::endl;
1232  if ( option[ OptionKeys::abinitio::steal_9mers ]() ) steal_frag_set_from_pose( *native_pose_, *fragset_large_,
1233  new FragData( new BBTorsionSRFD, fragset_large_->max_frag_length() ) );
1234  if ( option[ OptionKeys::abinitio::steal_3mers ]() ) steal_frag_set_from_pose( *native_pose_, *fragset_small_,
1235  new FragData( new BBTorsionSRFD, fragset_small_->max_frag_length() ) );
1236  } else if ( ( option[ OptionKeys::abinitio::steal_3mers ]() || option[ OptionKeys::abinitio::steal_9mers ]() ) && !native_pose_ && !templates_ ) {
1237  tr.Warning << "cannot steal fragments without native pose or homologue structures " << std::endl;
1238  }
1239 
1240  if ( option[ OptionKeys::abinitio::dump_frags ]() ) { //diagnosis
1241  utility::io::ozstream dump_frag_small( "fragset_small.dump" );
1242  for ( FrameIterator it=fragset_small_->begin(), eit=fragset_small_->end(); it!=eit; ++it ) {
1243  (*it)->show( dump_frag_small );
1244  }
1245  utility::io::ozstream dump_frag_large( "fragset_large.dump" );
1246  for ( FrameIterator it=fragset_large_->begin(), eit=fragset_large_->end(); it!=eit; ++it ) {
1247  (*it)->show( dump_frag_large );
1248  }
1249  }
1250 }
1251 
1252 ////////////////////////////////////////////////////////////////////////////////////////////////////
1253 ///@detail called by setup_fold(). Read template definitions
1255  using namespace basic::options;
1256  using namespace basic::options::OptionKeys;
1257 
1258  bool const bTemplates( option[ templates::config ].user() );
1259  if ( !bTemplates ) { // jump-out if not used
1260  if ( option[ templates::pairings ].user() )
1261  tr.Warning << "option templates:pairings ignored... specify templates:config!" << std::endl;
1262  return;
1263  }
1264 
1265  if ( native_pose_ ) tr.Info << "native strand pairings " << core::scoring::dssp::StrandPairingSet( *native_pose_ );
1266  templates_ = new Templates( option[ templates::config ], native_pose_ );
1267  templates_->target_sequence() = sequence_; // a hack until class SequenceMapping works better
1268  // want to pick fragments from templates... make sure they are not initialized yet
1269  runtime_assert( !fragset_large_ );
1270 
1271  if( !templates_->is_good() ){
1272  utility_exit_with_message("ERRORS occured during template setup. check BAD_SEQUENCES file!");
1273  }
1274 }
1275 
1276 ////////////////////////////////////////////////////////////////////////////////////////////////////
1277 ///@detail called by setup_fold(). Read jump definitions / barcodes (not yet) etc.
1278 /// if jump_def_ points to an object we will use JumpFoldConstraint-protocol in fold()
1279  void AbrelaxApplication::setup_jumps( pose::Pose const& extended_pose ) {
1280  using namespace basic::options;
1281  using namespace basic::options::OptionKeys;
1282 
1283  // setup jumps
1284  bool bDoubleDef = false;
1285  jump_def_ = NULL;
1286  ss_def_ = new core::fragment::SecondaryStructure( *fragset_small_, false /*no JustUseCentralResidue */ );
1287 
1288  if ( option [ jumps::extra_frags_for_ss ].user() ) {
1289  FragSetOP ss_frags = FragmentIO().read_data( option[ jumps::extra_frags_for_ss ]() );
1290  ss_def_ = new core::fragment::SecondaryStructure( *ss_frags, false );
1291  }
1292  if ( option[ jumps::loop_definition_from_file ].user() ) {
1294  ss_def_->read_from_file( option[ jumps::loop_definition_from_file ]() );
1295  }
1296 
1297  if ( option[ jumps::fix_jumps ].user() ) {
1298  JumpSetupOP ptr = new JumpSetup( extended_pose.total_residue() );
1299  ptr->read_file( option[ jumps::fix_jumps ]() );
1300  // initialize jumping
1301  jumping::JumpSample current_jumps( ptr->create_jump_sample() );
1302  if ( native_pose_ && !current_jumps.has_orientation_and_pleating() ) {
1303  tr.Warning << "abinitio:CHEAT JumpingFoldConstraints takes orienation and pleating from native structure !!!" << std::endl;
1304  current_jumps.steal_orientation_and_pleating( *native_pose_ );
1305  ptr->set_jump_sample( current_jumps );
1306  }
1307  jump_def_ = ptr;
1308  }
1309  if ( option[ jumps::jump_lib ].user() ) {
1310  bDoubleDef = jump_def_ != 0;
1311  JumpSelectorOP ptr = new JumpSelector( native_pose_->secstruct() );
1312  ptr->read_file( option[ jumps::jump_lib ] );
1313  jump_def_ = ptr;
1314  }
1315  if ( option[ jumps::sheets ].user() || option[ jumps::random_sheets ].user() ) {
1316  bDoubleDef = jump_def_ != 0;
1317 
1318  // get secondary structure info
1319  runtime_assert( fragset_small_ );
1320 
1321  ss_def_->show( tr.Trace );
1322  // get pairings file
1324  if ( option[ jumps::pairing_file ].user() )
1325  read_pairing_list( option[ jumps::pairing_file ](), pairings );
1326 
1327  // get sheet-topology
1329  if ( option[ jumps::sheets ].user() ) {
1330  sheets = option[ jumps::sheets ]();
1331  // done: instantiate sheet-builder
1332  jump_def_ = new SheetBuilder( ss_def_, pairings, sheets );
1333  } else {
1334  sheets = option[ jumps::random_sheets ]();
1335  jump_def_ = new RandomSheetBuilder( ss_def_, pairings, sheets );
1336  }
1337  }
1338 
1339  if ( option[ jumps::topology_file ].user() ) {
1340  utility::io::izstream is( option[ jumps::topology_file ] );
1341  if ( !is.good() ) {
1342  utility_exit_with_message(" did not find topology_file: " + std::string( option[ jumps::topology_file ]() ) );
1343  }
1345  is >> *ps;
1346  if ( is.fail() ) {
1347  utility_exit_with_message(" error reading file: " + std::string( option[ jumps::topology_file ]() ) );
1348  }
1349  tr.Info << *ps << std::endl;
1350  core::scoring::dssp::PairingList helix_pairings; //empty for now
1351  jump_def_ = new TemplateJumpSetup( NULL, ss_def_, ps, helix_pairings );
1352  }
1353 
1354  if ( option[ templates::pairings ] ) {
1355  bDoubleDef = false;
1356  if ( option[ jumps::fix_jumps ].user() ) {
1357  tr.Info << "use fixed jumps but take jump-geometries from template! " << std::endl;
1358  jump_def_ = new FixTemplateJumpSetup( *templates_->create_jump_def( ss_def_ ), jump_def_ );
1359  } else {
1360  bDoubleDef = jump_def_ != 0;
1361  jump_def_ = templates_->create_jump_def( ss_def_ );
1362  }
1363 
1364  if ( option[ constraints::forest_file ].user() ) utility_exit_with_message("can't use constraint-forest pairings with template pairings yet");
1365  }
1366 
1367  if ( option[ jumps::residue_pair_jump_file ].user() ) {
1368  bDoubleDef = jump_def_ != 0;
1369  ResiduePairJumpSetupOP ptr = new ResiduePairJumpSetup( extended_pose.total_residue() );
1370  ptr->read_file( option[ jumps::residue_pair_jump_file ]() );
1371  jump_def_ = ptr;
1372  }
1373 
1374  if ( bDoubleDef ) {
1375  utility_exit_with_message("you can only define one jump mode: choose one of -fix_jumps / -jump_lib / -sheets / -pairings");
1376  }
1377 
1378  if ( jump_def_ ) {
1379  //yields columns named nrjumps
1381  }
1382 }
1383 
1385  //using core::pose::datacache::CacheableDataType::MEMBRANE_TOPOLOGY;
1389  topology.initialize(spanfile);
1390 }
1391 
1392 
1393 ////////////////////////////////////////////////////////////////////////////////////////////////////
1394 ///@detail setup_fold() all initialization that is necessary to run abinitio production loop in fold()
1395 /// read fragments, make pose from sequence, get constraints, set jumps, movemap .etc
1396 /// the two parameters are OUTPUT:
1397 /// extended_pose to run A) with ( might actually contain native starting structure (option!) )
1398 /// prot_ptr: an initialized instance of ClassicAbinitio, FoldConstraints or JumpingFoldConstraints depending on
1399 /// user settings.
1400 void AbrelaxApplication::setup_fold( pose::Pose& extended_pose, ProtocolOP& prot_ptr ) {
1401  using namespace basic::options;
1402  using namespace basic::options::OptionKeys;
1403  // ==========================================================================
1404  /// --------- fold()-specific setup --------------------------
1405  // ==========================================================================
1406 
1407  // ---------------------------------------------------------------------------------------------------------------
1408  // initialize pose
1409  generate_extended_pose( extended_pose, sequence_ );
1410 
1411  // apply a mover which calculates only repulsive energy on designate residues
1413  replonly.apply( extended_pose );
1414 
1415 
1416  if ( option[ OptionKeys::abinitio::start_native ]() ) {
1417  copy_native_structure( extended_pose );
1418  } else if ( option[ in::file::s ].user() ) {
1419  core::pose::PoseOP tmp_pose( new core::pose::Pose );
1420  std::string fn = option[ in::file::s ](1);
1421  core::import_pose::pose_from_pdb( *tmp_pose, fn );
1422  copy_structure( extended_pose, *tmp_pose );
1423  }
1424 
1425  // Fix disulfides if a file is given
1426  if ( option[ basic::options::OptionKeys::in::fix_disulf ].user() ) {
1427  io::raw_data::DisulfideFile ds_file( option[ OptionKeys::in::fix_disulf ]() );
1429  ds_file.disulfides(disulfides, extended_pose);
1430  extended_pose.conformation().fix_disulfides( disulfides );
1431  }
1432 
1433  // ---------------------------------------------------------------------------------------------------------------
1434  bRelax_ = option[ OptionKeys::abinitio::relax ]() ||
1435  option[ OptionKeys::abinitio::fastrelax ]() ||
1436  option[ OptionKeys::abinitio::multifastrelax ]();
1437 
1438  // FRAGMENTS:
1439  // stores in FragSetOP fragset_large_, fragset_small_;
1440  setup_fragments();
1441 
1442  // read in constraint_forest, generate random sample
1443  initialize_constraint_forest( extended_pose );
1444 
1445  // add constraints if available
1446  add_constraints( extended_pose );
1447 
1448  if( option[OptionKeys::abinitio::membrane].user() ) {
1449  if(option[in::file::spanfile].user())
1450  {
1451  std::string spanfile(option[OptionKeys::in::file::spanfile]());
1452  std::cout << "Reading spanfile " << spanfile <<"\n";
1453  setup_membrane_topology(extended_pose, spanfile);
1454  //read in membrane jumps if available
1456  std::cout << "1.TEMPLATE SIZE: " << membrane_jumps_->template_size() << "\n";
1457  std::cout << "1.PAIRING SIZE: " << membrane_jumps_->pairings_size() << "\n";
1458  if(option[ jumps::pairing_file ].user() && option[ jumps::jump_lib].user())
1459  {
1460  membrane_jumps_->init(option[ jumps::jump_lib ], option[ jumps::pairing_file ]); //template_file,pairings_file)
1461  }
1462  std::cout << "2.TEMPLATE SIZE: " << membrane_jumps_->template_size() << "\n";
1463  std::cout << "2.PAIRING SIZE: " << membrane_jumps_->pairings_size() << "\n";
1464 
1465  }
1466  } else {
1467  // setup jumping... evtl. needs fragset to determine sheet/loop-fractions..
1468  setup_jumps( extended_pose );
1469  }
1470 
1471  // make a MoveMap
1473  movemap->set_bb( true );
1474 
1475  if ( option[ OptionKeys::abinitio::fix_residues_to_native ].user() ) {
1476  utility::vector1< int> const& fix_start_ends( option[ OptionKeys::abinitio::fix_residues_to_native ]() );
1477  for ( Size i=1; i + 1 <= fix_start_ends.size(); i+=2 ) {
1478  Size const start( fix_start_ends[ i ]);
1479  Size const end( fix_start_ends[ i + 1 ]);
1480  if ( !(end >= start) ) utility_exit_with_message("end < start in abinitio:fix_residues_to_native");
1481  fragment::Frame long_frame(start, end-start+1 );
1482  //create apropriate length FragData object
1483  FragData frag( new BBTorsionSRFD, end-start+1 );
1484 
1485  // get torsion angles from native pose
1486  frag.steal( *native_pose_, long_frame );
1487 
1488  // apply native torsions to extended structue
1489  frag.apply( extended_pose, long_frame );
1490 
1491  for ( Size pos = start; pos <= end; pos++ ) {
1492  movemap->set_bb( pos, false);
1493  }
1494  }
1495  }
1496 
1497  if ( option[ OptionKeys::loopfcst::use_general_protocol ] ) {
1498  // parse loops file Loops
1499  if ( option[ OptionKeys::loops::loop_file ].user() ) {
1501  }
1503  // if full-atom load starting structure as full-atom to recover sidechains later
1504  if ( option[ OptionKeys::loops::input_pdb ].user() ) {
1505  if ( option[ in::file::fullatom ]() ) {
1507  core::import_pose::pose_from_pdb( extended_pose, *rsd_set, option[ OptionKeys::loops::input_pdb ]().name() );
1508  if ( !extended_pose.is_fullatom() ) utility_exit_with_message(" this full-atom pose should be a full-atom pose, no? ");
1509  } else {
1510  // centroid starting structure for loop-modeling
1512  core::import_pose::pose_from_pdb( extended_pose, *rsd_set, option[ OptionKeys::loops::input_pdb ]().name() );
1513  if ( extended_pose.is_fullatom() ) utility_exit_with_message(" this centroid pose should not be a full-atom pose, no? ");
1514  }
1515  loops_in_.verify_against( extended_pose );
1516  if( option[ OptionKeys::loops::random_grow_loops_by ].user() ){
1517  loops_in_.grow_all_loops( extended_pose, option[ OptionKeys::loops::random_grow_loops_by ]() );
1518  tr.Info << "Enlarged loops: " << std::endl;
1519  tr.Info << loops_in_ << std::endl;
1520  };
1521  }
1522  loops_in_.verify_against( extended_pose );
1523  add_constraints( extended_pose );
1524  core::kinematics::simple_visualize_fold_tree( extended_pose.fold_tree(), tr.Debug );
1525 
1526  KinematicAbinitioOP sampler = new KinematicAbinitio( fragset_small_, fragset_large_, movemap /*this movemap will be ignored*/ );
1527  ResolutionSwitcher res_switch(
1528  extended_pose,
1529  extended_pose.is_fullatom(),
1530  sampler->start_from_centroid(),
1531  sampler->return_centroid()
1532  );
1533  if ( native_pose_ ) sampler->set_native_pose( native_pose_ );
1534  sampler->set_show_viol_level( option[ constraints::viol_level ] );
1535  sampler->init( res_switch.start_pose() );
1536 
1537  if ( option[ OptionKeys::abinitio::close_loops ]() ) {
1539 
1540  if ( option[ OptionKeys::loops::alternative_closure_protocol ]() ) {
1541  closure_protocol =
1543  }
1544 
1545  if ( option[ OptionKeys::loops::fa_closure_protocol ]() ) {
1547  closure_protocol = prot = new loops::loop_closure::ccd::FASelectSlidingWindowLoopClosure;
1548  //spaeter kann man hier einen ResolutionSwitcher uebergeben.
1549  runtime_assert( extended_pose.is_fullatom() );
1550  prot->set_fullatom_pose( extended_pose );
1551  }
1552 
1553  // set options here if you like
1554  // closure_protocol-> ... and write the setters/accessors, too, if you have to
1555  closure_protocol->scored_frag_cycle_ratio( option[ OptionKeys::loops::scored_frag_cycles ]() );
1556  closure_protocol->short_frag_cycle_ratio( option[ OptionKeys::loops::short_frag_cycles ]() );
1557  closure_protocol->set_native_pose( native_pose_ );
1558  bool const bIdeal( !option[ OptionKeys::loops::non_ideal_loop_closing ]() );
1559  closure_protocol->set_bIdealLoopClosing( bIdeal );
1560  closure_protocol->set_chainbreak_max( option[ OptionKeys::loops::chainbreak_max_accept ]() );
1561  if ( !bIdeal ) option[ basic::options::OptionKeys::out::file::silent_struct_type ].def( "binary");
1562  if ( option[ OptionKeys::abinitio::debug ] ) {
1563  closure_protocol->keep_fragments();
1564  }
1565 
1566  sampler->closure_protocol( closure_protocol );
1567  }
1568 
1569  LoopJumpFoldCstOP controller;
1570  if ( option[ OptionKeys::loops::extended_loop_file ].user() ) {
1571  std::string filename( option[ OptionKeys::loops::extended_loop_file ]().name() );
1572  loops::Loops extended_loops_in( filename ); // <== TODO: select these using density score
1573  extended_loops_in.verify_against( extended_pose );
1574  KinematicAbinitioOP stage1_sampler = new KinematicAbinitio( *sampler );
1575  sampler->bSkipStage1_ = true;
1576 
1577  stage1_sampler->init( res_switch.start_pose() ); //sets default options
1578  stage1_sampler->bSkipStage3_ = true;
1579  stage1_sampler->bSkipStage4_ = true;
1580  stage1_sampler->closure_protocol( NULL );
1581  loops::Loops rigid_core( loops_in_.invert( extended_pose.total_residue() ) );
1582  controller = new DoubleLayerKinematicAbinitio(
1583  jump_def_,
1584  extended_loops_in,
1585  rigid_core,
1586  sampler,
1587  stage1_sampler,
1588  ss_def_,
1589  option[ loopfcst::coord_cst_weight ],
1590  option[ loopfcst::coord_cst_all_atom ]
1591  );
1592  } else {
1593  controller = new LoopJumpFoldCst(
1594  jump_def_,
1595  loops_in_,
1596  sampler,
1597  ss_def_,
1598  option[ loopfcst::coord_cst_weight ],
1599  option[ loopfcst::coord_cst_all_atom ]
1600  );
1601  }
1602 
1603  controller->set_input_pose_is_fa( extended_pose.is_fullatom() );
1604  prot_ptr = controller;
1605  if ( evaluator_->size() ) sampler->set_evaluation( evaluator_ );
1606 
1607  if ( option[ loopfcst::coord_cst_weight_array ].user() ) {
1608  utility::io::izstream file( option[ loopfcst::coord_cst_weight_array ]() );
1609  if ( !file.good() ) {
1610  utility_exit_with_message("ERROR:: Unable to open coord_cst_weight_array file: ");
1611  }
1613  read_vector( file, weights );
1614  controller->set_coord_cst_weight_array( weights );
1615  }
1616 
1617  if ( option[ loopfcst::dump_coord_cst_weight_array ].user() ) {
1618  controller->set_dump_weights_file( option[ loopfcst::dump_coord_cst_weight_array ] );
1619  }
1620 
1621 
1622  } else { // not -use_general_protocol
1623  // setup abinitio protocol: one of either, MembraneAbinitio / ClassicAbinitio/ FoldConstraints/ JumpingFoldConstraints
1624  if ( option[ basic::options::OptionKeys::abinitio::membrane ]() ) {
1625  tr.Info << "run MembraneAbinitio.... " << std::endl;
1627  tr.Info << "After new MembraneAbinitio.... " << std::endl;
1628  } else {
1629  if ( jump_def_ ) {
1630  tr.Info << "run JumpingFoldConstraints....." << std::endl;
1631  // it doesn't matter if we have no constraints the extra FoldConstraints part in the Jumping protocl
1632  // won't do anything
1635  if ( native_pose_ ) pp->set_native_pose( native_pose_ ); //to steal native jumps
1636  pp->set_show_viol_level( option[ constraints::viol_level ] );
1637  prot_ptr = pp;
1638  } else {
1639  if ( extended_pose.constraint_set()->has_residue_pair_constraints() ) {
1640  // We have constraints: run xxxFoldConstraints
1641  tr.Info << "run FoldConstraints....." << std::endl;
1642  FoldConstraintsOP pp;
1643  pp = new FoldConstraints( fragset_small_, fragset_large_, movemap );
1644  pp->set_show_viol_level( option[ constraints::viol_level ] );
1645  prot_ptr = pp;
1646  } else {
1647  /// no constraints ---> ClassicAbinitio
1648  tr.Info << "run ClassicAbinitio....." << std::endl;
1649  prot_ptr = new ClassicAbinitio( fragset_small_, fragset_large_, movemap );
1650  }
1651  }
1652  }
1653  }
1654 
1655  Protocol& abinitio_protocol( *prot_ptr ); // hide the fact that protocol is a pointer
1656 
1657  /// initialize protocol
1658  abinitio_protocol.init( extended_pose );
1659  if ( option[ OptionKeys::loopfcst::use_general_protocol ] ) {
1660  abinitio_protocol.return_centroid( !(bRelax_ || option[ OptionKeys::abinitio::return_full_atom ]) );
1661  } else {
1662  abinitio_protocol.return_centroid( true );
1663  }
1664  if ( evaluator_->size() ) abinitio_protocol.set_evaluation( evaluator_ );
1665 }
1666 ////////////////////////////////////////////////////////////////////////////////////////////////////
1668  using namespace protocols::filters;
1669 
1670  // return true if we're not supposed to use filters
1671  if ( !basic::options::option[ basic::options::OptionKeys::abinitio::use_filters ]() ) return true;
1672  if ( option[ basic::options::OptionKeys::filters::disable_all_filters ]() ) return true; //makes a lot of sense IMHO
1673 
1674  // apply RG, contact-order and sheet filters
1678 
1679  if ( !option[ basic::options::OptionKeys::filters::disable_rg_filter ]() && !rg_filter.apply( pose) ) return false;
1680  if ( !option[ basic::options::OptionKeys::filters::disable_co_filter ]() && !co_filter.apply( pose) ) return false;
1681  if ( !option[ basic::options::OptionKeys::filters::disable_sheet_filter ]() && !sh_filter.apply( pose) ) return false;
1682 
1683  if( ( option[basic::options::OptionKeys::filters::set_pddf_filter ].user() ) &&
1684  ( option[basic::options::OptionKeys::score::saxs::ref_pddf ].user() ) ) {
1685 
1687  bool flag = pddf_filter->apply(pose);
1688  core::pose::setPoseExtraScores( pose, "pddf_score", pddf_filter->recent_score());
1689  if( ! flag ) return false; // We need this flag because filter's score must be set before this if statement
1690  }
1691 
1692  if( ( option[basic::options::OptionKeys::filters::set_saxs_filter ].user() ) &&
1694 
1696  bool flag = saxs_filter->apply(pose);
1697  core::pose::setPoseExtraScores( pose, "saxs_score", saxs_filter->recent_score());
1698  if( ! flag ) return false; // We need this flag because filter's score must be set before this if statement
1699  }
1700 
1701  tr.Info << " passed all filters " << std::endl;
1702  return true;
1703 }
1704 
1705 ////////////////////////////////////////////////////////////////////////////////////////////////////
1707  core::scoring::ScoreFunctionOP scorefxn( NULL );
1708  if ( fullatom ) {
1709  scorefxn = core::scoring::getScoreFunction();
1710  } else {
1711  if ( option[ basic::options::OptionKeys::abinitio::membrane ]() ) {
1712  scorefxn = core::scoring::ScoreFunctionFactory::create_score_function( "score_membrane" );
1713  } else if ( option[ OptionKeys::abinitio::stage4_patch ].user() ) {
1714  scorefxn = core::scoring::ScoreFunctionFactory::create_score_function( "score3", option[ OptionKeys::abinitio::stage4_patch ]() );
1715  } else {
1717  }
1718  }
1719  if ( jump_def_ && !option[ OptionKeys::jumps::no_chainbreak_in_relax ] ) {
1720  scorefxn->set_weight( core::scoring::linear_chainbreak, 1.0 );
1721  scorefxn->set_weight( core::scoring::overlap_chainbreak, 1.0 );
1722  }
1723  if ( cstset_ && cstset_->has_residue_pair_constraints() ) {
1724  scorefxn->set_weight( core::scoring::atom_pair_constraint, option[ OptionKeys::constraints::cst_weight ]() );
1725  scorefxn->set_weight( core::scoring::angle_constraint, option[ OptionKeys::constraints::cst_weight ]() );
1726  scorefxn->set_weight( core::scoring::dihedral_constraint, option[ OptionKeys::constraints::cst_weight ]() );
1727  }
1728  if ( option[ OptionKeys::loopfcst::coord_cst_weight ].user() ) {
1729  scorefxn->set_weight( core::scoring::coordinate_constraint, option[ OptionKeys::loopfcst::coord_cst_weight ]);
1730  }
1731  return scorefxn;
1732 }
1733 ////////////////////////////////////////////////////////////////////////////////////////////////////
1734 ///@detail everything happens in fold()!
1735 /// setup of stuff that is not needed for rerun()
1736 /// read fragments
1737 /// [ optional ] steal fragments ( take fragments from native pose )
1738 ///
1740  Protocol& abinitio_protocol( *prot_ptr ); // hide the fact that protocol is a pointer
1741 
1742  using namespace basic::options;
1743  using namespace basic::options::OptionKeys;
1744  using namespace core::scoring::constraints;
1748 
1749  // determine nstruct
1750  int const nstruct = std::max( 1, option [ out::nstruct ]() );
1751 
1752  // setup JobDistributor stuff
1753  utility::vector1< BasicJobOP > input_jobs;
1754 
1755  if ( option[ in::file::tags ].user() ) {
1756  // get input tags
1757  typedef utility::vector1< std::string > TagList;
1758  TagList input_tags;
1759  utility::io::izstream tag_file( option[ in::file::tagfile ]() );
1760 
1761  std::copy( std::istream_iterator< std::string >( tag_file ), std::istream_iterator< std::string >(),
1762  std::back_inserter( input_tags ) );
1763 
1764  // create jobs
1765  for ( TagList::const_iterator it = input_tags.begin(), eit = input_tags.end(); it!=eit; ++it ) {
1766  BasicJobOP job = new BasicJob( *it, "resample", nstruct);
1767  tr.Debug << "create resample job" << *it << std::endl;
1768  input_jobs.push_back( job );
1769  }
1770  } else { //default behaviour
1771  BasicJobOP job = new BasicJob("" /*no input tag*/, "abinitio_relax", nstruct);
1772  input_jobs.push_back( job );
1773  }
1774 
1775  PlainSilentFileJobDistributor jobdist( input_jobs );
1776  BasicJobOP curr_job;
1777  int curr_nstruct;
1778  jobdist.startup();
1779  bool bEndrun = false;
1780 
1781  // setup scorefunctions
1782  // this is called in setup_fold: add_constraints( extended_pose ); //such that scorefxn setup knows about constraints...
1783  core::scoring::ScoreFunctionOP centroid_scorefxn( generate_scorefxn( false /*fullatom*/ ) );
1784  core::scoring::ScoreFunctionOP fullatom_scorefxn( generate_scorefxn( true /*fullatom*/ ) ); // this is the score12 standard score function ?! );
1785  abinitio_protocol.set_fullatom_scorefxn( fullatom_scorefxn );
1786  abinitio_protocol.set_centroid_scorefxn( centroid_scorefxn );
1787 
1788  evaluation::TimeEvaluatorOP run_time( NULL );
1789  if ( !option[ OptionKeys::run::no_prof_info_in_silentout ]() ) {
1790  add_evaluation( run_time = new evaluation::TimeEvaluator ); //just don't use this in integration tests!
1791  abinitio_protocol.set_evaluation( evaluator_ );
1792  }
1793 
1794  // production loop
1795  while ( jobdist.next_job(curr_job, curr_nstruct) && !bEndrun ) {
1796  time_t pdb_start_time = time(NULL);
1797  if ( run_time && !option[ OptionKeys::abinitio::no_write_failures ]() ) { //if we omit decoys we want to count from write-event to write-
1798  run_time->reset(); //reset clock of TimeEvaluator
1799  }
1800 
1801  #ifdef BOINC
1802  std::cerr << "Starting work on structure: " << curr_job->output_tag(curr_nstruct) << std::endl;
1803  #endif
1804 
1805  // retrieve starting pose
1806  pose::Pose fold_pose ( init_pose );
1807  // Can we add the PyMOL mover here?
1808  if (option[OptionKeys::run::show_simulation_in_pymol].user()
1809  && option[OptionKeys::run::show_simulation_in_pymol].value() > 0.0)
1810  {
1812  option[OptionKeys::run::keep_pymol_simulation_history](),
1813  option[OptionKeys::run::show_simulation_in_pymol].value());
1814  }
1815 
1816 
1817 //membrane jumping set up the proper foldtree
1818  if( membrane_jumps_ && membrane_jumps_->defined() ) {
1819  Size njumps = option[jumps::njumps]();
1820  membrane_jumps_->setup_fold_tree(fold_pose,njumps);
1821  }
1822 
1823  // kill hairpins
1824  //using core::pose::datacache::CacheableDataType::SS_KILLHAIRPINS_INFO;
1825  if ( option[ OptionKeys::abinitio::kill_hairpins ].user() ) {
1827  runtime_assert( fold_pose.data().has( core::pose::datacache::CacheableDataType::SS_KILLHAIRPINS_INFO ) );
1829  hairpins.setup_killhairpins();
1830  }
1831 
1832  #ifdef BOINC_GRAPHICS
1833  // attach boinc graphics pose observer
1834  protocols::boinc::Boinc::attach_graphics_current_pose_observer( fold_pose );
1835  #endif
1836 
1837  if ( bRelax_ ) { //always add all f@@#$ columns so we never-ever have a column mismatch....
1838  relax::ClassicRelax().setPoseExtraScores( fold_pose );
1839  }
1840 
1841  // need to save RG states such that choices for constraints and fold-tree are the same.
1842  if( ! abrelax_checkpoints_.recover_checkpoint( fold_pose, jobdist.get_current_output_tag(), "rg_state") ){
1843  abrelax_checkpoints_.checkpoint( fold_pose, jobdist.get_current_output_tag(), "rg_state");
1844  }
1845  abrelax_checkpoints_.debug( jobdist.get_current_output_tag(), "rg_state", RG.uniform() );
1846 
1847  // perturb phi/psi randomly -- should be different each run
1848  if ( option[ OptionKeys::abinitio::perturb ].user() ) {
1849  Real sig = option[ OptionKeys::abinitio::perturb ];
1850  for ( Size pos = 1; pos <= fold_pose.total_residue(); pos++ ) {
1851  fold_pose.set_phi( pos, fold_pose.phi( pos ) + numeric::random::gaussian()*sig );
1852  fold_pose.set_psi( pos, fold_pose.psi( pos ) + numeric::random::gaussian()*sig );
1853  fold_pose.set_omega( pos, fold_pose.omega( pos ) );
1854  }
1855  }
1856 
1857  // run abinitio
1858 
1859  // set the TAG
1860  abinitio_protocol.set_current_tag( jobdist.get_current_output_tag() );
1861 
1862  // and the JOB (that's different)
1863  abinitio_protocol.set_current_job( curr_job );
1864  tr.Debug << "fold_pose is " << (fold_pose.is_fullatom() ? " fullatom " : " centroid " ) << "before protocol run "<<std::endl;
1865 
1866  std::string output_tag = abinitio_protocol.get_current_tag();
1867  abinitio_protocol.apply( fold_pose );
1868 
1869  bool loop_closure_failed( false ); //!fold_pose.fold_tree().num_cutpoint() );
1870 
1871  if ( option[ OptionKeys::abinitio::close_loops ]()
1872  && abinitio_protocol.get_last_move_status() == moves::MS_SUCCESS
1873  && !option[ OptionKeys::loopfcst::use_general_protocol ] )
1874  {
1875  tr.Info << "OLD PATHWAY: close loops" << std::endl;
1876  loop_closure_failed = !close_loops( fold_pose, centroid_scorefxn, jobdist.get_current_output_tag() );
1877  }
1878 
1879  if ( bRelax_ && option [ OptionKeys::abinitio::debug ] ) {
1881  std::string silent_file = option[ basic::options::OptionKeys::out::file::silent ]() + "_" + "before_relax";
1882 
1883  io::silent::SilentStructOP pss = io::silent::SilentStructFactory::get_instance()->get_silent_struct_out();
1884  process_decoy( fold_pose, fold_pose.is_fullatom() ? *fullatom_scorefxn : *centroid_scorefxn, jobdist.get_current_output_tag(), *pss );
1885  outsfd.write_silent_struct( *pss, silent_file );
1886  }
1887 
1888  // run relax if applicable. Use filters to decide which structures to relax and which not to relax!
1889  bool passes_filters = check_filters( fold_pose );
1890  if(option[OptionKeys::abinitio::membrane]){
1891  passes_filters=true;
1892  }
1893  bool bProcessDecoy( true );
1894  // run relax if applicable
1895  // don't relax if we failed filters or loop_closing, or if option[ relax_with_jumps ] is true
1896  bool bCanRelax = abinitio_protocol.get_last_move_status() == moves::MS_SUCCESS;
1897  if( option[ basic::options::OptionKeys::abinitio::relax_failures ]() ) bCanRelax = true;
1898  bCanRelax = bCanRelax && passes_filters
1899  && ( !loop_closure_failed || option[ OptionKeys::abinitio::relax_with_jumps ]() );
1900 
1901  if ( bRelax_ ) {
1902  if ( !fold_pose.is_fullatom() ) {
1903  pose::Pose const centroid_pose ( fold_pose );
1904  ResolutionSwitcher res_switch( centroid_pose, false, true, true );
1905 
1906  if ( option[ OptionKeys::constraints::cst_fa_file ].user() ) res_switch.set_map_cst_from_centroid_to_fa( false ); //will override any attempt to map centroid constraints to full-atom constraints -- use user-defined file instead!
1907 
1908  res_switch.apply( fold_pose );
1909 
1910  if ( option[ OptionKeys::constraints::cst_fa_file ].user() ) {
1912  fold_pose.constraint_set( cstset_ );
1913  }
1914  }
1915 
1916  if( option[ basic::options::OptionKeys::abinitio::close_loops_by_idealizing ]() ){
1917  // record cutpoints
1919  for ( Size ncut = 1; ncut <= (Size) fold_pose.fold_tree().num_cutpoint(); ncut++ ) {
1920  Size cutpoint = fold_pose.fold_tree().cutpoint( ncut );
1921  protocols::loops::Loop newloop (
1922  std::max( (int) 1, int(cutpoint - 5) ),
1923  std::min( (int) fold_pose.total_residue(), int(cutpoint + 5) ),
1924  0
1925  );
1926 
1927  if( cloops->size() >= 2 )
1928  if( newloop.start() <= ( *cloops )[cloops->size()-1].stop() ) newloop.set_start( ( *cloops )[cloops->size()-1].stop() +2 );
1929  newloop.choose_cutpoint( fold_pose );
1930  cloops->add_loop( newloop );
1931  }
1932 
1933  cloops->auto_choose_cutpoints( fold_pose );
1934 
1935  // forget about foldtree & cuts
1937  f_new.simple_tree( fold_pose.total_residue() );
1938  fold_pose.fold_tree( f_new );
1939 
1940  //idealize
1942  idealizer.fast( false );
1943  idealizer.apply( fold_pose );
1944 
1945  relax( fold_pose, fullatom_scorefxn, jobdist.get_current_output_tag() );
1946 
1947  if( option[ basic::options::OptionKeys::abinitio::optimize_cutpoints_using_kic ]() ){
1948  protocols::loops::fold_tree_from_loops( fold_pose, *cloops, f_new, true /* include terminal cutpoints */);
1949  fold_pose.fold_tree( f_new );
1950  core::scoring::ScoreFunctionOP refine_scorefxn = fullatom_scorefxn->clone();
1951  protocols::loops::loop_mover::refine::LoopMover_Refine_KIC refine_kic( cloops, refine_scorefxn );
1952  refine_kic.apply( fold_pose );
1953 
1954  // Return fold tree to norml state
1955  f_new.simple_tree( fold_pose.total_residue() );
1956  fold_pose.fold_tree( f_new );
1957  }
1958  }
1959 
1960  if ( bCanRelax ) {
1961  if ( option[ basic::options::OptionKeys::abinitio::multifastrelax ]() ) {
1962  bEndrun = multi_fast_relax( abinitio_protocol, fullatom_scorefxn, jobdist, curr_nstruct, curr_job );
1963  bProcessDecoy = false;
1964  if ( bEndrun ) break;
1965  } else {
1966  relax( fold_pose, fullatom_scorefxn, jobdist.get_current_output_tag() );
1967  }
1968  } else { //cannot relax
1969  (*fullatom_scorefxn)( fold_pose );
1970  if ( option[ basic::options::OptionKeys::abinitio::fastrelax ]() ) {
1971  } else {
1972  relax::ClassicRelax().setPoseExtraScores( fold_pose ); // ClassicRelax adds four columns
1973  }
1974  }
1975  } // if ( bRelax_ )
1976 
1977  //Add contact order to score file as an extra column
1979  Real contact_order = co_energy.calculate_contact_order( fold_pose );
1980  core::pose::setPoseExtraScores( fold_pose, "co", contact_order );
1981 
1982  // process decoy if this hasn't happened yet
1983  if ( bProcessDecoy ) {
1984  if( option[ run::checkpoint ]() ){
1985  core::pose::setPoseExtraScores( fold_pose, "ichkpnt",
1986  abinitio_protocol.get_checkpoints().get_checkpoint_recoveries() +
1988  }
1989 
1990  // analyze result
1992 
1993  //make sure that number of columns does not change -- ever
1994  outsfd.strict_column_mode( true );
1995 
1996  io::silent::SilentStructOP pss = io::silent::SilentStructFactory::get_instance()->get_silent_struct_out();
1997 
1998  // abinitio produces n_stored structures -- the last one is the same as the final structure n_stored.
1999  // Size n_stored( abinitio_protocol.structure_store().size() );
2000  std::string new_output_tag ( output_tag );
2001  if ( !passes_filters && loop_closure_failed ) {
2002  new_output_tag = "X_"+new_output_tag.substr(2);
2003  } else if( loop_closure_failed ) {
2004  new_output_tag = "C_"+new_output_tag.substr(2);
2005  } else if( !passes_filters ) {
2006  new_output_tag = "F_"+new_output_tag.substr(2);
2007  } else if ( abinitio_protocol.get_last_move_status() != moves::MS_SUCCESS ) {
2008  new_output_tag = "P_"+new_output_tag.substr(2);
2009  }
2010 
2011  if ( !option[ OptionKeys::abinitio::no_write_failures ]()
2012  || ( passes_filters && !loop_closure_failed && abinitio_protocol.get_last_move_status() == moves::MS_SUCCESS ) ) {
2013  // write to silent file
2014  process_decoy( fold_pose, fold_pose.is_fullatom() ? *fullatom_scorefxn : *centroid_scorefxn, new_output_tag, *pss );
2015 
2016  // write this to score-file if applicable
2017  if ( silent_score_file_ ) {
2018  silent_score_file_ -> write_silent_struct( *pss, silent_score_file_->filename(), true /* bWriteScoresOnly */ );
2019  }
2020  if ( option[ OptionKeys::out::pdb ] ) fold_pose.dump_pdb( std::string(option[ OptionKeys::out::path::path ]()) + "/" + new_output_tag + ".pdb");
2021  outsfd.add_structure( pss );
2022  if ( run_time && option[ OptionKeys::abinitio::no_write_failures ]() ) { //if we omit decoys we want to count from write-event to write-
2023  run_time->reset(); //reset clock of TimeEvaluator
2024  }
2025 
2026  }
2027 
2028  jobdist.dump_silent( outsfd ); // does the same thing as: outsfd.write_all( filename ); //cool bulk-writing makes clusters happy
2029  } //bProcessDecoy ( false if multi-fast_relax )
2030 
2031  // clean up
2032  time_t pdb_end_time = time(NULL);
2033  tr.Info << "Finished " << curr_job->output_tag(curr_nstruct) << " in " << (pdb_end_time - pdb_start_time) << " seconds." << std::endl;
2034  abinitio_protocol.get_checkpoints().clear_checkpoints();
2036  } // end of production loop
2037  jobdist.shutdown();
2038 }
2039 
2040 ////////////////////////////////////////////////////////////////////////////////////////////////////
2041 typedef std::pair < core::pose::Pose, core::Real > PoseWithScore;
2043 {
2044  return left.second < right.second;
2045 }
2046 
2047 ////////////////////////////////////////////////////////////////////////////////////////////////////
2048 ///@detail do fast relax on multiple structures that have been visited during abinitio-protocol.
2049 /// MIKE: please give more documentation to this
2051  Protocol& ,
2054  int& ,
2056 )
2057 {
2058  std::cerr << "multi_fast_relax stubbed out" << std::endl;
2059  return true;
2060 }
2061 
2062 ////////////////////////////////////////////////////////////////////////////////////////////////////
2063 ///@detail full-atom relax of decoys
2064 /// uses either ClassicRelax or FastRelax protocols.
2066  using namespace basic::options::OptionKeys;
2067  using namespace basic::options;
2068 
2069  //bail out if no relax is done
2070  if ( !option[ OptionKeys::abinitio::relax ]() &&
2071  !option[ OptionKeys::abinitio::fastrelax ]() ) return;
2072 
2073  // run relax if applicable
2074 
2075  // remove constraints if option is set
2076  ConstraintSetOP orig_cst = NULL;
2077  if ( option[ constraints::no_cst_in_relax ] ) {
2078  orig_cst = pose.constraint_set()->clone();
2079  pose.constraint_set( NULL );
2080  }
2081 
2082  add_fa_constraints_from_cmdline( pose, *scorefxn );
2083 
2084  if ( option[ OptionKeys::abinitio::detect_disulfide_before_relax ] ) {
2086  }
2087 
2088  // Support deprecated option
2089  if ( option[ basic::options::OptionKeys::abinitio::fastrelax ]() ) {
2090  tr.Error << "WARNING: Using DEPRECATED OPTION fastrelax ! " << std::endl;
2091  option[ basic::options::OptionKeys::abinitio::relax ].def( true );
2092  option[ basic::options::OptionKeys::relax::fast ].def( true );
2093  }
2094  if ( option[ OptionKeys::abinitio::relax ]() ) {
2095  if ( !abrelax_checkpoints_.recover_checkpoint( pose, tag, "relax", true, true) ) {
2096  relax::relax_pose( pose, scorefxn, tag );
2097  abrelax_checkpoints_.checkpoint( pose, tag, "relax", true ); //since relax_protocol throws away its checkpoints right here
2098  }
2099  abrelax_checkpoints_.debug( tag, "relax", (*scorefxn)( pose ) );
2100  }
2101 
2102  /// Do a final clean relax without the constraints ?
2103  if( option[ OptionKeys::loops::final_clean_fastrelax ]() ){
2104  if ( !abrelax_checkpoints_.recover_checkpoint( pose, tag, "final_fastrelax", true, true) ) {
2105  pose.constraint_set( NULL );
2106  relax::FastRelax fast_relax( scorefxn );
2107  fast_relax.set_current_tag( tag );
2108  fast_relax.apply( pose );
2109  abrelax_checkpoints_.checkpoint( pose, tag, "final_fastrelax", true ); //since relax_protocol throws away its checkpoints right here
2110  }
2111  abrelax_checkpoints_.debug( tag, "final_fastrelax", (*scorefxn)( pose ) );
2112  }
2113 } // AbrelaxApplication::relax
2114 
2115 ////////////////////////////////////////////////////////////////////////////////////////////////////
2116 ///@detail after setup() run either fold() or rerun()
2118  using namespace basic::options::OptionKeys;
2119  if ( !basic::options::option[ basic::options::OptionKeys::in::path::database ].user() ) {
2120  basic::options::option[ basic::options::OptionKeys::in::path::database ].def( "/work/olange/minirosetta_database");
2121  }
2122  setup();
2123 
2124  if ( option [ OptionKeys::abinitio::rerun ] ) {
2125  do_rerun();
2126  return;
2127  }
2128 
2129  if ( option [ OptionKeys::abinitio::jdist_rerun ] ) {
2131  return;
2132  }
2133 
2134  // setup pose and abinitio
2135  ProtocolOP prot_ptr;
2136  pose::Pose init_pose;
2137 #ifdef BOINC
2138  std::cerr << "Setting up folding (abrelax) ..." << std::endl;
2139 #endif
2140  setup_fold( init_pose, prot_ptr ); //init_pose may or may not be fullatom (depending on flag option[ in:file:fullatom] )
2141 
2142 #ifdef BOINC
2143  std::cerr << "Beginning folding (abrelax) ... " << std::endl;
2144 #endif
2145  fold( init_pose, prot_ptr );
2146  return;
2147 }
2148 
2149 //============= Implementation of PoseEvaluators ======================================
2150 ////////////////////////////////////////////////////////////////////////////////////////////////////
2151 ///@detail
2153  using namespace basic::options::OptionKeys;
2154  if ( pose.constraint_set()->has_residue_pair_constraints() ) {
2155  //don't remove its not active ( on BOINC ) if you don't say -viol !!!
2156  pose.constraint_set()->show_violations( std::cout, pose, option[ constraints::viol_level ] );
2157  }
2158 }
2159 
2160 ////////////////////////////////////////////////////////////////////////////////////////////////////
2161 ///@detail
2163  using namespace basic::options::OptionKeys;
2164  if ( pose.constraint_set()->has_residue_pair_constraints() ) {
2165  if ( !constraints_ ) {
2166  constraints_ = new ConstraintSet( *pose.constraint_set() ); //get rid of MAX_SEQ_SEP
2167  }
2168  if ( option[ constraints::compute_total_dist_cst ]() ) {
2169  pose::Pose my_pose ( pose ); //copy of pose, don't want to change any score terms.
2170  my_pose.constraint_set( constraints_ );
2172  scfxn.set_weight( core::scoring::atom_pair_constraint, option[ constraints::cst_weight ]() );
2173  scfxn( my_pose );
2174  pss.add_energy("total_dist_cst", my_pose.energies().total_energies()[ core::scoring::atom_pair_constraint ] );
2175  }
2176  }
2177 }
2178 
2179 ////////////////////////////////////////////////////////////////////////////////////////////////////
2180 void
2182  PCA::ProjectionVector proj;
2183  pca_->eval( pose, proj );
2184  pss.add_energy ( "pca1", proj[1] );
2185  pss.add_energy ( "pca2", proj[2] );
2186 }
2187 
2188 } //abinitio
2189 } //protocols