Rosetta
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ddg_benchmark.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
11 /// @brief
12 /// @author Liz Kellogg ekellogg@u.washington.edu
13 
14 #include <core/types.hh>
15 
16 #include <core/chemical/AA.hh>
17 
18 #include <core/scoring/Energies.hh>
19 #include <core/scoring/ScoreFunction.hh>
20 #include <core/scoring/ScoreFunctionFactory.hh>
21 
22 #include <core/pack/pack_rotamers.hh>
23 #include <core/pack/task/PackerTask.hh>
24 #include <core/pack/task/TaskFactory.hh>
25 
26 
27 #include <core/pose/Pose.hh>
28 
29 #include <basic/options/option.hh>
30 #include <basic/options/util.hh>
31 
32 #include <devel/init.hh>
33 #include <core/import_pose/import_pose.hh>
34 
35 #include <numeric/xyzVector.hh>
36 #include <numeric/random/random.hh>
37 #include <core/pack/task/ResfileReader.hh>
38 
39 // Utility Headers
40 #include <utility/vector1.hh>
41 #include <utility/file/FileName.hh>
43 #include <basic/Tracer.hh>
44 
45 // ObjexxFCL headers
46 #include <ObjexxFCL/format.hh>
47 #include <ObjexxFCL/FArray2D.hh>
48 
49 // C++ headers
50 #include <cstdlib>
51 #include <fstream>
52 #include <iostream>
53 #include <string>
54 #include <sstream>
55 #include <cmath>
56 
57 
58 // option key includes
59 
60 #include <basic/options/keys/out.OptionKeys.gen.hh>
61 #include <basic/options/keys/ddg.OptionKeys.gen.hh>
62 
63 #include <core/chemical/ResidueType.hh>
64 #include <utility/vector0.hh>
65 
66 
67 using basic::T;
68 using basic::Error;
69 using basic::Warning;
70 
71 
72 using namespace core;
73 using namespace basic;
74 using namespace scoring;
75 using namespace ObjexxFCL;
76 using namespace ObjexxFCL::format;
77 
78 typedef std::vector<Real> ddGs;
79 static THREAD_LOCAL basic::Tracer TR( "apps.pilot.yiliu.ddg" );
80 
81 ///////////////////////////////////////////////////////////////////////////////
82 // YAML helper function
83 std::ostream & writeYamlValue(std::ostream & S, std::string name, core::Real value)
84 {
85  S << "'" << name << "' : " << value << ", ";
86  return S;
87 }
88 
89 ///////////////////////////////////////////////////////////////////////////////
90 // YAML helper function
91 std::ostream & writeYamlValue(std::ostream & S, std::string name, bool value)
92 {
93  std::string sv;
94  if ( value ) sv = "True";
95  else sv = "False";
96 
97  S << "'" << name << "' : " << sv << ", ";
98  return S;
99 }
100 
101 
102 ////////////////////////// ddG Functions ////////////////////////////////////////
103 
104 Real
105 sum(ddGs &scores_to_sum)
106 {
107  Real sum=0;
108  for ( Size i =0; i<scores_to_sum.size(); i++ ) {
109  sum+=scores_to_sum[i];
110  }
111  return sum;
112 }
113 
114 Real
115 average( utility::vector1<Real> &scores_to_average)
116 {
117  Real sum = 0;
118  for ( Size i =1; i<=scores_to_average.size(); i++ ) {
119  sum+=scores_to_average[i];
120  }
121  return (sum/scores_to_average.size());
122 }
123 
124 Size
126  scoring::ScoreFunction &s,
127  pose::Pose &p, Size next_index , Size size_to_expect)
128 {
129  s(p); //score the pose
130  //all this to determine how many non-zero weights there are
131  Size num_score_components = 0;
132  EnergyMap::const_iterator it = s.weights().begin();
133  while ( it != (s.weights()).end() ) {
134  ++it;
135  if ( *it != 0 ) {
136  num_score_components++;
137  }
138  }
139 
140 
141  two_d_e_arrays.dimension(num_score_components,size_to_expect);
142 
143  Size current_score_component=0;
144  Size j =1;
145  for ( EnergyMap::const_iterator i = (s.weights()).begin(); i != s.weights().end(); ++i ) {
146  //get score component of pose, then store in next slot of two_d_e_arrays
147 
148  current_score_component++;
149  if ( *i != 0 ) {
150  two_d_e_arrays(j++,next_index)=(*i) *
151  ((p.energies()).total_energies())[ScoreType(current_score_component)];
152  }
153  }
154  return 0;
155 }
156 
157 Size
159  utility::vector1<Real> &averaged_scores )
160 {
161  averaged_scores = utility::vector1<Real>(scores_to_average.u1()-scores_to_average.l1()+1);
162  for ( Size i = Size(scores_to_average.l1()); i <= Size(scores_to_average.u1()); i++ ) {
163  Real sum_score_component = 0;
164  for ( Size j = Size(scores_to_average.l2()); j <= Size(scores_to_average.u2()); j++ ) {
165  sum_score_component += scores_to_average(i,j);
166  }
167  averaged_scores[i]=
168  sum_score_component/(scores_to_average.u2()-scores_to_average.l2()+1);
169  }
170  return 0;
171 }
172 
173 ////////////////// Correlation Functions /////////////////////////////////
174 //obtain the correlation coefficient for two array.
176  if ( sim.size()!=exp.size() ) {
177  TR << "size does not match" << std::endl;
178  //error, quit
179  exit(1);
180  }
181  Real xx=0, yy=0, xy=0, x=0,y=0;
182  //assuming the array start from 1 as in default of C/C++
183  for ( Size i=1; i<=sim.size(); i++ ) {
184  TR << "sim[i]: " << sim[i] << std::endl;
185  TR << "exp[i]: " << exp[i] << std::endl;
186  xx += sim[i]*sim[i];
187  yy += exp[i]*exp[i];
188  xy += sim[i]*exp[i];
189  x+=sim[i];
190  y+=sim[i];
191  }
192  xx/=sim.size();
193  yy/=sim.size();
194  xy/=sim.size();
195  x/=sim.size();
196  y/=sim.size();
197  xy = xy-x*y;
198  xx = xx-x*x;
199  yy = yy-y*y;
200  return xy/sqrt(xx*yy);
201 }
202 
203 void correlation(std::string ddg_out){
204  using namespace std;
205 
206  std::string const sim_filename( ddg_out.c_str() );
207  std::string const exp_filename( "./2lzm_ddg_exp.txt" );
208  std::ifstream sim_data( sim_filename.c_str() );
209  std::ifstream exp_data( exp_filename.c_str() );
210 
211  std::string sim_data_line,exp_data_line;
212  char tmp[100],wt[100], res[100], mut[100], ddg[100];
213  utility::vector1<Real> ddg_sim, ddg_exp;
214  utility::vector1<std::string> mut_sim, mut_exp;
215  std::string pos_info;
216 
217  /* get the ddg_exp vector */
218  if ( !exp_data.good() ) {
219  std::cout << "Unable to open exp data!" <<std::endl;
220  } else {
221  while ( getline(exp_data, exp_data_line) ) {
222  sscanf(exp_data_line.c_str(),"%s %s %s %s %s", tmp, wt, res, mut, ddg);
223  pos_info = string(wt) + string(" ") + string(res) + string(" ") + string(mut);
224  mut_exp.push_back(pos_info);
225  ddg_exp.push_back(atof(ddg));
226  }
227  }
228 
229  if ( !sim_data.good() ) {
230  std::cout << "Unable to open exp data!" <<std::endl;
231  } else {
232  /* get the ddg_sim vector */
233  while ( getline( sim_data,sim_data_line) ) {
234  sscanf(sim_data_line.c_str(),"%s %s %s %s", wt, res, mut, ddg);
235  pos_info = string(wt) + string(" ") + string(res) + string(" ") + string(mut);
236  mut_sim.push_back(pos_info);
237  ddg_sim.push_back(atof(ddg));
238  }
239  }
240 
241  Real correlation_result;
242  correlation_result = correlation_coefficient(ddg_sim, ddg_exp);
243 
244  std::string results_fname( ".results.log" );
245  std::ofstream staResult( results_fname.c_str() );
246  if ( !staResult ) {
247  TR.Error << "Can not open file " << results_fname;
248  } else {
249  char correlation_out[100];
250  sprintf(correlation_out,"%0.2f",correlation_result);
251  staResult << "The correlation coefficient for monomer ddG protocol on the t4-lysozyme test set: " << correlation_out << std::endl;
252  }
253 
254  std::string yaml_fname( ".results.yaml" );
255  std::ofstream yaml( yaml_fname.c_str() );
256  if ( !yaml ) {
257  TR.Error << "Can not open file " << yaml_fname;
258  } else {
259  yaml << "{ ";
260  writeYamlValue(yaml, "CorrelationCoefficient", correlation_result);
261  writeYamlValue(yaml, "_isTestPassed", correlation_result > 0.81 );
262  yaml << "}\n";
263  }
264 }
265 
266 
267 ///////////////// Main ////////////////////////////////
268 int
269 main( int argc, char * argv [] )
270 {
271  try{
272 
273  using namespace pose;
274  using namespace scoring;
275  using namespace conformation;
276 
277  using namespace basic::options;
278  using namespace basic::options::OptionKeys;
279  using namespace core::pack::task;
280 
281 
282  // setup random numbers and options
283  devel::init(argc, argv);
284 
285  // read the pose
287  import_pose::pose_from_pdb( pose, basic::options::start_file() ); // gets filename from -s option
288 
289  // this is the numbering system relevant for the resfiles (currently... ie not pdb resnums)
290 
291  //store all energies of 20 repacked poses
292  utility::vector1<Real> wt_averaged_score_components; // to be filled in and averaged later
293 
294 
295  std::string weight_file = option[ OptionKeys::ddg::weight_file ]();
296  ScoreFunctionOP score_structure_scorefxn(ScoreFunctionFactory::create_score_function(weight_file));
297 
298  Size num_iterations = option[ OptionKeys::ddg::iterations ]();
299  //initialize output options.
300  //debug output?
301  bool debug_output = option[ OptionKeys::ddg::debug_output ]();
302  if ( debug_output ) {
303  std::cout << "weights being used: " <<
304  score_structure_scorefxn->weights() << "\n";
305  }
306 
307  //dump repacked pdbs?
308  bool dump_pdbs = option[ OptionKeys::ddg::dump_pdbs ]();
309 
310  //output ddgs into what file?
311  std::string ddg_out = option[ OptionKeys::ddg::out ]();
312  std::ofstream ddg_output(ddg_out.c_str(), std::ios_base::app);
313  if ( !ddg_output ) {
314  std::cout << "having trouble opening output file for dumping predicted ddgs"
315  << ddg_out << std::endl;
316  utility::exit(EXIT_FAILURE, __FILE__, __LINE__);
317  }
318 
319  // initialize the scoring function stuff
320  (*score_structure_scorefxn)(pose);
321  /// Now handled automatically. score_structure_scorefxn->accumulate_residue_total_energies(pose);
322 
323  //initialize vector for storing ddg energy components
324  utility::vector1< ddGs> delta_delta_energy_components;
325  utility::vector1< std::string > delta_delta_G_prefix;
326 
327  pack::task::PackerTaskOP storage_task(pack::task::TaskFactory::create_packer_task(pose));
328 
329  storage_task->initialize_from_command_line();
330  pack::task::parse_resfile(pose, *storage_task);
331  storage_task->or_include_current(true);
332 
333  //write out information to repack_native logfile
334  //this eliminates unnecessary computations
335  std::ostringstream native_logfile;
336  native_logfile << "native.logfile";
337 
338  //initialize dG_wildtype which is final score
339  Real dG_wildtype;
340 
341  std::ifstream fh(native_logfile.str().c_str(),std::ios::in);
342  //check existence of file and for specific key-word
343  bool dG_native_calculated=false;
344  bool averaged_wt_scores_calculated=false;
345  if ( fh.is_open() ) {
346  if ( debug_output ) { std::cout <<
347  "native logfile exists! checking for dG of native"
348  << std::endl;
349  }
350  std::string line;
351  std::string result="";
352  std::string averaged_score_components="";
353 
354  while ( fh >> line ) {
355  //check for key-word dG_native:
356 
357  if ( line.compare("dG_wildtype:") == 0 ) {
358  fh >> result;
359  }
360  if ( !result.empty() ) {
361  if ( debug_output ) {
362  std::cout << "result string is not empty.\n";
363  }
364  dG_native_calculated=true;
365  }
366 
367  if ( line.compare("averaged_score_components:") == 0 ) {
368  while ( fh >> averaged_score_components ) {
369  //convert to double and store in wt_averaged_scores array
370  std::istringstream convert_to_double(averaged_score_components);
371  Real e_component;
372  convert_to_double >> e_component;
373  wt_averaged_score_components.push_back(e_component);
374  }
375  averaged_wt_scores_calculated=true;
376  }
377 
378  if ( dG_native_calculated ) {
379  if ( debug_output ) {
380  std::cout << "converting to double\n";
381  }
382  std::istringstream convert_to_double(result);
383  convert_to_double >> dG_wildtype;
384  if ( debug_output ) {
385  std::cout <<
386  "final value saved to variable dG_wildtype is: "
387  << dG_wildtype << std::endl;
388  }
389  if ( dG_native_calculated && averaged_wt_scores_calculated ) {
390  break;
391  }
392  }
393  }
394  }
395  //store all energies of 20 repacked poses
396  ObjexxFCL::FArray2D<Real> wt_score_components;
397 
398  if ( !dG_native_calculated ) {
399 
400  if ( debug_output ) {
401  std::cout << "dG_wildtype hasn't been calculated yet! " <<
402  "starting to calculate dG for native structure\n";
403  }
404 
405  //start filehandler for recording the native structure logfile
406  std::ofstream record_trajectories;
407  record_trajectories.open(native_logfile.str().c_str());
408 
409  //start usual calculation of DG for native structure
410  utility::vector1<Real> free_energy_wildtype(num_iterations,-999.999);
411 
412  //measure dG of input structure by repacking 20 times and taking the average score
413 
414  pack::task::PackerTaskOP repack_native(pack::task::TaskFactory::create_packer_task(pose));
415  repack_native->restrict_to_repacking();
416  for ( Size j =1; j<=pose.total_residue(); j++ ) {
417  //by default use ex1 and ex2
418  repack_native->nonconst_residue_task(j).or_ex1(true);
419  repack_native->nonconst_residue_task(j).or_ex2(true);
420  }
421  for ( Size i=1; i<=num_iterations; i++ ) { //repack for 20 cycles
422 
423  pose::Pose temporary_pose = pose;
424 
425  std::ostringstream q;
426  q << i;
427  //initialize packertask and prevent design at all positions but allow repacking.
428  Real start_score_dG_wildtype( (*score_structure_scorefxn)( temporary_pose ) );
429  if ( debug_output ) {
430  record_trajectories << "round: "
431  << q.str() << " score before repacking wildtype "
432  << start_score_dG_wildtype << " \n"
433  << "start packing pose round: " << q.str() << std::endl;
434  }//output
435  pack::pack_rotamers(temporary_pose,(*score_structure_scorefxn),repack_native);
436  if ( debug_output ) {
437  record_trajectories << "end packing pose round: " << q.str() << std::endl;
438  }//output
439 
440  //store final score
441  free_energy_wildtype[i]=(*score_structure_scorefxn)(temporary_pose);
442  Real final_score_dG_wildtype((*score_structure_scorefxn)(temporary_pose));
443 
444  //store components of energy breakdown in 2D array for easy averaging later on
445  store_energies(wt_score_components, (*score_structure_scorefxn), temporary_pose,i,num_iterations);
446  //end store components
447 
448 
449  if ( debug_output ) {
450  record_trajectories << "round: " << q.str() <<
451  " score after repacking wildtype " <<
452  final_score_dG_wildtype << ' ' <<
453  temporary_pose.energies().total_energies().weighted_string_of( score_structure_scorefxn->weights() )
454  << std::endl;
455  } //debug
456  //output the repacked native for this round
457  if ( dump_pdbs ) {
458  std::string out_path;
459  if ( option[out::path::pdb].active() ) {
460  out_path = option[out::path::pdb].value();
461  } else {
462  out_path = option[out::path::pdb].default_value();
463  }
464  std::string dump_repacked_wt = out_path + "repacked_wt_round_" + q.str() + ".pdb";
465  temporary_pose.dump_pdb(dump_repacked_wt);
466  }
467  }
468  //average scores
469  dG_wildtype = average(free_energy_wildtype);
470  average_score_components(wt_score_components,wt_averaged_score_components);
471 
472  //output averages to file
473  //===ddg_output << "WILDTYPE AVERAGED ENERGY COMPONENTS\n";
474  //output energy component headers
475  Size score_component =0;
476  std::string header="";
477  for ( EnergyMap::const_iterator i = (score_structure_scorefxn->weights()).begin();
478  i != score_structure_scorefxn->weights().end(); ++i ) {
479  score_component++;
480  if ( *i != 0 ) {
481  header = header + name_from_score_type(ScoreType(score_component)) + " ";
482  }
483  }
484 
485  //record the dG of the repacked wild-type structure to save computer time later
486  record_trajectories << "dG_wildtype: " << dG_wildtype << std::endl;
487  record_trajectories << "averaged_score_components: ";
488  //end output energy component headers
489  record_trajectories << std::endl; //stored in case we start running another parallel job
490  //end output averages to file
491 
492  record_trajectories.close(); //close the file after you're done.
493  }
494  //somehow create individual packertasks for each mutation.
495  //residues to store information on which residues to mutate, and which amino acid to mutate to
496  utility::vector1<bool> residues_to_mutate(pose.total_residue(),false);
497  utility::vector1<bool> residues_to_repack(pose.total_residue(),true);
498  utility::vector1<bool> aminoacids_to_mutate(20,false);
499 
500  //for each new point_mutant_task, create a new packertask object, copy the relevent information over
501  //then create the mutant, score, and spit out.
502  for ( Size i =1; i<=pose.total_residue(); i++ ) {
503 
504  if ( storage_task->design_residue(i) ) {
505  for ( ResidueLevelTask::ResidueTypeCOPListConstIter aa_iter(storage_task->residue_task(i).allowed_residue_types_begin()),
506  aa_end(storage_task->residue_task(i).allowed_residue_types_end());
507  aa_iter != aa_end; ++aa_iter ) {
508 
509  if ( debug_output ) {
510  std::cout << " mutating residue " << i << " from " <<
511  core::chemical::name_from_aa(pose.aa(i)) << " to amino acid: " <<
512  core::chemical::name_from_aa((*aa_iter)->aa()) << std::endl;
513  }
514  char mutant_aa = core::chemical::oneletter_code_from_aa((*aa_iter)->aa());
515  char wildtype_aa = core::chemical::oneletter_code_from_aa(pose.aa(i));
516  std::string str_wildtype_aa;
517  str_wildtype_aa.assign(&wildtype_aa,1);
518  std::string str_mutant_aa;
519  str_mutant_aa.assign(&mutant_aa,1);
520 
521  // create a log file for each structure for each mutation
522  // only create the file if not already existing, otherwise die
523  std::ofstream record_mutant_trajectories;
524  std::ostringstream filename;
525  filename << wildtype_aa << "_" << i << "_" << mutant_aa << ".logfile";
526 
527  std::ifstream fh( filename.str().c_str(), std::ios::in );
528  if ( fh.is_open() ) {
529  std::cout << "[DEBUG] file exists. "<< filename.str() << " skipping this mutation" << std::endl;
530  continue;
531  } else {
532  std::cout << "[DEBUG] file does not exist. "<< filename.str() << ". Creating logfile now.\n";
533  fh.close();
534  record_mutant_trajectories.open( filename.str().c_str() );
535  if ( debug_output ) {
536  record_mutant_trajectories << "beginning logfile" <<std::endl;
537  }
538 
539  }
540  // end
541 
542  utility::vector1<Real> free_energy_mutants(num_iterations,-999.999);
543  //storage for energy components of each of 20 repacks
544  FArray2D<Real> mutant_energy_components = FArray2D<Real>();
545  for ( Size k = 1; k <= num_iterations; k++ ) { //do this for 20 cycles
546  //restrict the amino acids as specified by PIKAA
547  //initialize new objects for the point-mutant
548  utility::vector1<bool> restrict_to_aa = aminoacids_to_mutate;
549  restrict_to_aa[(*aa_iter)->aa()]=true;
550 
551  //initialize packer and copy pose
552  pose::Pose temporary_pose = pose;
553  pack::task::PackerTaskOP point_mutant_packer_task(pack::task::TaskFactory::create_packer_task(temporary_pose));
554  utility::vector1<bool> point_mutant = residues_to_mutate;
555  point_mutant[i]=true;
556 
557  //debug output
558  Real start_score_dG_mutant( (*score_structure_scorefxn)( temporary_pose ) ); //debug ek
559 
560  if ( debug_output ) {
561  record_mutant_trajectories << "round: " <<
562  k << " score before mutation " <<
563  start_score_dG_mutant << ' ' << std::endl;
564  }//debug
565 
566  //restrict to repacking for everything but the mutant
567  for ( Size j=1; j <=temporary_pose.total_residue(); j++ ) {
568  if ( j!=i ) {
569  point_mutant_packer_task->nonconst_residue_task(j).restrict_to_repacking();
570  //always increase levels of rotamer sampling to ex1 ex2
571  point_mutant_packer_task->nonconst_residue_task(j).or_ex1(true);
572  point_mutant_packer_task->nonconst_residue_task(j).or_ex2(true);
573  }
574  }
575 
576  //restrict to the amino acid specified in the resfile for the residue-to-mutate
577  point_mutant_packer_task->nonconst_residue_task(i).restrict_absent_canonical_aas(restrict_to_aa);
578  point_mutant_packer_task->nonconst_residue_task(i).or_ex1(true);
579  point_mutant_packer_task->nonconst_residue_task(i).or_ex2(true);
580  //then do the mutation
581  if ( debug_output ) {
582  record_mutant_trajectories <<
583  "start packing pose round: " << k <<
584  std::endl;
585  }
586 
587  pack::pack_rotamers(temporary_pose,(*score_structure_scorefxn),point_mutant_packer_task);
588 
589  if ( debug_output ) {
590  record_mutant_trajectories <<
591  "end packing pose round: " << k <<
592  std::endl;
593  }
594 
595  Real const final_score( (*score_structure_scorefxn)( temporary_pose ) );
596  //store scores
597  store_energies(mutant_energy_components, (*score_structure_scorefxn),temporary_pose, k,num_iterations);
598 
599  record_mutant_trajectories <<
600  "score after mutation: residue " << wildtype_aa << " "
601  << i << " " << mutant_aa << " "
602  << final_score << ' ' <<
603  temporary_pose.energies().total_energies().weighted_string_of( score_structure_scorefxn->weights() ) << std::endl;
604 
605  //output the mutated pdb
606  std::ostringstream q;
607  q << k;
608  std::ostringstream o;
609  o << i;
610  record_mutant_trajectories << "round " << q.str()
611  << " mutate " << wildtype_aa
612  << " " << o.str() << " " <<
613  mutant_aa << " " << (final_score) << std::endl;
614 
615  free_energy_mutants[k]=final_score;
616 
617  if ( dump_pdbs ) {
618  std::string out_path;
619  if ( option[out::path::pdb].active() ) {
620  out_path = option[out::path::pdb].value();
621  } else {
622  out_path = option[out::path::pdb].default_value();
623  }
624  std::string output_pdb = out_path + "mut_" +
625  str_wildtype_aa + "_" + o.str() + "_" +
626  str_mutant_aa + "round_" + q.str() + ".pdb";
627  temporary_pose.dump_pdb(output_pdb);
628  }
629  }
630 
631  std::ostringstream resnum;
632  resnum << i;
633  //average scores
634  Real end_dG = average(free_energy_mutants);
635  utility::vector1<Real> averaged_score_components;
636  average_score_components(mutant_energy_components,averaged_score_components);
637 
638  //output averages to file
639  //end output averages to file
640  //store differences in energy
641  ddGs delta_delta_G;
642  for ( Size k =1; k<= averaged_score_components.size(); k++ ) {
643  if ( debug_output ) {
644  std::cout << "mutant score component at index " << k
645  << " is: " << averaged_score_components[k]
646  << " " << "wt score component at index " << k
647  << " is: " << wt_averaged_score_components[k] << std::endl;
648  }
649  Real delta_e = averaged_score_components[k]-wt_averaged_score_components[k];
650 
651  delta_delta_G.push_back(delta_e);
652  //would have been easier if i just did it with FArrays
653  }
654 
655  delta_delta_energy_components.push_back( delta_delta_G );
656  delta_delta_G_prefix.push_back(str_wildtype_aa + " " + resnum.str() + " " + str_mutant_aa);
657  std::ostringstream r;
658  r << i;
659  record_mutant_trajectories << "mutate " << wildtype_aa <<
660  " " << r.str() << " " << mutant_aa << " wildtype_dG is: "
661  << dG_wildtype << " and mutant_dG is: "
662  << end_dG << " ddG is: " << (end_dG-dG_wildtype)
663  << std::endl;
664  record_mutant_trajectories.close();
665  }
666  }
667  }
668 
669  //now output delta energy components for all mutations
670  for ( Size c=1; c<=delta_delta_G_prefix.size(); c++ ) {
671  ddg_output << delta_delta_G_prefix[c] << " ";
672  ddGs ddg_score_components = delta_delta_energy_components[c];
673  ddg_output << F(9,3,sum(ddg_score_components)) << " ";
674  ddg_output << std::endl;
675  }
676  //end
677  std::string const sim_filename( ddg_out.c_str() );
678  std::string const exp_filename( "2lzm_ddg_exp.txt" );
679  std::ifstream sim_data( sim_filename.c_str() );
680  std::ifstream exp_data( exp_filename.c_str() );
681  correlation(ddg_out);
682  exit(0);
683 
684  } catch ( utility::excn::EXCN_Base const & e ) {
685  std::cout << "caught exception " << e.msg() << std::endl;
686  return -1;
687  }
688  return 0;
689 }
690 
int u2() const
Upper Index of Dimension 2.
Definition: FArray2D.hh:532
void correlation(std::string ddg_out)
#define THREAD_LOCAL
virtual std::string const msg() const
Definition: EXCN_Base.hh:70
Size store_energies(ObjexxFCL::FArray2D< Real > &two_d_e_arrays, scoring::ScoreFunction &s, pose::Pose &p, Size next_index, Size size_to_expect)
std::vector< Real > ddGs
void exit(std::string const &file, int const line, std::string const &message, int const status)
Exit with file + line + message + optional status.
Definition: exit.cc:108
utility::keys::KeyLookup< KeyType >::const_iterator const_iterator
Key collection iterators.
vector0: std::vector with assert-checked bounds
static THREAD_LOCAL basic::Tracer TR("apps.pilot.yiliu.ddg")
Real average(utility::vector1< Real > &scores_to_average)
std::istream & getline(std::istream &stream, Fstring &s)
Get Line from Stream.
Definition: Fstring.cc:1610
void init(int argc, char *argv[])
Command line init() version.
Definition: init.cc:23
def x
int main(int argc, char *argv[])
core::pose::Pose Pose
Definition: supercharge.cc:101
utility::keys::lookup::end< KeyType > const end
int l2() const
Lower Index of Dimension 2.
Definition: FArray2D.hh:523
FArray2D & dimension(IR const &I1_a, IR const &I2_a)
Dimension by IndexRanges.
Definition: FArray2D.hh:567
Random number generator system.
Tracer & T(std::string const &channel, TracerPriority priority)
T is special function for assign tracer property on the static object.
Definition: Tracer.cc:567
common derived classes for thrown exceptions
std::string start_file()
kind of like the old -s – just one file
Definition: util.cc:41
member1 value
Definition: Tag.cc:296
Real sum(ddGs &scores_to_sum)
tuple p
Definition: docking.py:9
Tracer & Error(TracerPriority priority=t_error)
Predefined Error tracer.
Definition: Tracer.hh:395
Real correlation_coefficient(utility::vector1< Real > sim, utility::vector1< Real > exp)
Tracer IO system.
TracerProxy Error
Definition: Tracer.hh:262
File name class supporting Windows and UN*X/Linux format names.
rule< Scanner, options_closure::context_t > options
Definition: Tag.cc:377
Tracer & Warning(TracerPriority priority=t_warning)
Predefined Warning tracer.
Definition: Tracer.hh:398
list resnum
if line_edit[13:14]=='P': #Nucleic acid? Skip.
double Real
Definition: types.hh:39
static char * line
Definition: Svm.cc:2683
std::string F(int const w, int const d, float const &t)
Fixed Point Format: float.
Definition: format.cc:387
int u1() const
Upper Index of Dimension 1.
Definition: FArray2D.hh:505
ocstream cout(std::cout)
Wrapper around std::cout.
Definition: ocstream.hh:287
BooleanOptionKey const exit("options:exit")
Definition: OptionKeys.hh:51
vector1: std::vector with 1-based indexing
Class for handling user debug/warnings/errors. Use instance of this class instead of 'std::cout' for ...
Definition: Tracer.hh:134
utility::keys::lookup::begin< KeyType > const begin
std::ostream & writeYamlValue(std::ostream &S, std::string name, core::Real value)
rule< Scanner, string_closure::context_t > name
Definition: Tag.cc:376
Program options global and initialization function.
int l1() const
Lower Index of Dimension 1.
Definition: FArray2D.hh:496
Size average_score_components(ObjexxFCL::FArray2D< Real > &scores_to_average, utility::vector1< Real > &averaged_scores)
Fast (x,y,z)-coordinate numeric vector.
platform::Size Size
Definition: random.fwd.hh:30
StringOptionKey wt("revert_app:wt")
def y
rule< Scanner, option_closure::context_t > option
Definition: Tag.cc:378
FArray2D: Fortran-Compatible 2D Array.
Definition: FArray2.hh:27