Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RotamerTrialsMinMover.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 RotamerTrialsMinMover.cc
11 /// @brief protocols::moves::Mover for Rotamer-Trials with Minimization (based on RotamerTrialsMover)
12 /// @author Barak Raveh
13 
14 // Unit headers
17 
18 // Project headers
19 #include <core/pose/Pose.hh>
20 #include <core/scoring/Energies.hh>
25 
26 #include <core/pack/rtmin.hh>
27 
30 
31 #include <basic/options/option.hh>
32 #include <basic/options/keys/OptionKeys.hh>
33 #include <basic/options/keys/optimization.OptionKeys.gen.hh>
34 
35 // Utility Headers
36 #include <basic/Tracer.hh>
37 #include <utility/tag/Tag.hh>
38 
39 #include <utility/vector0.hh>
40 #include <utility/vector1.hh>
41 
42 
43 using basic::T;
44 using basic::Error;
45 using basic::Warning;
46 
47 static basic::Tracer TR("protocols.simple_moves.RotamerTrialsMinMover");
48 
49 namespace protocols {
50 namespace simple_moves {
51 
52 // default constructor
54 {
55  protocols::moves::Mover::type( "RotamerTrialsMin" );
56  init();
57 }
58 
59 // constructor with arguments
61  ScoreFunctionCOP scorefxn_in,
62  PackerTask & task_in
63 ) : protocols::moves::Mover(), scorefxn_( scorefxn_in ), factory_( NULL )
64 {
65  protocols::moves::Mover::type( "RotamerTrialsMin" );
66  task_ = task_in.clone();
67  init();
68 }
69 
70 // constructor with arguments
72  ScoreFunctionCOP scorefxn_in,
73  TaskFactoryCOP factory_in
74 ) : protocols::moves::Mover(), scorefxn_( scorefxn_in ), task_( NULL ), factory_( factory_in )
75 {
76  protocols::moves::Mover::type( "RotamerTrialsMin" );
77  init();
78 }
79 
80 void
82 {
83  nonideal_ = basic::options::option[ basic::options::OptionKeys::optimization::scmin_nonideal ]();
84  cartesian_ = basic::options::option[ basic::options::OptionKeys::optimization::scmin_cartesian ]();
85 }
86 
87 
89 
90 // setters
93 
94 void
96 {
97  //task() contains the call to the TaskFactory
98  //TR << *(task(pose)) << std::flush;
99  ( *scorefxn_ )(pose); // Ensure scorefunction data is appropriately initialized
100  core::pack::RTMin RTMin;
101  RTMin.set_nonideal(nonideal_);
102  RTMin.set_cartesian(cartesian_);
103  RTMin.rtmin( pose, *scorefxn_, task(pose) );
104 }
105 
108  return "RotamerTrialsMinMover";
109 }
110 
111 /// @brief read access for derived classes
114 {
115  return scorefxn_;
116 }
117 
118 /// @brief read access for derived classes
121 {
122  //if we have a factory, generate and return a new task
123  if(factory_) return factory_->create_task_and_apply_taskoperations( pose );
124  //else assert( task_is_valid( pose ) );
125 
126  //else return the unsafe one
127  return task_->clone();
128 }
129 
130 ///@brief Parse XML for RosettaScripts
131 void
133  TagPtr const tag,
134  protocols::moves::DataMap & datamap,
135  Filters_map const &,
137  Pose const &
138 )
139 {
140  assert( tag->getName() == "RotamerTrialsMinMover" );
141 
143  if ( new_score_function == 0 ) {
144  TR << "Using default score function for RotamerTrialsMinMover." << std::endl;
145  new_score_function = core::scoring::getScoreFunction();
146  }
147  score_function( new_score_function );
148 
150  if ( new_task_factory == 0) {
151  TR << "Using default Task Operations for RotamerTrialsMinMover." << std::endl;
152  new_task_factory = new core::pack::task::TaskFactory;
153  }
154  task_factory( new_task_factory );
155 
156  if (tag->hasOption( "nonideal" )) {
157  nonideal_ = tag->getOption<bool>( "nonideal" );
158  }
159  if (tag->hasOption( "cartesian" )) {
160  cartesian_ = tag->getOption<bool>( "cartesian" );
161  }
162 }
163 
164 ///@brief Return a new mover instance (for RosettaScripts)
167 {
168  return new RotamerTrialsMinMover;
169 }
170 
171 ///@brief Return a copy of this mover instance (for RosettaScripts)
174 {
176 }
177 
178 std::ostream &operator<< (std::ostream &os, RotamerTrialsMinMover const &mover)
179 {
180  moves::operator<<(os, mover);
181  if ( mover.scorefxn() != 0 ) {
182  os << "Score function: " << mover.scorefxn()->get_name() << std::endl;
183  }
184  else { os << "Score function: none" << std::endl; }
185 
186  return os;
187 }
188 
191 {
193 }
194 
197 {
198  return new RotamerTrialsMinMover;
199 }
200 
203 {
204  return "RotamerTrialsMinMover";
205 }
206 
207 // default constructor
209  protocols::simple_moves::RotamerTrialsMinMover()
210 {
211  protocols::moves::Mover::type( "EnergyCutRotamerTrialsMin" );
212  init();
213 }
214 
215 // constructor with arguments
217  ScoreFunctionCOP scorefxn_in,
218  PackerTask & task_in,
220  core::Real energycut_in
221 ) : protocols::simple_moves::RotamerTrialsMinMover(scorefxn_in, task_in), mc_( mc_in ), energycut_( energycut_in )
222 {
223  protocols::moves::Mover::type( "EnergyCutRotamerTrialsMin" );
224  init();
225 }
226 
227 // constructor with arguments
229  ScoreFunctionCOP scorefxn_in,
230  TaskFactoryCOP factory_in,
232  core::Real energycut_in
233 ) : protocols::simple_moves::RotamerTrialsMinMover(scorefxn_in, factory_in), mc_( mc_in ), energycut_( energycut_in )
234 {
235  protocols::moves::Mover::type( "EnergyCutRotamerTrialsMin" );
236  init();
237 }
238 
240 
241 void
243 {
244  PackerTaskOP rottrial_task( task(pose) );
245  ( *scorefxn() )(pose);
246  setup_energycut_task( pose, *mc_, *rottrial_task );
247  /// This call is dangerous. If sequence or length has changed since task was created, it will crash.
248  /// Not a problem if you used a TaskFactory
249  core::pack::RTMin RTMin;
250  RTMin.rtmin( pose, *scorefxn(), rottrial_task );
251 }
252 
253 
256  return "EnergyCutRotamerTrialsMinMover";
257 }
258 
259 /// @details starting from a fresh task, it reduces the number of residues to be repacked to only
260 /// those whose energy has increased by energycut_ since the application of the last move.
261 void
263  core::pose::Pose const & pose,
264  protocols::moves::MonteCarlo const & mc,
266 ) const
267 {
268  using namespace core;
270 
271  //Size count_fixed( 0 ), count_repacked( 0 );
272 
273  task_in.restrict_to_repacking();
274 
275  for ( int i=1, i_end = pose.total_residue(); i<= i_end; ++i ) {
276  core::Real const resE ( pose.energies().residue_total_energies(i)[ total_score ] );
277  core::Real const lowest_resE( mc.lowest_score_pose().energies().residue_total_energies(i)[ total_score ] );
278  core::Real const deltaE ( resE - lowest_resE );
279  if ( deltaE < energycut_ ) {
281  //++count_fixed;
282  } else {
283  // let this residue be repacked
284  //++count_repacked;
285  }
286  }
287 }
288 
289 } // moves
290 } // protocols