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>
28 #include <core/io/pdb/pose_io.hh>
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>
40 #include <core/scoring/hbonds/HBondOptions.hh>
41 #include <core/scoring/methods/EnergyMethodOptions.hh>
43 #include <core/pack/task/PackerTask.hh>
44 #include <core/pack/interaction_graph/SurfacePotential.hh>
46 #include <core/import_pose/import_pose.hh>
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>
58 #include <protocols/toolbox/pose_metric_calculators/NumberHBondsCalculator.hh>
59 #include <protocols/toolbox/pose_metric_calculators/BuriedUnsatisfiedPolarsCalculator.hh>
79 #include <basic/options/keys/ms.OptionKeys.gen.hh>
87 #if defined(WIN32) || defined(__CYGWIN__)
95 OPT_1GRP_KEY( Boolean, msd, fill_gen1_from_seed_sequences )
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 )
158 using namespace basic::options::OptionKeys;
159 using namespace core;
160 using namespace protocols::pack_daemon;
162 if ( !
option[ msd::seed_sequence_using_correspondence_file ].
user() ) {
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 ];
171 import_pose::pose_from_pdb(
pose, pdb_name );
174 if ( ! correspondence_file ) {
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 );
184 std::map< Size, chemical::AA > aa_for_design_position;
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() ) {
190 correspondence_file_name +
". Entity correspondence file should only include each residue once");
192 aa_for_design_position[ ii_entity ] =
pose.residue_type(
ii ).aa();
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() ) {
200 aa_string[
ii-1 ] = oneletter_code_from_aa( aa_for_design_position[
ii ] );
218 return core::pack::interaction_graph::SurfacePotential::get_instance()->compute_pose_hpatch_score( p );
230 protocols::pack_daemon::NPDPropCalculatorOP
246 core::pack::task::PackerTask
const &
task
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() );
253 if ( pose.residue(
ii ).chain() != last_chain ) {
254 last_chain = pose.residue(
ii ).chain();
255 first_residue_for_chain =
ii;
257 resid_2_chain_and_resid_[
ii ] = std::make_pair( pose.residue(
ii ).chain(),
ii + 1 - first_residue_for_chain );
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 );
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 ] );
280 core::pack::task::PackerTaskOP
task_;
291 protocols::pack_daemon::NPDPropCalculatorOP
307 core::pack::task::PackerTask
const &
task
310 task_ = task.clone();
311 sfxn_ = core::scoring::get_score_function();
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 );
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 );
341 if ( ! task_->being_packed(
ii ) )
continue;
342 pose_->replace_residue(
ii, p.residue(
ii ), false );
346 pose_->metric(
"unsat",
"all_bur_unsat_polars", nburied_unsats );
347 return nburied_unsats.
value();
352 core::pack::task::PackerTaskOP
task_;
353 core::scoring::ScoreFunctionOP
sfxn_;
363 protocols::pack_daemon::NPDPropCalculatorOP
373 int main(
int argc,
char ** argv )
377 using namespace utility;
378 using namespace protocols::pack_daemon;
379 using namespace core;
381 using namespace basic::options::OptionKeys;
382 using namespace protocols::genetic_algorithm;
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",
"" );
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" );
407 utility_exit_with_message(
"The fitness-function file must be specified for the mpi_msd application with the -msd::fitness_file <filename> flag" );
410 std::string entity_resfile(
option[ msd::entity_resfile ] );
411 std::string daf_filename(
option[ msd::fitness_file ] );
413 DaemonSetOP ds(
new DaemonSet );
418 core::scoring::ScoreFunctionOP
sfxn = core::scoring::get_score_function();
420 if ( !
option[ msd::dont_score_bbhbonds ] ) {
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 );
430 if (
option[ msd::exclude_background_energies ] ) {
431 ds->set_include_background_energies(
false );
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 ] );
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 );
456 daf->initialize_from_input_file( ds, daf_file );
458 std::cerr <<
"Caught exception" << std::endl;
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 ]() );
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 ]() );
477 protocols::genetic_algorithm::Mutate1RandomizerOP rand(
new protocols::genetic_algorithm::Mutate1Randomizer );
479 rand->set_mutation_rate( 0.0 );
480 protocols::pack_daemon::initialize_ga_randomizer_from_entity_task( rand, ds->entity_task() );
493 for (
Size ii = 1;
ii <= seedseqs.size(); ++
ii ) {
494 if ( seedseqs[
ii ].
size() != ds->entity_task()->total_residue() ) {
497 ga.add_entity( protocols::multistate_design::entity_elements_from_1letterstring( seedseqs[
ii ] ) );
500 if (
option[ msd::seed_sequence_from_input_pdb ].
user() ) {
502 ga.add_entity( protocols::multistate_design::entity_elements_from_1letterstring( seq ) );
505 if (
option[ msd::fill_gen1_from_seed_sequences ] &&
option[ msd::seed_sequences ].
user() ) {
506 ga.fill_with_perturbations_of_existing_entities();
508 ga.fill_with_random_entities();
513 while ( !ga.complete() ) {
514 clock_t starttime = clock();
515 if ( ga.current_generation_complete() ) ga.evolve_next_generation();
516 ga.evaluate_fitnesses();
518 TR(
t_debug) <<
"Generation " << ga.current_generation() <<
":" << std::endl;
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();
530 TR(
t_info) <<
"Final Generation " << ga.current_generation() <<
":" << std::endl;
536 typedef GeneticAlgorithm::TraitEntityHashMap TraitEntityHashMap;
537 TraitEntityHashMap
const & cache( ga.entity_cache() );
540 if ( it->second == 0 )
continue;
541 sortable.push_back( it->second );
543 std::sort( sortable.begin(), sortable.end(), lt_OP_deref< Entity > );
545 TR(
t_info) <<
"Evaluated " << sortable.size() <<
" sequences out of " << rand->library_size()
546 <<
" possible." << std::endl;
555 TR <<
"Top set #" << counter <<
". Writing pdbs for entity: " << **it << std::endl;
557 typedef std::list< std::pair< core::Size, core::pose::PoseOP > > SizePosePairList;
558 SizePosePairList pose_list = func->recover_relevant_poses_for_entity( **it );
572 iter != iter_end; ++iter ) {
573 std::string output_name =
"msd_output_";
575 output_name +=
"_" + daf->state_name( iter->first ) +
".pdb";
576 TR <<
"Writing structure " << output_name <<
" with score: " << (*sfxn)( *(iter->second) ) << std::endl;
578 core::io::pdb::dump_pdb( *(iter->second), outfile );
579 core::io::pdb::extract_scores( *(iter->second), outfile );
583 func->send_spin_down_signal();
585 ds->activate_daemon_mode();
593 std::cout <<
"caught exception " << e.
msg() << std::endl;
ocstream cerr(std::cerr)
Wrapper around std::cerr.
#define utility_exit_with_message(m)
Exit with file + line + message.
virtual protocols::pack_daemon::NPDPropCalculatorOP new_calculator() const
virtual std::string const msg() const
std::string read_native_sequence_for_entity_elements(core::Size n_designed_positions)
utility::keys::KeyLookup< KeyType >::const_iterator const_iterator
Key collection iterators.
vector0: std::vector with assert-checked bounds
StringOptionKey design("revert_app:design")
utility::vector1< core::pose::PoseOP > chains_
utility::vector1< std::pair< core::Size, core::Size > > resid_2_chain_and_resid_
void init(int argc, char *argv[])
Command line init() version.
BooleanOptionKey const user("options:user")
utility::keys::lookup::end< KeyType > const end
virtual core::Real calculate(core::pose::Pose const &p)
Random number generator system.
common derived classes for thrown exceptions
core::scoring::ScoreFunctionOP sfxn_
virtual protocols::pack_daemon::NPDPropCalculatorOP new_calculator() const
int main(int argc, char **argv)
virtual std::string calculator_name() const
static THREAD_LOCAL basic::Tracer TR("basic.options")
izstream: Input file stream wrapper for uncompressed and compressed files
Input file stream wrapper for uncompressed and compressed files.
bool visible() const
Is this tracer currently visible?.
rule< Scanner, options_closure::context_t > options
super::const_iterator const_iterator
core::pack::task::PackerTaskOP task_
virtual std::string calculator_name() const
utility::options::OptionCollection option
OptionCollection global.
Output file stream wrapper for uncompressed and compressed files.
core::pack::task::PackerTaskOP task_
#define NEW_OPT(akey, help, adef)
virtual protocols::pack_daemon::NPDPropCalculatorOP new_calculator() const
ocstream cout(std::cout)
Wrapper around std::cout.
BooleanOptionKey const exit("options:exit")
vector1: std::vector with 1-based indexing
virtual core::Real calculate(core::pose::Pose const &p)
ozstream: Output file stream wrapper for uncompressed and compressed files
#define OPT_1GRP_KEY(type, grp, key)
std::string to_string(const T &t)
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
virtual core::Real calculate(core::pose::Pose const &p)
virtual void setup(core::pose::Pose const &pose, core::pack::task::PackerTask const &task)
virtual void setup(core::pose::Pose const &pose, core::pack::task::PackerTask const &task)
virtual std::string const msg() const