Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RotamerTrialsMover.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 Monica Berrondo
13 /// @author Modified by Sergey Lyskov
14 
15 // Unit headers
18 
19 // Project headers
20 #include <core/pose/Pose.hh>
21 #include <core/scoring/Energies.hh>
25 // AUTO-REMOVED #include <core/pack/task/operation/TaskOperation.hh>
27 
30 
31 
33 
34 
35 // Parser headers
37 #include <utility/tag/Tag.hh>
38 
39 // Utility Headers
40 #include <basic/Tracer.hh>
41 // AUTO-REMOVED #include <utility/string_util.hh>
42 
43 #include <utility/vector0.hh>
44 #include <utility/vector1.hh>
45 
46 
47 
48 using basic::T;
49 using basic::Error;
50 using basic::Warning;
51 
52 static basic::Tracer TR("protocols.simple_moves.RotamerTrialsMover");
53 
54 namespace protocols {
55 namespace simple_moves {
56 
60 }
61 
64  return new RotamerTrialsMover;
65 }
66 
69  return "RotamerTrialsMover";
70 }
71 
72 // default constructor
74 {
75  protocols::moves::Mover::type( "RotamerTrials" );
76 }
77 
78 // constructor with arguments
80  ScoreFunctionCOP scorefxn_in,
81  PackerTask & task_in
82 ) : protocols::moves::Mover(), scorefxn_( scorefxn_in ), factory_( NULL ), show_packer_task_( false )
83 {
84  protocols::moves::Mover::type( "RotamerTrials" );
85  task_ = task_in.clone();
86 }
87 
88 // constructor with arguments
90  ScoreFunctionCOP scorefxn_in,
91  TaskFactoryCOP factory_in
92 ) : protocols::moves::Mover(), scorefxn_( scorefxn_in ), task_( NULL ), factory_( factory_in ), show_packer_task_( false )
93 {
94  protocols::moves::Mover::type( "RotamerTrials" );
95 }
96 
97 // copy constructor
99  //utility::pointer::ReferenceCount(),
100  protocols::moves::Mover( rval ),
101  scorefxn_( rval.scorefxn_ ),
102  task_( rval.task_ ),
103  factory_( rval.factory_ ),
104  show_packer_task_( rval.show_packer_task_ )
105 {}
106 
107 // destructor
109 
110 // clone this object
113 {
115 }
116 
117 // create this type of object
120 {
122 }
123 
124 // setters
127 
128 void
130 {
131  //task() contains the call to the TaskFactory
132  //TR << *(task(pose)) << std::flush;
133  PackerTaskCOP ptask = task( pose );
134  if( show_packer_task_ ) {
135  TR << *ptask;
136  }
137  core::pack::rotamer_trials( pose, *scorefxn_, ptask );
138 }
139 
142  return "RotamerTrialsMover";
143 }
144 
145 /// @brief read access for derived classes
148 {
149  return scorefxn_;
150 }
151 
152 /// @brief read access for derived classes
155 {
156  //if we have a factory, generate and return a new task
157  if(factory_) return factory_->create_task_and_apply_taskoperations( pose );
158  //else runtime_assert( task_is_valid( pose ) );
159 
160  //else return the unsafe one
161  return task_;
162 }
163 
164 /// @brief parse xml
165 void
167  TagPtr const tag,
169  Filters_map const &,
171  Pose const & )
172 {
173  typedef std::string String;
178 
179  String const scorefxn ( tag->getOption<String>( "scorefxn", "score12" ));
180  scorefxn_ = data.get< ScoreFunction * >( "scorefxns", scorefxn );
181  show_packer_task_ = tag->getOption<bool>( "show_packer_task", 0 );
183 }
184 
185 std::ostream &operator<< (std::ostream &os, RotamerTrialsMover const &mover)
186 {
187  moves::operator<<(os, mover);
188  if ( mover.scorefxn() != 0 ) {
189  os << "Score function: " << mover.scorefxn()->get_name() << std::endl;
190  }
191  else { os << "Score function: none" << std::endl; }
192 
193  return os;
194 }
195 
196 // default constructor
198  protocols::simple_moves::RotamerTrialsMover()
199 {
200  protocols::moves::Mover::type( "EnergyCutRotamerTrials" );
201 }
202 
203 // constructor with arguments
205  ScoreFunctionCOP scorefxn_in,
206  PackerTask & task_in,
208  core::Real energycut_in
209 ) : protocols::simple_moves::RotamerTrialsMover(scorefxn_in, task_in), mc_( mc_in ), energycut_( energycut_in )
210 {
211  protocols::moves::Mover::type( "EnergyCutRotamerTrials" );
212 }
213 
214 // constructor with arguments
216  ScoreFunctionCOP scorefxn_in,
217  TaskFactoryCOP factory_in,
219  core::Real energycut_in
220 ) : protocols::simple_moves::RotamerTrialsMover(scorefxn_in, factory_in), mc_( mc_in ), energycut_( energycut_in )
221 {
222  protocols::moves::Mover::type( "EnergyCutRotamerTrials" );
223 }
224 
226 
227 void
229 {
230  PackerTaskOP rottrial_task( task(pose)->clone() );
231  ( *scorefxn() )(pose);
232  /// Now handled automatically. scorefxn()->accumulate_residue_total_energies( pose );
233  setup_energycut_task( pose, *mc_, *rottrial_task );
234  /// This call is dangerous. If sequence or length has changed since task was created, it will crash.
235  /// Not a problem if you used a TaskFactory
236  core::pack::rotamer_trials( pose, *scorefxn(), rottrial_task );
237 }
238 
241  return "EnergyCutRotamerTrialsMover";
242 }
243 
244 
245 /// @details starting from a fresh task, it reduces the number of residues to be repacked to only
246 /// those whose energy has increased by energycut_ since the application of the last move.
247 void
249  core::pose::Pose const & pose,
250  protocols::moves::MonteCarlo const & mc,
252 ) const
253 {
254  using namespace core;
256 
257  //Size count_fixed( 0 ), count_repacked( 0 );
258 
259  task_in.restrict_to_repacking();
260 
261  for ( int i=1, i_end = pose.total_residue(); i<= i_end; ++i ) {
262  core::Real const resE ( pose.energies().residue_total_energy(i) );
263  core::Real const lowest_resE( mc.lowest_score_pose().energies().residue_total_energy(i) );
264  core::Real const deltaE ( resE - lowest_resE );
265  if ( deltaE < energycut_ ) {
267  //++count_fixed;
268  } else {
269  // let this residue be repacked
270  //++count_repacked;
271  }
272  }
273 }
274 // protected accessor function for derived mover
277 {
278  return mc_;
279 }
280 
281 } // moves
282 } // protocols