Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PackRotamersMover.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 // AUTO-REMOVED #include <protocols/moves/DataMap.hh>
22 
28 // AUTO-REMOVED #include <core/pack/task/operation/TaskOperation.hh>
30 #include <core/pose/Pose.hh>
31 #include <core/pose/PDBInfo.hh>
34 #include <basic/options/option.hh>
35 #include <basic/Tracer.hh>
36 
37 // Utility Headers
38 #include <utility/exit.hh>
39 #include <utility/tag/Tag.hh>
40 // AUTO-REMOVED #include <utility/string_util.hh> // string_split
41 
42 // option key includes
43 #include <basic/options/keys/packing.OptionKeys.gen.hh>
44 
45 #include <utility/vector0.hh>
46 #include <utility/vector1.hh>
47 
48 
49 namespace protocols {
50 namespace simple_moves {
51 
52 using namespace core;
53  using namespace basic::options;
54  using namespace pack;
55  using namespace task;
56  using namespace operation;
57  using namespace scoring;
58 
59 using basic::Warning;
60 using basic::t_warning;
61 static basic::Tracer TR("protocols.simple_moves.PackRotamersMover");
62 
63 /// PackRotamersMover
64 
67 {
69 }
70 
73  return new PackRotamersMover;
74 }
75 
78 {
79  return "PackRotamersMover";
80 }
81 
83  protocols::moves::Mover("PackRotamersMover"),
84  scorefxn_(0),
85  task_(0),
86  nloop_( option[ OptionKeys::packing::ndruns ].value() ),
87  task_factory_(0),
88  rotamer_sets_( new rotamer_set::RotamerSets ),
89  ig_(0)
90 {}
91 
93  protocols::moves::Mover( type_name ),
94  scorefxn_(0),
95  task_(0),
96  nloop_( option[ OptionKeys::packing::ndruns ].value() ),
97  task_factory_(0),
98  rotamer_sets_( new rotamer_set::RotamerSets ),
99  ig_(0)
100 {}
101 
102  // constructors with arguments
104  ScoreFunctionCOP scorefxn,
105  PackerTaskCOP task,
106  Size nloop
107 ) :
108  protocols::moves::Mover("PackRotamersMover"),
109  scorefxn_( scorefxn ),
110  task_( task ),
111  nloop_( nloop ),
112  task_factory_(0),
113  rotamer_sets_( new rotamer_set::RotamerSets ),
114  ig_(0)
115 {}
116 
118 
120  //utility::pointer::ReferenceCount(),
121  protocols::moves::Mover( other )
122 {
123  scorefxn_ = other.score_function();
124  task_ = other.task();
125  nloop_ = other.nloop();
126  task_factory_ = other.task_factory();
127  rotamer_sets_ = new rotamer_set::RotamerSets;
128  ig_ = 0;
129 }
130 
131 void
133 {
134  // get rotamers, energies
135  // also performs lazy initialization of ScoreFunction, PackerTask
136  this->setup( pose );
137 
138  core::PackerEnergy best_energy(0.);
139  Pose best_pose;
140  best_pose = pose;
141  for ( Size run(1); run <= nloop_; ++run ) {
142  // run SimAnnealer
143  core::PackerEnergy packer_energy( this->run( pose ) );
144 // Real const score( scorefxn_( pose ) ); another option for deciding which is the 'best' result
145  if ( run == 1 || packer_energy < best_energy ) {
146  best_pose = pose;
147  best_energy = packer_energy;
148  }
149  }
150  if ( nloop_ > 1 ) pose = best_pose;
151 
152  //guaruntees proper scoring if this mover is used as a protocol (as in fixbb)
153  (*scorefxn_)(pose);
154  /// Now handled automatically. scorefxn_->accumulate_residue_total_energies(pose);
155 }
156 
160 }
161 
162 ///@brief when the PackerTask was not generated locally, verify compatibility with pose
163 ///@details the pose residue types must be equivalent to the ones used to generate the ResidueLevelTasks, because of the way that prevent_repacking and its associated flags work
164 bool
166 {
167  if ( task_->total_residue() != pose.total_residue() ) return false;
168  for ( Size i(1); i <= pose.total_residue(); ++i ) {
169  if ( ! task_->residue_task(i).is_original_type( &pose.residue_type(i) ) ) return false;
170  }
171  return true;
172 }
173 
174 void PackRotamersMover::parse_def( utility::lua::LuaObject const & def,
175  utility::lua::LuaObject const & score_fxns,
176  utility::lua::LuaObject const & tasks,
177  protocols::moves::MoverCacheSP /*cache*/ ) {
178  if( def["nloop"] ) {
179  nloop_ = def["nloop"].to<Size>();
180  runtime_assert( nloop_ > 0 );
181  }
182 
183  if( def["scorefxn"] ) {
184  score_function( protocols::elscripts::parse_scoredef( def["scorefxn"], score_fxns ) );
185  } else {
186  score_function( score_fxns["score12"].to<ScoreFunctionSP>()->clone() );
187  }
188  if( def["tasks"] ) {
189  TaskFactoryOP new_task_factory( protocols::elscripts::parse_taskdef( def["tasks"], tasks ));
190  if ( new_task_factory == 0) return;
191  task_factory( new_task_factory );
192  }
193 }
194 
195 ///@brief parse XML (specifically in the context of the parser/scripting scheme)
196 void
198  TagPtr const tag,
199  protocols::moves::DataMap & datamap,
200  Filters_map const & filters,
201  protocols::moves::Movers_map const & movers,
202  Pose const & pose
203 )
204 {
205  //fpd (commenting out below) classes derived from PackRotamers may call this function
206  //if ( tag->getName() != "PackRotamersMover" ) {
207  // TR(t_warning) << " received incompatible Tag " << tag << std::endl;
208  // assert(false);
209  // return;
210  //}
211  if ( tag->hasOption("nloop") ) {
212  nloop_ = tag->getOption<Size>("nloop",1);
213  runtime_assert( nloop_ > 0 );
214  }
215  parse_score_function( tag, datamap, filters, movers, pose );
216  parse_task_operations( tag, datamap, filters, movers, pose );
217 }
218 
219 ///@brief parse "scorefxn" XML option (can be employed virtually by derived Packing movers)
220 void
222  TagPtr const tag,
223  protocols::moves::DataMap const & datamap,
224  Filters_map const &,
226  Pose const &
227 )
228 {
229  ScoreFunctionOP new_score_function( protocols::rosetta_scripts::parse_score_function( tag, datamap ) );
230  if ( new_score_function == 0 ) return;
231  score_function( new_score_function );
232 }
233 
234 ///@brief parse "task_operations" XML option (can be employed virtually by derived Packing movers)
235 void
237  TagPtr const tag,
238  protocols::moves::DataMap const & datamap,
239  Filters_map const &,
241  Pose const &
242 )
243 {
244  TaskFactoryOP new_task_factory( protocols::rosetta_scripts::parse_task_operations( tag, datamap ) );
245  if ( new_task_factory == 0) return;
246  task_factory( new_task_factory );
247 }
248 
249 ///@brief required in the context of the parser/scripting scheme
252 {
253  return new PackRotamersMover;
254 }
255 
256 ///@brief required in the context of the parser/scripting scheme
259 {
260  return new protocols::simple_moves::PackRotamersMover( *this );
261 }
262 
263 ///@brief get rotamers, energies. Also performs lazy initialization of ScoreFunction, PackerTask.
265 {
266  // jec update_residue_neighbors() required to update EnergyGraph (ensures graph_state == GOOD) when calling Interface.cc
268  // guarantee of valid ScoreFunction and PackerTask postponed until now
269  if ( scorefxn_ == 0 ) {
270  Warning() << "undefined ScoreFunction -- creating a default one" << std::endl;
272  }
273 
274  // if present, task_factory_ always overrides/regenerates task_
275  if ( task_factory_ != 0 ) {
276  task_ = task_factory_->create_task_and_apply_taskoperations( pose );
277  } else if ( task_ == 0 ) {
278  Warning() << "undefined PackerTask -- creating a default one" << std::endl;
279  task_ = TaskFactory::create_packer_task( pose );
280  }
281  // in case PackerTask was not generated locally, verify compatibility with pose
282  else runtime_assert( task_is_valid( pose ) );
283 
284  note_packertask_settings( pose );
285 
287 
289 }
290 
292 {
293  return pack_rotamers_run( pose, task_, rotamer_sets_, ig_, rot_to_pack );
294 }
295 
296 ///@brief note PackerTask's packable and designable residues as string info
298 {
299  std::ostringstream packable, designable;
300  packable << "REMARK PackingRes";
301  designable << "REMARK DesignRes";
302 
303  for ( Size i(1), end( task_->total_residue() ); i <= end; ++i ) {
304  ResidueLevelTask const & rtask( task_->residue_task(i) );
305  if ( rtask.being_designed() ) {
306  designable << ", ";
307  if ( pose.pdb_info() ) {
308  designable << pose.pdb_info()->number(i) << " " << pose.pdb_info()->chain(i);
309  } else {
310  designable << i;
311  }
312  } else if ( rtask.being_packed() ) {
313  packable << ", ";
314  if ( pose.pdb_info() ) {
315  packable << pose.pdb_info()->number(i) << " " << pose.pdb_info()->chain(i);
316  } else {
317  packable << i;
318  }
319  }
320  }
321  info().clear();
322  info().push_back( packable.str() );
323  info().push_back( designable.str() );
324 }
325 
326 // setters
328 {
329  runtime_assert( sf );
330  scorefxn_ = sf;
331 }
333 
335 {
336  runtime_assert( tf );
337  task_factory_ = tf;
338 }
339 
340 void PackRotamersMover::nloop( Size nloop_in ) { nloop_ = nloop_in; }
341 
342 // accessors
348 
349 std::ostream &operator<< (std::ostream &os, PackRotamersMover const &mover)
350 {
351  moves::operator<<(os, mover);
352  if ( mover.score_function() != 0 ) {
353  os << "Score function: " << mover.score_function()->get_name() << std::endl;
354  }
355  else { os << "Score function: none" << std::endl; }
356 
357  return os;
358 }
359 
360 } // moves
361 } // protocols
362