Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ShakeStructureMover.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 <core/types.hh>
15 
16 #include <core/chemical/AA.hh>
18 // AUTO-REMOVED #include <core/conformation/ResidueMatcher.hh>
19 // AUTO-REMOVED #include <core/chemical/ResidueTypeSet.hh>
20 // AUTO-REMOVED #include <core/chemical/ResidueSelector.hh>
21 // AUTO-REMOVED #include <core/conformation/ResidueFactory.hh>
22 
25 
26 // AUTO-REMOVED #include <core/pack/pack_rotamers.hh>
27 // AUTO-REMOVED #include <core/pack/task/PackerTask.hh>
28 // AUTO-REMOVED #include <core/pack/task/TaskFactory.hh>
29 
31 
34 
35 #include <core/pose/Pose.hh>
36 
37 // AUTO-REMOVED #include <basic/options/util.hh>
38 // AUTO-REMOVED #include <basic/options/after_opts.hh>
39 #include <basic/options/keys/OptionKeys.hh>
40 
41 // AUTO-REMOVED #include <core/init.hh>
42 // AUTO-REMOVED #include <core/io/pdb/pose_io.hh>
43 
44 #include <numeric/xyzVector.hh>
45 #include <numeric/random/random.hh>
46 // AUTO-REMOVED #include <core/pack/task/ResfileReader.hh>
47 
48 // AUTO-REMOVED #include <fstream>
49 #include <iostream>
50 #include <sstream>
51 // AUTO-REMOVED #include <ios>
52 // AUTO-REMOVED #include <utility/io/izstream.hh>
53 // AUTO-REMOVED #include <ObjexxFCL/format.hh>
54 
55 // C++ headers
56 #include <cstdlib>
57 #include <string>
58 
59 #include <basic/Tracer.hh>
60 
61 
63 
64 // AUTO-REMOVED #include <core/scoring/sasa.hh>
65 #include <core/scoring/rms_util.hh>
66 //#include <core/scoring/ScoringManager.hh>
68 // AUTO-REMOVED #include <core/scoring/constraints/ConstraintIO.hh>
74 // AUTO-REMOVED #include <core/id/AtomID_Map.hh>
75 // AUTO-REMOVED #include <core/id/AtomID_Map.Pose.hh>
76 #include <core/id/AtomID.hh>
77 #include <core/id/DOF_ID.hh>
78 // AUTO-REMOVED #include <core/kinematics/AtomTree.hh>
79 #include <core/kinematics/Jump.hh>
80 
81 #include <core/pose/Pose.fwd.hh>
82 // AUTO-REMOVED #include <core/pose/PDBInfo.hh>
83 
84 
85 // AUTO-REMOVED #include <basic/options/option.hh>
86 
87 // AUTO-REMOVED #include <basic/basic.hh>
88 // AUTO-REMOVED #include <basic/database/open.hh>
89 // AUTO-REMOVED #include <core/io/silent/SilentFileData.hh>
90 // AUTO-REMOVED #include <core/io/silent/ProteinSilentStruct.hh>
91 
92 // AUTO-REMOVED #include <core/pack/rotamer_trials.hh>
93 // AUTO-REMOVED #include <core/io/silent/silent.fwd.hh>
94 
95 //protocols
100 // AUTO-REMOVED #include <protocols/simple_moves/RotamerTrialsMover.hh>
103 #include <protocols/moves/Mover.hh>
104 
105 // AUTO-REMOVED #include <utility/file/FileName.hh>
106 #include <utility/vector1.hh>
107 // AUTO-REMOVED #include <utility/io/ozstream.hh>
108 // AUTO-REMOVED #include <time.h>
109 using basic::T;
110 using basic::Warning;
111 using basic::Error;
112 
113 // C++ headers
114 
115 #include <utility/vector0.hh>
116 
117 
118 
119 namespace protocols {
120 namespace simple_moves {
121 
122 static numeric::random::RandomGenerator rg(15433); // <- Magic number, do not change it!!!
123 
125  protocols::moves::Mover("ShakeStructureMover"),
126  mc_temp(0),
127  ramp_fa_rep(false),
128  min_cst(false),
129  scorefxn(0),
130  ensemble_ca_rmsd(-1),
131  ensemble_ca_rmsd_tolerance(0.75f),
132  is_properly_initialized(false),
133  harmonic_ca_cst_std_dev(2.0f),
134  scorefunction_initialized(false),
135  sc_min_only(false),
136  nrounds(1000),
137  cst_weight(1.0f),
138  skip_low_temp_phase(true),
139  min_scorefxn(0),
140  testing_phase(false)
141 {}
142 
144  protocols::moves::Mover("ShakeStructureMover"),
145  mc_temp(0),
146  ramp_fa_rep(false),
147  min_cst(false),
148  scorefxn(s),
149  ensemble_ca_rmsd(-1),
150  ensemble_ca_rmsd_tolerance(0.75),
151  is_properly_initialized(false),
152  harmonic_ca_cst_std_dev(2.0),
153  scorefunction_initialized(true),
154  sc_min_only(false),
155  nrounds(1000),
156  cst_weight(1.0),
157  skip_low_temp_phase(true),
158  min_scorefxn(0),
159  testing_phase(false)
160 {}
161 
164  core::Real temperature
165 ) :
166  protocols::moves::Mover("ShakeStructureMover"),
167  mc_temp(temperature),
168  ramp_fa_rep(false),
169  min_cst(false),
170  scorefxn(s),
171  ensemble_ca_rmsd(-1),
172  ensemble_ca_rmsd_tolerance(0.75),
173  is_properly_initialized(false),
174  harmonic_ca_cst_std_dev(2.0),
175  scorefunction_initialized(true),
176  sc_min_only(false),
177  nrounds(1000),
178  cst_weight(1.0),
179  skip_low_temp_phase(true),
180  min_scorefxn(0),
181  testing_phase(false)
182 {}
183 
186  core::Real ens_diversity, core::Real ens_div_tolerance
187 ):
188  protocols::moves::Mover("ShakeStructureMover"),
189  mc_temp(0),
190  ramp_fa_rep(false),
191  min_cst(false),
192  scorefxn(s),
193  ensemble_ca_rmsd(ens_diversity),
194  ensemble_ca_rmsd_tolerance(ens_div_tolerance),
195  is_properly_initialized(false),
196  harmonic_ca_cst_std_dev(2.0),
197  scorefunction_initialized(true),
198  sc_min_only(false),
199  nrounds(1000),
200  cst_weight(1.0),
201  skip_low_temp_phase(true),
202  min_scorefxn(0),
203  testing_phase(false)
204 {}
205 
207 
208 void
210  skip_low_temp_phase = truefalse;
211 }
212 
213 void
215  mc_temp=temp;
216 }
217 
218 void
220  nrounds=new_nrounds;
221 }
222 
223 
224 void
226  ramp_fa_rep=truefalse;
227 }
228 
229 void
231  min_cst=truefalse;
232 }
233 
234 void
236  scorefxn = s;
238 }
239 
240 void
242  ensemble_ca_rmsd=ca_rmsd;
243  ensemble_ca_rmsd_tolerance=((ca_rmsd*0.25)+0.1);
244  mc_temp=-1;
245 }
246 
247 
248 void
251 }
252 
253 void
255  sc_min_only=truefalse;
256  min_cst=true;
257 }
258 
259 void
261  testing_phase = truefalse;
262 }
263 
264 void
266  mc_temp = temperature;
267 }
268 
269 void
271  is_properly_initialized = truefalse;
272 }
273 
274 void
276  min_scorefxn = scfxn;
277 }
278 
279 //accessors
282  return mc_temp;
283 }
284 
285 bool
287  return ramp_fa_rep;
288 }
289 
290 bool
292  return min_cst;
293 
294 }
295 
298  return scorefxn;
299 }
300 
303  return ensemble_ca_rmsd;
304 }
305 
309 }
310 
311 bool
313  return sc_min_only;
314 }
315 
319 }
320 
323  return ensemble_ca_rmsd;
324 }
325 
326 bool
328  return skip_low_temp_phase;
329 }
330 
331 bool
333  return min_cst;
334 }
335 
336 bool
338  return testing_phase;
339 }
340 
341 bool
344 }
345 
348  return min_scorefxn;
349 }
350 
353  return nrounds;
354 }
355 
356 //run-time
357 
358 
359 void
361 
362  using namespace core;
363  using namespace core::pose;
364  using namespace utility;
365  using namespace basic::options;
366  using namespace basic::options::OptionKeys;
367  using namespace core::scoring;
368  using namespace core::scoring::constraints;
369 
371  setup_for_run(pose);
372  }
373 
374  create_ensemble(pose, *scorefxn);
375 }
376 
377 
380  return "ShakeStructureMover";
381 }
382 
385  s.set_weight(
387  s.get_weight(core::scoring::score_type_from_name("fa_rep"))*fraction_fa_rep);
388  return s;
389 }
390 
391 void
395  //std::cout << "[DEBUG]: scorefunction being initialized"<< std::endl;
396  s->set_weight(core::scoring::score_type_from_name("rama"), 4.0);
397  s->set_weight(core::scoring::score_type_from_name("omega"), 1.0);
398  s->set_weight(core::scoring::score_type_from_name("fa_dun"), 1.0);
399  s->set_weight(core::scoring::score_type_from_name("p_aa_pp"), 2.0);
400  scorefxn = s;
401  }
403 
404  if(min_cst || sc_min_only){
406  }
407 
408  if(mc_temp <= 0 && ensemble_ca_rmsd > 0){
409  //set mc_temp based on ensemble_ca_rmsd
410  testing_phase=true;
413  }else if(mc_temp > 0 && ensemble_ca_rmsd < 0){
414  //ready to go!
416  }else{
417  //what to do, what to do?
418  is_properly_initialized = false;
419  }
420 
421 
422 }
423 
424 void
427 
429  float const minimizer_tol = 0.0000001;
431  "dfpmin_armijo_nonmonotone",
432  minimizer_tol,
433  true /*use_nb_list*/,
434  false /*deriv_check_in*/,
435  false /*deriv_check_verbose_in*/);
436  options.nblist_auto_update( true );
437  // options.max_iter(5000);
439  if(!sc_min_only){
440  mm.set_bb(true);
441  }else{
442  mm.set_bb(false);
443  }
444  mm.set_chi(true);
445 
446  if(ramp_fa_rep){
447  core::scoring::ScoreFunction one_tenth_orig(s);
448  reduce_fa_rep(0.1,one_tenth_orig);
449  min_struc.run(p,mm,one_tenth_orig,options);
450  core::scoring::ScoreFunction one_third_orig(s);
451  reduce_fa_rep(0.33,one_third_orig);
452  min_struc.run(p,mm,one_third_orig,options);
453  }
454  min_struc.run(p,mm,s,options);
455 
456 }
457 
458 void
460  core::pose::Pose & pose,
462  float const CA_cutoff,
463  float const cst_tol
464 ){
465 
466  using namespace core::scoring::constraints;
467  using namespace core::id;
468  using namespace core;
469  //create constraints for all residues
470  //type: HARMONIC
471  //static float const CA_cutoff(9.0);
472  int nres = pose.total_residue();
473  for(int i = 1; i <= nres; i++){
474  if ( pose.residue(i).aa() == core::chemical::aa_vrt ) continue;
475  Vector const CA_i( pose.residue(i).xyz(" CA "));
476  for(int j = 1; j <=nres; j++){
477  if ( pose.residue(j).aa() == core::chemical::aa_vrt ) continue;
478  Vector const CA_j(pose.residue(j).xyz(" CA "));
479  Real const CA_dist = (CA_i - CA_j).length();
480  if(CA_dist < CA_cutoff){
481  ConstraintCOP cst(new AtomPairConstraint( AtomID(pose.residue(i).atom_index(" CA "),i),AtomID(pose.residue(j).atom_index(" CA "),j),new HarmonicFunc(CA_dist, cst_tol)));
482  pose.add_constraint(cst);
483  }
484  }
485  }
486 
488 
489 }
490 
491 void
494  core::Real small_H_angle_max, core::Real small_E_angle_max, core::Real small_L_angle_max,
495  core::Real shear_H_angle_max, core::Real shear_E_angle_max, core::Real shear_L_angle_max
496 ){
497  //smaller moves to boost acceptance rate
498  gsmall->angle_max( 'H', small_H_angle_max ); //def 0.5
499  gsmall->angle_max( 'E', small_E_angle_max ); //def 0.5
500  gsmall->angle_max( 'L', small_L_angle_max ); //def 0.75
501 
502  gshear->angle_max( 'H', shear_H_angle_max); //def 2.0
503  gshear->angle_max( 'E', shear_E_angle_max); //def 2.0
504  gshear->angle_max( 'L', shear_L_angle_max); //def 3.0
505 }
506 
507 
508 
509 void
512  core::Real temperature
513 ){
514 
515  using namespace protocols;
516  using namespace moves;
517 
518  core::pose::Pose init(p); //for comparison at the end
519 
520  core::Size nmoves = (core::Size)p.total_residue()/4; //number of moves for each move type
521 
523  mm->set_bb(true);
524 
525  simple_moves::SmallMoverOP small_mover(new simple_moves::SmallMover( mm, temperature, nmoves)) ;
526  simple_moves::ShearMoverOP shear_mover( new simple_moves::ShearMover(mm, temperature, nmoves));
527 
528  setup_movers(
529  small_mover,shear_mover,
530  0.2,0.2,0.4,
531  1.6,1.6,2.0);
532 
533  moves::RandomMoverOP apply_random_move( new moves::RandomMover());
534  apply_random_move->add_mover( small_mover, .5);
535  apply_random_move->add_mover( shear_mover, .5);
536 
537  simple_moves::SmallMoverOP small_mover_low(new simple_moves::SmallMover( mm, (temperature*0.25), nmoves)) ;
538  simple_moves::ShearMoverOP shear_mover_low( new simple_moves::ShearMover(mm, (temperature*0.25), nmoves));
539 
540  setup_movers(
541  small_mover_low,shear_mover_low,
542  0.1,0.1,0.2,
543  1.0,1.0,1.5);
544 
545  moves::RandomMoverOP apply_random_move_low( new moves::RandomMover());
546  apply_random_move_low->add_mover( small_mover_low, .5);
547  apply_random_move_low->add_mover( shear_mover_low, .5);
548 
549  protocols::moves::MonteCarloOP mc(new moves::MonteCarlo(p,s,temperature));
550  //time_t time_per_decoy = time(NULL);
551 
552  // mc->reset_counters();
553  // mc->reset(p);
554  mc->set_temperature(temperature);
555 
556  moves::TrialMoverOP tm( new moves::TrialMover(apply_random_move,mc));
557  RepeatMoverOP full_cycle(new moves::RepeatMover( tm, nrounds ));
558  full_cycle->apply( p );
559  // mc->show_counters();
560 
561  if(!skip_low_temp_phase){
562  mc->reset_counters();
563 
564  mc->set_lowest_score_pose(mc->last_accepted_pose()); //high energy mark for annealing back to native
565  core::Real low_temp = temperature * 0.25;
566  mc->set_temperature(low_temp);
567 
568  moves::TrialMoverOP ltm( new moves::TrialMover(apply_random_move_low,mc));
569  RepeatMoverOP full_cycle_2(new moves::RepeatMover( ltm, nrounds ));
570  full_cycle_2->apply( p );
571  //mc->show_counters();
572  p = mc->lowest_score_pose();
573  } else {
574  p = mc->last_accepted_pose();
575  }
576 
577  if(min_cst && !testing_phase){
578  //remove constraints
579  p.remove_constraints((p.constraint_set())->get_all_constraints());
580 
581  //std::cout << "minimizing with constraints" << std::endl;
582  //temporarily hardcode score12 into minimization.
583  setup_ca_constraints(p, (*min_scorefxn), 9.0, 0.5);
585 
586  //std::cout << " CA rmsd of current: " << core::scoring::CA_rmsd(p,init) << std::endl;
587  //time_t time_per_decoy_finish = time(NULL);
588  //std::cout << "time to finish decoy " << (time_per_decoy_finish-time_per_decoy) << std::endl;
589  }else{
590  //time_t time_per_decoy_finish = time(NULL);
591  //std::cout << " CA rmsd of current: " << core::scoring::CA_rmsd(p,init) << std::endl;
592  //std::cout << "time to finish decoy " << (time_per_decoy_finish-time_per_decoy) << std::endl;
593  }
594 }
595 
598  core::pose::Pose & p,
600 ){
601 
602  int numstruct = 10;
603  core::Real avg_ca_rmsd = -1;
604  core::Real temperature = 10;
605  core::Real increment = 0.75;
606 
608  core::pose::Pose test(p);
609  while((avg_ca_rmsd) > (ensemble_ca_rmsd+ensemble_ca_rmsd_tolerance) || (avg_ca_rmsd) < (ensemble_ca_rmsd-ensemble_ca_rmsd_tolerance)){
610  double avg_ca_rmsd=0;
611  for(int i =0;i<numstruct;i++){
612  test = init;
613  run_mc(test, s,temperature);
614  //std::cout << "[DEBUG]: rmsd in set temp " << core::scoring::CA_rmsd(test,init) << std::endl;
615  avg_ca_rmsd+=core::scoring::CA_rmsd(test,init);
616  }
617  avg_ca_rmsd = avg_ca_rmsd /numstruct;
618  if(avg_ca_rmsd > (ensemble_ca_rmsd+ensemble_ca_rmsd_tolerance)){
619  temperature -= increment;
620  //std::cout << "avg rmsd is " << avg_ca_rmsd << " which is greater than upper bound: " << ensemble_ca_rmsd+ensemble_ca_rmsd_tolerance << " so temp is decreased to " << temperature << std::endl;
621  }
622  else if(avg_ca_rmsd < (ensemble_ca_rmsd-ensemble_ca_rmsd_tolerance)){
623  temperature += increment;
624  //std::cout << "avg rmsd is " << avg_ca_rmsd << " which is less than lower bound: " << ensemble_ca_rmsd-ensemble_ca_rmsd_tolerance << " so temp is increased to " << temperature << std::endl;
625  }
626  }
627  testing_phase=false;
628  return temperature;
629 }
630 
631 void
633  using namespace protocols;
634  using namespace moves;
635 
636  run_mc(p,s,mc_temp);
637 }
638 
639 } //simple_moves
640 } //protocols
641