Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ScoringSecMatchRPE.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 // This file is part of the Rosetta software suite and is made available under license.
5 // The Rosetta software is developed by the contributing members of the Rosetta Commons consortium.
6 // (C) 199x-2009 Rosetta Commons participating institutions and developers.
7 // For more information, see http://www.rosettacommons.org/.
8 
9 /// @file protocols/match/downstream/ScoringSecMatchRPE.cc
10 /// @brief
11 /// @author Kui K. Chan, kuichan@u.washington.edu, Oct, 2009
12 
13 // Unit headers
15 
16 // Package headers
17 // AUTO-REMOVED #include <stdio.h>
18 
19 // Project headers
20 // AUTO-REMOVED #include <protocols/toolbox/match_enzdes_util/MatchConstraintFileInfo.hh>
22 #include <core/pose/Pose.hh>
24 // AUTO-REMOVED #include <basic/basic.hh>
30 
31 // for debug usage
32 // AUTO-REMOVED #include <protocols/match/Matcher.hh>
33 #include <core/io/pdb/pose_io.hh>
34 
35 // AUTO-REMOVED #include <protocols/match/Hit.hh> // REQUIRED FOR WINDOWS
36 
37 // Numeric headers
38 // AUTO-REMOVED #include <numeric/constants.hh>
39 // AUTO-REMOVED #include <numeric/xyz.functions.hh>
40 
41 // Utility headers
42 #include <numeric/random/random.hh>
43 #include <utility/pointer/ReferenceCount.hh>
44 #include <utility/string_util.hh>
45 
46 // C++ headers
47 #include <list>
48 
49 #include <utility/io/ozstream.hh>
50 // AUTO-REMOVED #include <time.h>
51 // AUTO-REMOVED #include <stdlib.h>
52 // AUTO-REMOVED #include <core/io/pdb/file_data.hh>
53 #include <basic/Tracer.hh>
54 
55 #if (defined _WIN32) && (!defined WIN_PYROSETTA)
56 // AUTO-REMOVED #include <windows.h>
57 
58 #include <utility/vector1.hh>
59 
60 #endif
61 
62 namespace protocols {
63 namespace match {
64 namespace downstream {
65 static basic::Tracer TR("core.protocols.match.downstream");
67 
68 
69 void
71 core::pose::Pose const & ref_pose )
72 {
73  ref_pose_ = new core::pose::Pose(ref_pose);
74 }
75 
76 /*
77 ScoringSecMatchRPE::ScoringSecMatchRPE(
78 std::string const & s_in, std::string const & pdb_file)
79 {
80  core::pose::Pose pose(pdb_file);
81  this->(s_in, pose);
82 }
83 */
84 
85 /**
86  * 1) I have not implement long range two bodies constraint.
87  * 2) I will not check "weight" parameter for two bodies constraint.
88  * 3) I check two bodies constraint for cutoff parameter.
89  * 4) All inputs constraints are handled in the constructor.
90  **/
92 std::string const & s_in, core::pose::Pose const & ref_pose)
93 {
94  //cd_2b_pose_ = new core::pose::Pose ();
95  cd_2b_pose_ = new core::pose::Pose(ref_pose);
96 
97  //scoringEval_counter = 0;
99  secmatch_value_cutoff_.clear();
100  ref_pose_ = new core::pose::Pose(ref_pose);
102  cutoff_flag_ = false;
103  cutoff_scoreType_flag_ = false;
104  longRange_ = false;
105  shortRange_ = false;
106 
107  //parse input into line
108  utility::vector1<std::string> vLineString = utility::string_split( s_in, '\n' );
109  TR << s_in << std::endl;
110  //keyword in the CONSTRAINT file
111  std::string const keywordSCORING ("SCORING_SECMATCH::");
112  std::string const keywordFilename ("weights_file:");
113  std::string const keywordWeight ("weights:");
114  std::string const keywordCutOff ("cutoff:");
115  std::string const keywordTotal_score ("total_score");
116 
117  for(utility::vector1< std::string >::iterator it_line=vLineString.begin(), end_line =vLineString.end();
118  it_line != end_line; ++it_line ) {
119 
120  //if line contain CONSTRINAT SCORING_SECMATCH keyword
121  if ((*it_line).find(keywordSCORING) != std::string::npos){
122 
123  //parse each line into words
124  utility::vector1<std::string> vString = utility::string_split( *it_line );
125  for (utility::vector1< std::string >::iterator it=vString.begin(), end = vString.end(); it != end; ++it){
126 
127  //weigh file ex. standard.wts
128  if ((*it).find(keywordFilename) != std::string::npos){
129  ++it;
130  //TR << "Filename:" + *it +"!" << std::endl;
131  sfxn_->add_weights_from_file(*it);
132 
133  //Weight for each of the score type
134  } else if ((*it).find(keywordWeight)!= std::string::npos){
135  while ( it != end ){
137 
139  //secmatch_scotypes_.push_back( sType );
140  //TR << "Weight Input from ScoringSecMatchRPE:" + *it +"!" << std::endl;
141  ++it;
142  core::Real weight = std::atof((*it).c_str());
143  //TR << "Weight Input from ScoringSecMatchRPE:" + *it +"!" << std::endl;
144  sfxn_->set_weight( sType, weight );
145  }
146  ++it;
147  }
148 
149  //CutOff
150  } else if ((*it).find(keywordCutOff)!= std::string::npos){
151 
152  while ( it != end ){
153 
154  //CutOff: total_score
155  if ((*it).find(keywordTotal_score) != std::string::npos){
156 
157  ++it;
158  total_score_cutoff_ = std::atof((*it).c_str());
159  //TR << "Total_score constraint:" + *it +"!" << std::endl;
160  cutoff_flag_ = true;
161  TR << "TotalScore is the sum of context independent two bodies and context dependent two bodies" << std::endl;
162 
163  //CutOff: scoretype
166 
167  //if scoretype is not 2b type, we skip and continue
168  //if (sType > core::scoring::n_shortranged_2b_score_types)
169  if (!ScoringSecMatchRPE::check2bsc( sType, sfxn_->core::scoring::ScoreFunction::get_weight( sType ))){
170  std::string errorStr = "This constraint, " + *it +", is not a two bodies scoretype.";
171  utility_exit_with_message (errorStr);
172  }
173 
174  //TR << "CutOff Input from ScoringSecMatchRPE sType:" + *it +"!" << std::endl;
175  ++it;
176  core::Real sc_cutoff ( std::atof((*it).c_str()) );
177  //TR << "CutOff Input from ScoringSecMatchRPE cutoff:" << sc_cutoff << "!" << std::endl;
178  secmatch_scotypes_cutoff_.push_back( sType );
179  secmatch_value_cutoff_.push_back( sc_cutoff );
180  cutoff_scoreType_flag_ = true;
181  }
182  ++it;
183  }
184  }
185  if (it == end) break;
186  }
187  }
188  }
189 
190 
191  /**check specified weight for corresponding cutoff value
192  *if there is cutoff value, but no weight specified, then error
193  **/
194  utility::vector1< core::scoring::ScoreType > secmatch_scotypes_temp = sfxn_->get_nonzero_weighted_scoretypes();
196  cut_it != secmatch_scotypes_cutoff_.end(); ++cut_it ){
197  bool noCutOff = true;
198 
199  for( utility::vector1< core::scoring::ScoreType>::const_iterator sco_it = secmatch_scotypes_temp.begin();
200  sco_it != secmatch_scotypes_temp.end(); ++sco_it ){
201 
202  //TR << *sco_it << ":" << *cut_it << std::endl;
203  if (*sco_it == *cut_it){
204  noCutOff = false;
205  }
206  }
207  if (noCutOff){
208  TR << "ERROR: There is no specific weight for the following scoretype " << *cut_it << std::endl;
209  exit(1);
210  }
211  }
212 
213 }
214 
215 /**
216  *Check incoming scoreType is two bodies scoreType.
217  *We also setup the long range and short range scoreType flag.
218  **/
219 bool
222  core::Real wts
223 )
224 {
225  using namespace core::scoring::methods;
226 
229  wtsV.push_back(wts);
230  energy_method_options->set_method_weights( sType , wtsV );
232  core::scoring::ScoringManager::get_instance()->energy_method( sType, *energy_method_options));
233 
234  bool twobodiesterm = false;
235  //The switch codes are copied from core::scoring::ScoreFunction.cc (approximately line 1740)
236  // PHIL replace these with utility::down_cast when it's working
237  switch ( method->method_type() ) {
238  case ci_2b:
239  twobodiesterm = true;
240  shortRange_ = true;
241  TR << "ci_2b:" << sType << " weight:" << wts << std::endl;
242  break;
243 
244  case cd_2b:
245  twobodiesterm = true;
246  shortRange_ = true;
247  TR << "cd_2b:" << sType << " weight:" << wts << std::endl;
248  break;
249 
250  case ci_1b:
251  twobodiesterm = false;
252  TR << "ci_1b:" << sType << " weight:" << wts << std::endl;
253  break;
254 
255  case cd_1b:
256  twobodiesterm = false;
257  TR << "cd_1b:" << sType << " weight:" << wts << std::endl;
258  break;
259 
260  case ci_lr_2b:
261  twobodiesterm = true;
262  longRange_ = true;
263  TR << "ci_lr_2b:" << sType << " weight:" << wts << std::endl;
264  break;
265 
266  case cd_lr_2b:
267  twobodiesterm = true;
268  longRange_ = true;
269  TR << "cd_lr_2b:" << sType << " weight:" << wts << std::endl;
270  break;
271 
272  case ws:
273  twobodiesterm = false;
274  TR << "ws:" << sType << " weight:" << wts << std::endl;
275  break;
276 
277  default:
278  utility_exit_with_message( "unrecognized scoreType:"
280 
281  } // switch
282 
283  return twobodiesterm;
284 }
285 
286 bool
288  core::conformation::Residue const & match_res,
289  core::conformation::Residue const & target_res
290 ) const
291 {
292  bool returnVal = false;
293  //utility_exit_with_message("I am in evaluate_residue, ScoringSecMatchRPE");
294  //evaluate two body short range terms
295  if (shortRange_){
296  returnVal = ScoringSecMatchRPE::eval_cd_2b_residues(match_res,target_res);
297  //utility_exit_with_message ("ScoringSecMatchRPE evaluate_residue");
298 
299  //for debug output 101509
300  //Output the PDB coordinates of match residue and target residue
301  if (returnVal){
302  //TR << "ScoringSecMatchRPE: match_res:" << match_res << " target_res:" << target_res
303  // << " returnVal:" << returnVal << std::endl;
304 
305 
306  //debug usage
307  std::string randNum;
308  std::stringstream out;
309  out << numeric::random::random_range(0,INT_MAX);
310  randNum = out.str();
311 #ifdef _WIN32
312  #ifndef WIN_PYROSETTA
313  Sleep( 10000 );
314  #endif
315 #else
316  sleep (10);
317 #endif
318  utility::io::ozstream outstream;
319  std::string timeStr("EV_" + randNum + ".run");
320  outstream.open( timeStr, std::ios::app );
321 
322  //core::pose::Pose pose1 (*ref_pose_);
323  //pose1.append_residue_by_jump( match_res, 1 );
324  //pose1.append_residue_by_jump( target_res, 1 );
325  //pose1.dump_pdb( outstream, "1");
326 
327  core::Size temp_counter (1);
328  core::io::pdb::dump_pdb_residue( match_res, temp_counter, outstream);
329  core::io::pdb::dump_pdb_residue( target_res, temp_counter, outstream);
330  outstream.close();
331  //debug
332  }
333  }
334  if( !returnVal ) return false;
335 
336  //need to implement two body long range terms
337  //currently, we are return false and exist program
338  if (longRange_)
339  returnVal = ScoringSecMatchRPE::eval_longRange_2b_residue(match_res,target_res);
340  return returnVal;
341 }
342 
343 bool
345  core::conformation::Residue const & /*match_res*/,
346  core::conformation::Residue const & /*target_res*/
347 ) const
348 {
349  TR << "CAUTION: There is no long range implementation" << std::endl;
350  utility_exit_with_message("CAUTION: There is no long range implementation");
351  return false;
352 }
353 
354 bool
356  core::conformation::Residue const & match_res,
357  core::conformation::Residue const & target_res
358 ) const
359 {
361 
362 
363  //debug
364  //emap.print();
365 
366  //TotalScore
367  if (cutoff_flag_){
368  core::Real value( 0.0 );
369  //debug
370  //TR <<"TotalScore emap size:"<< sizeof(emap) << std::endl;
371  //TR <<"TatalScore sfxn_->weight():"<< sizeof(sfxn_->weights()) << std::endl;
372 
373  //context independent two bodies energy term
374  sfxn_->eval_ci_2b( match_res, target_res, *ref_pose_, emap);
375  //context dependent two bodies energy term code
376  TR << "Caution::The context dependent two bodies energy term is computational expensive and it will slow down matcher." << std::endl;
377  ref_pose_->replace_residue(match_res.seqpos(),match_res,false);
378  ref_pose_->replace_residue(target_res.seqpos(),target_res,false);
379  sfxn_->setup_for_scoring( *ref_pose_ );
380  sfxn_->eval_cd_2b (match_res, target_res, *ref_pose_, emap);
381  //end context dependent code
382 
383  //core::scoring::ScoreFunction::eval_ci_2b ( match_res, target_res, ref_pose_, emap);
384  //sfxn_->eval_ci_2b ( match_res, target_res, *ref_pose_, emap);
385  value = emap.dot( sfxn_->weights() );
386  TR << "Calculated TotalScore:" << value << std::endl;
387  if (value > total_score_cutoff_) return false;
388  }
389 
390  //debug
391  //TR << "match_res:" << match_res << std::endl;
392  //TR << "target_res:" << target_res << std::endl;
393  //ref_pose_->dump_pdb("ref_pose_.txt","1");
394 
395 
396  //Check each score type
398 
400 
402  real_it != secmatch_value_cutoff_.end(); ++real_it ){
403 
404  //if scoretype is not 2b type, we skip and continue
405  //We will skip scoretype that is not 2b type to calculate the total score
407  continue;
408  //context independent two bodies energy term
409  } else if (*sco_it < core::scoring::n_ci_2b_score_types){
410  sfxn_->eval_ci_2b( match_res, target_res, *ref_pose_, emap);
411 
412  //context dependent two bodies energy term code
413  //*sco_it > core::scoring::n_ci_2b_score_types && *sco_it < core::scoring::n_shortranged_2b_score_types
414  } else {
415 
416  //context dependent two bodies energy term code
417  //This is computational expensive.
418  //Need optimaization
419  ref_pose_->replace_residue(match_res.seqpos(),match_res,false);
420  ref_pose_->replace_residue(target_res.seqpos(),target_res,false);
421  sfxn_->setup_for_scoring( *ref_pose_ );
422  sfxn_->eval_cd_2b (match_res, target_res, *ref_pose_, emap);
423  }
424  //end context dependent code
425 
426  //debug
427  //TR << "ScoreType cutoff:" << *sco_it << ":" << tmp_cutoff << std::endl;
428  //TR << "emap[ *sco_it ]:" << emap[ *sco_it ] << " sfxn_->weights()[ *sco_it ]:" << sfxn_->weights()[ *sco_it ] <<std::endl;
429  //TR << "sco_it:" << *sco_it << std::endl;
430 
431  //core::Real tmp_cutoff ( *real_it );
432  core::Real checkCutoff = emap[ *sco_it ] * sfxn_->weights()[ *sco_it ];
433  TR << "sco_it:" << *sco_it << " checkCutoff:" << checkCutoff << std::endl;
434  if (checkCutoff > *real_it) return false ;
435  ++sco_it;
436 
437  }
438 
439  }
440 
441  return true;
442 }
443 
444 
445 
448 {
449  return sfxn_;
450 }
451 
454 {
455  return sfxn_;
456 }
457 
460 {
461  return total_score_cutoff_;
462 }
463 
464 bool
466 {
467  return true;
468 }
469 
470 bool
472 {
473  return true;
474 }
475 
476 }
477 }
478 }
479