73 #include <basic/options/util.hh>
74 #if defined(WIN32) || defined(__CYGWIN__)
78 #include <basic/Tracer.hh>
85 #include <utility/io/izstream.hh>
86 #include <utility/vector1.hh>
87 #include <utility/vector1.functions.hh>
88 #include <utility/exit.hh>
89 #include <utility/file/FileName.hh>
90 #include <utility/file/PathName.hh>
91 #include <utility/file/file_sys_util.hh>
92 #include <utility/string_util.hh>
93 #include <utility/pointer/owning_ptr.hh>
94 #include <utility/pointer/ReferenceCount.hh>
96 #include <numeric/xyzVector.hh>
97 #include <numeric/statistics.functions.hh>
98 #include <numeric/random/random.hh>
100 #include <ObjexxFCL/FArray1D.hh>
101 #include <ObjexxFCL/string.functions.hh>
120 #include <basic/options/keys/optE.OptionKeys.gen.hh>
121 #include <basic/options/keys/in.OptionKeys.gen.hh>
124 #include <utility/vector0.hh>
125 #include <ObjexxFCL/format.hh>
128 namespace ObjexxFCL {
namespace fmt { } }
using namespace ObjexxFCL::fmt;
131 namespace protocols {
132 namespace optimize_weights {
134 using namespace core;
135 using namespace scoring;
136 using namespace optimization;
138 using namespace basic::options;
139 using namespace basic::options::OptionKeys;
141 using namespace utility;
145 basic::Tracer
TR(
"protocols.optimize_weights.IterativeOptEDriver");
146 basic::Tracer
TR_VERBOSE(
"protocols.optimize_weights.IterativeOptEDriver.verbose");
148 static numeric::random::RandomGenerator
optE_RG(10193);
161 scale_factor_( other.scale_factor_ )
176 task.
low_temp( 0.3 * scale_factor_ );
181 scale_factor_ = setting;
200 IterativeOptEDriver::IterativeOptEDriver() :
201 ligand_repack_pdbs_(),
202 ligand_repack_native_poses_(),
203 decoy_discrim_data_( 0 ),
204 ligand_discrim_data_( NULL ),
205 dG_binding_data_( NULL ),
206 ddG_bind_optE_data_( NULL ),
214 outer_loop_counter_( 0 ),
215 inner_loop_counter_( 1 ),
216 total_positions_( 0 ),
217 count_recovered_( 0 ),
222 mixing_factor_( 0.0 ),
223 outer_loop_last_sequence_recovery_rate_( 0.0 ),
224 outer_loop_seq_profile_cross_entropy_( 0.0 ),
225 inner_loop_sequence_recovery_rate_( 0.0 ),
226 using_unfolded_energy_term_( false )
232 if ( option[ optE::parse_tagfile ].user() ) {
233 using namespace core::pack::task::operation;
234 std::string tagfile_name( option[ optE::parse_tagfile ]() );
237 }
else if ( ! option[ optE::design_with_minpack ] ) {
243 MPI_Comm_rank (MPI_COMM_WORLD, &
mpi_rank);
244 MPI_Comm_size (MPI_COMM_WORLD, &mpi_nprocs);
251 if ( ! option[ optE::dont_use_reference_energies ].user() ) {
263 score_type_iter != end_iter; ++score_type_iter ) {
265 TR <<
"IterativeOptEDriver(): setting 'using_unfolded_energy_term_' to true." << std::endl;
270 score_type_iter != end_iter; ++score_type_iter ) {
272 TR <<
"IterativeOptEDriver(): setting 'using_unfolded_energy_term_' to true." << std::endl;
300 using namespace core::pack::task::operation;
303 for ( TaskOperationFactory::TaskOperationOPs::iterator it( tops.begin() ), itend( tops.end() ); it != itend; ++it ) {
304 task_factory->push_back( *it );
324 if ( option[ optE::load_from_silent ].user() ) {
329 Size slash_index = filename.find_last_of(
"/\\");
330 std::string path = filename.substr(0, slash_index);
332 std::string filename = option[ optE::load_from_silent ];
333 TR_VERBOSE <<
"loading: " << tag <<
"from " << path <<
"/" << filename << std::endl;
335 if ( prev_path != path ) {
341 (*sfd)[ tag ]->fill_pose( pose );
344 if ( option[ in::file::centroid_input ] && !ignore_centroid_input_flag) {
363 using namespace basic::options;
364 using namespace basic::options::OptionKeys;
371 Size const nextra = all_filenames.size() - num_pdbs_per_cpu *
MPI_nprocs_;
373 Size my_njobs = ( nextra >= 1 ? 1 : 0 ) + num_pdbs_per_cpu;
374 for (
Size ii = 1; ii <= my_njobs; ++ii ) {
386 Size ii_offset = my_njobs;
388 Size ii_njobs = ( nextra > ii ? 1 : 0 ) + num_pdbs_per_cpu;
389 MPI_Send( & ii_njobs, 1, MPI_UNSIGNED_LONG, ii, tag_, MPI_COMM_WORLD );
390 for (
Size jj = ii_offset + 1; jj <= ii_offset + ii_njobs; ++jj ) {
391 send_string_to_node( ii, all_filenames[ jj ] );
393 ii_offset += ii_njobs;
397 MPI_Recv( & my_njobs, 1, MPI_UNSIGNED_LONG, 0, tag_, MPI_COMM_WORLD, & stat_ );
399 for (
Size ii = 1; ii <= my_njobs; ++ii ) {
400 native_pdbs_.push_back( receive_string_from_node( 0 ) );
411 gethostname(hostname,
sizeof(hostname));
420 if ( option[ optE::optimize_decoy_discrimination ].user() ) {
424 std::ifstream native_and_decoy_lists( option[ optE::optimize_decoy_discrimination ]()().c_str() );
425 while ( native_and_decoy_lists ) {
429 native_and_decoy_lists >> native_files >> decoy_files >> crystal_native_file;
430 if ( native_files !=
"" && decoy_files !=
"" && crystal_native_file !=
"" ) {
431 file_lists.push_back( std::make_pair( native_files, decoy_files ));
432 crystal_native_list.push_back( crystal_native_file );
437 Size const nextra = file_lists.size() - num_pdbs_per_cpu *
MPI_nprocs_;
439 Size my_njobs = ( nextra >= 1 ? 1 : 0 ) + num_pdbs_per_cpu;
440 for (
Size ii = 1; ii <= my_njobs; ++ii ) {
450 Size ii_offset = my_njobs;
452 Size ii_njobs = ( nextra > ii ? 1 : 0 ) + num_pdbs_per_cpu;
453 MPI_Send( & ii_njobs, 1, MPI_UNSIGNED_LONG, ii, tag_, MPI_COMM_WORLD );
454 for (
Size jj = ii_offset + 1; jj <= ii_offset + ii_njobs; ++jj ) {
455 send_string_to_node( ii, file_lists[ jj ].first );
456 send_string_to_node( ii, file_lists[ jj ].second );
457 send_string_to_node( ii, crystal_native_list[ jj ] );
459 ii_offset += ii_njobs;
463 MPI_Recv( & my_njobs, 1, MPI_UNSIGNED_LONG, 0, tag_, MPI_COMM_WORLD, & stat_ );
466 for (
Size ii = 1; ii <= my_njobs; ++ii ) {
467 std::string native_pdb_list_name = receive_string_from_node( 0 );
468 std::string decoy_pdb_list_name = receive_string_from_node( 0 );
470 std::string crystal_native = receive_string_from_node( 0 );
483 if ( option[ optE::optimize_ligand_discrimination ].user() ) {
487 std::ifstream native_and_decoy_lists( option[ optE::optimize_ligand_discrimination ]()().c_str() );
488 while ( native_and_decoy_lists ) {
492 native_and_decoy_lists >> native_files >> decoy_files >> crystal_native_file;
493 if ( native_files !=
"" && decoy_files !=
"" && crystal_native_file !=
"" ) {
494 file_lists.push_back( std::make_pair( native_files, decoy_files ));
495 crystal_native_list.push_back( crystal_native_file );
500 Size const nextra = file_lists.size() - num_pdbs_per_cpu *
MPI_nprocs_;
502 Size my_njobs = ( nextra >= 1 ? 1 : 0 ) + num_pdbs_per_cpu;
503 for (
Size ii = 1; ii <= my_njobs; ++ii ) {
513 Size ii_offset = my_njobs;
515 Size ii_njobs = ( nextra > ii ? 1 : 0 ) + num_pdbs_per_cpu;
516 MPI_Send( & ii_njobs, 1, MPI_UNSIGNED_LONG, ii, tag_, MPI_COMM_WORLD );
517 for (
Size jj = ii_offset + 1; jj <= ii_offset + ii_njobs; ++jj ) {
518 send_string_to_node( ii, file_lists[ jj ].first );
519 send_string_to_node( ii, file_lists[ jj ].second );
520 send_string_to_node( ii, crystal_native_list[ jj ] );
522 ii_offset += ii_njobs;
526 MPI_Recv( & my_njobs, 1, MPI_UNSIGNED_LONG, 0, tag_, MPI_COMM_WORLD, & stat_ );
529 for (
Size ii = 1; ii <= my_njobs; ++ii ) {
530 std::string native_pdb_list_name = receive_string_from_node( 0 );
531 std::string decoy_pdb_list_name = receive_string_from_node( 0 );
533 std::string crystal_native = receive_string_from_node( 0 );
546 if ( option[ optE::optimize_ligand_rot ].user() ) {
549 std::ifstream pdb_list_file( option[ optE::optimize_ligand_rot ]()().c_str() );
550 while ( pdb_list_file ) {
552 pdb_list_file >> pdb_file;
553 if ( pdb_file !=
"" ) {
554 file_list.push_back( pdb_file );
561 Size my_njobs = ( nextra >= 1 ? 1 : 0 ) + num_pdbs_per_cpu;
562 for (
Size ii = 1; ii <= my_njobs; ++ii ) {
567 Size ii_offset = my_njobs;
569 Size ii_njobs = ( nextra > ii ? 1 : 0 ) + num_pdbs_per_cpu;
570 MPI_Send( & ii_njobs, 1, MPI_UNSIGNED_LONG, ii, tag_, MPI_COMM_WORLD );
571 for (
Size jj = ii_offset + 1; jj <= ii_offset + ii_njobs; ++jj ) {
572 send_string_to_node( ii, file_list[ jj ] );
574 ii_offset += ii_njobs;
578 MPI_Recv( & my_njobs, 1, MPI_UNSIGNED_LONG, 0, tag_, MPI_COMM_WORLD, & stat_ );
580 for (
Size ii = 1; ii <= my_njobs; ++ii ) {
581 std::string pdb_name = receive_string_from_node( 0 );
589 if ( option[ optE::optimize_dGbinding ].user() ) {
594 utility::io::izstream dg_data( option[ optE::optimize_dGbinding ]() );
597 Real dg_experimental;
598 dg_data >> bound_pdb;
599 if ( bound_pdb ==
"" )
break;
600 dg_data >> unbound_pdb;
601 dg_data >> dg_experimental;
602 dG_pdb_files.push_back( std::make_pair( bound_pdb, unbound_pdb ) );
603 dgs.push_back( dg_experimental );
611 Size my_njobs = ( nextra >= 1 ? 1 : 0 ) + num_dgs_per_cpu;
613 for (
Size ii = 1; ii <= my_njobs; ++ii ) {
622 Size ii_offset = my_njobs;
624 Size ii_njobs = ( nextra > ii ? 1 : 0 ) + num_dgs_per_cpu;
625 MPI_Send( & ii_njobs, 1, MPI_UNSIGNED_LONG, ii, tag_, MPI_COMM_WORLD );
626 for (
Size jj = ii_offset + 1; jj <= ii_offset + ii_njobs; ++jj ) {
627 send_string_to_node( ii, dG_pdb_files[ jj ].first );
628 send_string_to_node( ii, dG_pdb_files[ jj ].second );
629 MPI_Send( & dgs[ jj ], 1, MPI_DOUBLE, ii, tag_, MPI_COMM_WORLD );
631 ii_offset += ii_njobs;
635 MPI_Recv( & my_njobs, 1, MPI_UNSIGNED_LONG, 0, tag_, MPI_COMM_WORLD, & stat_ );
638 for (
Size ii = 1; ii <= my_njobs; ++ii ) {
639 std::string bound_pdb = receive_string_from_node( 0 );
640 std::string unbound_pdb = receive_string_from_node( 0 );
642 MPI_Recv( &
dG_binding_[ ii ], 1, MPI_DOUBLE, 0, tag_, MPI_COMM_WORLD, & stat_ );
653 if ( option[ optE::optimize_ddGmutation ].user() ) {
657 utility::io::izstream ddg_data( option[ optE::optimize_ddGmutation ]() );
660 Real ddg_experimental;
662 if ( wt_file ==
"" )
break;
663 ddg_data >> mut_file;
664 ddg_data >> ddg_experimental;
665 ddG_mut_files.push_back( std::make_pair( wt_file, mut_file ) );
666 ddgs.push_back( ddg_experimental );
674 Size my_njobs = ( nextra >= 1 ? 1 : 0 ) + num_ddgs_per_cpu;
676 for (
Size ii = 1; ii <= my_njobs; ++ii ) {
678 ddGs_.push_back( ddgs[ ii ] );
686 Size ii_offset = my_njobs;
688 Size ii_njobs = ( nextra > ii ? 1 : 0 ) + num_ddgs_per_cpu;
689 MPI_Send( & ii_njobs, 1, MPI_UNSIGNED_LONG, ii, tag_, MPI_COMM_WORLD );
690 for (
Size jj = ii_offset + 1; jj <= ii_offset + ii_njobs; ++jj ) {
691 send_string_to_node( ii, ddG_mut_files[ jj ].first );
692 send_string_to_node( ii, ddG_mut_files[ jj ].second );
693 MPI_Send( & ddgs[ jj ], 1, MPI_DOUBLE, ii, tag_, MPI_COMM_WORLD );
695 ii_offset += ii_njobs;
699 MPI_Recv( & my_njobs, 1, MPI_UNSIGNED_LONG, 0, tag_, MPI_COMM_WORLD, & stat_ );
701 ddGs_.resize( my_njobs, 0.0 );
702 for (
Size ii = 1; ii <= my_njobs; ++ii ) {
703 std::string wt_list = receive_string_from_node( 0 );
704 std::string mut_list = receive_string_from_node( 0 );
706 MPI_Recv( &
ddGs_[ ii ], 1, MPI_DOUBLE, 0, tag_, MPI_COMM_WORLD, & stat_ );
720 if ( option[ optE::optimize_ddG_bind_correlation ].user() ) {
724 utility::io::izstream ddG_bind_data( option[ optE::optimize_ddG_bind_correlation ]() );
725 while ( ddG_bind_data ) {
726 std::string wt_complexes_file, mut_complexes_file, wt_unbounds_file, mut_unbounds_file;
727 Real ddG_experimental;
728 ddG_bind_data >> wt_complexes_file;
if ( wt_complexes_file ==
"" )
break;
729 ddG_bind_data >> mut_complexes_file;
730 ddG_bind_data >> wt_unbounds_file;
731 ddG_bind_data >> mut_unbounds_file;
732 ddG_bind_data >> ddG_experimental;
735 files.push_back( wt_complexes_file ); files.push_back( mut_complexes_file );
736 files.push_back( wt_unbounds_file ); files.push_back( mut_unbounds_file );
737 ddG_bind_files.push_back( files );
738 ddGs_binding.push_back( ddG_experimental );
742 Size const nextra = ddGs_binding.size() - num_ddGs_per_cpu *
MPI_nprocs_;
744 Size my_njobs = ( nextra >= 1 ? 1 : 0 ) + num_ddGs_per_cpu;
748 for (
Size ii = 1; ii <= my_njobs; ++ii ) {
755 Size ii_offset = my_njobs;
757 Size ii_njobs = ( nextra > ii ? 1 : 0 ) + num_ddGs_per_cpu;
758 MPI_Send( & ii_njobs, 1, MPI_UNSIGNED_LONG, ii, tag_, MPI_COMM_WORLD );
759 for (
Size jj = ii_offset + 1; jj <= ii_offset + ii_njobs; ++jj ) {
764 MPI_Send( & ddGs_binding[ jj ], 1, MPI_DOUBLE, ii, tag_, MPI_COMM_WORLD );
766 ii_offset += ii_njobs;
771 MPI_Recv( & my_njobs, 1, MPI_UNSIGNED_LONG, 0, tag_, MPI_COMM_WORLD, & stat_ );
774 for (
Size ii = 1; ii <= my_njobs; ++ii ) {
775 std::string wt_complexes_file = receive_string_from_node( 0 );
776 std::string mut_complexes_file = receive_string_from_node( 0 );
777 std::string wt_unbounds_file = receive_string_from_node( 0 );
778 std::string mut_unbounds_file = receive_string_from_node( 0 );
781 files.push_back( wt_complexes_file ); files.push_back( mut_complexes_file );
782 files.push_back( wt_unbounds_file ); files.push_back( mut_unbounds_file );
785 MPI_Recv( &
ddGs_binding_[ ii ], 1, MPI_DOUBLE, 0, tag_, MPI_COMM_WORLD, & stat_ );
795 <<
"' and experimental ddG bind: " <<
ddGs_binding_[ ii ] << std::endl;
802 if ( option[ optE::rescore::context_round ].user() ) {
803 Size context_round = option[ optE::rescore::context_round ]();
804 if ( context_round != 0 ) {
821 using namespace pack::rotamer_set;
822 using namespace basic::options;
823 using namespace basic::options::OptionKeys;
848 if ( ! option[ optE::mpi_weight_minimization ] ) {
858 if ( option[ optE::rescore::weights ].user() ) {
862 if ( option[ optE::rescore::measure_sequence_recovery ].user() ) {
944 using namespace basic::options;
945 using namespace basic::options::OptionKeys;
946 using namespace core::pack::rotamer_set;
948 if (
MPI_rank_ == 0 )
TR <<
"compute_rotamer_energies_for_assigned_pdbs(): entered method" << std::endl;
952 if (
MPI_rank_ == 0 && option[ optE::constrain_weights ].user() ) {
954 std::string cstfilename = option[ optE::constrain_weights ]();
955 std::ifstream input( cstfilename.c_str() );
956 cst->initialize_constraints_from_file( input );
962 TR <<
"compute_rotamer_energies_for_assigned_pdbs(): created scorefxn for calculating rotamer energies" << std::endl;
963 scorefxn->show( std::cout );
976 if ( option[ optE::optimize_pssm ] ) {
983 if ( option[ in::file::centroid_input ] ) {
993 TR_VERBOSE <<
"compute_rotamer_energies_for_assigned_pdbs(): pushing " << native_filename <<
" onto native_poses_ vector." << std::endl;
1002 TR_VERBOSE <<
"compute_rotamer_energies_for_assigned_pdbs(): " <<
node_name(
MPI_rank_ ) <<
" calling get_opte_data for " << native_filename << std::endl;
1004 (*scorefxn)( pose );
1005 (*scorefxn)( native_pose );
1009 if ( option[ optE::optimize_nat_aa ] || option[ optE::optimize_pssm ] ) {
1011 natname.base(), pose, native_pose,
1016 if ( option[ optE::optimize_nat_rot ]() ) {
1020 if ( option[ optE::recover_nat_rot ] ) {
1023 context_pose = native_pose;
1033 natname.base(), context_pose, native_pose, include_rsd, *scorefxn,
1048 Size const which_protein
1053 std::string native_substr = native_filename.substr( 0, native_filename.size() - 4 );
1054 std::string pssm_file_name = native_substr +
".fasta.probs";
1056 std::ifstream pssm_file( pssm_file_name.c_str() );
1058 std::list< std::pair< chemical::AA, utility::vector1< Real > > >
pssm_data;
1061 while ( pssm_file ) {
1064 pssm_file >> line_aa;
1068 pssm_file >> pssm_prob_dist[ ii ];
1069 sum += pssm_prob_dist[ ii ];
1071 if ( std::abs( sum - 1 ) > 0.001 ) {
1072 TR <<
"Warning: pssm probability distribution does not sum to 1.0: " << sum << std::endl;
1073 TR <<
"Problem on line " << linenum <<
" of " << pssm_file_name << std::endl;
1075 pssm_data.push_back( std::make_pair( aa, pssm_prob_dist ));
1081 std::copy( pssm_data.begin(), pssm_data.end(),
pssm_data_.begin() );
1084 if (
pssm_data_.size() == 0 ) { std::cerr <<
"Did not read file -- possibly not found" << std::endl; }
1098 IterativeOptEDriver::send_string_to_node(
int destination,
std::string const & string_to_send )
1101 int len( string_to_send.size() );
1102 MPI_Send( &len, 1, MPI_INT, destination, tag, MPI_COMM_WORLD );
1103 MPI_Send( const_cast< char * > (string_to_send.c_str()), len, MPI_CHAR, destination, tag, MPI_COMM_WORLD );
1114 IterativeOptEDriver::receive_string_from_node(
int source )
1119 MPI_Recv( &len, 1, MPI_INT, source, tag, MPI_COMM_WORLD, & stat );
1120 char *
str =
new char[ len + 1 ];
1122 MPI_Recv( str, len, MPI_CHAR, source, tag, MPI_COMM_WORLD, & stat );
1125 return return_string;
1142 using namespace core::pack::rotamer_set;
1152 MPI_Send( free_energy_terms,
n_score_types, MPI_INT, 0, tag_, MPI_COMM_WORLD );
1153 MPI_Send( fixed_energy_terms,
n_score_types, MPI_INT, 0, tag_, MPI_COMM_WORLD );
1155 delete [] free_energy_terms; free_energy_terms = 0;
1156 delete [] fixed_energy_terms; fixed_energy_terms = 0;
1160 MPI_Send( & n_pos, 1, MPI_UNSIGNED_LONG, 0, tag_, MPI_COMM_WORLD );
1162 for ( OptEPositionDataOPs::const_iterator
1165 iter != iter_end; ++iter ) {
1166 int position_data_type = (*iter)->type();
1168 MPI_Send( & position_data_type, 1, MPI_INT, 0, tag_, MPI_COMM_WORLD );
1169 (*iter)->send_to_node( 0, tag_ );
1183 using namespace core::pack::rotamer_set;
1188 TR <<
"collect_rotamer_energies_from_slave_cpus(): master node with " <<
optE_data_->num_positions() <<
" positions" << std::endl;
1191 for ( OptEPositionDataOPs::const_iterator
1194 iter != iter_end; ++iter ) {
1195 total += (*iter)->memory_use();
1197 TR <<
"collect_rotamer_energies_from_slave_cpus(): master node using " << total <<
" bytes for "
1198 <<
optE_data_->num_positions() <<
" positions." << std::endl;
1212 using namespace core::io::pdb;
1213 using namespace core::pack::rotamer_set;
1214 using namespace core::pose;
1215 using namespace basic::options;
1216 using namespace basic::options::OptionKeys;
1217 using namespace core::scoring;
1222 bool const calc_decoy_score_sd( option[ optE::normalize_decoy_score_spread ].user() );
1227 if ( option[ optE::ramp_nativeness ] ) {
1228 if ( option[ optE::min_decoy_rms_to_native ].user() ) {
1231 if ( option[ optE::max_rms_from_native ].user() ) {
1244 if ( option[ optE::normalize_decoy_score_spread ].user() ) {
1246 if ( option[ optE::normalize_decoy_score_spread ]() ==
"SCORE12" ) {
1253 if ( option[ optE::repack_and_minimize_decoys ] ) {
1263 if ( option[ optE::n_top_natives_to_optimize ].user() ) {
1264 structure_data->n_top_natives_to_score( option[ optE::n_top_natives_to_optimize ] );
1269 structure_data->tag( cryst_fname.base() );
1278 while ( native_pdblist ) {
1280 native_pdblist >> native_pdb;
1281 if ( native_pdb !=
"" ) native_pdb_names.push_back( native_pdb );
1283 if ( native_pdb_names.size() == 0 ) {
1288 while ( decoy_pdblist ) {
1290 decoy_pdblist >> decoy_pdb;
1291 if ( decoy_pdb !=
"" ) decoy_pdb_names.push_back( decoy_pdb );
1293 if ( decoy_pdb_names.size() == 0 ) {
1297 TR_VERBOSE <<
"collect_decoy_discrimination_data(): scoring natives and decoys of " << structure_data->tag() << std::endl;
1301 if ( option[ optE::normalize_decoy_score_spread ].user() ) {
1302 decoy_energies.reserve( decoy_pdb_names.size() + native_pdb_names.size() );
1308 if ( option[ optE::repack_and_minimize_decoys ] ) {
1312 Size first_total_residue( 0 );
1313 for (
Size jj = 1; jj <= native_pdb_names.size(); ++jj ) {
1317 load_pose( pose, native_pdb_names[ jj ],
false );
1319 if ( option[ optE::repack_and_minimize_decoys ] ) {
1327 std::cerr <<
"Warning: total_residue for " << native_pdb_names[ jj ];
1328 std::cerr <<
"not equal to native #1 total_residue: " << first_total_residue <<
" vs ";
1330 std::cerr <<
"Excluding structure!" << std::endl;
1335 scorefxn, pose, crystal_native, free_data, fixed_data, native_pdb_names[ jj ] );
1339 decoy_energies.push_back( (*decoy_spread_reference_sfxn)( pose ) );
1342 if ( option[ optE::repack_and_minimize_input_structures ] ) {
1345 scorefxn, pose, crystal_native, free_data, fixed_data,
"rpmin_0_"+native_pdb_names[ jj ] );
1351 for (
Size jj = 1; jj <= decoy_pdb_names.size(); ++jj ) {
1356 load_pose( pose, decoy_pdb_names[ jj ],
false );
1359 std::cerr <<
"Warning: total_residue for " << decoy_pdb_names[ jj ];
1360 std::cerr <<
"not equal to native #1 total_residue: " << first_total_residue <<
" vs ";
1362 std::cerr <<
"Excluding structure!" << std::endl;
1366 if ( option[ optE::repack_and_minimize_decoys ] ) {
1371 scorefxn, pose, crystal_native, free_data, fixed_data, decoy_pdb_names[ jj ] );
1375 decoy_energies.push_back( (*decoy_spread_reference_sfxn)( pose ) );
1379 if ( option[ optE::repack_and_minimize_input_structures ] ) {
1382 scorefxn, pose, crystal_native, free_data, fixed_data,
"rpmin_0_" + decoy_pdb_names[ jj ] );
1388 if ( calc_decoy_score_sd ) {
1389 Real decoy_score_sd = numeric::statistics::std_dev( decoy_energies.begin(), decoy_energies.end(),
Real( 0.0 ) );
1390 if ( decoy_score_sd != 0 ) {
1391 structure_data->set_normalize_decoy_stddev(
true );
1392 structure_data->set_initial_decoy_stddev( decoy_score_sd );
1404 for ( OptEPositionDataOPs::const_iterator
1407 iter != iter_end; ++iter ) {
1413 runtime_assert( dynamic_cast< PNatStructureOptEData * > ( (*iter)() ) );
1415 static_cast< PNatStructureOptEData * > ( (*iter)() ) );
1420 new_nats.push_back( pose );
1421 new_nats_scores.push_back( ( *weighted_sfxn )( pose ) );
1431 new_decs.push_back( pose );
1432 new_decs_scores.push_back( ( *weighted_sfxn )( pose ) );
1439 if ( option[ optE::output_top_n_new_decoys ].user() ) {
1440 Size n_to_output = option[ optE::output_top_n_new_decoys ];
1442 utility::arg_least_several( new_decs_scores, top_decoy_inds );
1443 for (
Size ii = 1; ii <= top_decoy_inds.size(); ++ii ) {
1444 new_decs[ top_decoy_inds[ ii ] ].dump_pdb(
"workdir_" + to_string(
MPI_rank_ ) +
1446 + to_string( ii ) +
".pdb" );
1452 for ( OptEPositionDataOPs::const_iterator
1455 iter != iter_end; ++iter ) {
1475 (*scorefxn)( pose );
1485 ssd->rms( native_rms );
1486 ssd->tag( structure_tag );
1500 bool intended_native
1503 bool const ramp_nativeness( basic::options::option[ basic::options::OptionKeys::optE::ramp_nativeness ] );
1506 if ( intended_native ) {
1507 if ( ramp_nativeness ) {
1509 structure_data->add_decoy( ssd );
1513 structure_data->add_native( ssd );
1517 if ( option[ optE::max_rms_from_native ].user() ) {
1518 if ( ssd->rms() > option[ optE::max_rms_from_native ]() ) {
1519 if ( option[ optE::min_decoy_rms_to_native ]() ) {
1520 if ( ssd->rms() > option[ optE::min_decoy_rms_to_native ]() ) {
1521 structure_data->add_decoy( ssd );
1529 structure_data->add_native( ssd );
1532 if ( ramp_nativeness ) {
1534 structure_data->add_decoy( ssd );
1538 structure_data->add_native( ssd );
1543 if ( option[ optE::min_decoy_rms_to_native ].user() ) {
1544 if ( ssd->rms() < option[ optE::min_decoy_rms_to_native ]() ) {
1545 if ( option[ optE::max_rms_from_native ].user() ) {
1546 if ( ssd->rms() < option[ optE::max_rms_from_native ]() ) {
1547 structure_data->add_native( ssd );
1556 structure_data->add_decoy( ssd );
1572 using namespace basic::options;
1573 using namespace basic::options::OptionKeys;
1574 using namespace core::pack::rotamer_set;
1593 (*scorefxn)( native_pose );
1601 context_pose = native_pose;
1606 int const jump_id = context_pose.
num_jump();
1607 FArray1D_bool is_upstream ( context_pose.
total_residue(), false );
1611 if ( ! is_upstream(i) )
continue;
1616 if ( is_upstream(j) )
continue;
1619 double dist2 = lig_rsd.
xyz(k).distance_squared( prot_rsd.
xyz(prot_rsd.
nbr_atom()) );
1621 if ( dist2 <= cutoff * cutoff ) {
1622 include_rsd[i] =
true;
1623 goto END_LIGRES_LOOP;
1631 natname.base(), context_pose, native_pose, include_rsd, *scorefxn,
1646 using namespace core::pack::rotamer_set;
1674 while ( native_pdblist ) {
1676 native_pdblist >> native_pdb;
1677 if ( native_pdb !=
"" ) native_pdb_names.push_back( native_pdb );
1682 while ( decoy_pdblist ) {
1684 decoy_pdblist >> decoy_pdb;
1685 if ( decoy_pdb !=
"" ) decoy_pdb_names.push_back( decoy_pdb );
1689 if( native_pdb_names.size() == 0 ) {
1693 if( decoy_pdb_names.size() == 0 ) {
1707 Size first_total_residue( 0 );
1708 for (
Size jj = 1; jj <= native_pdb_names.size(); ++jj ) {
1722 std::cerr <<
"Warning [node " <<
MPI_rank_ <<
"]: total_residue for " << native_pdb_names[ jj ];
1723 std::cerr <<
" not equal to native #1 total_residue: " << first_total_residue <<
" vs ";
1739 structure_data->add_native( ssd );
1743 for (
Size jj = 1; jj <= decoy_pdb_names.size(); ++jj ) {
1755 std::cerr <<
"Warning [node " <<
MPI_rank_ <<
"]: total_residue for " << decoy_pdb_names[ jj ];
1756 std::cerr <<
" not equal to native #1 total_residue: " << first_total_residue <<
" vs ";
1780 if ( structure_data->size() != 0 ) structure_data->add_decoy( ssd );
1786 for ( OptEPositionDataOPs::const_iterator
1789 iter != iter_end; ++iter ) {
1808 int const jump_id = pose.
num_jump();
1813 trans_mover.
apply( split_pose );
1816 scorefxn(split_pose);
1839 Size const which_cpu
1846 using namespace core::pack::rotamer_set;
1857 MPI_Recv( free_energy_terms,
n_score_types, MPI_INT, which_cpu, tag_, MPI_COMM_WORLD, &stat_ );
1858 MPI_Recv( fixed_energy_terms,
n_score_types, MPI_INT, which_cpu, tag_, MPI_COMM_WORLD, &stat_ );
1865 utility_exit_with_message(
"Free energy term on Node 0 does not match free energy term remotely");
1869 utility_exit_with_message(
"Free energy term on Node 0 does not match fixed energy term remotely");
1873 delete [] free_energy_terms; free_energy_terms = 0;
1874 delete [] fixed_energy_terms; fixed_energy_terms = 0;
1878 MPI_Recv( & n_pos, 1, MPI_UNSIGNED_LONG, which_cpu, tag_, MPI_COMM_WORLD, &stat_ );
1881 for (
Size ii = 1; ii <= n_pos; ++ii ) {
1883 int position_data_type;
1884 MPI_Recv( & position_data_type, 1, MPI_INT, which_cpu, tag_, MPI_COMM_WORLD, &stat_ );
1888 ii_data->receive_from_node( which_cpu, tag_ );
1899 using namespace basic::options;
1900 using namespace basic::options::OptionKeys;
1902 return option[ optE::n_design_cycles ];
1920 using namespace basic::options;
1921 using namespace basic::options::OptionKeys;
1923 if ( ! option[ optE::dont_use_reference_energies ].user() ) {
1930 Real const rpp_refs[20] = {
1931 0.16, 1.7, -0.67, -0.81, 0.63, -0.17, 0.56, 0.24, -0.65, -0.1,
1932 -0.34, -0.89, 0.02, -0.97, -0.98, -0.37, -0.27, 0.29, 0.91, 0.51
1938 std::cout <<
"INITIALIZED before_minimization_reference_energies_ REFERENCE ENERGIES" << std::endl;
1961 using namespace basic::options;
1962 using namespace basic::options::OptionKeys;
1963 using namespace core::optimization;
1967 bool const optimize_in_parallel( option[ optE::mpi_weight_minimization ] );
1968 if (
MPI_rank_ != 0 && !optimize_in_parallel ) {
1972 if (
MPI_rank_ == 0 )
TR <<
"optimize_weights(): entered method" << std::endl;
1977 if ( option[ optE::wrap_dof_optimization ].user() )
1984 TR <<
"optimize_weights(): design_first flag in use. node " <<
MPI_rank_ <<
" leaving method." << std::endl;
1989 std::cout <<
"READING REFERENCE ENERGIES FROM FILE" << std::endl;
1990 std::cout <<
"FREE COUNT: " <<
free_count_ << std::endl;
1999 TR <<
"optimize weights early exit" << std::endl;
2016 if ( option[ optE::fit_reference_energies_to_aa_profile_recovery ] && option[ optE::dont_use_reference_energies ] ) {
2017 utility_exit_with_message(
"optimize_weights(): can't do fitting of reference energies to profile recovery when 'dont_use_reference_energies' flag in use.");
2028 clock_t starttime = clock();
2036 Real start_fitness = opt_min( start_dofs );
2037 Real end_fitness = 0.0;
2039 TR <<
"optimize_weights(): objective function start: " << start_fitness <<
" dofs: [ ";
2040 for (
Size ii = 1; ii <= start_dofs.size(); ++ii) {
TR << F( 8,4,start_dofs[ii] ) <<
", "; }
2041 TR <<
"]" << std::endl;
2045 Size ndofs = start_dofs.size();
2046 if ( option[ optE::wrap_dof_optimization ].user() ) {
2061 opt_min2 = opt_min_ptr;
2064 if( option[ optE::optimize_starting_free_weights ] ) {
2066 using namespace core::optimization;
2084 Multivec min( ndofs, 0.001), max( ndofs, 5.0);
2090 TR_VERBOSE <<
"optimize_weights(): node " <<
MPI_rank_ <<
" beginning round 1 of PSO." << std::endl;
2091 ParticleOPs particles = psm.
run( option[ optE::number_of_swarm_cycles ], *opt_min2, option[ optE::number_of_swarm_particles ] );
2095 for(
core::Size i = 1; i <= particles.size(); ++i) {
2096 Real start( (*opt_min2)( particles[i]->p_ ) );
2097 minimizer.
run( particles[i]->p_ );
2098 TR.Trace <<
"first round minimization: " << i <<
" start: " << start <<
", end: " << (*opt_min2)( particles[ i ]->p_ ) << std::endl;
2100 psm.
run( 0, *opt_min2, particles );
2103 TR_VERBOSE <<
"optimize_weights(): node " <<
MPI_rank_ <<
" beginning round 2 of PSO using [minimized] round 1 particles." << std::endl;
2105 psm.
run( option[ optE::number_of_swarm_cycles ], *opt_min2, particles );
2108 clock_t min_starttime = clock();
2111 Real start( (*opt_min2)( particles[ii]->p_ ) );
2112 TR.Trace <<
"starting minimization of particle " << ii << std::endl;
2113 minimizer2.
run( particles[ii]->p_ );
2114 TR.Trace <<
"second round minimization: " << ii <<
" start: " << F( 9,5,start ) <<
", end: " << F( 9,5,(*opt_min2)( particles[ ii ]->p_ )) << std::endl;
2117 clock_t min_stoptime = clock();
2118 TR_VERBOSE <<
"optimize_weights(): particle minimization took " << ((double)min_stoptime-min_starttime) / CLOCKS_PER_SEC <<
" seconds." << std::endl;
2121 psm.
run(0, *opt_min2, particles);
2125 TR_VERBOSE <<
"optimize_weights(): best particle fitness: " << F( 9,5,-1.0 * p->fitness_pbest() ) <<
" dofs: [";
2126 for (
core::Size j=1; j <= p->pbest().size(); ++j ) {
TR_VERBOSE << F(8,4,p->pbest()[j]) <<
", "; }
2129 start_dofs = particles[1]->pbest();
2134 end_fitness = (*opt_min2)( start_dofs );
2136 if ( ( end_fitness > start_fitness ) && option[ optE::repeat_swarm_optimization_until_fitness_improves ] ) {
2141 ParticleOPs particles = psm.
run( 2 * option[ optE::number_of_swarm_cycles ], *opt_min2, option[ optE::number_of_swarm_particles ],
2146 clock_t min_starttime = clock();
2148 Real start( (*opt_min2)( particles[ii]->p_ ) );
2149 TR_VERBOSE <<
"starting minimization of particle " << ii << std::endl;
2151 minimizer.
run( particles[ii]->p_ );
2152 TR_VERBOSE <<
"second round minimization: " << ii <<
" start: " << F( 9,5,start ) <<
", end: " << F( 9,5,(*opt_min2)( particles[ ii ]->p_ )) << std::endl;
2155 clock_t min_stoptime = clock();
2156 TR_VERBOSE <<
"optimize_weights(): particle minimization took " << ((double)min_stoptime-min_starttime) / CLOCKS_PER_SEC <<
" seconds." << std::endl;
2159 psm.
run( 0, *opt_min2, particles );
2163 TR_VERBOSE <<
"optimize_weights(): best particle fitness: " << F( 9,5,-1.0 * p->fitness_pbest() ) <<
" dofs: [";
2164 for (
core::Size j=1; j <= p->pbest().size(); ++j ) {
TR_VERBOSE << F(8,4,p->pbest()[j]) <<
", "; }
2167 start_dofs = particles[1]->pbest();
2171 if ( option[ optE::wrap_dof_optimization ].user() ) {
2180 TR <<
"optimize_weights(): minimization not recommended when using unfolded state energy" << std::endl;
2184 minimizer.
run( start_dofs );
2187 TR <<
"optimize_weights(): end: " << ( *opt_min2 )( start_dofs ) <<
", dofs: [ ";
2188 for(
Size ii = 1; ii <= start_dofs.size(); ++ii) {
TR << F(8,4,start_dofs[ii]) <<
", "; }
2189 TR <<
" ]" << std::endl;
2191 if ( option[ optE::wrap_dof_optimization ].user() ) {
2192 TR <<
"Wrapped weights after minimization" << std::endl;
2200 if ( ! option[ optE::dont_use_reference_energies ].user() ) {
2219 Size num_energy_dofs( free_count_ );
2221 int num_total_dofs( num_energy_dofs + num_ref_dofs );
2234 if ( ! option[ optE::dont_use_reference_energies ].user() ) {
2243 clock_t stoptime = clock();
2245 TR <<
"optimize_weights(): optimization took " << ((double) stoptime-starttime)/CLOCKS_PER_SEC <<
" seconds." << std::endl;
2249 if ( option[ optE::wrap_dof_optimization ].user() ) {
2254 if ( optimize_in_parallel ) {
2263 std::ofstream outlog( logname.c_str() );
2268 for( OptEPositionDataOPs::const_iterator itr =
optE_data_->position_data_begin(),
2269 e_itr =
optE_data_->position_data_end(); itr != e_itr ; ++itr ) {
2271 num_energy_dofs, num_ref_dofs, num_total_dofs,
2272 fixed_terms, score_list, fixed_score_list );
2273 cumulative_score_list[(*itr)->type()] += (*itr)->get_score(
2275 num_energy_dofs, num_ref_dofs, num_total_dofs,
2276 fixed_terms, score_list, fixed_score_list );
2284 <<
" " << cumulative_score_list[ii] << std::endl;
2293 Real const faux_max( -1234 );
Real const faux_min( 1234 );
2302 rawE_min[ ii ][ (
ScoreType) jj ] = faux_min;
2303 rawE_max[ ii ][ (
ScoreType) jj ] = faux_max;
2308 for( OptEPositionDataOPs::const_iterator itr =
optE_data_->position_data_begin(),
2309 e_itr =
optE_data_->position_data_end(); itr != e_itr ; ++itr ) {
2310 (*itr)->range( score_list, fixed_score_list,
2311 rawE_min[(*itr)->type()], rawE_max[(*itr)->type()] );
2315 for (
Size ii = 1; ii <= fixed_score_list.size(); ++ii ) {
2316 free_and_fixed.push_back( fixed_score_list[ ii ] );
2318 std::sort(free_and_fixed.begin(), free_and_fixed.end() );
2321 outlog <<
"DATA RANGE: ";
2324 for (
Size jj = 1; jj <= free_and_fixed.size(); ++jj ) {
2325 if ( rawE_min[ ii ][ free_and_fixed[ jj ] ] > rawE_max[ ii ][ free_and_fixed[ jj ] ] )
continue;
2327 outlog << rawE_min[ ii ][ free_and_fixed[ jj ] ] <<
", ";
2328 outlog << rawE_max[ ii ][ free_and_fixed[ jj ] ] <<
" ) ";
2338 TR <<
"leaving optimize_weights()" << std::endl;
2349 std::ofstream out( logname.c_str() );
2350 Real const minval = func(dofs);
2351 out <<
"Minimum function value " << minval << std::endl;
2355 Real maxval = minval;
2357 for(
Real val = 0.0; val <= 2.0; val += 0.1) {
2362 dofs_copy[dof_idx] = val;
2363 Real const newval = func(dofs_copy);
2364 maxval = std::max(maxval, newval);
2365 out <<
" " << (newval - minval);
2367 out <<
" maxDelta " << (maxval - minval) << std::endl;
2377 utility::io::izstream weight_file( fname.c_str() );
2378 bool read_refEs =
false;
2379 while ( weight_file ) {
2382 if ( tag ==
"METHOD_WEIGHTS" ) {
2384 if ( tag !=
"ref" )
continue;
2387 weight_file >> aa_refE;
2388 if (!weight_file)
break;
2389 reference_energies[ ii ] = aa_refE;
2394 if ( ! read_refEs ) {
2395 utility_exit_with_message(
"Failed to read METHOD_WEIGHTS from file " + fname +
". IterativeOptEDriver::read_reference_energies_from_file() " );
2397 return reference_energies;
2404 using namespace core::pack::rotamer_set;
2405 using namespace basic::options;
2406 using namespace basic::options::OptionKeys;
2408 runtime_assert( option[ optE::rescore::weights ].user() );
2410 bool const optimize_in_parallel( option[ optE::mpi_weight_minimization ] );
2416 if ( optimize_in_parallel ) {
2425 if ( optimize_in_parallel ) {
2435 std::ifstream weight_file( option[ optE::rescore::weights ]()().c_str() );
2436 while ( weight_file ) {
2439 if ( tag ==
"METHOD_WEIGHTS" ) {
2443 weight_file >> aa_refE;
2444 reference_energies[ ii ] = aa_refE;
2449 weight_file >> weight;
2450 TR <<
"Reading weight: " << st <<
" " << weight << std::endl;
2451 weight_set[ st ] = weight;
2453 TR <<
"Warning:: ignoring tag " << tag <<
" from " << option[ optE::rescore::weights ]()() << std::endl;
2464 int num_total_dofs( num_energy_dofs + num_ref_dofs );
2470 for (
Size ii = 1; ii <= score_list.size(); ++ii ) {
2474 free_parameters_[ free_score_list_[ ii ] ] = weight_set[ free_score_list_[ ii ] ];
2477 if ( ! option[ optE::dont_use_reference_energies ].user() ) {
2480 TR_VERBOSE << ii <<
" " << reference_energies[ ii ] <<
", ";
2481 vars[ ii +
free_count_ ] = reference_energies[ ii ];
2491 fixed_parameters_[ fixed_score_list_[ ii ] ] = weight_set[ fixed_score_list_[ ii ] ];
2495 std::ofstream outlog( option[ optE::rescore::outlog ]()().c_str() );
2496 TR_VERBOSE <<
"log file opened, scoring position data" << std::endl;
2501 for( OptEPositionDataOPs::const_iterator itr =
optE_data_->position_data_begin(), e_itr =
optE_data_->position_data_end() ; itr != e_itr ; ++itr ) {
2502 (*itr)->print_score( outlog,
component_weights_, vars, dE_dvars, num_energy_dofs, num_ref_dofs, num_total_dofs, fixed_terms, score_list, fixed_score_list );
2503 cumulative_score_list[(*itr)->type()] += (*itr)->get_score(
component_weights_, vars, dE_dvars, num_energy_dofs, num_ref_dofs, num_total_dofs, fixed_terms, score_list, fixed_score_list );
2510 if ( cumulative_score_list[ii] != 0 )
2512 <<
" " << cumulative_score_list[ii] << std::endl;
2534 using namespace basic::options;
2535 using namespace basic::options::OptionKeys;
2548 if ( option[ optE::fit_reference_energies_to_aa_profile_recovery ] ) {
2549 using namespace core::chemical;
2560 fa_atr_weight = 1.0;
2570 Real const pretty_close( 1.10 );
2571 Real const way_off( 1.5 );
2572 Real const way_way_off( 3.0 );
2573 Real const nowhere_close( 10.0 );
2574 Real const biggest_step( 0.8 * fa_atr_weight );
2575 Real const bigger_step( 0.4 * fa_atr_weight );
2576 Real const big_step( 0.1 * fa_atr_weight );
2577 Real const small_step( 0.05 * fa_atr_weight );
2578 Real const tiny_step( 0.01 * fa_atr_weight );
2584 if ( option[ optE::wrap_dof_optimization ].user() ) {
2587 utility_exit_with_message(
"ERROR in IterativeOptEDriver::write_new_scorefile(); wrapped_opt_min_ is NULL");
2596 if ( ! option[ optE::no_design ] ) {
2608 if ( option[ optE::rescore::measure_sequence_recovery ].user() ) {
mixing_factor_ = 1.0; alpha = 0.0; }
2609 if ( option[ optE::optimize_ddGmutation ].user() && ! ( option[ optE::optimize_nat_aa ].user() ) ) {
mixing_factor_ = 1.0; alpha = 0.0; }
2630 TR_VERBOSE <<
"write_new_scorefile(): reference energies after mixing: ";
2643 TR <<
"Tuning reference energies using amino acid profile recovery data: round " <<
2692 Real total_refE( 0.0 );
2702 if ( option[ optE::wrap_dof_optimization ].user() ) {
2705 utility_exit_with_message(
"ERROR in IterativeOptEDriver::write_new_scorefile(); wrapped_opt_min_ is NULL");
2714 if ( ! option[ optE::no_design ] ) {
2723 if ( option[ optE::rescore::measure_sequence_recovery ].user() ) {
mixing_factor_ = 1.0; alpha = 0.0; }
2724 if ( option[ optE::optimize_ddGmutation ].user() && ! ( option[ optE::optimize_nat_aa ].user() ) ) {
mixing_factor_ = 1.0; alpha = 0.0; }
2740 if ( ! option[ optE::dont_use_reference_energies ].user() ) {
2764 Real * ref_Es =
new Real[ n_ref_Es ];
2765 for (
Size ii = 0; ii < n_ref_Es; ++ii ) {
2770 MPI_Send( free_wts, n_score_types, MPI_DOUBLE, ii, tag_, MPI_COMM_WORLD );
2771 if ( ! option[ optE::dont_use_reference_energies ].user() ) {
2772 MPI_Send( & n_ref_Es, 1, MPI_UNSIGNED_LONG, ii, tag_, MPI_COMM_WORLD );
2773 MPI_Send( ref_Es, n_ref_Es, MPI_DOUBLE, ii, tag_, MPI_COMM_WORLD );
2777 delete [] ref_Es; ref_Es = 0;
2778 delete [] free_wts; free_wts = 0;
2783 MPI_Recv( free_wts,
n_score_types, MPI_DOUBLE, 0, tag_, MPI_COMM_WORLD, &stat_ );
2788 delete [] free_wts; free_wts = 0;
2791 if ( ! option[ optE::dont_use_reference_energies ].user() ) {
2794 MPI_Recv( & n_ref_Es, 1, MPI_UNSIGNED_LONG, 0, tag_, MPI_COMM_WORLD, &stat_ );
2795 Real * ref_Es =
new Real[ n_ref_Es ];
2796 MPI_Recv( ref_Es, n_ref_Es, MPI_DOUBLE, 0, tag_, MPI_COMM_WORLD, &stat_ );
2799 for (
Size ii = 0; ii < n_ref_Es; ++ii ) {
2803 delete[] ref_Es; ref_Es = 0;
2815 utility::file::create_directory_recursive( utility::file::PathName(scorefile_name).parent() );
2816 std::ofstream fout( scorefile_name.c_str() );
2819 if ( option[ optE::optE_soft_rep ].user() ) {
2820 fout <<
"ETABLE FA_STANDARD_SOFT" << std::endl;
2823 if ( ! option[ optE::dont_use_reference_energies ].user() ) {
2825 fout <<
"METHOD_WEIGHTS ref ";
2831 if ( option[ optE::no_hb_env_dependence ] ) {
2832 fout <<
"NO_HB_ENV_DEP\n";
2836 if ( combined_weights[
ScoreType( ii ) ] != 0 ) {
2841 if ( ! option[ optE::dont_use_reference_energies ].user() ) {
2869 unweighted_unfolded_emap[ aa ].zero();
2875 Real unfolded_energy_for_one_aa = 0.0;
2876 Real weighted_unfolded_energy_for_one_aa = 0.0;
2906 TR <<
"output_weighted_unfolded_energies(): unfolded term has no weight! using 1.0 to avoid errors." << std::endl;
2907 weighted_unfolded_energy_for_one_aa = unfolded_energy_for_one_aa * 1.0;
2910 TR <<
"output_weighted_unfolded_energies(): weighting unfolded energy '" << unfolded_energy_for_one_aa <<
"' by unfolded term weight: '"
2915 TR <<
"output_weighted_unfolded_energies(): weighting unfolded energy '" << unfolded_energy_for_one_aa <<
"' by unfolded term weight: '"
2920 TR <<
"output_weighted_unfolded_energies(): error with checking the weight of the unfolded term. using 1.0 to avoid errors." << std::endl;
2921 weighted_unfolded_energy_for_one_aa = unfolded_energy_for_one_aa * 1.0;
2924 wtd_unfE[ aa ] = weighted_unfolded_energy_for_one_aa;
2927 TR <<
"output_weighted_unfolded_energies(): weighted unfoldedE by aa: [ ";
2929 TR << wtd_unfE[ aa ] <<
" ";
2952 Size dof_index( 1 );
2955 itr != end_itr ; ++itr ) {
2956 return_map[ *itr ] = dofs[ dof_index++ ];
2974 if ( ! option[ optE::dont_use_reference_energies ].user() ) {
2976 reference_energies[ ii ] = vars[
free_count_ + ii ];
2997 if ( option[ optE::optE_soft_rep ].user() ) {
3000 scorefxn->set_energy_method_options( options );
3002 if ( option[ optE::optE_no_protein_hack_elec ]() ) {
3005 scorefxn->set_energy_method_options( options );
3007 if ( option[ optE::no_hb_env_dependence ] ) {
3010 scorefxn->set_energy_method_options( options );
3012 if ( option[ optE::no_hb_env_dependence_DNA ] ) {
3015 scorefxn->set_energy_method_options( options );
3020 scorefxn->set_energy_method_options( options );
3060 sfxn->set_weight(
ref, 1.0 );
3075 std::stringstream instream;
3077 std::string scorefile_name =
"weightdir/optE_scorefile_" + instream.str() +
".wts";
3078 return scorefile_name;
3089 using namespace basic::options;
3090 using namespace basic::options::OptionKeys;
3092 if ( option[ optE::no_design ]() ) {
3123 <<
" native amino acids recovered" << std::endl;
3134 TR <<
"amino acid counts: observed: ";
3141 TR <<
"amino acid counts: expected: ";
3147 Real cross_entropy( 0.0 );
3148 TR <<
"amino acid frequency: obs (exp):";
3166 Size const which_cpu
3175 MPI_Recv( & cpu_positions, 1, MPI_UNSIGNED_LONG, which_cpu, tag_, MPI_COMM_WORLD, &stat_ );
3176 MPI_Recv( & cpu_recovered, 1, MPI_UNSIGNED_LONG, which_cpu, tag_, MPI_COMM_WORLD, &stat_ );
3204 if ( basic::options::option[ basic::options::OptionKeys::in::file::centroid_input ] )
return;
3205 if ( ! basic::options::option[ basic::options::OptionKeys::optE::recover_nat_rot ] )
return;
3223 Size const which_cpu
3230 Size cpu_rotamer_positions;
3231 Size cpu_rotamer_recovered;
3232 MPI_Recv( & cpu_rotamer_positions, 1, MPI_UNSIGNED_LONG, which_cpu, tag_, MPI_COMM_WORLD, &stat_ );
3233 MPI_Recv( & cpu_rotamer_recovered, 1, MPI_UNSIGNED_LONG, which_cpu, tag_, MPI_COMM_WORLD, &stat_ );
3286 wts_vector[ ii ] = wts_map[
ScoreType(ii) ];
3294 if ( ! option[ optE::dont_use_reference_energies ].user() ) {
3296 sfxn->set_weight(
ref, 1.0 );
3300 TR_VERBOSE <<
"run_design_on_assigned_pdbs(): created scorefxn for running design" << std::endl;
3323 if ( basic::options::option[ basic::options::OptionKeys::in::file::centroid_input ] )
return;
3324 if ( ! basic::options::option[ basic::options::OptionKeys::optE::recover_nat_rot ] )
return;
3344 if ( ! option[ optE::dont_use_reference_energies ].user() ) {
3347 sfxn->set_weight(
ref, 1.0 );
3367 MPI_Send( &
total_positions_, 1, MPI_UNSIGNED_LONG, 0, tag_, MPI_COMM_WORLD );
3368 MPI_Send( &
count_recovered_, 1, MPI_UNSIGNED_LONG, 0, tag_, MPI_COMM_WORLD );
3388 if ( basic::options::option[ basic::options::OptionKeys::in::file::centroid_input ] )
return;
3389 if ( ! basic::options::option[ basic::options::OptionKeys::optE::recover_nat_rot ] )
return;
3406 using namespace basic::options;
3407 using namespace basic::options::OptionKeys;
3409 int accept_new_weight_set( 0 );
3413 MPI_Recv( & accept_new_weight_set, 1, MPI_INT, 0, tag_, MPI_COMM_WORLD, & stat_ );
3417 if ( option[ optE::fit_reference_energies_to_aa_profile_recovery ] ) {
3419 Real const Wcross_ent = -0.1;
3423 accept_new_weight_set = 1;
3437 Real cross_entropy( 0.0 );
3441 Real weighted_cross_entropy = cross_entropy * Wcross_ent;
3444 <<
", cross entropy: " << cross_entropy <<
", weighted cross entropy: " << weighted_cross_entropy
3449 accept_new_weight_set == 0 &&
3451 TR <<
"decide_if_sequence_recovery_improved(): accepting new weight set: "
3454 <<
", inner loop weighted cross entropy: " << weighted_cross_entropy
3456 accept_new_weight_set = 1;
3465 if ( accept_new_weight_set != 0 ) {
3470 TR <<
"decide_if_sequence_recovery_improved(): accepting new weight set: "
3474 accept_new_weight_set = 1;
3476 accept_new_weight_set = 0;
3482 MPI_Send( & accept_new_weight_set, 1, MPI_INT, ii, tag_, MPI_COMM_WORLD );
3488 if ( accept_new_weight_set != 0 &&
MPI_rank_ == 0 ) {
3490 if ( ! option[ optE::dont_use_reference_energies ].user() ) {
3494 TR <<
"decide_if_sequence_recovery_improved(): free_parameters_ before: ";
3498 TR <<
"decide_if_sequence_recovery_improved(): free_parameters_ after: ";
3507 TR <<
"decide_if_sequence_recovery_improved(): rejected weight set:\n";
3514 if ( ! option[ optE::dont_use_reference_energies ].user() ) {
3519 return accept_new_weight_set != 0;
3550 if ( ! ( option[ optE::optimize_nat_aa ] || option[ optE::optimize_pssm ] ) ) {
break; }
3560 if (
MPI_rank_ == 0 ) {
TR <<
"go(): DONE with weight optimization." << std::endl; }
3567 MPI_Barrier( MPI_COMM_WORLD );
3584 using namespace basic::options;
3585 using namespace basic::options::OptionKeys;
3592 std::ifstream data( listfile.c_str() );
3594 while ( getline( data,line ) ){
3595 filenames.push_back( line );
3627 using namespace basic::options;
3628 using namespace basic::options::OptionKeys;
3629 using namespace pose;
3630 using namespace pack::task;
3631 using namespace pack::rotamer_set;
3633 TR.Trace <<
"Getting native aa opte data for " << pdb_name <<
":";
3638 if(option[ optE::constant_logic_taskops_file ].user() ) {
3642 }
else if ( option[ optE::design_with_minpack ] ) {
3646 design_task =
task_factory_->create_task_and_apply_taskoperations( pose );
3648 ifcl_operation.
apply( pose, *design_task );
3650 design_task =
task_factory_->create_task_and_apply_taskoperations( pose ) ;
3652 design_task->set_bump_check(
true );
3655 scorefxn.
setup_for_packing( pose, design_task->repacking_residues(), design_task->designing_residues() );
3670 Size num_diffs_between_native_and_input( 0 );
3676 if ( ! design_task->residue_task( resi ).being_designed() )
continue;
3680 else TR.Trace << resi;
3684 PackerTaskOP single_residue_task = TaskFactory::create_packer_task( pose );
3685 single_residue_task->initialize_from_command_line();
3686 task_mask[ resi ] =
true;
3688 single_residue_task->restrict_to_residues( task_mask );
3689 task_mask[ resi ] =
false;
3693 if ( option[ optE::optimize_pssm ] && resi <=
pssm_data_.size() ) {
3696 data->set_pssm_probabilities(
pssm_data_[ resi ].second );
3697 this_pos_data = data;
3699 std::cerr <<
"Warning position " << resi <<
" in " << pdb_name <<
" pssm data does not match native amino acid: ";
3700 std::cerr <<
pssm_data_[ resi ].first <<
" vs " << native_pose.
residue( resi ).
aa() << std::endl;
3701 std::cerr <<
"Falling back on PNatAAOptEPositionData" << std::endl;
3705 if ( option[ optE::optimize_pssm ]() ) {
3706 TR <<
"Warning: " << pdb_name <<
".fasta.probs is shorter than PDB file!\n";
3707 TR <<
"Falling back on PNatAAOptEPositionData for residue " << resi << std::endl;
3723 this_pos_data->tag( pdb_name );
3724 this_pos_data->set_position( resi );
3725 this_pos_data->set_native_aa( native_pose.
residue( resi ).
aa() );
3728 ++num_diffs_between_native_and_input;
3730 this_pos_data->set_neighbor_count(
3739 rotset->set_resid( resi );
3740 rotset->build_rotamers( pose, scorefxn, *single_residue_task, packer_neighbor_graph );
3747 rotset->compute_one_body_energy_maps( pose, scorefxn, *single_residue_task, packer_neighbor_graph, emap_vector );
3749 for (
Size jj = 1; jj <= rotset->num_rotamers(); ++jj ) {
3750 EnergyMap & emap_total( emap_vector[jj] );
3753 if( emap_total[
fa_rep ] > 10.0 )
3754 emap_total[
fa_rep ] = 10.0;
3761 end_iter = score_list.end(); score_type_iter != end_iter; ++score_type_iter ) {
3762 energy_info.push_back( emap_total[ *score_type_iter ] );
3767 end_iter = fixed_score_vec.end(); score_type_iter != end_iter; ++score_type_iter ) {
3768 fixed_energy_info.push_back( emap_total[ *score_type_iter ] );
3775 this_pos_data->add_rotamer_line_data( new_rot_line );
3782 TR.Trace << std::endl;
3806 using namespace pose;
3807 using namespace pack::task;
3808 using namespace pack::rotamer_set;
3809 using namespace pack::dunbrack;
3810 using namespace chemical;
3812 TR.Trace <<
"Getting native rotamer opte data for " << pdb_name <<
":";
3815 if(option[ optE::constant_logic_taskops_file ].user() ) {
3817 }
else if ( option[ optE::design_with_minpack ] ) {
3821 packing_task =
task_factory_->create_task_and_apply_taskoperations( pose );
3823 ifcl_operation.
apply( pose, *packing_task );
3825 packing_task =
task_factory_->create_task_and_apply_taskoperations( pose ) ;
3828 packing_task->set_bump_check(
false );
3829 packing_task->restrict_to_repacking();
3831 scorefxn( native_pose );
3834 scorefxn.
setup_for_packing( pose, packing_task->repacking_residues(), packing_task->designing_residues() );
3839 if ( ! packing_task->residue_task( resi ).being_packed() )
continue;
3845 if ( ! include_rsd[ resi ] )
continue;
3849 else TR.Trace << resi;
3853 PackerTaskOP task = TaskFactory::create_packer_task( pose );
3854 task_mask[ resi ] =
true;
3855 task->restrict_to_residues( task_mask );
3856 task->restrict_to_repacking();
3857 task->initialize_from_command_line();
3858 task->set_bump_check(
false );
3860 task_mask[ resi ] =
false;
3864 SingleResidueDunbrackLibrary::n_rotamer_bins_for_aa( pose.
residue_type( resi ).
aa(), rot_wells );
3866 if ( rot_wells.size() == 0 )
continue;
3871 runtime_assert( dynamic_cast< SingleResidueDunbrackLibrary const * > ( srlib() ) );
3876 this_pos_data->aa() = pose.
residue( resi ).
aa();
3880 utility::to_string( resi );
3881 this_pos_data->tag( tag_to_assign );
3882 this_pos_data->phi() = pose.
phi( resi );
3883 this_pos_data->psi() = pose.
psi( resi );
3884 this_pos_data->set_rotamer_well_counts( rot_wells );
3886 this_pos_data->set_native_rotamer_chi( native_pose.
residue(resi).
chi() );
3891 srdlib->get_rotamer_from_chi(
3894 nat_rot_indices.resize( rot_wells.size() );
3895 this_pos_data->set_native_rotamer_index( nat_rot_indices );
3903 rotset->set_resid( resi );
3904 rotset->build_rotamers( pose, scorefxn, *task, packer_neighbor_graph );
3911 rotset->compute_one_body_energy_maps( pose, scorefxn, *task, packer_neighbor_graph, emap_vector );
3915 for (
Size jj = 1; jj <= rotset->num_rotamers(); ++jj ) {
3916 EnergyMap & emap_total( emap_vector[jj] );
3919 if( emap_total[
fa_rep ] > 10.0 ) emap_total[
fa_rep ] = 10.0;
3925 end_iter = score_list.end() ; score_type_iter != end_iter ; ++score_type_iter ) {
3926 free_energy_info.push_back( emap_total[ *score_type_iter ] );
3930 end_iter = fixed_score_vec.end() ; score_type_iter != end_iter ; ++score_type_iter ) {
3931 fixed_energy_info.push_back( emap_total[ *score_type_iter ] );
3935 srdlib->get_rotamer_from_chi(
3936 rotset->rotamer( jj )->chi(),
3939 rot_index_vector.resize( rot_wells.size() );
3944 rotset->rotamer( jj )->chi(),
3946 fixed_energy_info );
3948 this_pos_data->add_rotamer_line_data( new_rot_line );
3956 TR.Trace << std::endl;
3969 using namespace core::chemical;
3974 pos_data->set_native_chi_periodicity( asym1 );
3979 pos_data->set_native_chi_periodicity( sym2 );
3984 pos_data->set_native_chi_periodicity( asym2 );
3989 pos_data->set_native_chi_periodicity( sym3 );
3995 pos_data->set_native_chi_periodicity( asym3 );
4000 pos_data->set_native_chi_periodicity( asym4 );
4017 using namespace core::chemical;
4018 using namespace core::scoring;
4048 using namespace core::pose;
4050 if ( !info )
return false;
4052 for (
Size ii = 1; ii <= info->natoms( resid ); ++ii ) {
4054 if ( info->temperature( resid, ii ) > 40 ) {
4072 using namespace basic::options;
4073 using namespace basic::options::OptionKeys;
4076 if ( option[ in::file::centroid_input ] ) {
4110 using namespace basic::options;
4111 using namespace basic::options::OptionKeys;
4117 bool const no_fa_rep = option[ optE::pretend_no_ddG_repulsion ]();
4127 for ( OptEPositionDataOPs::const_iterator
4130 iter != iter_end; ++iter ) {
4145 using namespace basic::options;
4146 using namespace basic::options::OptionKeys;
4152 std::map< std::string, std::pair< SingleStructureDataOP, std::string > > structure_map;
4153 std::map< std::string, EnergyMap > structure_energy_map;
4154 std::map< std::string, Energy > structure_bestfarep_map;
4160 TR_VERBOSE <<
"collect_ddG_of_mutation_data(): created sfxn for calculating ddGs" << std::endl;
4161 sfxn->show( std::cout );
4187 ddg_data->set_experimental_ddg(
ddGs_[ ii ] );
4194 bool read_silent(
false );
4198 if(file_extension.compare(
"list") == 0){
4202 TR <<
"collect_ddG_of_mutation_data(): reading file '" << wts() <<
"' to get list of wt pdb names." << std::endl;
4203 std::ifstream wt_pdblist( wts().c_str() );
4204 while ( wt_pdblist ) {
4206 wt_pdblist >> wt_pdb;
4207 if ( wt_pdb !=
"" ) wt_pdb_names.push_back( wt_pdb );
4210 else if(file_extension.compare(
"out") == 0){
4214 std::cout <<
"[ERROR ERROR ERROR] did not read in silent file properly! " << wts() << std::endl;
4216 wt_pdb_names = sfd_wt.
tags();
4220 std::cerr <<
"ERROR! file " << wts() <<
" has un-recognized extension " << file_extension << std::endl;
4225 bool no_tag_yet_assigned(
true );
4227 file_extension = muts.ext();
4229 if(file_extension.compare(
"list") == 0){
4230 TR <<
"collect_ddG_of_mutation_data(): reading file '" << muts() <<
"' to get list of mutant pdb names." << std::endl;
4231 std::ifstream mut_pdblist( muts().c_str() );
4232 while ( mut_pdblist ) {
4234 mut_pdblist >> mut_pdb;
4235 if ( mut_pdb !=
"" ) mut_pdb_names.push_back( mut_pdb );
4236 if ( no_tag_yet_assigned ) {
4238 ddg_data->tag( mut1.base() );
4239 no_tag_yet_assigned =
false;
4243 else if(file_extension.compare(
"out") == 0){
4247 std::cout <<
"[ERROR ERROR ERROR] did not read in silent file properly! " << muts() << std::endl;
4249 mut_pdb_names = sfd_mut.
tags();
4250 if( no_tag_yet_assigned ){
4251 ddg_data->tag(mut_pdb_names[1]);
4252 no_tag_yet_assigned =
false;
4256 std::cerr <<
"ERROR! file " << muts() <<
" has un-recognized extension " << file_extension << std::endl;
4261 Real best_wt_rep( 12345678 ), best_mut_rep( 12345678 );
4262 bool collect_best_rep( option[ optE::exclude_badrep_ddGs ].user() );
4264 for (
Size jj = 1; jj <= wt_pdb_names.size(); ++jj ) {
4270 if ( structure_map.find( wts()+wt_pdb_names[ jj ] ) == structure_map.end() ) {
4274 if ( option[ in::file::centroid_input ] ) {
4282 ss->fill_pose(wt_structure,*rsd_set);
4290 if ( wt_seq != wt_structure.
sequence() ) {
4291 std::cerr <<
"Wild type sequence inconsistent across wts " << std::endl;
4292 std::cerr << wt_seq << std::endl;
4293 std::cerr << wt_structure.
sequence() << std::endl;
4294 std::cerr <<
"Node " <<
MPI_rank_ <<
" " << wt_pdb_names[ jj ] <<
" and " << wt_pdb_names[ 1 ] << std::endl;
4295 wt_structure.
dump_pdb(
"offending_wt_sequence.pdb");
4304 (*sfxn)( wt_structure );
4312 if ( collect_best_rep ) {
4316 structure_bestfarep_map[ wts()+wt_pdb_names[ jj ] ] = best_wt_rep;
4328 ddg_data->add_wt( ssd );
4329 structure_map[ wts()+wt_pdb_names[ jj ] ] = std::make_pair( ssd, wt_seq );
4342 structure_energy_map[ wts()+wt_pdb_names[ jj ] ] = e;
4351 wt_seq = structure_map[ wts()+wt_pdb_names[ jj ] ].second;
4354 if ( collect_best_rep ) {
4355 best_wt_rep = structure_bestfarep_map[ wts()+wt_pdb_names[ jj ] ];
4361 ddg_data() ))->set_wt_unfolded_energies_emap( structure_energy_map[ wts()+wt_pdb_names[ jj ] ] );
4365 ddg_data->add_wt( structure_map[ wts()+wt_pdb_names[ jj ] ].first );
4371 for (
Size jj = 1; jj <= mut_pdb_names.size(); ++jj ) {
4374 if ( option[ in::file::centroid_input ] ) {
4386 mut_seq = mut_structure.
sequence();
4388 if ( mut_seq != mut_structure.
sequence() ) {
4389 std::cerr <<
"Mutant sequence inconsistent across muts " << std::endl;
4390 std::cerr << mut_seq << std::endl;
4391 std::cerr << mut_structure.
sequence() << std::endl;
4392 std::cerr <<
"Node " <<
MPI_rank_ <<
" " << mut_pdb_names[ jj ] <<
" and " << mut_pdb_names[ 1 ] << std::endl;
4393 mut_structure.
dump_pdb(
"offending_mutant_structure_seq.pdb");
4402 (*sfxn)( mut_structure );
4408 if ( collect_best_rep ) {
4424 ddg_data->add_mutant( ssd );
4439 int discrepant_position( -1 );
4440 if ( wt_seq.size() != mut_seq.size() ) {
4441 std::cerr <<
"ERROR: Wild type and mutant sequences of different length: " << std::endl;
4442 std::cerr << wt_seq << std::endl;
4443 std::cerr << mut_seq << std::endl;
4444 std::cerr <<
"Rank " <<
MPI_rank_ <<
" " << wt_pdb_names[ 1 ] <<
" vs " << mut_pdb_names[ 1 ] << std::endl;
4447 for (
Size jj = 0; jj < wt_seq.size(); ++jj ) {
4448 if ( discrepant_position == -1 ) {
4449 if ( wt_seq[ jj ] != mut_seq[ jj ] ) {
4450 discrepant_position = jj;
4452 }
else if ( wt_seq[ jj ] != mut_seq[ jj ] ) {
4453 std::cerr <<
"Error: Wild type and mutant sequences differ at more than one position: "
4454 << discrepant_position <<
" " << jj << std::endl;
4455 std::cerr << wt_seq << std::endl;
4456 std::cerr << mut_seq << std::endl;
4457 std::cerr <<
"Rank " <<
MPI_rank_ <<
" " << wt_pdb_names[ 1 ] <<
" vs " << mut_pdb_names[ 1 ] << std::endl;
4462 if ( discrepant_position == -1 ) {
4463 std::cerr <<
"ERROR: mutant and wild type sequences must differ by at least one position";
4464 std::cerr <<
"Rank " <<
MPI_rank_ <<
" " << wt_pdb_names[ 1 ] <<
" vs " << mut_pdb_names[ 1 ] << std::endl;
4470 if ( ! collect_best_rep || best_mut_rep - best_wt_rep < option[ optE::exclude_badrep_ddGs ]() ) {
4474 <<
" with mt-wt rep delta: "<< best_mut_rep <<
" - " << best_wt_rep
4475 <<
" = " << best_mut_rep - best_wt_rep << std::endl;
4480 for ( OptEPositionDataOPs::const_iterator
4483 iter != iter_end; ++iter ) {
4499 using namespace core;
4500 using namespace basic::options;
4501 using namespace basic::options::OptionKeys;
4507 std::map< std::string, std::pair< SingleStructureDataOP, std::string > > structure_map;
4508 std::map< std::string, Energy > structure_bestfarep_map;
4513 TR_VERBOSE <<
"collect_ddG_of_binding_data(): created sfxn for calculating ddGs of binding" << std::endl;
4514 sfxn->show( std::cout );
4530 ddg_bind_position_data->set_experimental_ddg_bind(
ddGs_binding_[ ii ] );
4541 TR <<
"collect_ddG_of_binding_data(): reading file '" << wt_complexes_list_file() <<
"' to get list of wt complex pdb names." << std::endl;
4542 std::ifstream wt_complex_pdblist( wt_complexes_list_file().c_str() );
4543 while ( wt_complex_pdblist ) {
4545 wt_complex_pdblist >> wt_complex_pdb;
4546 if ( wt_complex_pdb !=
"" ) wt_complex_pdb_names.push_back( wt_complex_pdb );
4550 bool no_tag_yet_assigned(
true );
4552 TR <<
"collect_ddG_of_binding_data(): reading file '" << mut_complexes_list_file() <<
"' to get list of mutant complex pdb names." << std::endl;
4553 std::ifstream mut_complex_pdblist( mut_complexes_list_file().c_str() );
4554 while ( mut_complex_pdblist ) {
4556 mut_complex_pdblist >> mut_complex_pdb;
4557 if ( mut_complex_pdb !=
"" ) mut_complex_pdb_names.push_back( mut_complex_pdb );
4558 if ( no_tag_yet_assigned ) {
4560 ddg_bind_position_data->tag( mut1.base() );
4561 TR <<
"collect_ddG_of_binding_data(): assigned tag: '" << mut1.base() <<
"' to this set of ddG bind files." << std::endl;
4562 no_tag_yet_assigned =
false;
4567 TR <<
"collect_ddG_of_binding_data(): reading file '" << wt_unbounds_list_file() <<
"' to get list of wt unbounded pdb names." << std::endl;
4568 std::ifstream wt_unbounded_pdblist( wt_unbounds_list_file().c_str() );
4569 while ( wt_unbounded_pdblist ) {
4571 wt_unbounded_pdblist >> wt_unbounded_pdb;
4572 if ( wt_unbounded_pdb !=
"" ) wt_unbounded_pdb_names.push_back( wt_unbounded_pdb );
4576 TR <<
"collect_ddG_of_binding_data(): reading file '" << mut_unbounds_list_file() <<
"' to get list of mutant unbounded pdb names." << std::endl;
4577 std::ifstream mut_unbounded_pdblist( mut_unbounds_list_file().c_str() );
4578 while ( mut_unbounded_pdblist ) {
4580 mut_unbounded_pdblist >> mut_unbounded_pdb;
4581 if ( mut_unbounded_pdb !=
"" ) mut_unbounded_pdb_names.push_back( mut_unbounded_pdb );
4588 Real best_wt_complex_rep( 12345678 ), best_mut_complex_rep( 12345678 );
4589 bool filtering_bad_ddGs( option[ optE::exclude_badrep_ddGs ].user() );
4591 for (
Size jj = 1; jj <= wt_complex_pdb_names.size(); ++jj ) {
4596 if ( structure_map.find( wt_complexes_list_file()+wt_complex_pdb_names[ jj ] ) == structure_map.end() ) {
4603 wt_complex_seq = wt_complex.
sequence();
4605 if ( wt_complex_seq != wt_complex.
sequence() ) {
4606 std::cerr <<
"wild type complex sequence inconsistent across wts " << std::endl;
4607 std::cerr << wt_complex_seq << std::endl;
4608 std::cerr << wt_complex.
sequence() << std::endl;
4609 std::cerr <<
"Node " <<
MPI_rank_ <<
" " << wt_complex_pdb_names[ jj ] <<
" and " << wt_complex_pdb_names[ 1 ] << std::endl;
4610 wt_complex.
dump_pdb(
"offending_wt_complex_sequence.pdb");
4619 (*sfxn)( wt_complex );
4626 if ( filtering_bad_ddGs ) {
4630 structure_bestfarep_map[ wt_complexes_list_file()+wt_complex_pdb_names[ jj ] ] = best_wt_complex_rep;
4634 ddg_bind_position_data->add_wt_complex( ssd );
4635 structure_map[ wt_complexes_list_file()+wt_complex_pdb_names[ jj ] ] = std::make_pair( ssd, wt_complex_seq );
4643 wt_complex_seq = structure_map[ wt_complexes_list_file()+wt_complex_pdb_names[ jj ] ].second;
4645 if ( filtering_bad_ddGs )
4646 best_wt_complex_rep = structure_bestfarep_map[ wt_complexes_list_file()+wt_complex_pdb_names[ jj ] ];
4648 ddg_bind_position_data->add_wt_complex( structure_map[ wt_complexes_list_file()+wt_complex_pdb_names[ jj ] ].first );
4652 for (
Size jj = 1; jj <= mut_complex_pdb_names.size(); ++jj ) {
4659 mut_complex_seq = mut_complex.
sequence();
4661 if ( mut_complex_seq != mut_complex.
sequence() ) {
4662 std::cerr <<
"mutant complex sequence inconsistent across muts " << std::endl;
4663 std::cerr << mut_complex_seq << std::endl;
4664 std::cerr << mut_complex.
sequence() << std::endl;
4665 std::cerr <<
"Node " <<
MPI_rank_ <<
" " << mut_complex_pdb_names[ jj ] <<
" and " << mut_complex_pdb_names[ 1 ] << std::endl;
4666 mut_complex.
dump_pdb(
"offending_mutant_complex_structure_seq.pdb");
4675 (*sfxn)( mut_complex );
4682 if ( filtering_bad_ddGs ) {
4689 ddg_bind_position_data->add_mutant_complex( ssd );
4692 for (
Size jj = 1; jj <= wt_unbounded_pdb_names.size(); ++jj ) {
4694 if ( structure_map.find( wt_unbounds_list_file()+wt_unbounded_pdb_names[ jj ] ) == structure_map.end() ) {
4714 (*sfxn)( wt_unbounded );
4722 ddg_bind_position_data->add_wt_unbounds( ssd );
4723 structure_map[ wt_unbounds_list_file()+wt_unbounded_pdb_names[ jj ] ] = std::make_pair( ssd, wt_complex_seq );
4726 ddg_bind_position_data->add_wt_unbounds( structure_map[ wt_unbounds_list_file()+wt_unbounded_pdb_names[ jj ] ].first );
4730 for (
Size jj = 1; jj <= mut_unbounded_pdb_names.size(); ++jj ) {
4750 (*sfxn)( mut_unbounded );
4758 ddg_bind_position_data->add_mutant_unbounds( ssd );
4763 TR <<
"collect_ddG_of_binding_data(): looking for discrepant positions between wt and mut complex structures: ";
4764 bool one_discrepancy_found(
false );
4765 if ( wt_complex_seq.size() != mut_complex_seq.size() ) {
4766 std::cerr <<
"ERROR: Wild type and mutant complex sequences of different length: " << std::endl;
4767 std::cerr << wt_complex_seq << std::endl;
4768 std::cerr << mut_complex_seq << std::endl;
4771 for (
Size jj = 0; jj < wt_complex_seq.size(); ++jj ) {
4772 if ( wt_complex_seq[ jj ] != mut_complex_seq[ jj ] ) {
4776 ddg_bind_position_data->add_mutation(
4778 TR << wt_complex_seq[ jj ] << jj << mut_complex_seq[ jj ] <<
", ";
4779 one_discrepancy_found =
true;
4784 if ( one_discrepancy_found ==
false ) {
4785 std::cerr <<
"ERROR: mutant and wild type complex sequences must differ by at least one position";
4789 if ( filtering_bad_ddGs && ( best_mut_complex_rep - best_wt_complex_rep > option[ optE::exclude_badrep_ddGs ]() ) ) {
4791 <<
" with mut-wt rep delta: "<< best_mut_complex_rep <<
" - " << best_wt_complex_rep
4792 <<
" = " << best_mut_complex_rep - best_wt_complex_rep << std::endl;
4799 for ( OptEPositionDataOPs::const_iterator iter =
ddG_bind_optE_data_->position_data_begin(),
4832 Size & nresidues_designed,
4833 Size & nresidues_recovered
4836 using namespace basic::options;
4837 using namespace basic::options::OptionKeys;
4838 using namespace core::pack;
4839 using namespace core::pack::task;
4840 using namespace core::scoring;
4849 nresidues_designed = 0;
4850 nresidues_recovered = 0;
4859 TR <<
"measure_sequence_recovery(): designing with surface term, with weight: "
4864 if ( option[ optE::design_with_minpack ]) {
4866 minpack_mover->task_factory( task_factory_for_design );
4867 minpack_mover->score_function( sfxn );
4868 design_mover = minpack_mover;
4871 pack_mover->task_factory( task_factory_for_design );
4872 pack_mover->score_function( sfxn );
4873 design_mover = pack_mover;
4876 for (
Size poseindex = 1; poseindex <= native_pdb_names.size(); ++poseindex ) {
4877 TR <<
"begin measure_sequence_recovery(): PDB: " << native_pdb_names[ poseindex ] << std::endl;
4885 TR <<
"measure_sequence_recovery(): design_first in use! pushing "
4886 << native_pdb_names[poseindex] <<
" onto native_poses_ vector." << std::endl;
4892 if ( option[ optE::recover_nat_rot ] ) {
4918 for (
Size resi = 1; resi <= nresidues_pose; ++resi ) {
4919 full_input_sequence[ resi ] = pose.
residue(resi).
aa();
4923 design_mover->apply( pose );
4931 if(option[ optE::constant_logic_taskops_file ].user() ) {
4934 task_factory_for_design);
4937 ptask = task_factory_for_design->create_task_and_apply_taskoperations( pose ) ;
4943 for (
Size resi = 1; resi <= nresidues_pose; ++resi ) {
4945 if ( ! ptask->being_designed(resi) )
continue;
4947 ++nresidues_designed;
4948 ++
aa_exp_[ full_input_sequence[ resi ]];
4950 if ( full_input_sequence[ resi ] == pose.
residue(resi).
aa() ) ++nresidues_recovered;
4954 if ( ! option[ optE::no_design_pdb_output ] ) {
4965 if ( nresidues_designed != 0 ) {
4966 recovery = (
static_cast< Real > (nresidues_recovered) ) / nresidues_designed;
4967 TR_VERBOSE <<
"measure_sequence_recovery(): recovery: " << recovery << std::endl;
4983 Size & nresidues_repacked,
4984 Size & nrotamers_recovered
4987 using namespace basic::options;
4988 using namespace basic::options::OptionKeys;
4989 using namespace core::pack::dunbrack;
4998 nresidues_repacked = 0;
4999 nrotamers_recovered = 0;
5003 using namespace core::pack::task;
5008 pack_mover->
task_factory( task_factory_for_repacking );
5009 pack_mover->score_function( sfxn );
5011 for (
Size poseindex = 1; poseindex <= native_pdb_names.size(); ++poseindex ) {
5025 pack_mover->apply( pose );
5035 if(option[ optE::constant_logic_taskops_file ].user() ) {
5038 task_factory_for_repacking);
5041 ptask = task_factory_for_repacking->create_task_and_apply_taskoperations( pose ) ;
5043 for (
Size resi = 1; resi <= nresidues_pose; ++resi ) {
5045 if ( ! ptask->being_packed(resi) )
continue;
5047 if ( start_pose.
residue(resi).
nchi() == 0 )
continue;
5048 ++nresidues_repacked;
5050 RotVector original_rotbins, repacked_rotbins;
5054 bool all_chi_match(
true );
5055 for (
Size chi_index = 1; chi_index <=original_rotbins.size(); ++chi_index ) {
5056 if ( original_rotbins[ chi_index ] != repacked_rotbins[ chi_index ] ) {
5057 all_chi_match =
false;
5061 if ( all_chi_match ) ++nrotamers_recovered;
5069 Real recovery( 0.0 );
5070 if ( nresidues_repacked != 0 ) {
5071 recovery = (
static_cast< Real > (nrotamers_recovered) ) / nresidues_repacked;
5084 if ( outer_loop_counter == 1 ) {
5086 }
else if ( inner_loop_counter <= 5 ) {
5087 return ( 1.0 / ( outer_loop_counter + inner_loop_counter) );
5106 using namespace basic::options;
5107 using namespace basic::options::OptionKeys;
5109 if ( option[ optE::free ].user() && option[ optE::fixed ].user() ) {
5110 utility::io::izstream input_free( option[ optE::free ]() );
5111 if( !input_free ) utility_exit_with_message(
"Couldn't find input file for 'free' parameters");
5112 Size free_line_number = 1;
5113 while ( input_free ) {
5115 if ( line_tokens.size() == 0 ) {
5117 }
else if ( line_tokens.size() == 1 && ! option[ optE::design_first ].user() ) {
5120 free_parameters[ free_score_type ] =
optE_RG.uniform();
5121 }
else if ( line_tokens.size() == 2 ) {
5123 Real free_starting_weight = utility::from_string( line_tokens[ 2 ],
Real(0.0) );
5124 free_parameters[ free_score_type ] = free_starting_weight;
5125 if ( option[ optE::randomly_perturb_starting_free_weights ].user() && free_parameters[ free_score_type ] != 0.0 ) {
5126 Real perturb_range = option[ optE::randomly_perturb_starting_free_weights ]();
5127 free_parameters[ free_score_type ] += 2 * perturb_range *
optE_RG.uniform() - perturb_range;
5128 if ( free_parameters[ free_score_type ] == 0.0 ) {
5129 free_parameters[ free_score_type ] = 0.0001;
5133 if ( option[ optE::design_first ].user() ) {
5134 std::cerr <<
"\n\n";
5135 std::cerr <<
"Error reading weight file line: " << free_line_number <<
" ";
5136 for (
Size ii = 1; ii <= line_tokens.size(); ++ii ) {
5137 std::cerr << line_tokens[ ii ] <<
" ";
5139 std::cerr << std::endl <<
"Expected exactly 2 arguments (i.e. you cannot ask for a random starting weight!) since optE:design_first flag found on command line" << std::endl;
5141 std::cerr <<
"Error reading free weight file line: " << free_line_number <<
" ";
5142 for (
Size ii = 1; ii <= line_tokens.size(); ++ii ) {
5143 std::cerr << ii <<
": " << line_tokens[ ii ];
5145 std::cerr << std::endl <<
"Expected only 2 tokens" << std::endl;
5152 utility::io::izstream input_fixed( option[ optE::fixed ]() );
5153 if( !input_fixed ) utility_exit_with_message(
"Couldn't find input file for 'fixed' parameters");
5154 Size fixed_line_number = 1;
5155 while ( input_fixed ) {
5157 if ( line_tokens.size() == 0 ) {
5159 }
else if ( line_tokens.size() == 2 ) {
5161 Real fixed_weight = utility::from_string( line_tokens[ 2 ],
Real(0.0) );
5162 fixed_parameters[ fixed_score_type ] = fixed_weight;
5163 if ( free_parameters[ fixed_score_type ] != 0 ) {
5164 std::cerr <<
"Error reading free weights file. Term '" << line_tokens[ 1 ] <<
"' is listed as both free and fixed.";
5168 std::cerr <<
"Error reading free weight file line: " << free_line_number <<
" ";
5169 for (
Size ii = 1; ii <= line_tokens.size(); ++ii ) {
5170 std::cerr << ii <<
": " << line_tokens[ ii ];
5172 std::cerr << std::endl <<
"Expected exactly 2 tokens" << std::endl;
5175 ++fixed_line_number;
5180 }
else if ( option[ in::file::centroid_input ] ) {
5182 free_parameters[
vdw ] = 1;
5183 free_parameters[
pair ] = 1;
5184 free_parameters[
rama ] = 1;
5185 free_parameters[
p_aa_pp ] = 1;
5186 free_parameters[
cenpack ] = 1;
5188 fixed_parameters[
env ] = 0.4;
5203 free_parameters[
fa_rep ] = 0.44;
5207 free_parameters[
fa_dun ] = 0.56;
5209 free_parameters[
p_aa_pp ] = 0.64;
5214 fixed_parameters[
fa_atr ] = 0.8;
5225 if ( free_parameters[ (
ScoreType) ii ] != 0 ) {
5227 <<
" " << free_parameters[ (
ScoreType) ii ] << std::endl;
5232 if ( fixed_parameters[ (
ScoreType) ii ] != 0 ) {
5234 <<
" " << fixed_parameters[ (
ScoreType) ii ] << std::endl;
5256 using namespace core::scoring;
5258 if ( ! option[ optE::dont_use_reference_energies ].user() ) {
5259 runtime_assert( reference_energies_prev.size() == reference_energies_curr.size() );
5263 if ( std::abs( free_parameters_prev[ (
ScoreType) ii ] - free_parameters_curr[ (
ScoreType) ii ]) > 0.001 ) {
5268 if ( ! option[ optE::dont_use_reference_energies ].user() ) {
5269 for (
Size ii = 1; ii <= reference_energies_prev.size(); ++ii ) {
5270 if ( std::abs( reference_energies_prev[ ii ] - reference_energies_curr[ ii ]) > 0.001 ) {
5276 TR <<
"Converged: " << std::endl;
5278 if ( free_parameters_prev[ (
ScoreType) ii ] != 0 || free_parameters_curr[ (
ScoreType) ii ] != 0)
5282 if ( ! option[ optE::dont_use_reference_energies ].user() ) {
5283 for (
Size ii = 1; ii <= reference_energies_prev.size(); ++ii ) {
5284 TR << ii <<
" prev " << reference_energies_prev[ ii ] <<
" curr " << reference_energies_curr[ ii ] << std::endl;
5296 if ( free_parameters[ (
ScoreType) ii ] != 0 )
5299 for (
Size ii = 1; ii <= reference_energies.size(); ++ii ) {
5300 TR <<
"Reference energy for " << ii <<
" " << reference_energies[ ii ] << std::endl;
5319 Size const outer_loop_counter,
5325 pdbs_next_round.resize( native_pdb_names.size() );
5326 for (
Size ii = 1; ii <= native_pdb_names.size(); ++ii ) {
5330 pdbs_next_round[ ii ] = natfilename.base() +
"_" + to_string( outer_loop_counter ) +
".pdb";
5333 pdbs_next_round[ ii ] =
"workdir_" + to_string(
MPI_rank_ ) +
"/" + natfilename.base() +
"_" + to_string( outer_loop_counter ) +
".pdb";
5345 using namespace moves;
5346 using namespace core::pack::task;
5355 packer.
apply( pose );
5358 minmover.
min_type(
"dfpmin_armijo_nonmonotone_atol" );
5359 minmover.score_function( sfxn );
5361 minmover.apply( pose );
5377 using namespace basic::options;
5378 using namespace basic::options::OptionKeys;
5381 std::fill( component_weights.begin(), component_weights.end(), 1.0 );
5383 if ( option[ optE::component_weights ].user() ) {
5384 utility::io::izstream input( option[ optE::component_weights ]() );
5385 if( !input ) utility_exit_with_message(
"Couldn't find input file for 'component_weights_file' parameters");
5386 Size line_number = 1;
Size nread = 0;
5389 if ( line_tokens.size() == 0 ) {
5391 }
else if ( line_tokens.size() == 2 ) {
5393 utility_exit_with_message(
"Error reading optE component weights file: Token 1 on line " + utility::to_string( line_number ) +
" " + line_tokens[ 1 ] +
" is not recognized as an optE data type" );
5396 Real component_weight = utility::from_string( line_tokens[ 2 ],
Real(1.0) );
5397 component_weights[ component_type ] = component_weight;
5400 std::cerr <<
"Error reading optE component weights file line: " << line_number <<
" ";
5401 for (
Size ii = 1; ii <= line_tokens.size(); ++ii ) {
5402 std::cerr << ii <<
": " << line_tokens[ ii ];
5404 std::cerr << std::endl <<
"Expected exactly 2 tokens" << std::endl;
5409 if ( line_number == 1 ) {
5410 TR <<
"WARNING: read no lines from component weight file: " << option[ optE::component_weights ]() << std::endl;
5411 }
else if ( nread == 0 ) {
5412 TR <<
"WARNING: only blank lines found in component weight file: " << option[ optE::component_weights ]() << std::endl;
5429 using namespace core::pack::task;
5431 std::string context_tagfile( option[ optE::constant_logic_taskops_file ]() );
5434 PackerTaskOP context_task = context_taskfactory->create_task_and_apply_taskoperations( context_pose );
5438 mimic_nat_task_op->apply( context_pose, *(context_task) );
5440 return context_task;
5454 gethostname(hostname,
sizeof(hostname));
5455 printf(
"PID %d on %s ready for attach\n", getpid(), hostname);
5470 return "master node";
5472 std::stringstream r;
5473 r <<
"slave node " << rank;
5492 os <<
"---------------------------------------------------" << std::endl;
5495 float sum_weighted = 0.0;
5517 if ( weight != 0.0 ) {
5520 os << LJ(18,
ScoreType(jj)) << F(7,4,weight) <<
X(4) << F(10,3,val) <<
X(4) << F(10,3, weight * val ) << std::endl;
5521 sum_weighted += weight * val;
5529 os <<
"---------------------------------------------------\n" << LJ(25,
"Total weighted score: ") <<
X(12) << F(10,3,sum_weighted) << std::endl;