32 #include <basic/options/option.hh>
33 #include <basic/options/keys/enzdes.OptionKeys.gen.hh>
51 #include <basic/MetricValue.hh>
68 #include <numeric/random/random.hh>
72 #include <ObjexxFCL/FArray1D.hh>
73 #include <ObjexxFCL/format.hh>
76 #include <utility/io/izstream.hh>
77 #include <utility/tag/Tag.hh>
79 #include <utility/vector0.hh>
80 #include <utility/excn/Exceptions.hh>
81 #include <utility/vector1.hh>
85 using namespace core::scoring;
86 using namespace ObjexxFCL::fmt;
88 static basic::Tracer
TR(
"protocols.enzdes.EnzFilters" );
89 static numeric::random::RandomGenerator
RG( 14084760 );
94 using namespace protocols::filters;
95 using namespace protocols::moves;
96 using namespace utility::tag;
100 LigDSasaFilter::LigDSasaFilter(
core::Real const lower_threshold,
core::Real const upper_threshold ) :
Filter(
"DSasa" ), lower_threshold_( lower_threshold ), upper_threshold_(upper_threshold) {}
106 TR<<
"dsasa is "<<dsasa<<
". ";
108 TR<<
"passing." <<std::endl;
112 TR<<
"failing."<<std::endl;
120 out<<
"DSasa= "<< dsasa<<
'\n';
131 basic::MetricValue< core::Real > mv_sasa;
137 prot_chain = pose.
chain( 1 );
138 std::string lig_ch_string = utility::to_string( lig_chain );
139 std::string prot_ch_string = utility::to_string( prot_chain );
140 if( lig_chain == prot_chain ) { utility_exit_with_message(
"WTF?!? ligand and residue 1 are on the same chain... " );}
142 TR<<
"Now calculating SaSa"<<std::endl;
143 pose.
metric(
"sasa_interface",
"frac_ch2_dsasa", mv_sasa);
144 sasa = mv_sasa.value() ;
155 TR<<
"LigDSasaFilter with lower threshold of "<<
lower_threshold_<<
" and upper threshold of "<< upper_threshold_ <<std::endl;
164 bool const dsasa(
compute( pose ) );
167 TR<<
"Diff Atom Sasa filter passing." <<std::endl;
171 TR<<
"Diff Atom Sasa filter failing."<<std::endl;
178 bool const dsasa(
compute( pose ));
179 out<<
"Diff Sasa= "<< dsasa<<
'\n';
184 bool const dsasa(
compute( pose ));
185 if( dsasa )
return 1;
191 basic::MetricValue< id::AtomID_Map< core::Real > > atom_sasa;
192 bool setting (
false);
193 pose.
metric(
"sasa_interface",
"delta_atom_sasa", atom_sasa );
196 core::Real const atom1_delta_sasa( atom_sasa.value()( atomid1 ) );
197 core::Real const atom2_delta_sasa( atom_sasa.value()( atomid2 ) );
198 TR<<
"Atom1: Dsasa is "<< atom1_delta_sasa <<
" and Atom2 Dsasa is "<< atom2_delta_sasa << std::endl;
200 if (atom1_delta_sasa > atom2_delta_sasa) setting=
true;
202 else if (atom1_delta_sasa < atom2_delta_sasa) setting=
true;
209 if ( tag->hasOption(
"res1_res_num") )
resid1_ = tag->getOption<
core::Size>(
"res1_res_num", 0 );
210 if ( tag->hasOption(
"res2_res_num") )
resid2_ = tag->getOption<
core::Size>(
"res2_res_num", 0 );
225 runtime_assert( sample_type_==
"more" || sample_type_ ==
"less" );
226 TR<<
" Defined LigDSasaFilter "<< std::endl;
235 TR<<
"Number of interface neighbors of ligand is "<<count_neighbors<<std::endl;
243 out<<
"Number of interface neighbors of residue is "<<count_neighbors<<
'\n';
250 return( count_neighbors );
258 if (real_lig_id==0) {
261 TR<<
"Calculating neighbors of Ligand resid is " << real_lig_id << std::endl;
270 return( count_neighbors);
282 TR<<
"LigBurialFilter with distance threshold of "<<distance_threshold_<<
" around residue "<<
lig_id_<<
" with "<<neighbors_<<
" neighbors."<<std::endl;
290 using namespace core::scoring;
300 using namespace core::scoring;
308 using namespace core::scoring;
311 TR <<
"pose must contain at least two chains!" << std::endl;
315 TR<<
" \n \t --------- computing ---------- \n \t-------- ligand interface energies --------\n \t \t------------------- \n" << std::endl;
326 using namespace core::scoring;
327 using ObjexxFCL::FArray1D_bool;
330 FArray1D_bool prot_res( in_pose.total_residue(), false );
333 in_pose.update_residue_neighbors();
336 (*scorefxn_)( in_pose );
338 out<<
"\n"<<
A(9,
"chain")<<
A( 9,
"res")<<
A( 9,
"AA")<<
A( 9,
"total")<<
A( 9,
"contact")<<
A( 9,
"fa_atr")<<
A( 9,
"fa_rep")<<
A( 9,
"hb_bb_sc")<<
A( 9,
"hb_sc")<<
A( 9,
"fa_sol")<<
A( 9,
"fa_dun")<<
A( 9,
"fa_pair")<<
"\n";
350 Real weighted_contact_score = weighted_fa_atr + weighted_fa_rep + weighted_hbond_bb_sc + weighted_hbond_sc + weighted_fa_sol;
355 out<<
A (9 , in_pose.pdb_info()->chain( resnum_) )<< I(9,0, in_pose.pdb_info()->number(resnum_))<<
A (9,in_pose.residue( resnum_).name3())
356 <<F (9 , 3, total) <<
" "
357 <<F (9 , 3, weighted_contact_score)<<
" "
358 <<F (9 , 3, weighted_fa_atr) <<
" "
359 <<F (9 , 3, weighted_fa_rep) <<
" "
360 <<F (9 , 3, weighted_hbond_bb_sc )<<
" "
361 <<F (9 , 3, weighted_hbond_sc )<<
" "
362 <<F (9 , 3, weighted_fa_sol )<<
" "
363 <<F (9 , 3, weighted_fa_dun )<<
" "
364 <<F (9 , 3, weighted_fa_pair )<<
"\n";
376 using namespace core::scoring;
385 using namespace core::scoring;
386 using namespace core::pose::metrics;
389 (*scorefxn_)( in_pose );
393 basic::MetricValue< core::Real > mv_interfE;
394 in_pose.metric(
"liginterfE",
"weighted_total", mv_interfE);
395 core::Real weighted_score = mv_interfE.value();
396 TR<<
"Calculated Interface Energy is before cst correction is:"<<weighted_score<<std::endl;
398 TR<<
"Calculated Interface Energy is "<<weighted_score<<std::endl;
399 return( weighted_score );
405 using namespace core::scoring;
411 if( which_res == -1){
423 using namespace core::scoring;
434 utility::lua::LuaObject
const & score_fxns,
435 utility::lua::LuaObject
const & ){
436 using namespace core::scoring;
438 if( def[
"scorefxn"] ) {
444 include_cstE_ = def[
"include_cstE"] ? def[
"include_cstE"].to<
bool>() :
false;
451 EnzScoreFilter::EnzScoreFilter(
core::Size const resnum,
std::string const cstid,
core::scoring::ScoreFunctionOP scorefxn,
core::scoring::ScoreType const score_type,
core::Real const threshold,
bool const whole_pose,
bool const is_cstE ) :
Filter(
"EnzScore" ), resnum_( resnum ), cstid_( cstid ), score_type_( score_type ),
threshold_( threshold ), whole_pose_ ( whole_pose ), is_cstE_ ( is_cstE ) {
453 using namespace core::scoring;
468 using namespace core::scoring;
475 using namespace core::scoring;
477 TR<<
"Score found as "<<energy <<
" and threshold is " <<
threshold_<<std::endl;
485 using namespace core::scoring;
486 out<<
"Weighted score "<<
compute( pose )<<
'\n';
496 using namespace core::pose;
497 using namespace core::scoring;
506 (*scorefxn_)( *in_pose );
510 TR<<
"Raw Score is: " << score << std::endl;
515 (*scorefxn_)( *in_pose );
523 TR<<
"Evaluating constraint score for whole pose..."<<std::endl;
527 TR<<
"And constraint energy is..."<< all_cstE << std::endl;
531 core::Real const weighted_score( weight * score );
532 TR<<
"Weighted Score is: " << weighted_score << std::endl;
533 return( weighted_score );
538 (*scorefxn_)( *in_pose );
539 TR<<
"For Resid:"<< resnum << std::endl;
540 runtime_assert(resnum>0);
543 (*scorefxn_)( *in_pose );
547 else return (in_pose->energies().residue_total_energies( resnum )[
ScoreType(
score_type_ )] - resnum_cstE );
557 using namespace core::scoring;
560 else if (tag->hasOption(
"res_num" ))
resnum_ = tag->getOption<
core::Size>(
"res_num", 0 );
566 if (sco_name ==
"cstE") {
572 whole_pose_ = tag->getOption<
bool>(
"whole_pose" , 0 );
575 runtime_assert(tag->hasOption(
"res_num" )|| tag->hasOption(
"pdb_num" ) || tag->hasOption(
"cstid" ) ||
whole_pose_==1 );
576 runtime_assert(!( (tag->hasOption(
"res_num" )|| tag->hasOption(
"pdb_num" )) && tag->hasOption(
"cstid" )));
577 runtime_assert(!( (tag->hasOption(
"res_num" )|| tag->hasOption(
"pdb_num" )) &&
whole_pose_==1));
578 runtime_assert(!(tag->hasOption(
"cstid" ) &&
whole_pose_==1));
581 TR<<
"energies for whole pose will be calculated "
582 <<
"\n and scorefxn " <<scorefxn_name <<
" will be used" <<std::endl;
585 TR<<
"EnzScoreFilter for residue or cstid with cutoff "<<
threshold_<<std::endl;
633 (*scorefxn_)(rnl_pose) ;
638 rnl.
apply( rnl_pose );
639 (*scorefxn_)(rnl_pose);
643 TR<<
"Total energy with ligand is: "<<wl_score<<
" and total energy without ligand is "<<nl_score<<std::endl;
644 return (wl_score - nl_score);
647 ObjexxFCL::FArray1D_bool rms_seqpos( pose.
total_residue(), false );
650 TR<<
"Getting identities of all pack residues... "<< std::endl;
652 for(
core::Size i = 1; i <= rnl_ptask->total_residue(); ++i ){
653 if( rnl_ptask->residue_task( i ).being_packed() && pose.
residue( i ).
is_protein() ) {
654 trg_res.push_back( i );
662 std::unique( trg_res.begin(), trg_res.end() );
664 TR<<
"Calculating RMS for residues ";
668 if (resfind != trg_res.end()) {
669 rms_seqpos( i ) =
true;
676 TR<<
"Total rms of requested region is: "<< rmsd <<std::endl;
685 TR<<
" Defining RepackWithoutLigandFilter "<< std::endl;
690 runtime_assert( tag->hasOption(
"energy_threshold") || tag->hasOption(
"rms_threshold") );
691 if (tag->hasOption(
"rms_threshold")) {
694 if( tag->hasOption(
"target_res") ) {
699 if( tag->hasOption(
"target_cstids") ) {
704 else if (tag->hasOption(
"energy_threshold")) {
708 TR<<
" Defined RepackWithoutLigandFilter "<< std::endl;
733 no_packstat_calc_( basic::options::option[basic::options::OptionKeys::enzdes::no_packstat_calculation] ),
734 native_comparison_(basic::options::option[basic::options::OptionKeys::enzdes::compare_native].user() ),
735 repack_no_lig_(basic::options::option[basic::options::OptionKeys::enzdes::final_repack_without_ligand]),
736 keep_rnl_pose_(basic::options::option[basic::options::OptionKeys::enzdes::dump_final_repack_without_ligand_pdb]),
758 no_packstat_calc_( other.no_packstat_calc_ ),
759 native_comparison_(other.native_comparison_ ),
760 repack_no_lig_( other.repack_no_lig_),
761 keep_rnl_pose_( other.keep_rnl_pose_),
762 rnl_pose_( other.rnl_pose_),
763 sfxn_( other.sfxn_->
clone() ),
764 enzcst_io_( other.enzcst_io_),
765 residue_calculators_(other.residue_calculators_),
766 native_compare_calculators_(other.native_compare_calculators_),
767 native_comp_(other.native_comp_),
768 silent_Es_(other.silent_Es_),
769 relevant_scoreterms_(other.relevant_scoreterms_),
770 spec_segments_(other.spec_segments_),
771 reqfile_name_(other.reqfile_name_)
786 std::set<std::string> found_evaluators;
791 std::map< std::string, ValueEvaluator >::const_iterator val_it(evaluators.find(sco_it->name() ) );
792 if( val_it != evaluators.end() ){
793 found_evaluators.insert( sco_it->name() );
794 if( !val_it->second.value_passes( sco_it->value() ) ){
795 TR <<
"EnzdesScorefileFilter returning false for parameter " << sco_it->name() <<
" with cutoff " << val_it->second.cutoff_ <<
" and value " << sco_it->value() <<
"." << std::endl;
801 if( found_evaluators.size() != evaluators.size() ){
802 std::cerr <<
"Not all parameters from requirement file " <<
reqfile_name_ <<
" were found in EnzdesScorefileFilter values, filering likely not working correctly." << std::endl;
803 std::cerr <<
"Missing parameters: ";
804 for( std::map< std::string, ValueEvaluator >::const_iterator val_it(evaluators.begin()), val_end(evaluators.end()); val_it != val_end; ++val_it){
805 if( found_evaluators.find( val_it->first ) == found_evaluators.end() ) std::cerr << val_it->first <<
", ";
807 std::cerr << std::endl;
818 else throw utility::excn::EXCN_RosettaScriptsOption(
"For EnzdesScorefileFilter, a requirements file needs to be specified in the tag.");
834 using namespace core::io::silent;
842 (*sfxn_)( calc_pose );
848 bool separate_out_constraints =
false;
858 int width = std::max( 10, (
int) sco_name.length() + 3 );
861 if( *sco_it ==
"all_cst" ) {
864 else if( separate_out_constraints && ( *sco_it ==
"total_score" ) ){
866 new_se =
SilentEnergy(sco_name, desired_value, 1, width);
875 std::map< Size, utility::vector1< std::pair< std::string, std::string > > >::const_iterator totcalc_it =
residue_calculators_.find( 0 );
879 for(
utility::vector1< std::pair< std::string, std::string > >::const_iterator calc_it = tot_calculators.begin();
880 calc_it != tot_calculators.end(); ++calc_it){
883 if( calc_it->first ==
"charges_pm" ) calc_name =
"tot_" + calc_it->second;
884 int width = std::max( 10, (
int) calc_name.length() + 3 );
889 if( calc_it->first ==
"hbond_pm" || calc_it->first ==
"burunsat_pm" || calc_it->first ==
"NLconts_pm" || calc_it->second ==
"total_pos_charges" || calc_it->second ==
"total_neg_charges" ){
890 basic::MetricValue< core::Size > mval_size;
891 calc_pose.metric( calc_it->first, calc_it->second, mval_size );
892 calc_value = mval_size.value();
893 }
else if (calc_it->first ==
"seq_recovery") {
900 basic::MetricValue< core::Real > mval_real;
901 calc_pose.metric( calc_it->first, calc_it->second, mval_real );
902 calc_value = mval_real.value();
912 Size spec_res_counter(0);
919 std::stringstream temp;
920 temp << spec_res_counter;
927 dummy_vec.push_back( *res_it );
932 std::string segname(
"Seg_" + utility::to_string( specseg ) );
951 rnl_mov.
apply( *rnlpose );
963 std::map< std::string, std::map< std::string, ValueEvaluator > >::iterator map_it(
evaluator_map_.find( filename ) );
969 TR <<
"EnzdesScorefileFilter initializing filter params from file " << filename <<
"..." << std::endl;
971 utility::io::izstream filedata( filename.c_str() );
974 if( !filedata ) utility_exit_with_message(
"File " + filename +
" couldn't be opened by EnzdesScorefileFilter.");
976 while( !filedata.eof() ){
977 getline(filedata,line);
979 tokens.clear(); tokens.push_back(
"");
981 if( tokens.size() < 1 )
continue;
983 if( tokens[1] ==
"req"){
984 if(tokens.size() < 5 ) utility_exit_with_message(
"Could not initialize filter params from line '" + line +
"' because it was too short. Check your file format.");
985 if( tokens[3] !=
"value"){
986 TR <<
"Warning: instruction '" << tokens[3] <<
"' in filter requirements file could not be understand, line will be ignored." << std::endl;
996 else utility_exit_with_message(
"Comparison mode " + tokens[4] +
" for requirement " + param_name +
" was not understood, needs to be either '>', '<' or '='");
997 map_it->second.insert( std::pair<std::string, ValueEvaluator>(param_name,
ValueEvaluator(mode,param_cutoff )) );
998 TR <<
"Instantiated " << param_name <<
" requirement with cutoff " << param_cutoff <<
" and compare mode " << mode <<
"..." << std::endl;
1003 TR <<
" ...finished reading " << filename <<
"." << std::endl;
1010 bool separate_out_constraints,
1015 using namespace core::io::silent;
1021 int width = std::max( 10, (
int) sco_name.length() + 3 );
1024 if( *sco_it ==
"all_cst" ) {
1029 else if( separate_out_constraints && ( *sco_it ==
"total_score" ) ){
1032 new_se =
SilentEnergy(sco_name, desired_value, 1, width);
1047 std::map< Size, utility::vector1< std::pair< std::string, std::string > > >::const_iterator res_calc_it =
residue_calculators_.find( res_subset[1] );
1051 for(
utility::vector1< std::pair< std::string, std::string > >::iterator calc_it = calculators_this_res.begin();
1052 calc_it != calculators_this_res.end(); calc_it++ ){
1054 std::string res_calc_name = sub_name +
"_" + calc_it->first;
1055 int width = std::max( 10, (
int) res_calc_name.length() + 3 );
1059 basic::MetricValue< core::Real > mval_real;
1060 basic::MetricValue< utility::vector1< core::Size > >mval_sizevec;
1061 basic::MetricValue< utility::vector1< core::Real > >mval_realvec;
1064 if( ( calc_it->first ==
"hbond_pm") || ( calc_it->first ==
"burunsat_pm") || ( calc_it->first ==
"NLconts_pm" ) ){
1065 calc_pose.
metric( calc_it->first, calc_it->second, mval_sizevec );
1066 for(
core::Size ii =1; ii <= res_subset.size(); ++ii ) calc_value += mval_sizevec.value()[ res_subset[ii] ];
1068 else if( calc_it->first ==
"nlsurfaceE_pm" ){
1069 calc_pose.
metric( calc_it->first, calc_it->second, mval_realvec );
1070 for(
core::Size ii =1; ii <= res_subset.size(); ++ii ) calc_value += mval_realvec.value()[ res_subset[ii] ];
1072 else if( (calc_it->first ==
"pstat_pm") || (calc_it->first ==
"nlpstat_pm" ) ) {
1073 calc_pose.
metric( calc_it->first, calc_it->second, mval_realvec );
1075 for(
core::Size ii =1; ii <= res_subset.size(); ++ii ) pstat_sum += mval_realvec.value()[ res_subset[ii] ];
1076 calc_value = pstat_sum / res_subset.size();
1079 calc_pose.
metric( calc_it->first, calc_it->second, mval_real );
1081 calc_value = mval_real.value();
1085 SilentEnergy new_se( res_calc_name, calc_value, 1, width);
1100 using namespace core::pose::metrics;
1115 std::string noligpackstat_calc_name =
"nlpstat_pm";
1116 std::string nonlocalcontacts_calc_name =
"NLconts_pm";
1121 if( !CalculatorFactory::Instance().check_calculator_exists( hbond_calc_name ) ){
1125 if( !CalculatorFactory::Instance().check_calculator_exists( burunsat_calc_name ) ){
1129 if( !CalculatorFactory::Instance().check_calculator_exists( packstat_calc_name ) ){
1133 if( !CalculatorFactory::Instance().check_calculator_exists( noligpackstat_calc_name ) ){
1137 if( !CalculatorFactory::Instance().check_calculator_exists( nonlocalcontacts_calc_name ) ){
1141 if( !CalculatorFactory::Instance().check_calculator_exists( surface_calc_name ) ){
1145 if( !CalculatorFactory::Instance().check_calculator_exists( charge_calc_name ) ){
1157 total_pose_calculators.push_back( std::pair< std::string, std::string > ( packstat_calc_name,
"total_packstat") );
1158 total_pose_calculators.push_back( std::pair< std::string, std::string > ( noligpackstat_calc_name,
"total_packstat") );
1161 total_pose_calculators.push_back( std::pair< std::string, std::string > ( burunsat_calc_name,
"all_bur_unsat_polars") );
1162 total_pose_calculators.push_back( std::pair< std::string, std::string > ( hbond_calc_name,
"all_Hbonds") );
1163 total_pose_calculators.push_back( std::pair< std::string, std::string > ( nonlocalcontacts_calc_name,
"total_nlcontacts") );
1164 total_pose_calculators.push_back( std::pair< std::string, std::string > ( surface_calc_name,
"total_surface") );
1165 total_pose_calculators.push_back( std::pair< std::string, std::string > (charge_calc_name,
"total_charge") );
1166 total_pose_calculators.push_back( std::pair< std::string, std::string > (charge_calc_name,
"total_pos_charges") );
1167 total_pose_calculators.push_back( std::pair< std::string, std::string > (charge_calc_name,
"total_neg_charges") );
1168 total_pose_calculators.push_back( std::pair< std::string, std::string > (
"seq_recovery",
"seq_recovery") );
1175 if( !basic::options::option[basic::options::OptionKeys::enzdes::no_packstat_calculation] ){
1190 std::set< core::Size > spec_seg_first_res;
1199 std::set< core::Size > protein_chains;
1202 protein_chains.insert(pose.
chain( *vecit ));
1215 std::string lig_ch_string = utility::to_string( lig_chain );
1216 for (std::set< core::Size >::const_iterator vecit2(protein_chains.begin()); vecit2!=protein_chains.end(); ++vecit2) {
1217 Size prot_chain=*vecit2;
1218 std::string prot_ch_string = utility::to_string( prot_chain );
1219 if( lig_chain == prot_chain ) { utility_exit_with_message(
"WTF?!? ligand and residue 1 are on the same chain... " );}
1221 std::string lig_interface_neighbor_calc_name =
"neighbor_def_" + prot_ch_string +
"_" + lig_ch_string;
1222 std::string lig_dsasa_calc_name =
"dsasa_" + prot_ch_string +
"_" + lig_ch_string;
1223 std::string lig_interface_e_calc_name =
"interf_E_" + prot_ch_string +
"_" + lig_ch_string;
1225 if( !CalculatorFactory::Instance().check_calculator_exists( lig_interface_neighbor_calc_name ) ){
1227 CalculatorFactory::Instance().register_calculator( lig_interface_neighbor_calc_name, lig_neighbor_calc );
1229 if( !CalculatorFactory::Instance().check_calculator_exists( lig_dsasa_calc_name ) ){
1231 CalculatorFactory::Instance().register_calculator( lig_dsasa_calc_name, lig_dsasa_calc );
1233 if( !CalculatorFactory::Instance().check_calculator_exists( lig_interface_e_calc_name ) ){
1235 if (separate_out_constraints) {
1242 CalculatorFactory::Instance().register_calculator( lig_interface_e_calc_name, lig_interf_E_calc );
1245 calculators_this_res.push_back( std::pair< std::string, std::string > ( lig_interface_e_calc_name,
"weighted_total") );
1246 calculators_this_res.push_back( std::pair< std::string, std::string > ( lig_dsasa_calc_name,
"frac_ch2_dsasa") );
1251 calculators_this_res.push_back( std::pair< std::string, std::string > ( hbond_calc_name,
"residue_Hbonds") );
1252 calculators_this_res.push_back( std::pair< std::string, std::string > ( burunsat_calc_name,
"residue_bur_unsat_polars") );
1255 if( pose.
residue_type( *vecit ).
is_protein() && ( !basic::options::option[basic::options::OptionKeys::enzdes::no_packstat_calculation] ) ){
1256 calculators_this_res.push_back( std::pair< std::string, std::string > ( packstat_calc_name,
"residue_packstat") );
1257 calculators_this_res.push_back( std::pair< std::string, std::string > ( noligpackstat_calc_name,
"residue_packstat") );
1260 if(spec_seg_first_res.find( *vecit ) != spec_seg_first_res.end()){
1261 calculators_this_res.push_back( std::pair< std::string, std::string > ( nonlocalcontacts_calc_name,
"residue_nlcontacts") );
1262 calculators_this_res.push_back( std::pair< std::string, std::string > ( surface_calc_name,
"residue_surface") );