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