Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
EnzFilters.cc
Go to the documentation of this file.
1 // -*- mode:c++;tab-width:2;indent-tabs-mode:t;show-trailing-whitespace:t;rm-trailing-spaces:t -*-
2 // vi: set ts=2 noet:
3 //
4 // (c) Copyright Rosetta Commons Member Institutions.
5 // (c) This file is part of the Rosetta software suite and is made available under license.
6 // (c) The Rosetta software is developed by the contributing members of the Rosetta Commons.
7 // (c) For more information, see http://www.rosettacommons.org. Questions about this can be
8 // (c) addressed to University of Washington UW TechTransfer, email: license@u.washington.edu.
9 
10 /// @file protocols/enzdes/EnzFilters.cc
11 /// @brief
12 /// @author Sagar Khare (khares@uw.edu)
13 /// @author Roland A Pache
14 
15 
16 // unit headers
19 
20 // package headers
27 
28 // Project Headers
31 #include <core/id/AtomID.hh>
32 #include <basic/options/option.hh>
33 #include <basic/options/keys/enzdes.OptionKeys.gen.hh>
35 #include <core/pose/PDBInfo.hh>
36 #include <core/pose/PDBPoseMap.hh> //for PDB-info-to-resid functionality
37 #include <core/pose/Pose.hh>
42 #include <core/scoring/Energies.hh>
46 // AUTO-REMOVED #include <core/scoring/ScoreTypeManager.hh>
49 #include <core/types.hh>
51 #include <basic/MetricValue.hh>
52 
57 #include <core/pose/selection.hh>
67 
68 #include <numeric/random/random.hh>
69 
70 
71 //Objectxxxx header
72 #include <ObjexxFCL/FArray1D.hh>
73 #include <ObjexxFCL/format.hh>
74 
75 //utility headers
76 #include <utility/io/izstream.hh>
77 #include <utility/tag/Tag.hh>
78 
79 #include <utility/vector0.hh>
80 #include <utility/excn/Exceptions.hh>
81 #include <utility/vector1.hh>
82 
83 
84 using namespace core;
85 using namespace core::scoring;
86 using namespace ObjexxFCL::fmt;
87 
88 static basic::Tracer TR( "protocols.enzdes.EnzFilters" );
89 static numeric::random::RandomGenerator RG( 14084760 ); // <- Magic number, do not change it!!!
90 
91 namespace protocols {
92 namespace enzdes {
93 
94 using namespace protocols::filters;
95 using namespace protocols::moves;
96 using namespace utility::tag;
97 
98 using core::pose::Pose;
99 
100 LigDSasaFilter::LigDSasaFilter( core::Real const lower_threshold, core::Real const upper_threshold ) : Filter( "DSasa" ), lower_threshold_( lower_threshold ), upper_threshold_(upper_threshold) {}
101 
102 bool
104  core::Real const dsasa( compute( pose ) );
105 
106  TR<<"dsasa is "<<dsasa<<". ";
107  if( dsasa >= lower_threshold_ && dsasa <= upper_threshold_){
108  TR<<"passing." <<std::endl;
109  return true;
110  }
111  else {
112  TR<<"failing."<<std::endl;
113  return false;
114  }
115 }
116 
117 void
118 LigDSasaFilter::report( std::ostream & out, core::pose::Pose const & pose ) const {
119  core::Real const dsasa( compute( pose ));
120  out<<"DSasa= "<< dsasa<<'\n';
121 }
122 
125  core::Real const dsasa( compute( pose ));
126  return( dsasa );
127 }
128 
131  basic::MetricValue< core::Real > mv_sasa;
132  core::Real sasa (0.0);
133  core::Size lig_chain(2), prot_chain;
134  for( core::Size i = 1; i<= pose.total_residue(); ++i){
135  if (pose.residue_type( i ).is_ligand()) lig_chain = pose.chain( i );
136  }
137  prot_chain = pose.chain( 1 ); //we're making the not so wild assumption that the the first residue in the pose belongs to the protein
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... " );}
141  else{
142  TR<<"Now calculating SaSa"<<std::endl;
143  pose.metric( "sasa_interface", "frac_ch2_dsasa", mv_sasa); // if this seems like its come out of nowhere see declaration in protocols/jd2/DockDesignParser.cc
144  sasa = mv_sasa.value() ;
145  }
146  return( sasa );
147 }
148 
149 void
151 {
152  lower_threshold_ = tag->getOption<core::Real>( "lower_threshold", 0 );
153  upper_threshold_ = tag->getOption<core::Real>( "upper_threshold", 1 );
154 
155  TR<<"LigDSasaFilter with lower threshold of "<<lower_threshold_<<" and upper threshold of "<< upper_threshold_ <<std::endl;
156 }
157 
159 
160 DiffAtomSasaFilter::DiffAtomSasaFilter( core::Size resid1, core::Size resid2, std::string atomname1, std::string atomname2, std::string sample_type ) : Filter( "DiffAtomBurial" ), resid1_( resid1 ), resid2_( resid2), aname1_( atomname1 ), aname2_( atomname2 ), sample_type_( sample_type ) {}
161 
162 bool
164  bool const dsasa( compute( pose ) );
165 
166  if( dsasa ){
167  TR<<"Diff Atom Sasa filter passing." <<std::endl;
168  return true;
169  }
170  else {
171  TR<<"Diff Atom Sasa filter failing."<<std::endl;
172  return false;
173  }
174 }
175 
176 void
177 DiffAtomSasaFilter::report( std::ostream & out, core::pose::Pose const & pose ) const {
178  bool const dsasa( compute( pose ));
179  out<<"Diff Sasa= "<< dsasa<<'\n';
180 }
181 
184  bool const dsasa( compute( pose ));
185  if( dsasa ) return 1;
186  else return 0;
187 }
188 
189 bool
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;
199  if (sample_type_ == "more") {
200  if (atom1_delta_sasa > atom2_delta_sasa) setting=true;
201  }
202  else if (atom1_delta_sasa < atom2_delta_sasa) setting=true; //sample_type == less i.e. see if a1 is less buried than a2 upon binding
203  return setting;
204 }
205 
206 void
208 {
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 );
211  if ( tag->hasOption("res1_pdb_num") ) resid1_ = core::pose::get_resnum(tag, pose, "res1_");
212  if ( tag->hasOption("res2_pdb_num") ) resid2_ = core::pose::get_resnum(tag, pose, "res2_");
213  if (resid1_==0 || resid2_==0){//ligand
215  if (resid1_==0) resid1_ = ligdock.get_ligand_id(pose);
216  if (resid2_==0) resid2_ = ligdock.get_ligand_id(pose);
217  }
218  aname1_ = tag->getOption<std::string>("atomname1", "CA" );
219  aname2_ = tag->getOption<std::string>("atomname2", "CA" );
220  sample_type_ = tag->getOption<std::string>("sample_type", "more" ); //a1 is more buried than a2 i.e. dsasa is more
221  runtime_assert(resid1_>0 && resid1_<=pose.total_residue() );
222  runtime_assert(resid2_>0 && resid2_<=pose.total_residue() );
223  runtime_assert (pose.residue( resid1_ ).has( aname1_ ));
224  runtime_assert (pose.residue( resid2_ ).has( aname2_ ));
225  runtime_assert( sample_type_=="more" || sample_type_ == "less" );
226  TR<<" Defined LigDSasaFilter "<< std::endl;
227 }
228 
230 
231 bool
233  core::Size const count_neighbors( compute( pose ) );
234 
235  TR<<"Number of interface neighbors of ligand is "<<count_neighbors<<std::endl;
236  return( count_neighbors >= neighbors_ );
237 }
238 
239 void
240 LigBurialFilter::report( std::ostream & out, core::pose::Pose const & pose ) const {
241  core::Size const count_neighbors( compute( pose ) );
242 
243  out<<"Number of interface neighbors of residue is "<<count_neighbors<<'\n';
244 }
245 
248  core::Size const count_neighbors( compute( pose ) );
249 
250  return( count_neighbors );
251 }
252 
253 /// @details counts the number of residues contacting the ligand
256 
257  core::Size real_lig_id (lig_id_);
258  if (real_lig_id==0) {
260  real_lig_id = ligdock.get_ligand_id(pose);
261  TR<<"Calculating neighbors of Ligand resid is " << real_lig_id << std::endl;
262  }
263  core::Size count_neighbors( 0 );
264  core::conformation::Residue const res_target( pose.conformation().residue( real_lig_id ) );
265  for( core::Size i=1; i<=pose.total_residue(); ++i ){
266  core::conformation::Residue const resi( pose.residue( i ) );
267  core::Real const distance( resi.xyz( resi.nbr_atom() ).distance( res_target.xyz( res_target.nbr_atom() ) ) );
268  if( distance <= distance_threshold_ ) ++count_neighbors;
269  }
270  return( count_neighbors);
271 }
272 
273 /// @details: this filter basically works exactly as ResidueBurialFilter, but with the advantage that it has the capability to
274 /// @details: figure out resid of the ligand
275 void
277 {
278  lig_id_ = tag->getOption<core::Size>( "lig_id", 0 );
279  distance_threshold_ = tag->getOption<core::Real>( "distance", 8.0 );
280  neighbors_ = tag->getOption<core::Size>( "neighbors", 1 );
281 
282  TR<<"LigBurialFilter with distance threshold of "<<distance_threshold_<<" around residue "<<lig_id_<<" with "<<neighbors_<<" neighbors."<<std::endl;
283  TR.flush();
284 }
285 
287 
288 LigInterfaceEnergyFilter::LigInterfaceEnergyFilter( core::scoring::ScoreFunctionOP scorefxn, core::Real const threshold, bool const include_cstE, core::Size const rb_jump, core::Real const interface_distance_cutoff ) : Filter( "LigInterfaceEnergy" ), threshold_( threshold ), include_cstE_ ( include_cstE ), rb_jump_ ( rb_jump ), interface_distance_cutoff_ ( interface_distance_cutoff ) {
289 
290  using namespace core::scoring;
291 
292  if( scorefxn ) scorefxn_ = new core::scoring::ScoreFunction( *scorefxn );
294  }
295 
297  //utility::pointer::ReferenceCount(),
298  Filter( init ), threshold_( init.threshold_ ),
300  using namespace core::scoring;
301  if( init.scorefxn_ ) scorefxn_ = new core::scoring::ScoreFunction( *init.scorefxn_ );
302  }
303 
304 
305 bool
307 {
308  using namespace core::scoring;
309 
310  if ( pose.conformation().num_chains() < 2 ) {
311  TR << "pose must contain at least two chains!" << std::endl;
312  return false;
313  }
314  else {
315  TR<<" \n \t --------- computing ---------- \n \t-------- ligand interface energies --------\n \t \t------------------- \n" << std::endl;
316  core::Real interf_E (compute(pose));
317  return (interf_E < threshold_);
318  }
319 }
320 
321 
322 void
323 LigInterfaceEnergyFilter::report( std::ostream & out, core::pose::Pose const & pose ) const
324 
325 {
326  using namespace core::scoring;
327  using ObjexxFCL::FArray1D_bool;
328 
329  core::pose::Pose in_pose = pose;
330  FArray1D_bool prot_res( in_pose.total_residue(), false );
331  in_pose.fold_tree().partition_by_jump( rb_jump_, prot_res);
333  in_pose.update_residue_neighbors();
334  interface_obj.distance( interface_distance_cutoff_ );
335  interface_obj.calculate( in_pose );
336  (*scorefxn_)( in_pose );
337 
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";
339  for ( core::Size resnum_ = 1; resnum_ <= pose.total_residue(); ++resnum_) {
340 // if ( !in_pose.residue(resnum_).is_protein() ) continue;
341  if( interface_obj.is_interface( resnum_ ) ) { // in interface
342 
343  Real total=in_pose.energies().residue_total_energies( resnum_ )[ ScoreType( total_score ) ];
344  if (!include_cstE_) total-= constraint_energy(in_pose, resnum_ );
345  Real weighted_fa_atr=( (*scorefxn_)[ ScoreType( fa_atr) ] ) * ( in_pose.energies().residue_total_energies( resnum_ )[ ScoreType( fa_atr ) ]);
346  Real weighted_fa_rep=( (*scorefxn_)[ ScoreType( fa_rep) ] ) * ( in_pose.energies().residue_total_energies( resnum_ )[ ScoreType( fa_rep) ]);
347  Real weighted_hbond_bb_sc=( (*scorefxn_)[ ScoreType( hbond_bb_sc) ] ) * ( in_pose.energies().residue_total_energies( resnum_ )[ ScoreType( hbond_bb_sc ) ]);
348  Real weighted_hbond_sc=( (*scorefxn_)[ ScoreType( hbond_sc) ] ) * ( in_pose.energies().residue_total_energies( resnum_ )[ ScoreType( hbond_sc ) ]);
349  Real weighted_fa_sol=( (*scorefxn_)[ ScoreType( fa_sol) ] ) * ( in_pose.energies().residue_total_energies( resnum_ )[ ScoreType( fa_sol ) ]);
350  Real weighted_contact_score = weighted_fa_atr + weighted_fa_rep + weighted_hbond_bb_sc + weighted_hbond_sc + weighted_fa_sol;
351 
352  Real weighted_fa_dun=( (*scorefxn_)[ ScoreType( fa_dun) ] ) * ( in_pose.energies().residue_total_energies( resnum_ )[ ScoreType( fa_dun ) ]);
353  Real weighted_fa_pair=( (*scorefxn_)[ ScoreType( fa_pair ) ] ) * ( in_pose.energies().residue_total_energies( resnum_ )[ ScoreType( fa_pair ) ]);
354 
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";
365 
366 
367  }
368  }
369 
370 }
371 
372 
375 {
376  using namespace core::scoring;
377 
378  core::Real const energy( compute( pose ) );
379  return( energy );
380 }
381 
384 {
385  using namespace core::scoring;
386  using namespace core::pose::metrics;
387  core::pose::Pose in_pose = pose;
388  in_pose.update_residue_neighbors();
389  (*scorefxn_)( in_pose );
391  core::Size const lig_id = ligdock.get_ligand_id(pose);
393  basic::MetricValue< core::Real > mv_interfE;
394  in_pose.metric( "liginterfE","weighted_total", mv_interfE); // if this seems like its come out of nowhere see declaration in protocols/jd2/DockDesignParser.cc
395  core::Real weighted_score = mv_interfE.value();
396  TR<<"Calculated Interface Energy is before cst correction is:"<<weighted_score<<std::endl;
397  if (!include_cstE_) weighted_score -= 2*constraint_energy(in_pose, lig_id);
398  TR<<"Calculated Interface Energy is "<<weighted_score<<std::endl;
399  return( weighted_score );
400 }
401 
403 LigInterfaceEnergyFilter::constraint_energy( core::pose::Pose const & in_pose , int which_res ) const
404 {
405  using namespace core::scoring;
406  core::pose::Pose pose (in_pose);
407  (*scorefxn_)(pose);
408  EnergyMap all_weights = pose.energies().weights();
409  EnergyMap scores;
410 
411  if( which_res == -1){ //means we want to know stuff for the whole pose
412  scores = pose.energies().total_energies();
413  }
414  else{ scores = pose.energies().residue_total_energies( which_res ); }
415 
416  return scores[ coordinate_constraint ] * all_weights[ coordinate_constraint ] + scores[atom_pair_constraint] * all_weights[ atom_pair_constraint] +
417  scores[ angle_constraint ] * all_weights[ angle_constraint ] + scores[ dihedral_constraint ] * all_weights[ dihedral_constraint ];
418 
419 }
420 void
422 {
423  using namespace core::scoring;
424 
425  std::string const scorefxn_name( tag->getOption<std::string>( "scorefxn", "score12" ) );
426  scorefxn_ = new ScoreFunction( *(data.get< ScoreFunction * >( "scorefxns", scorefxn_name ) ));
427  threshold_ = tag->getOption<core::Real>( "energy_cutoff", 0.0 );
428  include_cstE_ = tag->getOption<bool>( "include_cstE" , 0 );
429  rb_jump_ = tag->getOption<core::Size>( "jump_number", pose.num_jump() ); //assume ligand is connected by last jump
430  interface_distance_cutoff_ = tag->getOption<core::Real>( "interface_distance_cutoff" , 8.0 );
431 
432 }
433 void LigInterfaceEnergyFilter::parse_def( utility::lua::LuaObject const & def,
434  utility::lua::LuaObject const & score_fxns,
435  utility::lua::LuaObject const & /*tasks*/ ){
436  using namespace core::scoring;
437 
438  if( def["scorefxn"] ) {
439  scorefxn_ = new ScoreFunction( *(protocols::elscripts::parse_scoredef( def["scorefxn"], score_fxns ) ) );
440  } else {
441  scorefxn_ = new ScoreFunction( *(score_fxns["score12"].to<ScoreFunctionSP>()) );
442  }
443  threshold_ = def["threshold"] ? def["threshold"].to<core::Real>() : 0.0;
444  include_cstE_ = def["include_cstE"] ? def["include_cstE"].to<bool>() : false;
445  rb_jump_ = def["jump_number"] ? def["jump_number"].to<core::Size>() : 0;
446  interface_distance_cutoff_ = def["interface_distance_cutoff"] ? def["interface_distance_cutoff"].to<core::Real>() : 8.0;
447 }
448 
450 
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 ) {
452 
453  using namespace core::scoring;
454 
455  if( scorefxn ) scorefxn_ = new core::scoring::ScoreFunction( *scorefxn );
456  //if(score_type_ == total_score || is_cstE_ ) enzutil::enable_constraint_scoreterms(scorefxn_);
457  if( score_type_ != total_score ) {
458  core::Real const old_weight( scorefxn_->get_weight( score_type_ ) );
459  scorefxn_->reset();
460  scorefxn_->set_weight( score_type_, old_weight );
461  }
462  }
463 
465  //utility::pointer::ReferenceCount(),
466  Filter( init ), resnum_( init.resnum_ ), cstid_( init.cstid_ ),score_type_( init.score_type_ ), threshold_( init.threshold_ ),
467  whole_pose_ (init.whole_pose_), is_cstE_ ( init.is_cstE_ ) {
468  using namespace core::scoring;
469  if( init.scorefxn_ ) scorefxn_ = new core::scoring::ScoreFunction( *init.scorefxn_ );
470  }
471 
472 bool
474 {
475  using namespace core::scoring;
476  core::Real energy (compute(pose));
477  TR<<"Score found as "<<energy <<" and threshold is " << threshold_<<std::endl;
478  return (energy<threshold_);
479 }
480 
481 void
482 EnzScoreFilter::report( std::ostream & out, core::pose::Pose const & pose ) const
483 
484 {
485  using namespace core::scoring;
486  out<<"Weighted score "<<compute( pose )<<'\n';
487 }
488 
491  return( compute( pose ) );
492 }
493 
496  using namespace core::pose;
497  using namespace core::scoring;
498  PoseOP in_pose = new Pose( pose );
499  core::Size resnum = resnum_;
500  if (resnum==0){//means we want ligand scores
502  resnum = ligdock.get_ligand_id(pose);
503  }
504  core::Real weight(0.0), score(0.0);
505  if (whole_pose_){
506  (*scorefxn_)( *in_pose );
507  if (!is_cstE_ ) {
508  weight = ( (*scorefxn_)[ ScoreType( score_type_ ) ] );
509  score = ( in_pose->energies().total_energies()[ ScoreType( score_type_ ) ]);
510  TR<<"Raw Score is: " << score << std::endl;
511  }
512  if( score_type_ == total_score ) {
513  if (pose.constraint_set()->has_constraints()) {//check if constraints exist, and remove their score
515  (*scorefxn_)( *in_pose );
516  LigInterfaceEnergyFilter liginter( scorefxn_,0.0,false, 1, 0.0 );
517  core::Real all_cstE = liginter.constraint_energy(*in_pose, -1);// for whole pose;
518  score -= all_cstE;
519  }
520  return( score );
521  }
522  else if (is_cstE_){
523  TR<<"Evaluating constraint score for whole pose..."<<std::endl;
525  LigInterfaceEnergyFilter liginter( scorefxn_,0.0,false, 1, 0.0 );
526  core::Real all_cstE = liginter.constraint_energy(*in_pose, -1); // for whole pose;
527  TR<<"And constraint energy is..."<< all_cstE << std::endl;
528  return( all_cstE ) ;
529  }
530  else {
531  core::Real const weighted_score( weight * score );
532  TR<<"Weighted Score is: " << weighted_score << std::endl;
533  return( weighted_score );
534  }
535  }
536  else{ //score for a particular residue/cstid
537  if (! (cstid_ =="")) resnum = enzutil::get_resnum_from_cstid( cstid_, *in_pose );
538  (*scorefxn_)( *in_pose );
539  TR<<"For Resid:"<< resnum << std::endl;
540  runtime_assert(resnum>0);
541  if (is_cstE_ || score_type_ == total_score ){
543  (*scorefxn_)( *in_pose );
544  LigInterfaceEnergyFilter liginter( scorefxn_,0.0,false, 1, 0.0 );
545  core::Real resnum_cstE = liginter.constraint_energy(*in_pose, resnum);
546  if (is_cstE_) return resnum_cstE;
547  else return (in_pose->energies().residue_total_energies( resnum )[ ScoreType( score_type_ )] - resnum_cstE );
548  }
549  else return( ( (*scorefxn_)[ ScoreType( score_type_ ) ] ) * (in_pose->energies().residue_total_energies( resnum )[ ScoreType( score_type_ )]) );
550  }
551  return 0.0;
552 }
553 
554 void
555 EnzScoreFilter::parse_my_tag( TagPtr const tag, DataMap & data, Filters_map const &, Movers_map const &, core::pose::Pose const &pose)
556 {
557  using namespace core::scoring;
558  is_cstE_ = false;
559  if (tag->hasOption( "pdb_num" )) resnum_ = core::pose::get_resnum(tag, pose);
560  else if (tag->hasOption( "res_num" )) resnum_ = tag->getOption<core::Size>( "res_num", 0 );
561  cstid_ = tag->getOption<std::string>( "cstid", "" );
562 
563  std::string const scorefxn_name( tag->getOption<std::string>( "scorefxn", "score12" ) );
564  scorefxn_ = new ScoreFunction( *(data.get< ScoreFunction * >( "scorefxns", scorefxn_name ) ));
565  std::string sco_name = tag->getOption<std::string>( "score_type", "total_score" );
566  if (sco_name == "cstE") {
567  is_cstE_ = true;
568  score_type_=atom_pair_constraint; //dummy assignment, never actually used.
569  }
571  threshold_ = tag->getOption<core::Real>( "energy_cutoff", 0.0 );
572  whole_pose_ = tag->getOption<bool>( "whole_pose" , 0 );
573 
574  //check to make sure one and only one of resnum, cstid and whole_pose are specified
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));
579 
580  if (whole_pose_==1 ) {
581  TR<<"energies for whole pose will be calculated "
582  << "\n and scorefxn " <<scorefxn_name <<" will be used" <<std::endl;
583  }
584  else {
585  TR<<"EnzScoreFilter for residue or cstid with cutoff "<<threshold_<<std::endl;
586  }
587 }
589 
590 RepackWithoutLigandFilter::RepackWithoutLigandFilter( core::scoring::ScoreFunctionOP scorefxn, core::Real rms_thresh, core::Real energy_thresh, utility::vector1< core::Size > rms_target_res ) : Filter( "RepackWithoutLigand" ), scorefxn_(scorefxn), rms_threshold_( rms_thresh ), energy_threshold_( energy_thresh ), target_res_( rms_target_res ) {}
591 
592 bool
594 {
595 
596  core::Real const value( compute( pose ) );
597 
598  if (calc_dE_) {
599  if (value > energy_threshold_) return false;
600  else return true;
601  }
602  else if (calc_rms_){
603  if (value > rms_threshold_) return false;
604  else return true;
605  }
606  return false;
607 }
608 
609 void
610 RepackWithoutLigandFilter::report( std::ostream & out, core::pose::Pose const & pose ) const
611 {
612  //Output to tracer triggers the compute function separately. Since this is an expensive filter, we don't want to unncessarily compute, hence disabled.
613  // Dummy use of pose to avoid compiler warning.
614 // core::Real value( compute( pose ));
615 // if (calc_rms_) out<<"RMS= "<< value<<'\n';
616 // else out<<"dEnergy = "<< value<<'\n';
617  out<<"Ligand to take out is: "<< pose.total_residue();
618  out<<'\n';
619 }
620 
623 {
624  return ( compute( pose ));
625 }
626 
629 {
630  core::Real value(10000.);
631  core::pose::Pose rnl_pose = pose;
633  (*scorefxn_)(rnl_pose) ;
634  core::Real wl_score = rnl_pose.energies().total_energies()[total_score];
635 
638  rnl.apply( rnl_pose );
639  (*scorefxn_)(rnl_pose);
640  core::Real nl_score = rnl_pose.energies().total_energies()[total_score];
641 
642  if (calc_dE_) {
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);
645  }
646  else if (calc_rms_){
647  ObjexxFCL::FArray1D_bool rms_seqpos( pose.total_residue(), false );
649  if (rms_all_rpked_) {
650  TR<<"Getting identities of all pack residues... "<< std::endl;
651  core::pack::task::PackerTaskCOP rnl_ptask = rnl.get_ptask();
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 );
655  }
656  }
657  }
658  else if( use_cstids_ ) {
660  }
661  trg_res.insert( trg_res.begin(), target_res_.begin(), target_res_.end() );
662  std::unique( trg_res.begin(), trg_res.end() );
663 
664  TR<<"Calculating RMS for residues ";
665  for (core::Size i=1; i<=pose.total_residue(); ++i){
666  if (! (pose.residue_type( i ).is_ligand()) ){
667  utility::vector1< core::Size >::const_iterator resfind = find( trg_res.begin(), trg_res.end(), i );
668  if (resfind != trg_res.end()) {
669  rms_seqpos( i ) =true;
670  TR<< i<< ", ";
671  }
672  }
673  }
674  TR<< std::endl;
676  TR<<"Total rms of requested region is: "<< rmsd <<std::endl;
677  return rmsd;
678  }
679  return value; //should not get here
680 }
681 
682 void
684 {
685  TR<<" Defining RepackWithoutLigandFilter "<< std::endl;
686  std::string const scorefxn_name( tag->getOption<std::string>( "scorefxn", "score12" ) );
687  scorefxn_ = new ScoreFunction( *(data.get< ScoreFunction * >( "scorefxns", scorefxn_name ) ));
688 
689  calc_rms_ = false; calc_dE_ = false; rms_all_rpked_ = false; use_cstids_ = false;
690  runtime_assert( tag->hasOption("energy_threshold") || tag->hasOption("rms_threshold") );
691  if (tag->hasOption("rms_threshold")) {
692  rms_threshold_ = tag->getOption<core::Real>("rms_threshold", 0.5 );
693  calc_rms_ = true;
694  if( tag->hasOption("target_res") ) {
695  std::string target_res = tag->getOption<std::string>("target_res", "" );
696  if (target_res=="all_repacked") rms_all_rpked_ = true;
697  else target_res_ = core::pose::get_resnum_list(tag, "target_res",pose);
698  }
699  if( tag->hasOption("target_cstids") ) {
700  cstid_list_ = tag->getOption<std::string>("target_cstids", "" );
701  use_cstids_ = true;
702  }
703  }
704  else if (tag->hasOption("energy_threshold")) {
705  energy_threshold_ = tag->getOption<core::Real>("energy_threshold", 0.0 );
706  calc_dE_ = true;
707  }
708  TR<<" Defined RepackWithoutLigandFilter "<< std::endl;
709 }
710 
712 
714 : mode_(mode),
715  cutoff_(cutoff)
716 {}
717 
719 
720 bool
722 {
723  if( mode_ == SMALLER ) return value < cutoff_;
724  else if( mode_ == LARGER ) return value > cutoff_;
725  else return value == cutoff_;
726 }
727 
728 //initializing static member variable
729 std::map< std::string, std::map<std::string, ValueEvaluator > > EnzdesScorefileFilter::evaluator_map_;
730 
732  : Filter(),
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]),
737  rnl_pose_(NULL),
738  sfxn_(core::scoring::ScoreFunctionFactory::create_score_function("enzdes") ),
739  enzcst_io_(NULL),
740  native_comp_(NULL),
741  reqfile_name_("")
742 {
744  residue_calculators_.clear();
746  silent_Es_.clear();
747  relevant_scoreterms_.clear();
748  spec_segments_.clear();
749 
750  relevant_scoreterms_.push_back( "total_score" );
751  relevant_scoreterms_.push_back( "fa_rep" );
752  relevant_scoreterms_.push_back( "hbond_sc" );
753  relevant_scoreterms_.push_back( "all_cst" );
754 }
755 
757 : /*utility::pointer::ReferenceCount(),*/ Filter( other ),
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_)
772 {}
773 
774 
776 
777 
778 bool
780  runtime_assert( evaluator_map_.find(reqfile_name_) != evaluator_map_.end() );
781 
782  std::map< std::string, ValueEvaluator > const & evaluators( evaluator_map_.find(reqfile_name_)->second );
783 
784  this->examine_pose( pose );
785 
786  std::set<std::string> found_evaluators; //make sure all the desired values are returned by the scorefile
787 
788  for( utility::vector1< core::io::silent::SilentEnergy >::const_iterator sco_it(silent_Es_.begin()), sco_end(silent_Es_.end()); sco_it != sco_end; ++sco_it){
789 
790  //std::cerr << "iterating " << sco_it->name() << " val " << sco_it->value() << std::endl;
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;
796  return false;
797  }
798  }
799  } //loop over all score terms produced by scorefile
800 
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 << ", ";
806  }
807  std::cerr << std::endl;
808  }
809 
810  return true;
811 }
812 
813 /// @details not implemented yet
814 void
816 {
817  if ( tag->hasOption("requirements") ) reqfile_name_ = tag->getOption<std::string>( "requirements","" );
818  else throw utility::excn::EXCN_RosettaScriptsOption("For EnzdesScorefileFilter, a requirements file needs to be specified in the tag.");
819 
821 }
822 
823 void
826 {
827  enzcst_io_ = enzcst_io;
828 }
829 
830 void
832  core::pose::Pose const & pose ) const
833 {
834  using namespace core::io::silent;
835 
836  silent_Es_.clear();
837  //flo jan 2010 with the new cst cache, some calcs that take the
838  //ligand out of the pose will crash. for now, let's make a copy
839  //of the pose and remove the cst cache from it
840  core::pose::Pose calc_pose = pose;
841  toolbox::match_enzdes_util::get_enzdes_observer( calc_pose )->set_cst_cache( NULL );
842  (*sfxn_)( calc_pose );
843 
845  spec_segments_ = utility::pointer::static_pointer_cast< core::pose::datacache::SpecialSegmentsObserver const >(pose.observer_cache().get_const_ptr( core::pose::datacache::CacheableObserverType::SPECIAL_SEGMENTS_OBSERVER ) )->segments();
846  }
847 
848  bool separate_out_constraints = false;
850  if( cstfind != relevant_scoreterms_.end() ) separate_out_constraints = true;
851 
852  setup_pose_metric_calculators( pose, separate_out_constraints );
853 
854  //first write out the relevant score terms for the pose total
856  sco_it != relevant_scoreterms_.end(); ++sco_it ){
857  std::string sco_name = *sco_it;
858  int width = std::max( 10, (int) sco_name.length() + 3 );
859 
860  SilentEnergy new_se;
861  if( *sco_it == "all_cst" ) {
862  new_se = SilentEnergy ( sco_name, enzutil::sum_constraint_scoreterms(pose, -1 ), 1, width);
863  }
864  else if( separate_out_constraints && ( *sco_it == "total_score" ) ){
866  new_se = SilentEnergy(sco_name, desired_value, 1, width);
867  }
868  else{
869  new_se = SilentEnergy ( sco_name, pose.energies().total_energies()[ core::scoring::score_type_from_name( *sco_it ) ] * pose.energies().weights()[ core::scoring::score_type_from_name( *sco_it ) ], 1 ,width);
870  }
871  silent_Es_.push_back( new_se );
872 
873  }
874  //pose metric calculators for pose total
875  std::map< Size, utility::vector1< std::pair< std::string, std::string > > >::const_iterator totcalc_it = residue_calculators_.find( 0 );
876  if( totcalc_it != residue_calculators_.end() ){
877 
878  utility::vector1< std::pair< std::string, std::string > > const & tot_calculators = totcalc_it->second;
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){
881 
882  std::string calc_name = "tot_" + calc_it->first;
883  if( calc_it->first == "charges_pm" ) calc_name = "tot_" + calc_it->second;
884  int width = std::max( 10, (int) calc_name.length() + 3 );
885 
886  core::Real calc_value;
887 
888  //following lines fairly hacky, but don't know a better solution at the moment
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") {
894  if ( toolbox::match_enzdes_util::get_enzdes_observer( calc_pose ) -> get_seq_recovery_cache() ) {
895  calc_value = toolbox::match_enzdes_util::get_enzdes_observer( calc_pose ) -> get_seq_recovery_cache() -> sequence_recovery( calc_pose );
896  } else {
897  calc_value= 0.0;
898  }
899  } else {
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();
903  }
904 
905  SilentEnergy new_se( calc_name, calc_value, 1, width);
906  silent_Es_.push_back( new_se );
907  }
908 
909  }
910 
911  //then write out the relevant scoreterms (and potentially pose metrics) for each of the special residues
912  Size spec_res_counter(0);
913  utility::vector1< Size > special_res = enzutil::catalytic_res( pose );
914 
915  for( utility::vector1<Size>::const_iterator res_it = special_res.begin(); res_it != special_res.end(); res_it++ ){
916 
917  spec_res_counter++;
918  //for convenience, the sequence number of the residue will be written out
919  std::stringstream temp;
920  temp << spec_res_counter;
921  std::string spec_res_name = "SR_" + temp.str();
922  //std::cerr << "name for res " << *res_it << " is " << spec_res_name ;
923  SilentEnergy res_name(spec_res_name, *res_it, 1, 10);
924  silent_Es_.push_back( res_name );
925 
927  dummy_vec.push_back( *res_it );
928  compute_metrics_for_residue_subset( spec_res_name, separate_out_constraints, calc_pose, dummy_vec);
929  }
930 
931  for( core::Size specseg(1); specseg <= spec_segments_.size(); ++specseg ){
932  std::string segname( "Seg_" + utility::to_string( specseg ) );
933  //SilentEnergy segname_e( segname, specseg, 1, 10 );
934  //silent_Es_.push_back( segname_e );
936  for( core::Size i = spec_segments_[specseg].first; i < spec_segments_[specseg].second; ++i ) segment.push_back( i );
937  compute_metrics_for_residue_subset( segname, separate_out_constraints, calc_pose, segment );
938  }
939 
940  //if comparison to native is requested
941  if( native_comparison_ ){
942  native_comp_->compare_to_native( calc_pose, native_compare_calculators_, sfxn_, silent_Es_ );
943  }
944 
945  //if repack without lig requested
946  if( repack_no_lig_ ){
947 
948  core::pose::PoseOP rnlpose = new core::pose::Pose( pose );
950  if( enzcst_io_ ) rnl_mov.set_cstio( enzcst_io_ );
951  rnl_mov.apply( *rnlpose );
952  for( core::Size i =1; i<= rnl_mov.silent_Es().size(); ++i ) silent_Es_.push_back( rnl_mov.silent_Es()[i] );
953 
954  if( keep_rnl_pose_ ) rnl_pose_ = rnlpose;
955  }
956 } //examine pose
957 
958 
959 void
961 {
962 
963  std::map< std::string, std::map< std::string, ValueEvaluator > >::iterator map_it( evaluator_map_.find( filename ) );
964  if( map_it != evaluator_map_.end() ) return; //means this has already been done
965 
966  evaluator_map_.insert( std::pair< std::string, std::map< std::string, ValueEvaluator > >( filename, std::map< std::string, ValueEvaluator >() ) );
967  map_it = evaluator_map_.find( filename );
968 
969  TR << "EnzdesScorefileFilter initializing filter params from file " << filename << "..." << std::endl;
970 
971  utility::io::izstream filedata( filename.c_str() );
973  std::string line("");
974  if( !filedata ) utility_exit_with_message("File " + filename + " couldn't be opened by EnzdesScorefileFilter.");
975 
976  while( !filedata.eof() ){
977  getline(filedata,line);
978 
979  tokens.clear(); tokens.push_back(""); //weird utilvec1 copy behaviour makes this necessary
980  tokens = utility::split( line );
981  if( tokens.size() < 1 ) continue;
982 
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;
987  continue;
988  }
989 
990  std::string param_name( tokens[2] );
991  core::Real param_cutoff( core::Real(atof(tokens[5].c_str()) ) );
993  if( tokens[4] == "<" ) mode = ValueEvaluator::SMALLER;
994  else if( tokens[4] == "=" ) mode = ValueEvaluator::EQUALS;
995  else if( tokens[4] == ">" ) mode = ValueEvaluator::LARGER;
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;
999 
1000  } //if we have a line in proper format
1001 
1002  } //file reading
1003  TR << " ...finished reading " << filename << "." << std::endl;
1004  filedata.close();
1005 }
1006 
1007 void
1009  std::string sub_name,
1010  bool separate_out_constraints,
1011  core::pose::Pose const & calc_pose,
1012  utility::vector1< core::Size > const & res_subset ) const
1013 {
1014 
1015  using namespace core::io::silent;
1016 
1018  sco_it != relevant_scoreterms_.end(); ++sco_it ){
1019 
1020  std::string sco_name = sub_name + "_" + *sco_it ;
1021  int width = std::max( 10, (int) sco_name.length() + 3 );
1022 
1023  SilentEnergy new_se;
1024  if( *sco_it == "all_cst" ) {
1025  core::Real value(0.0);
1026  for( core::Size ii =1; ii <= res_subset.size(); ++ii ) value += enzutil::sum_constraint_scoreterms(calc_pose, res_subset[ii]);
1027  new_se = SilentEnergy ( sco_name, value , 1, width);
1028  }
1029  else if( separate_out_constraints && ( *sco_it == "total_score" ) ){
1030  core::Real desired_value(0.0);
1031  for( core::Size ii =1; ii <= res_subset.size(); ++ii ) desired_value += calc_pose.energies().residue_total_energies( res_subset[ii] )[ core::scoring::score_type_from_name( *sco_it ) ] - enzutil::sum_constraint_scoreterms(calc_pose, res_subset[ii] );
1032  new_se = SilentEnergy(sco_name, desired_value, 1, width);
1033  }
1034  else{
1035  core::Real value(0.0);
1036  for( core::Size ii =1; ii <= res_subset.size(); ++ii ) value += calc_pose.energies().residue_total_energies( res_subset[ii] )[ core::scoring::score_type_from_name( *sco_it ) ];
1037  value *= calc_pose.energies().weights()[ core::scoring::score_type_from_name( *sco_it ) ];
1038  new_se = SilentEnergy ( sco_name, value, 1 ,width);
1039  }
1040 
1041  silent_Es_.push_back( new_se );
1042  }//loop over relevant scoreterms
1043 
1044 
1045  //if there are calculators that need to be evaluated for this residue, let's do that now
1046  //note: section still under development, right now only calculators that return reals are supported
1047  std::map< Size, utility::vector1< std::pair< std::string, std::string > > >::const_iterator res_calc_it = residue_calculators_.find( res_subset[1] );
1048  if( res_calc_it != residue_calculators_.end() ){
1049 
1050  utility::vector1< std::pair< std::string, std::string > > calculators_this_res = res_calc_it->second;
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++ ){
1053 
1054  std::string res_calc_name = sub_name + "_" + calc_it->first;
1055  int width = std::max( 10, (int) res_calc_name.length() + 3 );
1056 
1057  core::Real calc_value(0.0);
1058 
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;
1062 
1063  //following lines fairly hacky, but don't know a better solution at the moment
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] ];
1067  }
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] ];
1071  }
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 );
1074  core::Real pstat_sum(0.0);
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();
1077  }
1078  else {
1079  calc_pose.metric( calc_it->first, calc_it->second, mval_real );
1080  //for( core::Size ii =1; ii <= res_subset.size(); ++ii ) calc_value += mval_realvec.value()[ res_subset[ii] ];
1081  calc_value = mval_real.value();
1082  }
1083  //std::cerr << " hehe, just executed pose metric for " << calc_it->first << " calculator ";
1084 
1085  SilentEnergy new_se( res_calc_name, calc_value, 1, width);
1086  silent_Es_.push_back( new_se );
1087 
1088  } // for calculators this res
1089 
1090  }// if calculators for this res
1091  //else std::cerr << "resi " << *res_it << " has no calcs." << std::endl;
1092 } //compute_metrics_for_residue_subset
1093 
1094 
1095 /// @brief function to setup residue specific calculators for all the catalytic residues and the ligand
1096 void
1097 EnzdesScorefileFilter::setup_pose_metric_calculators( core::pose::Pose const & pose, bool separate_out_constraints ) const
1098 {
1099 
1100  using namespace core::pose::metrics;
1101  residue_calculators_.clear();
1103 
1104  //calculators setup by this function ( under development )
1105  //1. packstat for the complete pose (with and without ligand)
1106  //2. SASA and interface delta for ligand
1107  //3. number of Hbonds for catalytic residues + ligand
1108  //4. number of buried polars for catalytic residues + ligand
1109  //5. packstat for every catalytic residue
1110  //6. further down the road maybe some stuff to compare native and designed structure
1111 
1112  std::string hbond_calc_name = "hbond_pm";
1113  std::string burunsat_calc_name = "burunsat_pm";
1114  std::string packstat_calc_name = "pstat_pm";
1115  std::string noligpackstat_calc_name = "nlpstat_pm";
1116  std::string nonlocalcontacts_calc_name = "NLconts_pm";
1117  std::string surface_calc_name = "nlsurfaceE_pm";
1118  std::string charge_calc_name = "charges_pm";
1119 
1120  //before starting, we make sure that all necessary calculators are instantiated
1121  if( !CalculatorFactory::Instance().check_calculator_exists( hbond_calc_name ) ){
1124  }
1125  if( !CalculatorFactory::Instance().check_calculator_exists( burunsat_calc_name ) ){
1127  core::pose::metrics::CalculatorFactory::Instance().register_calculator( burunsat_calc_name, burunsat_calc );
1128  }
1129  if( !CalculatorFactory::Instance().check_calculator_exists( packstat_calc_name ) ){
1131  core::pose::metrics::CalculatorFactory::Instance().register_calculator( packstat_calc_name, pstat_calc );
1132  }
1133  if( !CalculatorFactory::Instance().check_calculator_exists( noligpackstat_calc_name ) ){
1135  core::pose::metrics::CalculatorFactory::Instance().register_calculator( noligpackstat_calc_name, noligpstat_calc );
1136  }
1137  if( !CalculatorFactory::Instance().check_calculator_exists( nonlocalcontacts_calc_name ) ){
1139  core::pose::metrics::CalculatorFactory::Instance().register_calculator( nonlocalcontacts_calc_name, nlcontacts_calc );
1140  }
1141  if( !CalculatorFactory::Instance().check_calculator_exists( surface_calc_name ) ){
1143  core::pose::metrics::CalculatorFactory::Instance().register_calculator( surface_calc_name, surface_calc );
1144  }
1145 if( !CalculatorFactory::Instance().check_calculator_exists( charge_calc_name ) ){
1147  core::pose::metrics::CalculatorFactory::Instance().register_calculator( charge_calc_name, charge_calc );
1148  }
1149 
1150 
1151 
1152  //first general pose calculators
1153 
1155 
1156  if( !no_packstat_calc_ ){
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") );
1159  }
1160 
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") );
1169 
1170  residue_calculators_.insert( std::pair< Size, utility::vector1< std::pair< std::string, std::string > > > ( 0, total_pose_calculators ) );
1171 
1172  //if native compare is requested
1173  if( native_comparison_ ){
1174  native_compare_calculators_.push_back( std::pair< std::string, std::string > ( burunsat_calc_name, "all_bur_unsat_polars") );
1175  if( !basic::options::option[basic::options::OptionKeys::enzdes::no_packstat_calculation] ){
1176  native_compare_calculators_.push_back( std::pair< std::string, std::string > ( packstat_calc_name, "total_packstat") );
1177  }
1178  native_compare_calculators_.push_back( std::pair< std::string, std::string > ( hbond_calc_name, "all_Hbonds") );
1179  native_compare_calculators_.push_back( std::pair< std::string, std::string > ( nonlocalcontacts_calc_name, "total_nlcontacts") );
1180  native_compare_calculators_.push_back( std::pair< std::string, std::string > ( surface_calc_name, "total_surface") );
1181  native_compare_calculators_.push_back( std::pair< std::string, std::string > ( charge_calc_name, "total_charge") );
1182  native_compare_calculators_.push_back( std::pair< std::string, std::string > ( charge_calc_name, "total_pos_charges") );
1183  native_compare_calculators_.push_back( std::pair< std::string, std::string > ( charge_calc_name, "total_neg_charges") );
1184  }
1185 
1186  //general pose calculators done, now onto the residue specific calculators
1187  //note: all residue calculators will also be used to calculate stuff for the special segments
1188  //they'll be added to the map under the seqpos of the first residue in the
1189  //special segment
1190  std::set< core::Size > spec_seg_first_res;
1192 
1193  for( core::Size speccount =1; speccount <= spec_segments_.size(); ++speccount ){
1194  spec_seg_first_res.insert( spec_segments_[speccount].first );
1195  scoreres.push_back( spec_segments_[speccount].first );
1196  }
1197 
1198  //detect all protein chains
1199  std::set< core::Size > protein_chains;
1200  for( utility::vector1< core::Size >::const_iterator vecit( scoreres.begin() ); vecit != scoreres.end(); ++vecit){
1201  if (pose.residue_type( *vecit ).is_protein()) {
1202  protein_chains.insert(pose.chain( *vecit ));
1203  }
1204  }
1205 
1206  for( utility::vector1< core::Size >::const_iterator vecit( scoreres.begin() ); vecit != scoreres.end(); ++vecit){
1207 
1208  //if( ! (enzutil::is_catalytic_seqpos( pose, i ) || (spec_seg_first_res.find( i ) != spec_seg_first_res.end()) ) ) continue;
1209 
1211 
1212  //first a couple of ligand specific calculators ( interface SASA and interface energetics)
1213  if( pose.residue_type( *vecit ).is_ligand() ){
1214  Size lig_chain = 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... " );}
1220 
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;
1224 
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 );
1228  }
1229  if( !CalculatorFactory::Instance().check_calculator_exists( lig_dsasa_calc_name ) ){
1231  CalculatorFactory::Instance().register_calculator( lig_dsasa_calc_name, lig_dsasa_calc );
1232  }
1233  if( !CalculatorFactory::Instance().check_calculator_exists( lig_interface_e_calc_name ) ){
1234  utility::vector1<ScoreType> score_types_to_ignore;
1235  if (separate_out_constraints) {
1236  score_types_to_ignore.push_back( ScoreType( coordinate_constraint ) );
1237  score_types_to_ignore.push_back( ScoreType( atom_pair_constraint ) );
1238  score_types_to_ignore.push_back( ScoreType( angle_constraint ) );
1239  score_types_to_ignore.push_back( ScoreType( dihedral_constraint ) );
1240  }
1241  PoseMetricCalculatorOP lig_interf_E_calc = new core::pose::metrics::simple_calculators::InterfaceDeltaEnergeticsCalculator( lig_interface_neighbor_calc_name, score_types_to_ignore );
1242  CalculatorFactory::Instance().register_calculator( lig_interface_e_calc_name, lig_interf_E_calc );
1243  }
1244 
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") );
1247  }
1248  } //ligand specific calculators set up
1249 
1250  //now calculators for every residue, for starters number of Hbonds and number of buried polars
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") );
1253 
1254  //and for protein residues, we also want to know the packstat
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") );
1258 
1259  //for loop residues also non local contacts and surface E
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") );
1263  }
1264  }
1265  //debug
1266  //for( utility::vector1< std::pair< std::string, std::string > >::iterator calc_it = calculators_this_res.begin();
1267  // calc_it != calculators_this_res.end(); calc_it++ ){
1268  // std::cerr << "calculator " << calc_it->first << " created for residue " << *res_it << std::endl;
1269  //}
1270  //debug over
1271 
1272  residue_calculators_.insert( std::pair< Size, utility::vector1< std::pair< std::string, std::string > > > ( *vecit, calculators_this_res ) );
1273 
1274  } // loop over all (catalytic) residues
1275 } //setup_pose_metric_calculators
1276 
1277 
1280 {
1281  return rnl_pose_;
1282 }
1283 
1284 /// @brief clear rnl pose to save some memory
1285 void
1287 {
1288  rnl_pose_ = NULL;
1289 }
1290 
1293 
1295 DiffAtomSasaFilterCreator::keyname() const { return "DiffAtomBurial"; }
1296 
1299 
1301 EnzScoreFilterCreator::keyname() const { return "EnzScore"; }
1302 
1305 
1307 LigBurialFilterCreator::keyname() const { return "LigBurial"; }
1308 
1311 
1313 LigDSasaFilterCreator::keyname() const { return "DSasa"; }
1314 
1317 
1319 LigInterfaceEnergyFilterCreator::keyname() const { return "LigInterfaceEnergy"; }
1320 
1323 
1325 RepackWithoutLigandFilterCreator::keyname() const { return "RepackWithoutLigand"; }
1326 
1329 
1331 EnzdesScorefileFilterCreator::keyname() const { return "EnzdesScorefileFilter"; }
1332 
1333 
1334 } // enzdes
1335 } // protocols