Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ddG_main.cc
Go to the documentation of this file.
1 
2 // -*- mode:c++;tab-width:2;indent-tabs-mode:t;show-trailing-whitespace:t;rm-trailing-spaces:t -*-
3 // vi: set ts=2 noet:
4 //
5 // (c) Copyright Rosetta Commons Member Institutions.
6 // (c) This file is part of the Rosetta software suite and is made available under license.
7 // (c) The Rosetta software is developed by the contributing members of the Rosetta Commons.
8 // (c) For more information, see http://www.rosettacommons.org. Questions about this can be
9 // (c) addressed to University of Washington UW TechTransfer, email: license@u.washington.edu.
10 
11 /// @file
12 /// @brief
13 /// @author Liz Kellogg ekellogg@u.washington.edu
14 
15 #include <core/types.hh>
16 
17 #include <core/chemical/AA.hh>
20 // AUTO-REMOVED #include <core/conformation/ResidueMatcher.hh>
21 // AUTO-REMOVED #include <core/chemical/ResidueTypeSet.hh>
22 // AUTO-REMOVED #include <core/chemical/ResidueSelector.hh>
23 // AUTO-REMOVED #include <core/conformation/ResidueFactory.hh>
24 
27 
28 // AUTO-REMOVED #include <core/pack/pack_rotamers.hh>
32 // AUTO-REMOVED #include <core/kinematics/MoveMap.hh>
33 
34 // AUTO-REMOVED #include <core/optimization/AtomTreeMinimizer.hh>
35 // AUTO-REMOVED #include <core/optimization/MinimizerOptions.hh>
36 
37 #include <core/pose/Pose.hh>
38 
39 #include <basic/options/util.hh>
40 #include <basic/options/after_opts.hh>
41 #include <basic/options/option_macros.hh>
42 #include <basic/options/keys/OptionKeys.hh>
43 #include <basic/options/keys/ddg.OptionKeys.gen.hh>
44 #include <basic/options/keys/in.OptionKeys.gen.hh>
45 #include <basic/options/keys/score.OptionKeys.gen.hh>
46 #include <basic/options/keys/packing.OptionKeys.gen.hh>
47 
48 #include <basic/database/open.hh>
49 
50 // AUTO-REMOVED #include <core/init.hh>
51 // AUTO-REMOVED #include <core/io/pdb/pose_io.hh>
52 
53 #include <numeric/xyzVector.hh>
54 // AUTO-REMOVED #include <numeric/random/random.hh>
55 // AUTO-REMOVED #include <core/pack/task/ResfileReader.hh>
56 
57 #include <fstream>
58 #include <iostream>
59 #include <sstream>
60 // AUTO-REMOVED #include <ios>
61 // AUTO-REMOVED #include <utility/io/izstream.hh>
62 
63 // C++ headers
64 #include <cstdlib>
65 #include <string>
68 
69 #include <basic/Tracer.hh>
70 
72 #include <utility/vector0.hh>
73 #include <utility/vector1.hh>
74 #include <ObjexxFCL/format.hh>
75 
76 using basic::T;
77 using basic::Error;
78 using basic::Warning;
79 static basic::Tracer TR("pilot_apps.fix_bb_monomer_ddg");
80 
81 
82 //numeric::random::RandomGenerator RG(54324); // <- Magic number, do not change it!!!
83 
84 using namespace core;
85 using namespace scoring;
86 
89 
90 namespace protocols{
91 void
93  std::string label,
94  ddgs delta_e_components,
95  ddgs /*mut_avg_components*/,
96  double total_ddgs
97  ){
98  std::ofstream ddg_output(ddg_out.c_str(), std::ios_base::app);
99  if(!ddg_output){
100  TR << "having trouble opening output file for dumping predicted ddgs"
101  << ddg_out << std::endl;
102  utility::exit(EXIT_FAILURE, __FILE__, __LINE__);
103  }
104 
105  // utility::vector1<std::string> scorefxn_header = get_wt_score.get_scorefunction_header();
106 
107  // ddg_output << "ddG: description total ";
108  // for(Size i =1; i <=scorefxn_header.size();i++){
109  // ddg_output << scorefxn_header[i] << " ";
110  // }
111  if(label.compare("") != 0){
112  using namespace ObjexxFCL::fmt;
113  ddg_output << "ddG: " << label << " " << F(9,3,total_ddgs) << " ";
114  for(Size m=1;m<=delta_e_components.size();m++){
115  ddg_output << F(9,3,delta_e_components[m]) << " ";
116  }
117  ddg_output << "\n";
118  }
119 
120  ddg_output << std::endl;
121 }
122 
123 void
125  std::ifstream inputstream;
126  inputstream.open(filename.c_str());
127  if(inputstream.is_open()){
128  int total; std::string total_keyword;
129  inputstream >> total_keyword;
130  assert(total_keyword.compare("total") == 0);
131 
132  inputstream >> total; //keep for cross-checking
133  while(!inputstream.eof()){
134  mutations current_mutation(pose.total_residue(),core::chemical::aa_unk);
135  int num_mutations;
136  inputstream >> num_mutations;
137  while(num_mutations > 0){
138  char wt; int resnum; char mut;
139  inputstream >> wt >> resnum >> mut;
140  TR << "wt is " << wt << " resnum is " << resnum << " and mut is " << mut << std::endl;
141  assert(pose.residue(resnum).name1() == wt);
143  current_mutation[resnum]=mutation;
144  num_mutations--; total--;
145  }
146  TR << "end reading mutations for this" << std::endl;
147  if(num_mutations < 0){
148  TR.Error << "number of mutations mismatch! num_mutations < 0" << std::endl;
149  return;
150  }else{
151  res_to_mut.push_back(current_mutation);
152  }
153  }
154  if(total < 0){
155  TR.Error << "total number of mutations mismatch! total < 0" << std::endl;
156  return;
157  }
158  }
159 }
160 
161 int
163 {
164  using namespace pose;
165  using namespace scoring;
166  using namespace conformation;
167 
168  using namespace basic::options;
169  using namespace basic::options::OptionKeys;
170  using namespace core::pack::task;
171  using namespace protocols::moves;
172 
173 
174 
175  OPT(ddg::weight_file);
176  OPT(ddg::iterations);
177  OPT(ddg::debug_output);
178  OPT(ddg::dump_pdbs);
179  OPT(ddg::out);
180  OPT(ddg::interface_ddg);
181  OPT(ddg::opt_radius);
182 // OPT(score::weights);
183 // OPT(score::patch);
184  OPT(in::file::s);
185 
186  // setup random numbers and options
187  // devel::init(argc, argv);
188 
189  // read the pose
190  pose::Pose pose;
191  core::import_pose::pose_from_pdb( pose, basic::options::start_file() ); // gets filename from -s option
192 
193  std::string weight_file = option[ OptionKeys::ddg::weight_file ]();
194  basic::options::option[ score::fa_max_dis ](9.0); //set fa_max_dis before scorefunction is created!
195  ScoreFunctionOP score_structure_scorefxn(ScoreFunctionFactory::create_score_function(weight_file));
196 
197  ScoreFunctionOP minimize_sfxn;
198  if(basic::options::option[OptionKeys::ddg::minimization_scorefunction].user() && basic::options::option[OptionKeys::ddg::minimization_patch].user()){
199  minimize_sfxn=ScoreFunctionFactory::create_score_function(basic::options::option[OptionKeys::ddg::minimization_scorefunction](),
200  basic::options::option[OptionKeys::ddg::minimization_patch]());
201  }else if(basic::options::option[OptionKeys::ddg::minimization_scorefunction].user()){
202  minimize_sfxn=ScoreFunctionFactory::create_score_function(basic::options::option[OptionKeys::ddg::minimization_scorefunction]());
203  }else{
204  minimize_sfxn=ScoreFunctionFactory::create_score_function(basic::database::full_name("scoring/weights/standard.wts"),
205  basic::database::full_name("scoring/weights/score12.wts_patch"));
206  }
207 
208  int num_iterations = option[ OptionKeys::ddg::iterations ]();
209  bool opt_nbrs = false;
210  double cutoff = -1;
211  if(basic::options::option[ OptionKeys::ddg::opt_radius].user()){
212  opt_nbrs = true;
213  cutoff = basic::options::option[ OptionKeys::ddg::opt_radius ]();
214  }else if(basic::options::option[OptionKeys::ddg::local_opt_only]()){
215  opt_nbrs = true;
216  cutoff = 8.0; //default cutoff
217  }
218 
219  //initialize output options.
220  //debug output?
221  bool debug_output = option[ OptionKeys::ddg::debug_output ]();
222  if(debug_output){
223  TR << "weights being used: " <<
224  score_structure_scorefxn->weights() << "\n";
225  }
226 
227  //dump repacked pdbs?
228  bool dump_pdbs = option[ OptionKeys::ddg::dump_pdbs ]();
229 
230  //output ddgs into what file?
231  std::string ddg_out = option[ OptionKeys::ddg::out ]();
232 
233 
234  //interface mode?
235  bool interface_ddg = option[ OptionKeys::ddg::interface_ddg ]();
236 
237  //minimize after repacking?
238  bool min_cst = option[OptionKeys::ddg::min_cst]();
239 
240  //take mean or min energy as predicted ddg?
241  bool mean = option[OptionKeys::ddg::mean]();
242  bool min = option[OptionKeys::ddg::min]();
243 
244  ObjexxFCL::FArray2D<double> wt_scores(20,num_iterations);
245 
246  utility::vector1<core::chemical::AA> all_unk(pose.total_residue(),core::chemical::aa_unk);
247 
248  utility::vector1<double> wt_averaged_score_components;
249  utility::vector1<ddgs> delta_energy_components;
250  utility::vector1<double> total_ddgs;
251  utility::vector1<ddgs> mutant_averaged_score_components;
252  utility::vector1<std::string> delta_delta_G_label;
253 
254  ddg::ddGMover get_wt_score(score_structure_scorefxn,minimize_sfxn,all_unk);
255 
256  if(basic::options::option[OptionKeys::ddg::mut_only].user() && basic::options::option[OptionKeys::ddg::mut_only]()){
257 
258  }else{
259 
260 
261  get_wt_score.set_min_cst(min_cst);
262  get_wt_score.set_min(min);
263  get_wt_score.set_mean(mean);
264  if(!opt_nbrs){
265  get_wt_score.restrict_to_nbrs(opt_nbrs);
266  get_wt_score.neighbor_cutoff(cutoff);
267  get_wt_score.num_iterations(num_iterations);
268  get_wt_score.dump_pdbs(dump_pdbs);
269  get_wt_score.is_interface_ddg(interface_ddg);
270  get_wt_score.debug_output(debug_output);
271  get_wt_score.num_iterations(num_iterations);
272  get_wt_score.residues_to_mutate(all_unk);
273  get_wt_score.apply(pose);
274  wt_averaged_score_components=get_wt_score.get_wt_averaged_score_components();
275  }
276 
277  if(basic::options::option[OptionKeys::ddg::wt_only].user() && basic::options::option[OptionKeys::ddg::wt_only]()){
278  std::cout << "optimizing only wt structure. exiting" << std::endl;
279  return 1; //early exit
280  }
281  }
282  if(option[ OptionKeys::ddg::mut_file ].user()){//check if mutfile is specified
283  TR << "reading in mutfile" << std::endl;
284  std::string filename = option[OptionKeys::ddg::mut_file]();
285  utility::vector1<mutations> res_to_mut;
286  read_in_mutations(res_to_mut, filename,pose);
287  TR << "size of res_to_mut is: " << res_to_mut.size() << std::endl;
288  //initialize wildtype scores
289  for(Size i=1; i <= res_to_mut.size(); i++){
290  utility::vector1<core::chemical::AA> residues_to_mutate = res_to_mut[i];
291  bool mutation_defined = false; //to check if any mutation was specified
292  for(Size m =1; m<= residues_to_mutate.size(); m++){
293  if(residues_to_mutate[m] != core::chemical::aa_unk){
294  mutation_defined=true;
295  }
296  }
297  if(mutation_defined){
298  ddg::ddGMover point_mutation(score_structure_scorefxn,minimize_sfxn,residues_to_mutate);
299  point_mutation.set_min_cst(min_cst);
300  point_mutation.set_min(min);
301  point_mutation.set_mean(mean);
302  if(!opt_nbrs && get_wt_score.is_wt_calc_complete() &&
303  !(basic::options::option[OptionKeys::ddg::mut_only].user() && basic::options::option[OptionKeys::ddg::mut_only]())){
304  TR << "testing if wt calc is complete. should be complete!" << std::endl;
305  point_mutation.wt_score_components(get_wt_score.wt_score_components());
306  }
307  point_mutation.restrict_to_nbrs(opt_nbrs);
308  point_mutation.neighbor_cutoff(cutoff);
309  point_mutation.dump_pdbs(dump_pdbs);
310  point_mutation.debug_output(debug_output);
311  point_mutation.num_iterations(num_iterations);
312  point_mutation.apply(pose);
313  delta_delta_G_label.push_back(point_mutation.mutation_label(pose));
314  TR << "mutation label for this round is " << point_mutation.mutation_label(pose) << std::endl;
315  if(point_mutation.is_wt_calc_complete() &&
316  point_mutation.is_mutant_calc_complete()){
317  //TR << " both calculations are complete so start storing info!" << std::endl;
318  //output everything or store everything for output later
319  delta_energy_components.push_back(point_mutation.get_delta_energy_components());
320  mutant_averaged_score_components.push_back(point_mutation.get_mutant_averaged_score_components());
321  total_ddgs.push_back(point_mutation.ddG());
322  print_ddgs(ddg_out,
323  point_mutation.mutation_label(pose),
324  point_mutation.get_delta_energy_components(),
325  point_mutation.get_mutant_averaged_score_components(),
326  point_mutation.ddG());
327  }
328  }
329  }
330  }
331 
332  if(option[packing::resfile].user()){ //check is resfile is specified
334 
335  storage_task->initialize_from_command_line();
336  pack::task::parse_resfile(pose, *storage_task);
337  storage_task->or_include_current(true);
338 
339  for(Size i =1;i<=pose.total_residue();i++){
340  if(storage_task->design_residue(i)){
341  for(ResidueLevelTask::ResidueTypeCOPListConstIter aa_iter(storage_task->residue_task(i).allowed_residue_types_begin()),
342  aa_end(storage_task->residue_task(i).allowed_residue_types_end());
343  aa_iter != aa_end; ++aa_iter){
344  utility::vector1<core::chemical::AA> residues_to_mutate(pose.total_residue(),core::chemical::aa_unk);
345  residues_to_mutate[i]=((*aa_iter)->aa());
346  if(residues_to_mutate[i] != core::chemical::aa_unk){
347  ddg::ddGMover point_mutation(score_structure_scorefxn,minimize_sfxn,residues_to_mutate);
348  point_mutation.set_min_cst(min_cst);
349  point_mutation.set_min(min);
350  point_mutation.set_mean(mean);
351  //initialize wildtype scores
352  if(!opt_nbrs && get_wt_score.is_wt_calc_complete()){
353  TR << "testing if wt calc is complete. should be complete!" << std::endl;
354  point_mutation.wt_score_components(get_wt_score.wt_score_components());
355  }
356  point_mutation.restrict_to_nbrs(opt_nbrs);
357  point_mutation.neighbor_cutoff(cutoff);
358  point_mutation.dump_pdbs(dump_pdbs);
359  point_mutation.debug_output(debug_output);
360  point_mutation.num_iterations(num_iterations);
361  point_mutation.apply(pose);
362  delta_delta_G_label.push_back(point_mutation.mutation_label(pose));
363  if(point_mutation.is_wt_calc_complete() &&
364  point_mutation.is_mutant_calc_complete()){
365  //TR << " both calculations are complete so start storing info!" << std::endl;
366  //output everything
367  delta_energy_components.push_back(point_mutation.get_delta_energy_components());
368  mutant_averaged_score_components.push_back(point_mutation.get_mutant_averaged_score_components());
369  total_ddgs.push_back(point_mutation.ddG());
370  //output information to file
371  print_ddgs(ddg_out,
372  point_mutation.mutation_label(pose),
373  point_mutation.get_delta_energy_components(),
374  point_mutation.get_mutant_averaged_score_components(),
375  point_mutation.ddG());
376  }else{
377  std::cout << "cannot output ddgs. either mut or wt arrays are incomplete\ni hope you don't mind!\n" << std::endl;
378  }
379  }
380  }
381  }
382  }
383  }
384 
385  //INTERFACE MODE
386  if(interface_ddg){
387 
388  //TR << "[DEBUG]: now in interface mode"<< std::endl;
389  //detect interface residues
390  using namespace core;
391  using namespace core::conformation;
392  using namespace core::chemical;
393 
394  utility::vector1<core::chemical::AA> residues_to_mutate;
395  //set up interface object
396  protocols::scoring::Interface protein_interface(1);
397  protein_interface.distance(10.0);
398  protein_interface.calculate(pose);
399  protein_interface.print(pose);
400 
401  //debug statement
402  for(Size i =1;i<=pose.total_residue();i++){
403  if(protein_interface.is_interface(i)){
404  TR << "[DEBUG]:" << i << " is in the interface " << std::endl;
405  }
406  }
407  //debug statement end
408 
409  for(Size i =1;i<=pose.total_residue();i++){
410  if(protein_interface.is_interface(i)){//is interface residue
411  for(Size j =1; j <= 20 ; j++){ //iterate through all amino acids
412  residues_to_mutate = all_unk; //mutate each interface residue one at a time
414  if(curr_aa != pose.aa(i) && (pose.aa(i) != aa_unk)/*this hopefully will never happen?*/ ){
415  residues_to_mutate[i]=curr_aa;
416  ddg::ddGMover interface_mutation(score_structure_scorefxn,minimize_sfxn,residues_to_mutate);
417  interface_mutation.set_min_cst(min_cst);
418  interface_mutation.is_interface_ddg(interface_ddg);
419  interface_mutation.set_min(min);
420  interface_mutation.set_mean(mean);
421  if(get_wt_score.is_wt_calc_complete()){
422  TR << "testing if wt calc is complete. should be complete!" << std::endl;
423  interface_mutation.wt_score_components(get_wt_score.wt_score_components());
424  interface_mutation.wt_unbound_score_components(get_wt_score.wt_unbound_score_components());
425  }
426 
427  if(dump_pdbs) interface_mutation.dump_pdbs(dump_pdbs);
428  if(debug_output) interface_mutation.debug_output(debug_output);
429 
430  interface_mutation.num_iterations(num_iterations);
431  interface_mutation.apply(pose);
432  delta_delta_G_label.push_back(interface_mutation.mutation_label(pose));
433  TR << "mutation label for this round is " << interface_mutation.mutation_label(pose) << std::endl;
434  if(interface_mutation.is_wt_calc_complete() &&
435  interface_mutation.is_mutant_calc_complete()){
436 
437  delta_energy_components.push_back(interface_mutation.get_delta_energy_components());
438  mutant_averaged_score_components.push_back(interface_mutation.get_mutant_averaged_score_components());
439  total_ddgs.push_back(interface_mutation.ddG());
440  print_ddgs(ddg_out,
441  interface_mutation.mutation_label(pose),
442  interface_mutation.get_delta_energy_components(),
443  interface_mutation.get_mutant_averaged_score_components(),
444  interface_mutation.ddG());
445  TR << "interface mutation is complete and ddg is: " << interface_mutation.ddG() << std::endl;
446  }
447  }
448  }//iterate through all amino acids
449  }
450  }
451  }
452 
453  //format and output all the stored information
454 // utility::vector1<std::string> scorefxn_header = get_wt_score.get_scorefunction_header();
455 
456  return 1;
457 }
458 } //namespace protocols
459