Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ddGMover.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
13 
14 #include <protocols/moves/Mover.hh>
16 
17 #include <core/types.hh>
18 
19 // AUTO-REMOVED #include <basic/database/open.hh>
20 
21 #include <core/chemical/AA.hh>
23 // AUTO-REMOVED #include <core/conformation/ResidueMatcher.hh>
25 // AUTO-REMOVED #include <core/chemical/ResidueSelector.hh>
26 // AUTO-REMOVED #include <core/conformation/ResidueFactory.hh>
27 #include <protocols/scoring/Interface.hh> //added ek for interface ddgs
28 
29 #include <core/scoring/Energies.hh>
31 // AUTO-REMOVED #include <core/scoring/ScoreFunctionFactory.hh>
32 
36 
38 
41 
42 //constraint stuff
50 
51 // AUTO-REMOVED #include <core/id/AtomID_Map.hh>
52 #include <core/id/AtomID.hh>
53 #include <core/id/DOF_ID.hh>
54 
55 #include <core/pose/Pose.hh>
56 #include <core/pose/Pose.fwd.hh>
57 
60 
61 #include <basic/options/util.hh>
62 // AUTO-REMOVED #include <basic/options/after_opts.hh>
63 #include <basic/options/keys/OptionKeys.hh>
64 // AUTO-REMOVED #include <basic/options/keys/score.OptionKeys.gen.hh>
65 #include <basic/options/keys/ddg.OptionKeys.gen.hh>
66 #include <basic/options/keys/constraints.OptionKeys.gen.hh>
67 #include <basic/options/keys/out.OptionKeys.gen.hh>
68 #include <basic/options/keys/packing.OptionKeys.gen.hh>
69 
70 // AUTO-REMOVED #include <core/init.hh>
71 // AUTO-REMOVED #include <core/io/pdb/pose_io.hh>
72 
73 #include <numeric/xyzVector.hh>
74 #include <numeric/random/random.hh>
75 // AUTO-REMOVED #include <core/pack/task/ResfileReader.hh>
76 
78 
79 #include <fstream>
80 #include <iostream>
81 #include <sstream>
82 // AUTO-REMOVED #include <ios>
83 // AUTO-REMOVED #include <utility/io/izstream.hh>
84 // AUTO-REMOVED #include <ObjexxFCL/format.hh>
85 
86 //new includes for rotamer constraints
87 // AUTO-REMOVED #include <core/pack/dunbrack/RotamerConstraint.hh>
88 // AUTO-REMOVED #include <core/pack/dunbrack/RotamerLibrary.hh>
89 // AUTO-REMOVED #include <core/pack/dunbrack/RotamerLibraryScratchSpace.hh>
90 // AUTO-REMOVED #include <protocols/simple_moves/ScoreMover.hh>
91 
92 // C++ headers
93 #include <cstdlib>
94 #include <string>
95 #include <sys/stat.h>
96 
97 #include <basic/Tracer.hh>
98 
99 #include <utility/vector0.hh>
100 #include <utility/vector1.hh>
101 
102 using basic::T;
103 using basic::Error;
104 using basic::Warning;
105 static basic::Tracer TR("protocols.moves.ddGMover");
106 
107 namespace protocols {
108 namespace ddg {
109 
110 static numeric::random::RandomGenerator RG(15430); // <- Magic number, do not change it!!!
111 
112 using namespace core;
113 using namespace core::scoring;
114 
115 typedef std::vector<double> ddGs;
116 
118  Mover("ddGMover"),
119  num_decoys_used_in_calculations_(20), //default to number of iterations
120  mean_(false),
121  min_(true),
122  min_cst_(true),
123  nbr_cutoff_(8.0),
124  restrict_to_nbrhood_(false),
125  interface_ddg_(false),
126  scorefxn_(0),
127  min_cst_sfxn_(0),
128  min_cst_sfxn_no_cst_weight_( 0 ),
129  cst_set_(new core::scoring::constraints::ConstraintSet()),
130  min_cst_set_wt_(new core::scoring::constraints::ConstraintSet()),
131  min_cst_wt_types_(),
132  min_cst_set_mut_(new core::scoring::constraints::ConstraintSet()),
133  min_cst_mut_types_(),
134  repack_cst_set_wt_(new core::scoring::constraints::ConstraintSet()),
135  repack_wt_types_(),
136  repack_cst_set_mut_(new core::scoring::constraints::ConstraintSet()),
137  repack_mut_types_(),
138  residues_to_mutate_(0,core::chemical::aa_unk),
139  num_iterations_(20),
140  dmp_pdb_(false),
141  dbg_output_(false),
142  wt_components_(1,1,-999.99),
143  wt_unbound_components_(1,1,-999.99),//only used for interface ddg
144  mutant_components_(1,1,-999.99),
145  mutant_unbound_components_(1,1,-999.99),//only used for interface ddg
146  natives_(),
147  mutants_()
148 {}
149 
154 ) :
155  Mover("ddGMover"),
156  num_decoys_used_in_calculations_(20),
157  mean_(false),
158  min_(true),
159  min_cst_(true),
160  nbr_cutoff_(8.0),
161  restrict_to_nbrhood_(false),
162  interface_ddg_(false),
163  scorefxn_(s),
164  min_cst_sfxn_( new core::scoring::ScoreFunction( *m )),
165  min_cst_sfxn_no_cst_weight_( new core::scoring::ScoreFunction( *m ) ),
166  cst_set_(new core::scoring::constraints::ConstraintSet()),
167  min_cst_set_wt_(new core::scoring::constraints::ConstraintSet()),
168  min_cst_wt_types_(),
169  min_cst_set_mut_(new core::scoring::constraints::ConstraintSet()),
170  min_cst_mut_types_(),
171  repack_cst_set_wt_(new core::scoring::constraints::ConstraintSet()),
172  repack_wt_types_(),
173  repack_cst_set_mut_(new core::scoring::constraints::ConstraintSet()),
174  repack_mut_types_(), //these arrays only because
175  //theres no easy way to get constraint info after the fact
176  residues_to_mutate_(res_to_mutate),
177  num_iterations_(20),
178  dmp_pdb_(false),
179  dbg_output_(false),
180  wt_components_(1,1,-999.99),
181  wt_unbound_components_(1,1,-999.99),//only used for interface ddg
182  mutant_components_(1,1,-999.99),
183  mutant_unbound_components_(1,1,-999.99),//only used for interface ddg
184  natives_(),
185  mutants_()
186 {}
187 
189 
190 
193  pose::Pose & p,
194  utility::vector1<int> & mutation_position,
195  double radii
196 ){
198  for(core::Size i = 1; i <= mutation_position.size();++i) {
200  if (p.residue(mutation_position[i]).name1() == 'G') {
201  i_pos = p.residue(mutation_position[i]).xyz(" CA ");
202  } else {
203  i_pos = p.residue(mutation_position[i]).xyz(" CB ");
204  }
205  for(core::Size j = 1; j <= p.total_residue(); j++) {
207  if(p.residue(j).name1() == 'G') {
208  j_pos = p.residue(j).xyz(" CA ");
209  } else {
210  j_pos = p.residue(j).xyz(" CB ");
211  }
212  if(i_pos.distance(j_pos) <= radii) {
213  nbrs.push_back(j);
214  }
215  }
216  }
217  return nbrs;
218 }
219 
220 bool
221 ddGMover::is_complete(ObjexxFCL::FArray2D<double> to_check){
222  bool is_complete=true;
223  for(int i = to_check.l1(); i <= to_check.u1();i++){
224  for(int j = to_check.l2(); j <= to_check.u2();j++){
225  if(to_check(i,j) == -999.99){
226  is_complete=false;
227  }
228  }
229  }
230  return is_complete;
231 }
232 
233 double
234 ddGMover::sum(ddGs &scores_to_sum)
235 {
236  double sum=0;
237  for(unsigned int i =0;i<scores_to_sum.size();i++) {
238  sum+=scores_to_sum[i];
239  }
240  return sum;
241 }
242 
243 double
245 {
246  double sum = 0;
247  for(unsigned int i =1;i<=scores_to_average.size();i++) {
248  sum+=scores_to_average[i];
249  }
250  return (sum/scores_to_average.size());
251 }
252 
253 int
255  ObjexxFCL::FArray2D< double > & two_d_e_arrays,
257  pose::Pose &p,
258  int next_index,
259  int size_to_expect
260 )
261 {
263  s(p);
264 
265  //hack. we don't want to consider atom-pair constraints in computing ddgs!
267  core::scoring::ScoreType const atom_pair_cst = score_type_from_name("atom_pair_constraint");
268  core::Real saved_weight = 0;
269  if(s.get_weight( atom_pair_cst) > 0){
270  saved_weight = s.get_weight(atom_pair_cst);
271  }
272  s.set_weight( atom_pair_cst, (core::Real)0);
273  //
274 
275  //all this to determine how many non-zero weights there are
276  int num_score_components = 0;
279  for ( EnergyMap::const_iterator it = s.weights().begin(); it != s.weights().end(); ++it ) {
280  if ( *it != 0.0 ){
281  num_score_components++;
282  }
283  }
284  //
285  if((two_d_e_arrays.u1() != num_score_components) ||
286  (two_d_e_arrays.u2() != size_to_expect)){
287  two_d_e_arrays.dimension(num_score_components,size_to_expect,-999.99);
288  }
289  int current_score_component=0;
290  int j =1;
291  for( EnergyMap::const_iterator i = (s.weights()).begin(); i != s.weights().end();i++){
292  //get score component of pose, then store in next slot of two_d_e_arrays
293  current_score_component++;
294  if(*i != 0){
295  two_d_e_arrays(j++,next_index)=(*i) *
296  ((p.energies()).total_energies())[ScoreType(current_score_component)];
297  }
298  }
299 
300  s.set_weight(atom_pair_cst,saved_weight);
301 
302  return 0;
303 }
304 
305 int
307  ObjexxFCL::FArray2D< double > &scores_to_average,
308  utility::vector1<double> &averaged_scores
309 )
310 {
313  } //if user specifies more decoys to use than produced, simply set to the number
314  //of decoys produced.
315 
316  if(num_decoys_used_in_calculations_ == num_iterations_ ){ //if we do a straight average, things are easy
317  averaged_scores = utility::vector1<double>(scores_to_average.u1()-scores_to_average.l1()+1);
318  for(int i = scores_to_average.l1(); i <= scores_to_average.u1(); i++){
319  double sum_score_component = 0;
320  for(int j = scores_to_average.l2(); j <= scores_to_average.u2(); j++){
321  sum_score_component += scores_to_average(i,j);
322  }
323  averaged_scores[i]=
324  sum_score_component/(scores_to_average.u2()-scores_to_average.l2()+1);
325  }
326  return 0;
327  }else{
328  typedef utility::vector1<double> score_components;
329  typedef std::pair<double,score_components> enrgs;
330 
331  utility::vector1<enrgs> scores_to_sort;
332 
333  for(int i = scores_to_average.l2(); i <= scores_to_average.u2(); i++){
334  double total_score = 0; utility::vector1<double> sc;
335  enrgs e;
336  for(int j = scores_to_average.l1(); j <= scores_to_average.u1(); j++){
337  total_score += scores_to_average(j,i);
338  sc.push_back(scores_to_average(j,i));
339  }
340  e.first = total_score;
341  e.second = sc;
342  scores_to_sort.push_back(e);
343 
344  }
346 
347  while(sorted.size() < num_decoys_used_in_calculations_){
348  double min = 1000; int min_index = -1;
349  for(unsigned int i=1; i<= scores_to_sort.size(); i++){
350  if(scores_to_sort[i].first < min){
351  min = scores_to_sort[i].first;
352  min_index = i;
353  }
354  }
355  if(min_index != -1){
356  sorted.push_back(scores_to_sort[min_index]);
357  scores_to_sort.erase(scores_to_sort.begin()+(min_index-1));
358  }
359  }
360 
361  for(unsigned int i =1; i <= sorted[1].second.size(); i++){
362  double sum_score_component = 0.0;
363  for(unsigned int j = 1; j <= sorted.size(); j++){
364  sum_score_component += sorted[j].second[i];
365  }
366  averaged_scores.push_back(sum_score_component/(sorted.size()));
367  }
368 
369  return 0;
370  }
371 }
372 
373 void
375  core::pose::Pose & p,
378 )
379 {
380 
381  using namespace protocols::moves;
382  using namespace core::pack;
383  //from sarel. thank you!
384  int const rb_jump(1);
385  rigid::RigidBodyTransMoverOP separate_partners(
386  new rigid::RigidBodyTransMover(p,rb_jump));
387  separate_partners->step_size(1000.0);
388  separate_partners->apply(p);
389  core::pack::pack_rotamers(p,(*s),pt);
390 }
391 
392 void
394  pose::Pose & pose,
395  ScoreFunctionOP sfxn,
396  bool /*all_but_mut_site*/,
397  utility::vector1<char> & /*constraints_at_pos*/
398 )
399 {
400  using namespace core::scoring;
401  using namespace core::scoring::constraints;
402  using namespace basic::options::OptionKeys;
403  using namespace basic::options;
404 
405  double const CONSTRAINT_WEIGHT = 1.0;
406 
407  pose.remove_constraints();
408  //if member object constraint set is non-zero, then
409  //transfer constraints and be done with it!
411  for(unsigned int i=1; i <= residues_to_mutate_.size(); i++){
413  mutations.push_back(i);
414  }
415  } //i is mutation position
416 
417  sfxn->set_weight(atom_pair_constraint, CONSTRAINT_WEIGHT);
418 
419 }
420 
421 void
423  pose::Pose & pose,
424  ScoreFunctionOP sfxn,
425  float const cst_tol,
426  bool /*all_but_mut_site*/,
427  utility::vector1<char> & /*constraints_at_pos*/
428 )
429 {
430  //create constraints for all residues
431  //type: HARMONIC
432  using namespace core::scoring;
433  using namespace core::scoring::constraints;
434  using namespace basic::options::OptionKeys;
435  using namespace basic::options;
436  static float const CA_cutoff(9.0);
437  double const CONSTRAINT_WEIGHT = 1.0;
438 
439  pose.remove_constraints();
440 
441  //if member object constraint set is non-zero, then
442  //transfer constraints and be done with it!
443  //if(cst_set_->has_constraints()){ //depreciated. replaced by specific constraintsets for each phase of optimization
444  // TR << "constraint set already exists, using member object" << std::endl;
445  // pose.constraint_set(cst_set_);
446  //}//if we defined constraints outside of the program, use those instead
447  if(basic::options::option[basic::options::OptionKeys::constraints::cst_file].user()){
451  option[basic::options::OptionKeys::constraints::cst_file][1],cstset,
452  pose);
453  pose.constraint_set(cstset);
454  } else { //otherwise, define your own constraints
455  int nres = pose.total_residue();
456  for(int i = 1; i <= nres; i++){
457  if(pose.residue(i).is_protein()){
458  Vector const CA_i( pose.residue(i).xyz(" CA "));
459  for(int j = 1; j < i; j++){
460  if(pose.residue(j).is_protein()){
461  Vector const CA_j(pose.residue(j).xyz(" CA "));
462  Real const CA_dist = (CA_i - CA_j).length();
463  if(CA_dist < CA_cutoff){
465  core::id::AtomID(pose.residue(i).atom_index(" CA "),i),
466  core::id::AtomID(pose.residue(j).atom_index(" CA "),j),
467  new HarmonicFunc(CA_dist, cst_tol)));
468  pose.add_constraint(cst);
469  }
470  }
471  }
472  }
473  }
474  }
475  sfxn->set_weight(atom_pair_constraint, CONSTRAINT_WEIGHT);
476  TR.Debug<< "size of cst set is " << pose.constraint_set()->get_all_constraints().size() << std::endl;
477 }
478 
479 void
481  pose::Pose & pose,
482  ScoreFunctionOP s,
484 )
485 {
486  using namespace basic::options::OptionKeys;
487  using namespace basic::options;
488 
490  float minimizer_tol = 0.000001;
492  "dfpmin_armijo_nonmonotone", minimizer_tol,
493  true /*use_nb_list*/,
494  false /*deriv_check_in*/,
495  true /*deriv_check_verbose_in*/);
496 
497  options.nblist_auto_update( true );
498  options.max_iter(5000); //otherwise, they don't seem to converge
500  mm.set_bb(true);
501  mm.set_chi(true);
502 
503  if(basic::options::option[OptionKeys::ddg::sc_min_only]()){
504  mm.set_bb(false);
505  minimizer_tol = 0.0001;
506  }
507 
508 
509  if (basic::options::option[OptionKeys::ddg::ramp_repulsive]()) {
510  //set scorefxn fa_rep to 1/10 of original weight and then minimize
511  ScoreFunction one_tenth_orig(*s);
512  //reduce_fa_rep(0.1,one_tenth_orig);
513  //min_struc.run(p,mm,s,options);
514 
515  one_tenth_orig.set_weight( core::scoring::fa_rep, s->get_weight(core::scoring::fa_rep)*0.1 );
516  min_struc.run(pose,mm,one_tenth_orig,options);
517 
518  //then set scorefxn fa_rep to 1/3 of original weight and then minimize
519  ScoreFunction one_third_orig(*s);
520  //reduce_fa_rep(0.33,one_third_orig);
521  one_third_orig.set_weight( core::scoring::fa_rep, s->get_weight(core::scoring::fa_rep)*0.3333);
522 
523  min_struc.run(pose,mm,one_third_orig,options);
524  //then set scorefxn fa_rep to original weight and then minimize
525  }
526 
527  (*s)(pose);
528  s->show(std::cout,pose);
529  pose::Pose before(pose);
530  min_struc.run(pose,mm,*s,options);
531  //(*s)(pose);
532  while ( std::abs((*s)(pose)-(*s)(before)) > 1 ){
533  //std::cout << "running another iteration of minimization. difference is: " << ((*s)(pose)-(*s)(before)) << std::endl;
534  before=pose;
535 
536  if(basic::options::option[OptionKeys::ddg::pack_until_converge]()){
537  core::pack::pack_rotamers(pose,(*(this->score_function())),pt);
538  //use packing score function, not minimization score function
539  }
540 
541  if ( basic::options::option[OptionKeys::ddg::ramp_repulsive]() ) {
542  //set scorefxn fa_rep to 1/10 of original weight and then minimize
543  ScoreFunction one_tenth_orig(*s);
544  //reduce_fa_rep(0.1,one_tenth_orig);
545  //min_struc.run(p,mm,s,options);
546 
547  one_tenth_orig.set_weight(core::scoring::fa_rep, s->get_weight(core::scoring::fa_rep)*0.1);
548  min_struc.run(pose,mm,one_tenth_orig,options);
549 
550  //then set scorefxn fa_rep to 1/3 of original weight and then minimize
551  ScoreFunction one_third_orig(*s);
552  //reduce_fa_rep(0.33,one_third_orig);
553  one_third_orig.set_weight(core::scoring::fa_rep, s->get_weight(core::scoring::fa_rep)*0.3333);
554  min_struc.run(pose,mm,one_third_orig,options);
555  }
556  //then set scorefxn fa_rep to original weight and then minimize
557  min_struc.run(pose,mm,*s,options);
558 
559  }
560 
561 
562  s->show(std::cout, pose);
563 }
564 
565 bool
566 sort_numerically_ascending(double a, double b){
567  return a < b;
568 }
569 
570 /// @details APL Note that utility::arg_min does exactly this without the awful 99999999 bug
571 int
573 {
574  double min=9999999;
575  int min_index=-1;
576  for(unsigned int i=1;i<=scores.size();i++){
577  if(scores[i] < min) {
578  min_index=i;
579  min = scores[i];
580  }
581  }
582  return min_index;
583 }
584 
585 void
587  nbr_cutoff_ = cutoff;
588 }
589 
590 void
592  restrict_to_nbrhood_ = truefalse;
593 }
594 
595 void
599 }
600 
601 void
603  scorefxn_=*s;
604 }
605 
606 void
608  num_iterations_=num;
609 }
610 
611 void
612 ddGMover::dump_pdbs(bool truefalse){
613  dmp_pdb_=truefalse;
614 }
615 
616 void
617 ddGMover::debug_output(bool truefalse){
618  dbg_output_=truefalse;
619 }
620 
621 void
623  interface_ddg_=truefalse;
624 }
625 
626 void
627 ddGMover::wt_score_components(ObjexxFCL::FArray2D<double> wsc){
628  wt_components_=wsc;
629 }
630 
631 void
632 ddGMover::wt_unbound_score_components(ObjexxFCL::FArray2D<double> wusc){
634 }
635 
636 void
637 ddGMover::mutant_score_components(ObjexxFCL::FArray2D<double> msc){
638  mutant_components_=msc;
639 }
640 
641 void
643  residues_to_mutate_=residues;
644 }
645 
646 void
647 ddGMover::set_min_cst(bool truefalse){
648  min_cst_ = truefalse;
649 }
650 
651 void
652 ddGMover::set_mean(bool truefalse){
653  mean_ = truefalse;
654 }
655 
656 void
657 ddGMover::set_min(bool truefalse){
658  min_ = truefalse;
659  if(min_){
661  }
662 }
663 
664 void
666  num_decoys_used_in_calculations_ = num_lowe_used;
667 }
668 
669 Real
671  return nbr_cutoff_;
672 }
673 
674 bool
676  return restrict_to_nbrhood_;
677 }
678 
681  return scorefxn_;
682 }
683 
686  return min_cst_sfxn_;
687 }
688 
689 int
691 
692 bool
694 
695 ObjexxFCL::FArray2D<double>
697  return wt_components_;
698 }
699 
700 ObjexxFCL::FArray2D<double>
702  return wt_unbound_components_;
703 }
704 
705 ObjexxFCL::FArray2D<double>
707  return mutant_components_;
708 }
709 
712  return residues_to_mutate_;
713 }
714 
717  //std::cout << "computing minimum energy components" << std::endl;
718  utility::vector1<double> wt_min_score_components;
719  utility::vector1<double> total_scores;
720  //sum all components for each structure
721  for(int i = wt_components_.l2(); i <= wt_components_.u2(); i++){
722  double total_score = 0.0;
723  for(int j = wt_components_.l1(); j <= wt_components_.u1(); j++){
724  total_score += wt_components_(j,i);
725  }
726  //std::cout << "total score computed for wt number " << i << " is " << total_score << std::endl;
727  total_scores.push_back(total_score);
728  }
729  //num_score_components, size_to_expect
730  //find minimum index
731  int min_index = -1;
732  double min_score = 10000;
733  for(unsigned int i = 1; i <= total_scores.size(); i++){
734  if(total_scores[i] < min_score){
735  min_index = i;
736  min_score = total_scores[i];
737  }
738  }
739  assert(min_index != -1);
740  //std::cout << "min_index is " << min_index << " and corresponds to an energy " << min_score << std::endl;
741  //return score components of min energy structure
742  for(int i = wt_components_.l1(); i <= wt_components_.u1(); i++){
743  wt_min_score_components.push_back(wt_components_(i,min_index));
744  }
745  return wt_min_score_components;
746 }
747 
750  //std::cout << "computing wt averaged score components" << std::endl;
751  utility::vector1<double> wt_averaged_score_components;
752  if(!interface_ddg_){
753  average_score_components(wt_components_,wt_averaged_score_components);
754  }else{
757  ObjexxFCL::FArray2D<double> dG_bound_unbound((wt_components_.u1()-wt_components_.l1()+1),
758  (wt_components_.u2()-wt_components_.l2()+1),-999.99);
759  for(int i =wt_components_.l1();i<=wt_components_.u1();i++){
760  for(int j = wt_components_.l2();j<= wt_components_.u2();j++){
761  dG_bound_unbound(i,j)=wt_components_(i,j)- wt_unbound_components_(i,j);
762  }
763  }
764  average_score_components(dG_bound_unbound,wt_averaged_score_components);
765  }
766  return wt_averaged_score_components;
767 }
768 
771  //std::cout << "computing minimum energy score components for mutant" << std::endl;
772  utility::vector1<double> mutant_min_score_components;
773  utility::vector1<double> total_scores;
774  //sum all components for each structure
775  for(int i = mutant_components_.l2(); i <= mutant_components_.u2(); i++){
776  double total_score = 0.0;
777  for(int j = mutant_components_.l1(); j <= mutant_components_.u1(); j++){
778  total_score += mutant_components_(j,i);
779  }
780  //std::cout << "total score computed for mut number " << i << " is " << total_score << std::endl;
781  total_scores.push_back(total_score);
782  }
783  //num_score_components, size_to_expect
784  //find minimum index
785  int min_index = -1;
786  double min_score = 10000;
787  for(unsigned int i = 1; i <= total_scores.size(); i++){
788  if(total_scores[i] < min_score){
789  min_index = i;
790  min_score = total_scores[i];
791  }
792  }
793  assert(min_index != -1);
794  //std::cout << "MUT min_index is " << min_index << " and corresponds to an energy " << min_score << std::endl;
795  //return score components of min energy structure
796  for(int i = mutant_components_.l1(); i <= mutant_components_.u1(); i++){
797  mutant_min_score_components.push_back(mutant_components_(i,min_index));
798  }
799  return mutant_min_score_components;
800 }
801 
804  //std::cout << "computing average mutant score components" << std::endl;
805  utility::vector1<double> mutant_averaged_score_components;
806  if(!interface_ddg_){
807  average_score_components(mutant_components_, mutant_averaged_score_components);
808  } else {
809  assert(
812  ObjexxFCL::FArray2D<double> dG_bound_unbound(
815  -999.99);
816  for ( int i = mutant_components_.l1(); i <= mutant_components_.u1(); ++i) {
817  for(int j = mutant_components_.l2(); j <= mutant_components_.u2(); ++j ) {
818  dG_bound_unbound(i,j) = mutant_components_(i,j) - mutant_unbound_components_(i,j);
819  }
820  }
821  average_score_components(dG_bound_unbound,mutant_averaged_score_components);
822  }
823  return mutant_averaged_score_components;
824 }
825 
828 {
831  if(mean_){
834  } else if (min_) {
835  wt = this->get_wt_min_score_components();
836  mut = this->get_mutant_min_score_components();
837  }
838  utility::vector1<double> delta_energy;
839  assert(wt.size() == mut.size());
840  for( unsigned int i=1;i<=wt.size();i++) {
841  delta_energy.push_back(mut[i]-wt[i]);
842  }
843  return delta_energy;
844 }
845 
846 void
849  utility::vector1<std::string> & components
850 )
851 {
852  //utility::vector1<std::string> components;
853  int score_component=0;
854  core::scoring::ScoreType const atom_pair_cst = score_type_from_name("atom_pair_constraint"); //atom-pair-csts not considered in ddg score
855  if(sfxn != 0){
856  for( EnergyMap::const_iterator i = (sfxn->weights()).begin();
857  i != sfxn->weights().end(); i++){
858  score_component++;
859  if(*i != 0 && ScoreType(score_component) != atom_pair_cst ){
860  components.push_back(name_from_score_type(ScoreType(score_component)));
861  }
862  }
863  }
864  // return components;
865 }
866 
869 {
871  if(residues_to_mutate_.size() != pose.total_residue()){
872  return mutation_label; //residues_to_mutate_ hasn't been initialized
873  } else {
874  for ( unsigned int i=1; i <= residues_to_mutate_.size(); i++ ) {
876  std::ostringstream q;
877  q << i;
878  mutation_label = mutation_label + (pose.residue(i)).name1() + q.str() + core::chemical::oneletter_code_from_aa(residues_to_mutate_[i]);
879  //std::cout << "at position " << i << " the mutation label now becomes " << mutation_label << std::endl; //DEBUG
880  }
881  }
882  }
883  return mutation_label;
884 }
885 
886 double
889  double sum=0;
890  for(unsigned int i =1;i<=wt.size();i++){
891  sum=sum+wt[i];
892  }
893  return sum;
894 }
895 
896 double
899  double sum = 0;
900  for(unsigned int i =1;i <= wt.size();i++){
901  sum = sum + wt[i];
902  }
903  return sum;
904 }
905 
906 
907 double
910  double sum=0;
911  for(unsigned int i =1;i<=mut.size();i++){
912  sum=sum+mut[i];
913  }
914  return sum;
915 }
916 
917 double
920  double sum = 0;
921  for(unsigned int i =1;i <= mut.size();i++){
922  sum = sum + mut[i];
923  }
924  return sum;
925 }
926 
927 double
929  if ( mean_ ) {
931  } else if( min_ ) {
933  } else {
934  std::cerr << "neither mean or min set, reverting to default" << std::endl;
935  min_=true; mean_=false;
937  }
938 }
939 
940 bool
942  return is_complete(wt_components_);
943 }
944 
945 bool
948 }
949 
950 bool
952  pose::Pose & pose
953 )
954 {
955  bool is_initialized=true;
956  //check scorefxn
957  //check residues_to_mutate_
958  if(residues_to_mutate_.size() != pose.total_residue()){
959  is_initialized=false;
960  }
961  //check num_iterations_
962  //check dmp_pdbs
963  //check dbg_output
964  return is_initialized;
965 }
966 
967 bool
969  return min_cst_;
970 }
971 
972 bool
974  return mean_;
975 }
976 
977 bool
979  return min_;
980 }
981 
985 }
986 
987 void
989  core::pose::Pose & pose,
990  protocols::scoring::Interface & protein_interface,
991  std::string const & wt_traj,
992  bool output_silent
993 )
994 {
995  using namespace pose;
996  using namespace scoring;
997  using namespace conformation;
998 
999  using namespace basic::options;
1000  using namespace basic::options::OptionKeys;
1001  using namespace core::pack::task;
1002 
1003 
1004  //debug output?
1005  if(dbg_output_){
1006  TR.Debug << "weights being used: " <<
1007  scorefxn_->weights() << "\n";
1008  }
1009  min_cst_wt_types_.resize(pose.total_residue(),'X');
1010  min_cst_mut_types_.resize(pose.total_residue(),'X');
1011  repack_wt_types_.resize(pose.total_residue(),'X');
1012  repack_mut_types_.resize(pose.total_residue(),'X');
1013 
1014  //store constraints for later usage
1015  if(basic::options::option[OptionKeys::ddg::use_rotamer_constraints_to_native]()){
1016  setup_repack_constraints(pose,scorefxn_,false,repack_wt_types_); //not going to use now, but later
1018  //
1021  }
1022 
1023  if(basic::options::option[OptionKeys::ddg::min_cst]()){
1024  if(basic::options::option[OptionKeys::ddg::harmonic_ca_tether].user()){
1025  setup_constraints( pose, min_cst_sfxn_, basic::options::option[OptionKeys::ddg::harmonic_ca_tether](), false, min_cst_wt_types_);
1027  //
1028  setup_constraints( pose, min_cst_sfxn_, basic::options::option[OptionKeys::ddg::harmonic_ca_tether](), true, min_cst_mut_types_);
1030 
1031  } else {
1034  //
1037  }
1038  }
1039  pose.remove_constraints(); //only reason we added constraints was to create a storage set of constraints
1040  //for later use
1041 
1042  if( option[OptionKeys::ddg::opt_input_structure].user() && option[OptionKeys::ddg::opt_input_structure]() ) {
1043  PackerTaskOP norepacking(pack::task::TaskFactory::create_packer_task(pose));
1044  norepacking->temporarily_fix_everything();
1046  minimize_with_constraints(pose,min_cst_sfxn_,norepacking);
1047  pose.dump_pdb("input_pose.pdb");
1048  }
1049 
1050  // initialize the scoring function stuff
1051  (*scorefxn_)(pose);
1052  /// Now handled automatically. scorefxn_->accumulate_residue_total_energies(pose);
1053 
1054  if( interface_ddg_) {
1055  protein_interface.distance(10.0);
1056  protein_interface.calculate(pose);
1057  }
1058 
1059  bool dG_native_calculated = this->is_wt_calc_complete();
1060  if(!dG_native_calculated &&
1061  !(basic::options::option[OptionKeys::ddg::mut_only].user() && (basic::options::option[OptionKeys::ddg::mut_only]()))){
1062 
1063  if(dbg_output_){
1064  TR << "dG_wildtype hasn't been calculated yet! " <<
1065  "starting to calculate dG for native structure\n";}
1066 
1067  //start filehandler for recording the native structure logfile
1068  std::ofstream record_trajectories;
1069  if(wt_traj != ""){
1070  record_trajectories.open(wt_traj.c_str());
1071  }else{
1072  TR << "wt_traj is emtpy, not recording trajectories.\n";
1073  }
1074 
1076  std::string silentfilename;
1077  if(basic::options::option[out::file::silent].user()){
1078  silentfilename = basic::options::option[out::file::silent]();
1079  sfd.set_filename(silentfilename);
1080  }else{
1081  silentfilename = "wt_"+this->mutation_label(pose)+".out";
1082  sfd.set_filename(silentfilename); //setup in case we dump in form of silent file
1083  }
1084 
1085  //end add in interface specific stuff
1086 
1087  //PACKERTASK SETUP FOR NATIVE START
1088  //measure dG of input structure by repacking n times and taking the average score
1089  //this corresponds to wt bound energies of protein complex
1090  pack::task::PackerTaskOP repack_native(pack::task::TaskFactory::create_packer_task(pose));
1091  //add option here to restrict to local region
1092  //find mutation position
1094  for(unsigned int i=1; i <= residues_to_mutate_.size(); i++){
1096  mutations.push_back(i);
1097  }
1098  } //i is mutation position
1099  //find all neighbors within 8 angstrom
1101  if(mutations.size() == 0){
1102  TR << "FATAL ERROR no mutations specified, which are needed to determine neighbors" << std::endl;
1103  exit(1);
1104  }
1105 
1106  utility::vector1< bool > neighborhood = neighborhood_of_mutations( pose, mutations );
1107  // Now: report which residues will be repacked
1108  for ( core::Size ii = 1; ii <= pose.total_residue(); ++ii ) {
1109  if ( neighborhood[ ii ] ) {
1110  TR << "residue " << ii << " is within range of a mutating residue and will be repacked" << std::endl;
1111  repack_native->nonconst_residue_task(ii).restrict_to_repacking();
1112  } else {
1113  TR << "residue " << ii << " is not within range of any mutating residue and will NOT be repacked" << std::endl;
1114  repack_native->nonconst_residue_task(ii).prevent_repacking();
1115  }
1116  }
1117 
1118  } else {
1119  repack_native->restrict_to_repacking();
1120  }
1121 
1122  for ( unsigned int j =1; j <= pose.total_residue(); j++ ) {
1123  initialize_rotamer_behavior_for_residue_level_task( repack_native->nonconst_residue_task(j) );
1124  if( interface_ddg_) {
1125  if( ! protein_interface.is_interface( j ) ) {
1126  repack_native->nonconst_residue_task(j).prevent_repacking();
1127  }
1128  }
1129  }
1130  initialize_task_level_behavior( repack_native );
1131 
1132  //PACKERTASK SETUP FOR NATIVE END
1135  pose::Pose temporary_pose = pose;
1136 
1137  temporary_pose.constraint_set(repack_cst_set_wt_);
1138  pack::pack_rotamers_loop(temporary_pose,(*scorefxn_),repack_native,num_iterations_,results,poses);
1139 
1140  for(unsigned int i=1;i<=poses.size();i++){
1141 
1142  std::ostringstream q;
1143  q << i;
1144 
1145  pose::Pose resulting_pose=(*poses[i]);
1146  resulting_pose.remove_constraints();
1147  if(min_cst_){
1148  resulting_pose.constraint_set(min_cst_set_wt_);
1149 
1150  minimize_with_constraints(resulting_pose,min_cst_sfxn_,repack_native);
1151  ( *min_cst_sfxn_no_cst_weight_) ( resulting_pose ); // now, report the score in the absence of constraints
1153 
1154 
1155  }else{
1156  resulting_pose.constraint_set(repack_cst_set_wt_);
1157  }
1158 
1159  TR << i <<
1160  " score before mutation: residue ";
1161  if(!min_cst_){
1162  TR << (*scorefxn_)(resulting_pose) << " " << resulting_pose.energies().total_energies().weighted_string_of( scorefxn_->weights() ) << std::endl;
1163  }else{
1164  TR << (*min_cst_sfxn_no_cst_weight_)(resulting_pose) << " " << resulting_pose.energies().total_energies().weighted_string_of( min_cst_sfxn_no_cst_weight_->weights()) << std::endl;
1165  }
1166 
1167  if(!interface_ddg_ && !min_cst_){
1168  store_energies(wt_components_, (*scorefxn_), resulting_pose,i,num_iterations_);
1169  //end store components
1170  }else if(interface_ddg_){
1171  assert(resulting_pose.chain(resulting_pose.total_residue())-pose.chain(1) !=0);
1172  //dGinterface = Gbound-Gunbound
1173  //double debug_bound_score = (*scorefxn_)(temporary_pose);
1174  store_energies(wt_components_, (*scorefxn_), resulting_pose,i,num_iterations_);
1175  pose::Pose temporary_unbound_pose = resulting_pose;
1176  calculate_interface_unbound_energy(temporary_unbound_pose,scorefxn_,repack_native);
1177  //store in wt_components_
1178  store_energies(wt_unbound_components_, (*scorefxn_),temporary_unbound_pose,i,num_iterations_);
1179  //double debug_unbound_score = (*scorefxn_)(temporary_unbound_pose);
1180  }
1181  //store repacked pose
1182  natives_.push_back(resulting_pose);
1183  if(dmp_pdb_ && !restrict_to_nbrhood_ && !output_silent){
1184  std::string dump_repacked_wt = "repacked_wt_round_" + q.str() + ".pdb";
1185  resulting_pose.dump_pdb(dump_repacked_wt);
1186  } else if ((restrict_to_nbrhood_ && dmp_pdb_) || output_silent) {
1187  //if you optimize the local neighborhood, automatically dumps out in silent file form
1188  //otherwise there'll be too many files!!!
1189  core::io::silent::BinaryProteinSilentStruct ss(resulting_pose,"repacked_wt_round_" + q.str());
1190  sfd.write_silent_struct(ss,silentfilename,false);
1191  }
1192  }
1193  }
1194 
1195 
1197 
1198 }
1199 
1200 void
1202  core::pose::Pose const & pose,
1203  protocols::scoring::Interface const & protein_interface,
1205  core::pack::task::PackerTaskOP packer_task
1206 )
1207 {
1208  using namespace pose;
1209  using namespace scoring;
1210  using namespace conformation;
1211 
1212  using namespace basic::options;
1213  using namespace basic::options::OptionKeys;
1214  using namespace core::pack::task;
1215 
1216 
1217  //PACKERTASK SETUP FOR MUTANT
1218  utility::vector1< bool > neighborhood;
1219  if (restrict_to_nbrhood_) neighborhood = neighborhood_of_mutations( pose, mutations );
1220 
1221  for(unsigned int i = 1;i<=pose.total_residue();i++){
1223  //contains_mutation=true;
1224  //add option here to restrict to local neighborhood
1225  utility::vector1<bool> restrict_to_aa(20,false);
1226  restrict_to_aa[(int)residues_to_mutate_[i]]=true;
1227  packer_task->nonconst_residue_task(i).restrict_absent_canonical_aas(restrict_to_aa);
1228  initialize_rotamer_behavior_for_residue_level_task( packer_task->nonconst_residue_task(i) );
1229  } else {
1231  if(neighborhood[i]){
1232  TR << "MUT residue " << i << " is within the cutoff distance to a mutation and will be repacked " << std::endl;
1233  initialize_rotamer_behavior_for_residue_level_task( packer_task->nonconst_residue_task(i) );
1234  packer_task->nonconst_residue_task(i).restrict_to_repacking();
1235  }else{
1236  TR << "MUT residue " << i << " is not within the cutoff distance to any mutation and will NOT be repacked " << std::endl;
1237  packer_task->nonconst_residue_task(i).prevent_repacking();
1238  }
1239  }else{ //not a mutation position, not restricted by distance to mutation site, so allow all to repack
1240  packer_task->nonconst_residue_task(i).restrict_to_repacking();
1241  initialize_rotamer_behavior_for_residue_level_task( packer_task->nonconst_residue_task(i) );
1242  }
1243  }
1244  }
1245 
1246 
1247  if( interface_ddg_) { // further restrict non-interface aa's if we're in interface_ddg mode
1248  for( core::Size i = 1; i<= pose.total_residue(); ++i ) {
1249  if( ! protein_interface.is_interface( i ) ) {
1250  packer_task->nonconst_residue_task(i).prevent_repacking();
1251  }
1252  }
1253  }
1254  //PACKERTASK SETUP FOR MUTANT END
1255 }
1256 
1257 /// @details Experimental: add extra options controlling how the packer behaves
1258 void
1260  core::pack::task::PackerTaskOP packer_task
1261 )
1262 {
1263  using namespace basic::options;
1264  using namespace basic::options::OptionKeys;
1265 
1266  packer_task->initialize_extra_rotamer_flags_from_command_line();
1267  if ( option[ packing::multi_cool_annealer ].user() ) {
1268  packer_task->or_multi_cool_annealer( true );
1269  packer_task->increase_multi_cool_annealer_history_size( option[ packing::multi_cool_annealer ] );
1270  }
1271 }
1272 
1273 
1274 /// @details determine if we need to do any work, or if we have checkpoints saving us from some work
1275 bool
1277  core::pose::Pose const & pose,
1278  std::string const & mutant_traj,
1279  bool const output_silent
1280 ) const
1281 {
1282  using namespace pose;
1283  using namespace scoring;
1284  using namespace conformation;
1285 
1286  using namespace basic::options;
1287  using namespace basic::options::OptionKeys;
1288  using namespace core::pack::task;
1289 
1290  bool any_pdb_empty = false;
1291  struct stat filesize;
1292  if(!dmp_pdb_ && stat(mutant_traj.c_str(), &filesize) == 0){
1293  std::cout << "mutation " << this->mutation_label(pose) << " already has a trajectory file. skipping!....." << std::endl;
1294  any_pdb_empty = false;
1295  } else if (!restrict_to_nbrhood_ && !output_silent ) {
1296  for(int i =1; i <= num_iterations_; i++){
1297  std::ostringstream q;
1298  q << i;
1299  std::string file_to_check = ("mut_" + this->mutation_label(pose) + "_"
1300  + "round_" + q.str() + ".pdb");
1301  if(stat(file_to_check.c_str(), &filesize) == 0 && !basic::options::option[OptionKeys::ddg::suppress_checkpointing]()){
1302  //std::cout << "file " << file_to_check << " exists. checking to see if all files non-empty" << std::endl;
1303  if(filesize.st_size == 0){
1304  any_pdb_empty = true;
1305  std::cout << "file " << file_to_check << " is empty! re-doing calculations " << std::endl;
1306  }
1307  }else{
1308  any_pdb_empty = true;
1309  }
1310  }
1311  }else{
1312  //silentfile specific behavior when local repacks activated
1313  std::string file_to_check = "mut_"+this->mutation_label(pose)+".out";;
1314  if(!basic::options::option[OptionKeys::ddg::suppress_checkpointing]()){
1315 
1316  std::cout << "checking for decoys in silent file: " << file_to_check << std::endl;
1317  if(stat(file_to_check.c_str(), &filesize) == 0){
1318  std::cout << "silent file " << file_to_check << " exists. checking how many tags exist" << std::endl;
1319  core::io::silent::SilentFileData sfd(file_to_check,false,false,"binary");
1320  sfd.read_file(file_to_check);
1321  utility::vector1<std::string> tags = sfd.read_tags_fast(file_to_check);
1322  if(/**num tags**/ tags.size() < core::Size(num_iterations_)){
1323  std::cout << "number of tags " << tags.size() << " is less than number of iterations " << num_iterations_ << " re-doing calculations " << std::endl;
1324  any_pdb_empty = false;
1325  }
1326  } else{
1327  std::cout << "mutant silent file " << file_to_check << " doesn't exist. starting calculations" << std::endl;
1328  any_pdb_empty=true;
1329  }
1330  }
1331  }
1332  return any_pdb_empty;
1333 }
1334 
1335 
1338  core::pose::Pose const & pose,
1340 ) const
1341 {
1342  utility::vector1< bool > neighbors( pose.total_residue(), false );
1343  Real rad2 = nbr_cutoff_ * nbr_cutoff_;
1344 
1345  for( core::Size ii = 1; ii <= mutations.size(); ++ii ) {
1346  Size iiresid = mutations[ ii ];
1347  core::Vector ii_pos;
1348  if ( pose.residue(iiresid).name1() == 'G' ){
1349  ii_pos = pose.residue(iiresid).xyz(" CA ");
1350  }else{
1351  ii_pos = pose.residue(iiresid).xyz(" CB ");
1352  }
1353  for ( core::Size jj = 1; jj <= pose.total_residue(); ++jj ) {
1354  if ( neighbors[ jj ] ) continue;
1355  core::Vector jj_pos;
1356  /// Gee -- this will crash if we're dealing with something other than a protein
1357  if(pose.residue(jj).name1() == 'G') {
1358  jj_pos = pose.residue(jj).xyz(" CA ");
1359  }else{
1360  jj_pos = pose.residue(jj).xyz(" CB ");
1361  }
1362  //if c-beta is within x angstrom, set movemap(i) true
1363  if(ii_pos.distance_squared(jj_pos) <= rad2 ){
1364  neighbors[ jj ] = true;
1365  }
1366  }//for all jj
1367  } // for all mutation positions
1368 
1369  return neighbors;
1370 }
1371 
1372 void
1375 ) const
1376 {
1377  rltask.or_include_current(true);
1378  rltask.or_ex1(true);
1379  rltask.or_ex2(true);
1380 }
1381 
1382 
1383 void
1385 {
1386  using namespace pose;
1387  using namespace scoring;
1388  using namespace conformation;
1389 
1390  using namespace basic::options;
1391  using namespace basic::options::OptionKeys;
1392  using namespace core::pack::task;
1393 
1394  /// This mover operates in two phases:
1395  /// first, it relaxes the wild type structure in the region of the mutation, then
1396  /// second, it relaxes the mutant structure in the region of the mutation. It is critical
1397  /// that both relaxation protocols be as similar as possible, excluding of course,
1398  /// the introduction of the non-native amino acid in the protocol modeling the mutant.
1399 
1400  std::string wt_traj = "wt_traj";
1401  std::string mutant_traj = "mutant_traj"+this->mutation_label(pose);
1402 
1403  // set fa_max_dis to 9.0
1404  // APL NOTE: this does not work if the Etable has already been created, and it probably has.
1405  // basic::options::option[ score::fa_max_dis ](9.0);
1406 
1407  protocols::scoring::Interface protein_interface(1); // need to define this outside if, to prevent compilation errors
1408  //check for properly initialized variables
1409 
1410  //initialize output_silent variable. should go as boolean in private class data?
1411  bool output_silent = false;
1412  //force output of silent file
1413  if(basic::options::option[OptionKeys::ddg::output_silent].user()){
1414  output_silent = basic::options::option[OptionKeys::ddg::output_silent]();
1415  }
1416 
1417 
1418  if (this->is_properly_initialized(pose) ) {
1419  relax_wildtype_structure( pose, protein_interface, wt_traj, output_silent );
1420  } //for now can only store one. will be last listed mutation
1421 
1422  //also initialize packertask using this array
1423  pack::task::PackerTaskOP packer_task(pack::task::TaskFactory::create_packer_task(pose));
1424 
1425  bool contains_mutation=false;
1427 
1428  //TR << "restricting to local mutant neighborhood" << std::endl;
1429  //find mutation position
1430  //bug?//utility::vector1<int> mutations;
1431  for(unsigned int j=1; j <= residues_to_mutate_.size(); j++){
1432  //bool contains_mutation = false;
1434  contains_mutation = true;
1435  mutations.push_back(j);
1436  }
1437  } //j is mutation position
1438 
1439  setup_packer_task_for_mutations( pose, protein_interface, mutations, packer_task );
1440  initialize_task_level_behavior( packer_task );
1441 
1442  if(!contains_mutation){
1443  return; // no mutation specified, so no work to be done.
1444  }
1445 
1446  //apply all mutations in packertask to pose
1447  std::ofstream record_mutant_trajectories;
1448 
1449  bool any_pdb_empty = is_any_pdb_empty( pose, mutant_traj, output_silent );
1450 
1451  if(any_pdb_empty || basic::options::option[OptionKeys::ddg::suppress_checkpointing]()){
1452  TR << "[DEBUG] file does not exist. "<< mutant_traj << ". Creating logfile now.\n";
1453 
1454  record_mutant_trajectories.open( mutant_traj.c_str() );
1455  if(dbg_output_){
1456  record_mutant_trajectories << "beginning logfile" <<std::endl;
1457  }
1458 
1460  std::string silentfilename;
1461  if(basic::options::option[out::file::silent].user()){
1462  silentfilename = basic::options::option[out::file::silent]();
1463  sfd.set_filename(silentfilename);
1464  }else{
1465  silentfilename = "mut_"+this->mutation_label(pose)+".out";
1466  sfd.set_filename(silentfilename); //setup in case we dump in form of silent file
1467  }
1468 
1471 
1472 
1473  pose::Pose temporary_pose = pose;
1474  temporary_pose.remove_constraints();
1475  temporary_pose.constraint_set(repack_cst_set_mut_);
1476 
1477  pack::pack_rotamers_loop(temporary_pose,(*scorefxn_),packer_task,num_iterations_,results,poses);
1478 
1479  for(unsigned int i = 1; i <= poses.size(); i++){
1480  pose::Pose resulting_pose = (*poses[i]);
1481  resulting_pose.remove_constraints();
1482  if(min_cst_){
1483  resulting_pose.constraint_set(min_cst_set_mut_);
1484  minimize_with_constraints(resulting_pose,min_cst_sfxn_,packer_task);
1485  ( * min_cst_sfxn_no_cst_weight_)( resulting_pose ); // now compute the score in the absence of the constranits.
1487  }else{
1488  resulting_pose.constraint_set(repack_cst_set_mut_);
1489  }
1490  Real final_score = -1;
1491  if(!min_cst_){
1492  final_score=(*scorefxn_)( resulting_pose ) ;
1493  }else{
1494  final_score=(*min_cst_sfxn_no_cst_weight_)(resulting_pose);
1495  }
1496 
1497  //store scores
1498  if(!interface_ddg_ && !min_cst_){
1500  }else if(interface_ddg_){
1501  assert(pose.chain(pose.total_residue())-pose.chain(1) !=0);
1502  //dGinterface = Gbound-Gunbound
1503  //double debug_bound = (*scorefxn_)(resulting_pose);
1505  pose::Pose temporary_unbound_pose = resulting_pose;
1506  calculate_interface_unbound_energy(temporary_unbound_pose,scorefxn_,packer_task);
1507  //store in wt_components_
1508  // double debug_unbound = (*scorefxn_)(temporary_unbound_pose);
1510  //TR << "debug unbound " << debug_unbound << " debug bound is " << debug_bound << " so dg is " << (debug_bound-debug_unbound) << std::endl;
1511  }
1512 
1513  TR << i <<
1514  " score after mutation: residue " << this->mutation_label(pose) << " "
1515  << final_score << " ";
1516  if(!min_cst_){
1517  TR << resulting_pose.energies().total_energies().weighted_string_of( scorefxn_->weights() ) << std::endl;
1518  }else{
1519  TR << resulting_pose.energies().total_energies().weighted_string_of( min_cst_sfxn_no_cst_weight_->weights()) << std::endl;
1520  }
1521 
1522  //output the mutated pdb
1523  std::ostringstream q;
1524  q << i;
1525  //record_mutant_trajectories << "round " << q.str()
1526  TR << "round " << q.str()
1527  << " mutate " << this->mutation_label(pose)
1528  << " " << (final_score) << std::endl;
1529 
1530  if(dmp_pdb_ && !restrict_to_nbrhood_ && !output_silent){
1531  std::string output_pdb = "mut_" +
1532  this->mutation_label(pose) + "_" + "round_" + q.str() + ".pdb";
1533  resulting_pose.dump_pdb(output_pdb);
1534  }else if((dmp_pdb_ && restrict_to_nbrhood_) || output_silent){
1535  core::io::silent::BinaryProteinSilentStruct ss(resulting_pose,"mut_" + this->mutation_label(pose) + "_round_" + q.str());
1536  sfd.write_silent_struct(ss,silentfilename,false);
1537  }
1538  mutants_.push_back(resulting_pose);
1539  }
1540 
1541  TR << "mutate " << this->mutation_label(pose) << //DEBUG
1542  " " << " " << " wildtype_dG is: "
1543  << this->get_wt_min_totals() << " and mutant_dG is: "
1544  << this->get_mutant_min_totals() << " ddG is: " << (this->get_mutant_min_totals()-this->get_wt_min_totals())
1545  << std::endl;
1546  record_mutant_trajectories.close();
1547 
1548 
1549  }
1550 }
1551 
1552 
1555  return "ddGMover";
1556 }
1557 
1558 } //moves
1559 } //protocols
1560 
1561 
1562 
1563 
1564 
1565 
1566