Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
LoopMover.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 protocols/loops/loop_mover/LoopMover.cc
11 /// @brief loop mover base class
12 /// @author Mike Tyka
13 
14 // Unit headers
16 
17 // Package Headers
18 #include <protocols/loops/Loop.hh>
19 #include <protocols/loops/Loops.hh>
22 
26 #include <core/pose/Pose.hh>
27 #include <basic/Tracer.hh> // tracer output
28 
29 #include <core/fragment/FragSet.hh>
30 
32 
35 
36 #include <utility/vector1.hh>
37 
38 #include <basic/options/option.hh>
39 #include <basic/options/keys/loops.OptionKeys.gen.hh>
40 
41 //Utility Headers
42 
43 // AS -- to get access to get_torsion_bin()
45 
46 /// ObjexxFCL headers
47 // AUTO-REMOVED #include <ObjexxFCL/string.functions.hh>
48 
49 // C++ Headers
50 #include <iostream>
51 #include <map>
52 #include <string>
53 #if defined(WIN32) || defined(__CYGWIN__)
54  #include <ctime>
55 #endif
56 // option key includes
57 // AUTO-REMOVED #include <basic/options/keys/loops.OptionKeys.gen.hh>
58 
59 // AUTO-REMOVED #include <basic/options/option.hh>
60 #include <numeric/random/random.hh>
61 
62 //Auto Headers
63 
64 // AUTO-REMOVED #include <ObjexxFCL/format.hh>
65 
66 // Auto-header: duplicate removed #include <utility/vector1.hh>
67 
68 //Auto using namespaces
69 namespace ObjexxFCL { namespace fmt { } } using namespace ObjexxFCL::fmt; // AUTO USING NS
70 //Auto using namespaces end
71 
72 
73 
74 
75 
76 namespace protocols {
77 namespace loops {
78 namespace loop_mover {
79 
80 ///////////////////////////////////////////////////////////////////////////////
81 using namespace core;
82 using namespace ObjexxFCL;
83 using namespace ObjexxFCL::fmt;
84 
85 LoopMover::LoopMover() :
86  Mover(),
87  guarded_loops_( new GuardedLoopsFromFile )
88 {
89  init();
90 }
91 
92 /// @details GuardedLoops constructed with a pointer to a loops object:
93 /// sets the GuardedLoops object into it's "not in charge" mode; i.e.
94 /// the external source of the LoopsOP is responsible for resolving loop indices
96 :
97  Mover(),
98  guarded_loops_( new GuardedLoopsFromFile( loops_in ))
99 {
100  init();
101 }
102 
103 /// @details GuardedLoops constructed with an unresolve-loop-indices object:
104 /// sets the GuardedLoops object into it's "in charge" mode; i.e.
105 /// before the loops object may be used, the loop indices must be resolved.
107  Mover(),
108  guarded_loops_( new GuardedLoopsFromFile( loops_from_file ))
109 {
110  init();
111 }
112 
114  Mover(),
115  guarded_loops_( guarded_loops )
116 {
117  init();
118 }
119 
120 
122 {
123  Mover::type( "LoopMover" );
125  checkpoints_ = new checkpoint::CheckPointer( "LoopMover" );
127 }
128 
129 // destructor
131 
132 void
134 {
135  guarded_loops_->in_charge( false );
136 }
137 
138 
139 //////////////////////////////////////////////////////////////////////////////////
140 
141 // accessors //
142 
144 {
145  scorefxn_ = score_in;
146 }
147 
149 {
150  return scorefxn_;
151 }
152 
154 {
155  // pointer assignment
156  guarded_loops_->set_loops_pointer( lptr );
157 }
158 
160 {
161  // pointer assignment
162  guarded_loops_->loops( loops );
163 }
164 
165 /// @brief Set the guarded_loops pointer
167 {
168  guarded_loops_ = guarded_loops;
169 }
170 
172 {
173  return guarded_loops_->loops();
174 }
175 
177 {
178  return guarded_loops_->loops();
179 }
180 
181 
182 
184 {
185  return frag_libs_;
186 }
187 
188 void LoopMover::set_use_loops_from_observer_cache( bool const loops_from_observer_cache )
189 {
190  loops_from_observer_cache_ = loops_from_observer_cache;
191 }
192 
194 {
196 }
197 
199 {
200  return checkpoints_;
201 }
202 
204 {
205  false_movemap_ = mm;
206 }
207 
209 {
210  return false_movemap_;
211 }
212 
213 // end of accessors
214 
215 // Additional MoveMap method
217 {
218  return mm->import_false( *false_movemap() );
219 }
220 
221 
222 /// @details Set a loop to extended torsion angles.
224  core::pose::Pose & pose,
225  Loop const & loop
226 )
227 {
228  Real const init_phi ( -150.0 );
229  Real const init_psi ( 150.0 );
230  Real const init_omega( 180.0 );
231 
232  static int counter = 0;
233 
234  tr().Debug << "Extending loop torsions" << loop.start() << " " << loop.stop()
235  << std::endl;
236 
237  idealize_loop(pose, loop );
238 
239  Size start_extended = std::max((Size)1,loop.start());
240  Size end_extended = std::min(pose.total_residue(),loop.stop());
241  for ( Size i = start_extended; i <= end_extended; ++i ) {
242  if ( i != start_extended ) pose.set_phi( i, init_phi );
243  if ( i != end_extended ) pose.set_psi( i, init_psi );
244  if ( ( i != start_extended ) && ( i != end_extended ) ) pose.set_omega( i, init_omega );
245  }
246 
247  counter++;
248 }
249 
252  return "LoopMover";
253 }
254 
257 ) {
258  if ( fragset->size() > 0 ) {
259  frag_libs_.push_back( fragset->clone() );
260  }
261 }
262 
264  frag_libs_.clear();
265 }
266 
267 void
269 
271  LoopsOP loops = new Loops();
273  for( core::Size i = 1; i <= segments.size(); ++i ){
274  core::Size loop_end = segments[i].second - 1; //segment convention
275  if( loop_end <= segments[i].first ) continue; //safeguard against faulty or segments of length 1
276  tr() << "Setting loop from observer cache between seqpos " << segments[i].first << " and " << loop_end << "." << std::endl;
277  loops->add_loop( segments[i].first, loop_end, numeric::random::random_range( int(segments[i].first), int(loop_end) ) );
278  }
279  guarded_loops_->loops( *loops ); // <--- deep copy into the GuardedLoops existing Loops object
280  }
281  else{
282  utility_exit_with_message("trying to set loops from observer cache even though no cache was detected in the pose");
283  }
284 }
285 
286 
287 // Used by both LoopMover_Refine_KIC and LoopMover_Perturb_KIC - maybe it should be there, then?
288 void
290  bool const use_linear_chainbreak( basic::options::option[basic::options::OptionKeys::loops::kic_use_linear_chainbreak]() );
291  if ( use_linear_chainbreak ){
292  scorefxn->set_weight( core::scoring::linear_chainbreak, float( round ) * 150.0 / 3.0 );
293  scorefxn->set_weight( core::scoring::chainbreak, 0.0 );
294  } else { // default behavior.
295  scorefxn->set_weight( core::scoring::chainbreak, float(round) * 10.0 / 3.0 );
296  }
297 }
298 
299 ///@brief copy ctor
301  Mover(rhs)
302 {
304 }
305 
306 ///@brief assignment operator
308  //abort self-assignment
309  if (this == &rhs) return *this;
310 
311  Mover::operator=(rhs);
313  return *this;
314 }
315 
317  //going through all of member data and assigning it
318  lhs.guarded_loops_ = rhs.guarded_loops_; // shallow copy of the guarded_loops_ pointer.
319  lhs.scorefxn_ = rhs.scorefxn_;
320  lhs.frag_libs_ = rhs.frag_libs_;
321  lhs.checkpoints_ = rhs.checkpoints_;
323  lhs.false_movemap_ = rhs.false_movemap_;
324 }
325 
327 {
328  guarded_loops_->resolve_loop_indices( p );
329 }
330 
331 ///@brief bin torsion angles as described in http://www.ncbi.nlm.nih.gov/pubmed/19646450
332 ///@detail generates a string with the torsion angle bins, using uppercase letters as in the publication above for omega ~ 180, and lowercase letters for omega ~ 0; to be used in loop sampling analysis
333 ///@author Amelie Stein
334 ///@date April 26, 2012
336 {
337  std::string torsion_bins, pos_bin;
338 
339  // currently this generates one string for all loops, so the user has to map the positions -- alternatively one could return a vector of torsion feature strings or some other more complex construct
340  // note: won't work properly for multiple loops at the moment -- TODO
341  for ( Loops::const_iterator it=loops()->begin(), it_end=loops()->end(); it != it_end; ++it ) {
342  if (torsion_bins != "") {
343  torsion_bins += "-"; // next loop
344  }
345  for ( core::Size i = it->start(), l_end = it->stop(); i <= l_end; i++ ) {
346  torsion_bins += core::conformation::get_torsion_bin(pose.phi(i), pose.psi(i), pose.omega(i));
347  //std::cerr << i << " " << pose.phi(i) << " " << pose.psi(i) << " " << pose.omega(i) << " " << torsion_bins << std::endl; // debugging
348  }
349  }
350 
351  return torsion_bins;
352 
353 } // torsion_features_string
354 
355 } // namespace loop_mover
356 } // namespace loops
357 } // namespace protocols