Rosetta
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
mpi_msd.cc
Go to the documentation of this file.
1 // -*- mode:c++;tab-width:2;indent-tabs-mode:t;show-trailing-whitespace:t;rm-trailing-spaces:t -*-
2 // vi: set ts=2 noet:
3 //
4 // (c) Copyright Rosetta Commons Member Institutions.
5 // (c) This file is part of the Rosetta software suite and is made available under license.
6 // (c) The Rosetta software is developed by the contributing members of the Rosetta Commons.
7 // (c) For more information, see http://www.rosettacommons.org. Questions about this can be
8 // (c) addressed to University of Washington UW TechTransfer, email: license@u.washington.edu.
9 
10 /// @file apps/pilot/andrew/apl_msd.cc
11 /// @brief Multistate design executable as written by apl.
12 /// @author Andrew Leaver-Fay (aleaverfay@gmail.com)
13 
14 #ifdef USEMPI
15 #include <mpi.h>
16 #endif
17 
18 /// Pack Daemon headers
19 #include <protocols/pack_daemon/EntityCorrespondence.hh>
20 #include <protocols/pack_daemon/DynamicAggregateFunction.hh>
21 #include <protocols/pack_daemon/MultistateAggregateFunction.hh>
22 #include <protocols/pack_daemon/MultistateFitnessFunction.hh>
23 #include <protocols/pack_daemon/PackDaemon.hh>
24 #include <protocols/pack_daemon/util.hh>
25 
26 /// Core headers
27 #include <devel/init.hh>
28 #include <core/io/pdb/pose_io.hh>
29 #include <basic/options/option.hh>
31 #include <basic/MetricValue.hh>
32 
33 #include <core/chemical/ResidueType.hh>
34 #include <core/conformation/Residue.hh>
35 #include <core/pose/Pose.hh>
36 #include <core/pose/metrics/CalculatorFactory.hh>
37 #include <core/scoring/ScoreFunction.hh>
38 #include <core/scoring/ScoreFunctionFactory.hh>
39 
40 #include <core/scoring/hbonds/HBondOptions.hh>
41 #include <core/scoring/methods/EnergyMethodOptions.hh>
42 
43 #include <core/pack/task/PackerTask.hh>
44 #include <core/pack/interaction_graph/SurfacePotential.hh>
45 
46 #include <core/import_pose/import_pose.hh>
47 
48 #include <basic/Tracer.hh>
49 
50 // Protocols headers
51 #include <protocols/genetic_algorithm/Entity.hh>
52 #include <protocols/genetic_algorithm/EntityRandomizer.hh>
53 #include <protocols/genetic_algorithm/Mutate1Randomizer.hh>
54 #include <protocols/genetic_algorithm/GeneticAlgorithm.hh>
55 #include <protocols/multistate_design/util.hh>
56 
57 //#include <protocols/toolbox/pose_metric_calculators/HPatchCalculator.hh>
58 #include <protocols/toolbox/pose_metric_calculators/NumberHBondsCalculator.hh>
59 #include <protocols/toolbox/pose_metric_calculators/BuriedUnsatisfiedPolarsCalculator.hh>
60 
61 // Devel headers
62 //This comment brackets a snippet of code that is automatically stripped from the release, usually for semi-forbidden interactions with the unreleased devel library
63 //If you want non-devel code stripped from the release, see the release machinery in tools/release and contact the release manager (Steven Lewis smlewi@gmail.com at this time)
64 // DELETED BY RELEASE SCRIPT
65 // DELETED BY RELEASE SCRIPT
66 // DELETED BY RELEASE SCRIPT
67 //end automatic stripping comment
68 
69 // Utility headers
70 #include <utility/mpi_util.hh>
71 #include <utility/string_util.hh>
73 
74 // Numeric headers
76 #include <numeric/random/random.hh>
77 
78 // option key includes
79 #include <basic/options/keys/ms.OptionKeys.gen.hh>
80 
81 #include <utility/vector0.hh>
82 #include <utility/vector1.hh>
83 #include <utility/io/izstream.hh>
84 #include <utility/io/ozstream.hh>
85 
86 
87 #if defined(WIN32) || defined(__CYGWIN__)
88 #include <ctime>
89 #endif
90 
91 
92 OPT_1GRP_KEY( String, msd, entity_resfile )
93 OPT_1GRP_KEY( String, msd, fitness_file )
94 OPT_1GRP_KEY( StringVector, msd, seed_sequences )
95 OPT_1GRP_KEY( Boolean, msd, fill_gen1_from_seed_sequences )
96 OPT_1GRP_KEY( Integer, msd, double_lazy_ig_mem_limit )
97 OPT_1GRP_KEY( Boolean, msd, dont_score_bbhbonds )
98 OPT_1GRP_KEY( Boolean, msd, exclude_background_energies )
99 OPT_1GRP_KEY( String, msd, seed_sequence_from_input_pdb )
100 OPT_1GRP_KEY( String, msd, seed_sequence_using_correspondence_file )
101 
102 /* Option( 'double_lazy_ig_mem_limit', 'Integer',
103 desc="The amount of memory, in MB, that each double-lazy interaction graph should be allowed \
104 to allocate toward rotamer pair energies. Using this flag will not trigger the \
105 use of the double-lazy interaction graph, and this flag is not read in the PackerTask's \
106 initialize_from_command_line routine. For use in multistate design",
107 default='0',
108 ),*/
109 
110 
111 using basic::t_info;
112 using basic::t_debug;
113 static THREAD_LOCAL basic::Tracer TR( "apps.public.design.mpi_msd", t_info );
114 
115 /*class SimpleDGBindAggregateFunction : public protocols::pack_daemon::MultistateAggregateFunction
116 {
117 public:
118 typedef protocols::pack_daemon::MultistateAggregateFunction parent;
119 
120 public:
121 SimpleDGBindAggregateFunction() : parent() {}
122 virtual ~SimpleDGBindAggregateFunction() {}
123 
124 virtual core::Real evaluate( utility::vector1< core::Real > const & vec, Entity const & ) {
125 if ( vec.size() != 2 ) {
126 utility_exit_with_message( "SimpleDGBindAggregateFunction expects exactly 2 states" );
127 }
128 return vec[ 1 ] - vec[ 2 ];
129 }
130 
131 virtual StateIndices select_relevant_states( StateEnergies const & ) {
132 StateIndices two_vec;
133 two_vec.push_back( 1 );
134 two_vec.push_back( 2 );
135 return two_vec;
136 }
137 };*/
138 
139 
140 //protocols::genetic_algorithm::EntityElements
141 //entity_elements_from_1letterstring(
142 // std::string const & input
143 //)
144 //{
145 // protocols::genetic_algorithm::EntityElements elements( input.size() );
146 // for ( core::Size ii = 0, count = 1; ii < input.size(); ++ii, ++count ) {
147 // std::ostringstream output;
148 // output << "AA:" << count << ":" << input[ ii ];
149 // elements[ count ] = protocols::genetic_algorithm::EntityElementFactory::get_instance()->element_from_string( output.str() );
150 // }
151 // return elements;
152 //}
153 
154 std::string
155 read_native_sequence_for_entity_elements( core::Size n_designed_positions )
156 {
157  using namespace basic::options;
158  using namespace basic::options::OptionKeys;
159  using namespace core;
160  using namespace protocols::pack_daemon;
161 
162  if ( ! option[ msd::seed_sequence_using_correspondence_file ].user() ) {
163  utility_exit_with_message( "Must provide correspondence file to read the native sequence" );
164  }
165 
166  std::string pdb_name = option[ msd::seed_sequence_from_input_pdb ];
167  std::string correspondence_file_name = option[ msd::seed_sequence_using_correspondence_file ];
168 
169  /// Read in the pdb
171  import_pose::pose_from_pdb( pose, pdb_name );
172 
173  utility::io::izstream correspondence_file( correspondence_file_name );
174  if ( ! correspondence_file ) {
175  utility_exit_with_message( "Could not open correspondence file named: " + correspondence_file_name );
176  }
177 
178  EntityCorrespondenceOP ec( new EntityCorrespondence );
179  ec->set_pose( core::pose::PoseCOP( core::pose::PoseOP( new pose::Pose( pose ) ) ));
180  ec->set_num_entities( n_designed_positions );
181  ec->initialize_from_correspondence_file( correspondence_file );
182 
183 
184  std::map< Size, chemical::AA > aa_for_design_position;
185  for ( Size ii = 1; ii <= pose.total_residue(); ++ii ) {
186  Size ii_entity = ec->entity_for_residue( ii );
187  if ( ii_entity == 0 ) continue;
188  if ( aa_for_design_position.find( ii_entity ) != aa_for_design_position.end() ) {
189  utility_exit_with_message( "Repeat entity element for native pdb: " + pdb_name + " with correspondence file " +
190  correspondence_file_name + ". Entity correspondence file should only include each residue once");
191  }
192  aa_for_design_position[ ii_entity ] = pose.residue_type( ii ).aa();
193  }
194  std::string aa_string( n_designed_positions, 'X' );
195  for ( Size ii = 1; ii <= n_designed_positions; ++ii ) {
196  if ( aa_for_design_position.find( ii ) == aa_for_design_position.end() ) {
197  utility_exit_with_message( "Did not find residue assigned to correspond to entity element " +
198  utility::to_string( ii ) + " while reading correspondence file " + correspondence_file_name );
199  }
200  aa_string[ ii-1 ] = oneletter_code_from_aa( aa_for_design_position[ ii ] );
201  }
202  return aa_string;
203 
204 
205 }
206 
207 ///////////////////////////////////////////////////////////////////////////////
208 /////////////////////// HPatchNPDCalculator ///////////////////////////////
209 ///////////////////////////////////////////////////////////////////////////////
210 
212 {
213 public:
214 
215  virtual
216  core::Real
218  return core::pack::interaction_graph::SurfacePotential::get_instance()->compute_pose_hpatch_score( p );
219  }
220 
221 };
222 
224 {
225  virtual
226  std::string
227  calculator_name() const {return "hpatch"; }
228 
229  virtual
230  protocols::pack_daemon::NPDPropCalculatorOP
231  new_calculator() const { return protocols::pack_daemon::NPDPropCalculatorOP( new HPatchNPDCalculator ); }
232 };
233 
234 ///////////////////////////////////////////////////////////////////////////////
235 /////////////////////// HPatchByChainNPDCalculator ////////////////////////
236 ///////////////////////////////////////////////////////////////////////////////
237 
238 
240 {
241 public:
242  virtual
243  void
245  core::pose::Pose const & pose,
246  core::pack::task::PackerTask const & task
247  ){
248  chains_ = pose.split_by_chain();
249  task_ = task.clone();
250  Size last_chain( 1 ), first_residue_for_chain( 1 );
251  resid_2_chain_and_resid_.resize( pose.total_residue() );
252  for ( core::Size ii = 1; ii <= pose.total_residue(); ++ii ) {
253  if ( pose.residue( ii ).chain() != last_chain ) {
254  last_chain = pose.residue( ii ).chain();
255  first_residue_for_chain = ii;
256  }
257  resid_2_chain_and_resid_[ ii ] = std::make_pair( pose.residue( ii ).chain(), ii + 1 - first_residue_for_chain );
258  }
259  }
260 
261  virtual
262  core::Real
264  // MJO COMMENTING OUT BECAUSE IT IS UNUSED:
265  // Size chain_offset = 0;
266  for ( core::Size ii = 1; ii <= p.total_residue(); ++ii ) {
267  if ( ! task_->being_packed( ii ) ) continue;
268  chains_[ resid_2_chain_and_resid_[ ii ].first ]->replace_residue(
269  resid_2_chain_and_resid_[ ii ].second, p.residue( ii ), false );
270  }
271 
272  core::Real hpatch_sum = 0;
273  for ( Size ii = 1; ii <= chains_.size(); ++ii ) {
274  hpatch_sum += core::pack::interaction_graph::SurfacePotential::get_instance()->compute_pose_hpatch_score( *chains_[ ii ] );
275  }
276  return hpatch_sum;
277  }
278 private:
280  core::pack::task::PackerTaskOP task_;
282 };
283 
285 {
286  virtual
287  std::string
288  calculator_name() const {return "hpatch_by_chain"; }
289 
290  virtual
291  protocols::pack_daemon::NPDPropCalculatorOP
292  new_calculator() const { return protocols::pack_daemon::NPDPropCalculatorOP( new HPatchByChainNPDCalculator ); }
293 };
294 
295 
296 ///////////////////////////////////////////////////////////////////////////////
297 /////////////////////// BunsCalculator ///////////////////////////////
298 ///////////////////////////////////////////////////////////////////////////////
299 
301 {
302 public:
303  virtual
304  void
306  core::pose::Pose const & pose,
307  core::pack::task::PackerTask const & task
308  ){
309  pose_ = core::pose::PoseOP( new core::pose::Pose( pose ) );
310  task_ = task.clone();
311  sfxn_ = core::scoring::get_score_function();
312 
313  //register calculators
314 
315  //This comment brackets a snippet of code that is automatically stripped from the release, usually for semi-forbidden interactions with the unreleased devel library
316  //If you want non-devel code stripped from the release, see the release machinery in tools/release and contact the release manager (Steven Lewis smlewi@gmail.com at this time)
317 // DELETED BY RELEASE SCRIPT
318 // DELETED BY RELEASE SCRIPT
319 // DELETED BY RELEASE SCRIPT
320 // DELETED BY RELEASE SCRIPT
321 // DELETED BY RELEASE SCRIPT
322 // DELETED BY RELEASE SCRIPT
323  //end automatic stripping comment
324 
325  if ( ! core::pose::metrics::CalculatorFactory::Instance().check_calculator_exists( "num_hbonds" ) ) {
326  core::pose::metrics::PoseMetricCalculatorOP num_hbonds_calculator( new protocols::toolbox::pose_metric_calculators::NumberHBondsCalculator() );
327  core::pose::metrics::CalculatorFactory::Instance().register_calculator( "num_hbonds", num_hbonds_calculator );
328  }
329 
330  if ( ! core::pose::metrics::CalculatorFactory::Instance().check_calculator_exists( "unsat" ) ) {
331  core::pose::metrics::PoseMetricCalculatorOP unsat_calculator( new protocols::toolbox::pose_metric_calculators::BuriedUnsatisfiedPolarsCalculator("sasa", "num_hbonds") );
332  core::pose::metrics::CalculatorFactory::Instance().register_calculator( "unsat", unsat_calculator );
333  }
334 
335  }
336 
337  virtual
338  core::Real
340  for ( core::Size ii = 1; ii <= pose_->total_residue(); ++ii ) {
341  if ( ! task_->being_packed( ii ) ) continue;
342  pose_->replace_residue( ii, p.residue( ii ), false );
343  }
344  (*sfxn_)(*pose_);
345  basic::MetricValue< core::Size > nburied_unsats;
346  pose_->metric( "unsat", "all_bur_unsat_polars", nburied_unsats );
347  return nburied_unsats.value();
348  }
349 
350 private:
351  core::pose::PoseOP pose_;
352  core::pack::task::PackerTaskOP task_;
353  core::scoring::ScoreFunctionOP sfxn_;
354 };
355 
357 {
358  virtual
359  std::string
360  calculator_name() const {return "nbunsats"; }
361 
362  virtual
363  protocols::pack_daemon::NPDPropCalculatorOP
364  new_calculator() const { return protocols::pack_daemon::NPDPropCalculatorOP( new NBuriedUnsatsCalcultor ); }
365 };
366 
367 
368 ///////////////////////////////////////////////////////////////////////////////
369 /////////////////////// main ///////////////////////////////
370 ///////////////////////////////////////////////////////////////////////////////
371 
372 
373 int main( int argc, char ** argv )
374 {
375  try {
376 
377  using namespace utility;
378  using namespace protocols::pack_daemon;
379  using namespace core;
380  using namespace basic::options;
381  using namespace basic::options::OptionKeys;
382  using namespace protocols::genetic_algorithm;
383 
384  NEW_OPT( msd::entity_resfile, "Resfile for the entity elements which are shared between the multiple states", "" );
385  NEW_OPT( msd::fitness_file, "Fitness function file specifying the multiple states and the objective function to optimize", "" );
386  NEW_OPT( msd::double_lazy_ig_mem_limit, "The amount of memory, in MB, that each double-lazy interaction graph should be allowed to allocate toward rotamer pair energies.", 0 );
387  NEW_OPT( msd::dont_score_bbhbonds, "Disable the default activation of the decompose_bb_hb_into_pair_energies flag for hbonds", false );
388  NEW_OPT( msd::exclude_background_energies, "Disable the default activation of the inclusion of background one-body and background/background two-body interaction energies in the state energies (which until now held only the packer energies)", false );
389  NEW_OPT( msd::seed_sequences, "Seed the GA's population with the given input sequences", "" );
390  NEW_OPT( msd::fill_gen1_from_seed_sequences, "Fill the entirety of the first generation from perturbations off the seed sequences that were provided", false );
391  NEW_OPT( msd::seed_sequence_from_input_pdb, "Seed the GA's population with the given input sequences using the sequence already present in a given pdb file; requires the use of the msd::seed_sequence_using_correspondence_file flag ", "" );
392  NEW_OPT( msd::seed_sequence_using_correspondence_file, "The name of the correspondence file to guide the seeding of the GA's population with the sequence from a particular pdb", "" );
393 
394  devel::init( argc, argv );
395 
396  //std::string secondary_resfile( "2wo2_secondary.resfile" );
397  //std::string bound_pdb( "2wo2.pdb" );
398  //std::string unbound_pdb( "2wo2_sep.pdb" );
399  //std::string entity_correspondence_file( "entity_map.txt" );
400  //std::string daf_filename = "objective_function.daf";
401 
402  if ( ! option[ msd::entity_resfile ].user() ) {
403  utility_exit_with_message("The entity resfile must be specified for the mpi_msd application with the -msd::entity_resfile <filename> flag" );
404  }
405 
406  if ( ! option[ msd::fitness_file ].user() ) {
407  utility_exit_with_message("The fitness-function file must be specified for the mpi_msd application with the -msd::fitness_file <filename> flag" );
408  }
409 
410  std::string entity_resfile( option[ msd::entity_resfile ] );
411  std::string daf_filename( option[ msd::fitness_file ] );
412 
413  DaemonSetOP ds( new DaemonSet );
414  ds->add_npdpro_calculator_creator( NPDPropCalculatorCreatorOP( new HPatchNPDCalculatorCreator ) );
415  ds->add_npdpro_calculator_creator( NPDPropCalculatorCreatorOP( new HPatchByChainNPDCalculatorCreator ) );
416  ds->add_npdpro_calculator_creator( NPDPropCalculatorCreatorOP( new NBuriedUnsatsCalcultorCreator ) );
417 
418  core::scoring::ScoreFunctionOP sfxn = core::scoring::get_score_function();
419 
420  if ( ! option[ msd::dont_score_bbhbonds ] ) {
421  /// Count bb/bb hydrogen bonds in the packer energy; otherwise, the MSD
422  /// code cannot say that one set of bb/bb contacts is worse than
423  /// another set of bb/bb contacts
424  if ( mpi_rank() == 0 ) { TR << "Activating decompose_bb_hb_into_pair_energies in the score function" << std::endl; }
425  using namespace core;
426  scoring::methods::EnergyMethodOptionsOP emopts( new scoring::methods::EnergyMethodOptions( sfxn->energy_method_options() ) );
427  emopts->hbond_options().decompose_bb_hb_into_pair_energies( true );
428  sfxn->set_energy_method_options( *emopts );
429  }
430  if ( option[ msd::exclude_background_energies ] ) {
431  ds->set_include_background_energies( false );
432  }
433 
434 
435  ds->set_score_function( *sfxn );
436  ds->set_entity_resfile( entity_resfile );
437  if ( option[ msd::double_lazy_ig_mem_limit ].user() ) {
438  std::cout << "Setting dlig nmeg limit" << option[ msd::double_lazy_ig_mem_limit ] << std::endl;
439  ds->set_dlig_nmeg_limit( option[ msd::double_lazy_ig_mem_limit ] );
440  }
441 
442  //if ( mpi_rank() == 0 ) {
443  // ds->add_pack_daemon( 1, bound_pdb, entity_correspondence_file, secondary_resfile );
444  //} else {
445  // ds->add_pack_daemon( 2, unbound_pdb, entity_correspondence_file, secondary_resfile );
446  //}
447 
448 
449  if ( mpi_rank() == 0 ) {
450  protocols::pack_daemon::MPIMultistateFitnessFunctionOP func( new protocols::pack_daemon::MPIMultistateFitnessFunction );
451  protocols::pack_daemon::DynamicAggregateFunctionDriverOP daf( new DynamicAggregateFunctionDriver );
452  daf->set_num_entity_elements( ds->entity_task()->total_residue() );
453  daf->set_score_function( *sfxn ); // assume one score function for the entire
454  utility::io::izstream daf_file( daf_filename );
455  try {
456  daf->initialize_from_input_file( ds, daf_file );
457  } catch ( utility::excn::EXCN_Msg_Exception & e ) {
458  std::cerr << "Caught exception" << std::endl;
459  std::cerr << e.msg() << std::endl;
460  exit(1);
461  }
462  func->daemon_set( ds );
463  func->set_num_pack_daemons( daf->num_states() );
464  func->set_num_npd_properties( daf->num_npd_properties() );
465  func->aggregate_function( daf );
466  func->set_history_size( option[ ms::numresults ]() );
467 
468  // <stolen code>
469  // set up genetic algorithm
470  GeneticAlgorithm ga;
471  ga.set_max_generations( option[ ms::generations ] );
472  ga.set_max_pop_size( option[ ms::pop_size ]() );
473  ga.set_num_to_propagate( static_cast<core::Size>(0.5*option[ ms::pop_size ]) );
474  ga.set_frac_by_recomb( option[ ms::fraction_by_recombination ]() );
475 
476  // set up sequence randomizer
477  protocols::genetic_algorithm::Mutate1RandomizerOP rand( new protocols::genetic_algorithm::Mutate1Randomizer );
478  // reset the default value of 1.0, but the mutation-rate variable is not used by the Mutate1Randomizer!
479  rand->set_mutation_rate( 0.0 /*option[ ms::mutate_rate ]()*/ );
480  protocols::pack_daemon::initialize_ga_randomizer_from_entity_task( rand, ds->entity_task() );
481 
482  // done setting up randomizer
483  ga.set_rand( rand );
484  ga.set_func( func );
485  // </stolen code>
486 
487  /// Now initialize the GA with a population from which to begin exploration.
488  /// Initialize this population completely randomly so that the native sequence
489  /// is not arrived at unfairly.
490 
491  if ( option[ msd::seed_sequences ].user() ) {
492  utility::vector1< std::string > seedseqs = option[ msd::seed_sequences ];
493  for ( Size ii = 1; ii <= seedseqs.size(); ++ii ) {
494  if ( seedseqs[ ii ].size() != ds->entity_task()->total_residue() ) {
495  utility_exit_with_message( "Input seed sequence " + seedseqs[ ii ] + " has " + utility::to_string( seedseqs[ ii ].size() ) + " elements; must have the same number of elements as the number specified in the entity resfile (" + utility::to_string( ds->entity_task()->total_residue()) + ")" );
496  }
497  ga.add_entity( protocols::multistate_design::entity_elements_from_1letterstring( seedseqs[ ii ] ) );
498  }
499  }
500  if ( option[ msd::seed_sequence_from_input_pdb ].user() ) {
501  std::string seq = read_native_sequence_for_entity_elements( ds->entity_task()->total_residue() );
502  ga.add_entity( protocols::multistate_design::entity_elements_from_1letterstring( seq ) );
503  }
504 
505  if ( option[ msd::fill_gen1_from_seed_sequences ] && option[ msd::seed_sequences ].user() ) {
506  ga.fill_with_perturbations_of_existing_entities();
507  } else {
508  ga.fill_with_random_entities();
509  }
510  // clear parents for the next generation
511  // ga.clear_parents(); // do I need this?
512  // loop over generations
513  while ( !ga.complete() ) {
514  clock_t starttime = clock();
515  if ( ga.current_generation_complete() ) ga.evolve_next_generation();
516  ga.evaluate_fitnesses();
517  if ( TR.visible( t_debug ) ) {
518  TR(t_debug) << "Generation " << ga.current_generation() << ":" << std::endl;
519  ga.print_population( TR(t_debug) );
520  }
521  clock_t stoptime = clock();
522  TR << "Generation " << ga.current_generation() << " took " << ((double) stoptime - starttime)/CLOCKS_PER_SEC
523  << " seconds; best fitness = " << ga.best_fitness_from_current_generation() << std::endl;
524 #ifdef APL_MEASURE_MSD_LOAD_BALANCE
525  func->print_load_balance_statistics( TR );
526  func->reset_load_balance_statistics();
527 #endif
528  }
529 
530  TR(t_info) << "Final Generation " << ga.current_generation() << ":" << std::endl;
531  ga.print_population( TR(t_info) );
532 
533 
534  // <stolen code>
535  // sort local copy of sequence/fitness cache
536  typedef GeneticAlgorithm::TraitEntityHashMap TraitEntityHashMap;
537  TraitEntityHashMap const & cache( ga.entity_cache() );
539  for ( TraitEntityHashMap::const_iterator it( cache.begin() ), end( cache.end() ); it != end; ++it ) {
540  if ( it->second == 0 ) continue; /// Why would this be?
541  sortable.push_back( it->second );
542  }
543  std::sort( sortable.begin(), sortable.end(), lt_OP_deref< Entity > );
544 
545  TR(t_info) << "Evaluated " << sortable.size() << " sequences out of " << rand->library_size()
546  << " possible." << std::endl;
547 
548  int counter = 1;
549  for ( utility::vector1<Entity::OP>::const_iterator it( sortable.begin() ), end( sortable.end() );
550  it != end && counter <= option[ ms::numresults ](); ++it, ++counter ) {
551  if ( ! *it ) {
552  --counter;
553  continue;
554  }
555  TR << "Top set #" << counter << ". Writing pdbs for entity: " << **it << std::endl;
556  // This next line of code is in fact original and not stolen from JA.
557  typedef std::list< std::pair< core::Size, core::pose::PoseOP > > SizePosePairList;
558  SizePosePairList pose_list = func->recover_relevant_poses_for_entity( **it );
559  /* Old code from my hard-coded test case that involved exactly four poses.
560  utility::vector1< core::pose::PoseOP > poses( 4 );
561  for ( std::list< std::pair< core::Size, core::pose::PoseOP > >::const_iterator
562  iter = pose_list.begin(), iter_end = pose_list.end(); iter != iter_end; ++iter ) {
563  poses[ iter->first ] = iter->second;
564  }
565  poses[ 1 ]->dump_pdb( "msa_design_" + utility::to_string( counter ) + "_bound1.pdb" );
566  poses[ 2 ]->dump_pdb( "msa_design_" + utility::to_string( counter ) + "_bound2.pdb" );
567  poses[ 3 ]->dump_pdb( "msa_design_" + utility::to_string( counter ) + "_unbound1.pdb" );
568  poses[ 4 ]->dump_pdb( "msa_design_" + utility::to_string( counter ) + "_unbound2.pdb" );
569  //break;
570  */
571  for ( SizePosePairList::const_iterator iter = pose_list.begin(), iter_end = pose_list.end();
572  iter != iter_end; ++iter ) {
573  std::string output_name = "msd_output_";
574  output_name += utility::to_string( counter );
575  output_name += "_" + daf->state_name( iter->first ) + ".pdb";
576  TR << "Writing structure " << output_name << " with score: " << (*sfxn)( *(iter->second) ) << std::endl;
577  utility::io::ozstream outfile( output_name );
578  core::io::pdb::dump_pdb( *(iter->second), outfile );
579  core::io::pdb::extract_scores( *(iter->second), outfile );
580  }
581  }
582 
583  func->send_spin_down_signal();
584  } else {
585  ds->activate_daemon_mode();
586  }
587 
588 #ifdef USEMPI
589  MPI_Finalize();
590 #endif
591 
592  } catch ( utility::excn::EXCN_Base const & e ) {
593  std::cout << "caught exception " << e.msg() << std::endl;
594  return -1;
595  }
596  return 0;
597 }
598 
599 
ocstream cerr(std::cerr)
Wrapper around std::cerr.
Definition: ocstream.hh:290
#define utility_exit_with_message(m)
Exit with file + line + message.
Definition: exit.hh:47
virtual protocols::pack_daemon::NPDPropCalculatorOP new_calculator() const
Definition: mpi_msd.cc:364
#define THREAD_LOCAL
virtual std::string const msg() const
Definition: EXCN_Base.hh:70
std::string read_native_sequence_for_entity_elements(core::Size n_designed_positions)
Definition: mpi_msd.cc:155
T const & value() const
Definition: MetricValue.hh:60
std::string String
Definition: remodel.cc:69
utility::keys::KeyLookup< KeyType >::const_iterator const_iterator
Key collection iterators.
dictionary size
Definition: amino_acids.py:44
vector0: std::vector with assert-checked bounds
StringOptionKey design("revert_app:design")
utility::vector1< core::pose::PoseOP > chains_
Definition: mpi_msd.cc:279
utility::vector1< std::pair< core::Size, core::Size > > resid_2_chain_and_resid_
Definition: mpi_msd.cc:281
void init(int argc, char *argv[])
Command line init() version.
Definition: init.cc:23
BooleanOptionKey const user("options:user")
Definition: OptionKeys.hh:40
core::pose::Pose Pose
Definition: supercharge.cc:101
utility::keys::lookup::end< KeyType > const end
virtual core::Real calculate(core::pose::Pose const &p)
Definition: mpi_msd.cc:339
Random number generator system.
common derived classes for thrown exceptions
core::scoring::ScoreFunctionOP sfxn_
Definition: mpi_msd.cc:353
virtual protocols::pack_daemon::NPDPropCalculatorOP new_calculator() const
Definition: mpi_msd.cc:231
int main(int argc, char **argv)
Definition: mpi_msd.cc:373
virtual std::string calculator_name() const
Definition: mpi_msd.cc:288
static THREAD_LOCAL basic::Tracer TR("basic.options")
tuple p
Definition: docking.py:9
Tracer IO system.
izstream: Input file stream wrapper for uncompressed and compressed files
Definition: izstream.hh:44
Input file stream wrapper for uncompressed and compressed files.
bool visible() const
Is this tracer currently visible?.
Definition: Tracer.hh:190
core::pose::PoseOP pose_
Definition: mpi_msd.cc:351
rule< Scanner, options_closure::context_t > options
Definition: Tag.cc:377
super::const_iterator const_iterator
Definition: vector1.hh:62
core::pack::task::PackerTaskOP task_
Definition: mpi_msd.cc:352
virtual std::string calculator_name() const
Definition: mpi_msd.cc:227
utility::options::OptionCollection option
OptionCollection global.
Definition: option.cc:45
Output file stream wrapper for uncompressed and compressed files.
double Real
Definition: types.hh:39
core::pack::task::PackerTaskOP task_
Definition: mpi_msd.cc:280
#define NEW_OPT(akey, help, adef)
virtual protocols::pack_daemon::NPDPropCalculatorOP new_calculator() const
Definition: mpi_msd.cc:292
ocstream cout(std::cout)
Wrapper around std::cout.
Definition: ocstream.hh:287
BooleanOptionKey const exit("options:exit")
Definition: OptionKeys.hh:51
vector1: std::vector with 1-based indexing
int mpi_rank()
Definition: mpi_util.cc:254
virtual core::Real calculate(core::pose::Pose const &p)
Definition: mpi_msd.cc:263
Numeric functions.
ozstream: Output file stream wrapper for uncompressed and compressed files
Definition: ozstream.hh:53
tuple seq
Definition: PyMOL_demo.py:72
#define OPT_1GRP_KEY(type, grp, key)
std::string to_string(const T &t)
Definition: string_util.hh:205
Some std::string helper functions.
static THREAD_LOCAL basic::Tracer TR("apps.public.design.mpi_msd", t_info)
Program options global and initialization function.
virtual std::string calculator_name() const
Definition: mpi_msd.cc:360
virtual core::Real calculate(core::pose::Pose const &p)
Definition: mpi_msd.cc:217
virtual void setup(core::pose::Pose const &pose, core::pack::task::PackerTask const &task)
Definition: mpi_msd.cc:305
virtual void setup(core::pose::Pose const &pose, core::pack::task::PackerTask const &task)
Definition: mpi_msd.cc:244
platform::Size Size
Definition: random.fwd.hh:30
virtual std::string const msg() const
Definition: Exceptions.hh:66