Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
StepWiseProteinCCD_Closer.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 StepWiseProteinCCD_Closer
11 /// @brief Makes a list of (phi, psi, omega) at moving_residues that
12 /// could be useful for full-atom packing
13 /// @detailed
14 /// @author Rhiju Das
15 
16 
17 //////////////////////////////////
19 // AUTO-REMOVED #include <protocols/swa/protein/StepWiseProteinUtil.hh>
21 // AUTO-REMOVED #include <protocols/swa/InputStreamWithResidueInfo.hh>
22 
23 //////////////////////////////////
24 #include <core/types.hh>
25 // AUTO-REMOVED #include <core/chemical/util.hh>
26 // AUTO-REMOVED #include <core/chemical/ChemicalManager.hh>
28 #include <core/id/AtomID.hh>
29 #include <core/id/TorsionID.hh>
30 // AUTO-REMOVED #include <core/io/silent/ProteinSilentStruct.hh>
31 // AUTO-REMOVED #include <core/io/silent/SilentFileData.hh>
32 // AUTO-REMOVED #include <core/io/silent/SilentFileData.fwd.hh>
33 #include <core/pose/Pose.hh>
34 // AUTO-REMOVED #include <core/scoring/Energies.hh>
35 // AUTO-REMOVED #include <core/scoring/rms_util.tmpl.hh>
36 // AUTO-REMOVED #include <core/scoring/ScoreFunction.hh>
37 // AUTO-REMOVED #include <core/scoring/ScoreFunctionFactory.hh>
38 // AUTO-REMOVED #include <core/scoring/Ramachandran.hh>
39 #include <basic/Tracer.hh>
40 #include <core/kinematics/Jump.hh>
41 
42 #include <protocols/loops/Loop.hh>
44 
45 // AUTO-REMOVED #include <ObjexxFCL/format.hh>
46 // AUTO-REMOVED #include <ObjexxFCL/string.functions.hh>
47 #include <ObjexxFCL/FArray1D.hh>
48 
49 #include <utility/exit.hh>
50 
51 #ifdef WIN32
52 #include <time.h>
53 #endif
54 
55 #include <string>
56 
57 //Auto Headers
60 #include <utility/vector1.hh>
61 
62 
63 using namespace core;
64 using core::Real;
65 
66 //////////////////////////////////////////////////////////////////////////
67 // CCD loop closure. Applied to loops whose N-terminal
68 // and C-terminal segment have been modeled in, e.g., different silent
69 // files.
70 //
71 // Later, should sample omega recursively for pre-prolines.
72 //////////////////////////////////////////////////////////////////////////
73 
74 static basic::Tracer TR( "protocols.swa.protein.stepwise_protein_ccd_closer" );
75 
76 namespace protocols {
77 namespace swa {
78 namespace protein {
79 
80  //////////////////////////////////////////////////////////////////////////
81  //constructor!
82  StepWiseProteinCCD_Closer::StepWiseProteinCCD_Closer( StepWisePoseSampleGeneratorOP sample_generator,
83  StepWiseJobParametersOP job_parameters ):
84  Mover(),
85  sample_generator_( sample_generator ),
86  working_bridge_res_( job_parameters->working_bridge_res() ),
87  moving_residues_( job_parameters->working_moving_res_list() ),
88  is_pre_proline_( job_parameters->is_pre_proline() ),
89  ccd_close_res_( 0 ),
90  verbose_( true )
91  {
92  Mover::type("StepWiseProteinCCD_Closer");
93  if ( working_bridge_res_.size() >= 3 ) utility_exit_with_message( "Cannot supply more than 2 bridge residues");
94  }
95 
96  //////////////////////////////////////////////////////////////////////////
97  //destructor
99  {}
100 
101  /////////////////////
104  return "StepWiseProteinCCD_Closer";
105  }
106 
107  //////////////////////////////////////////////////////////////////////////
108  //////////////////////////////////////////////////////////////////////
109  void
111  {
112 
113  clock_t const time_start( clock() );
114 
115  Pose pose_save = pose;
116 
117  setup_torsions( pose );
118 
119  figure_out_loop( pose );
120 
121  sample_generator_->reset();
122 
123  pose_count_ = 0;
124  while ( sample_generator_->has_another_sample() ){
125 
126  sample_generator_->get_next_sample( pose );
127 
128  save_phi_psi_omega_over_loop_residues( pose ); // trying to avoid memory effects, where solutions will depend on order of when processed.
129  CCD_loop_close_sample_omega_recursively( pose, 0 /*offset*/ );
131 
132  }
133 
134  Size const num_successes = main_chain_torsion_sets_for_moving_residues_.size();
135  std::cout << "CCD closed: " << num_successes << " out of " << pose_count_ << " tries." << std::endl;
136 
137  // Kind of silly -- should have at least one output.
138  if ( num_successes == 0 ) grab_main_chain_torsion_set_list( pose );
139 
140  std::cout << "Total time in StepWiseProteinCCD_Closer: " <<
141  static_cast<Real>(clock() - time_start) / CLOCKS_PER_SEC << std::endl;
142 
143  pose = pose_save;
144 
145  }
146 
147 
148 
149  ///////////////////////////////////////////////////////////////////////////
150  bool
152 
153  // param for ccd_closure
154  int const ccd_cycles = { 1000 }; // num of cycles of ccd_moves
155  Real const ccd_tol = { 0.001 }; // criterion for a closed loop
156  bool const rama_check = { true };
157  Real const max_rama_score_increase = { 100.0 }; // dummy number when rama_check is false
158  Real const max_total_delta_helix = { 100.0 }; // max overall angle changes for a helical residue
159  Real const max_total_delta_strand = { 500.0 }; // ... for a residue in strand
160  Real const max_total_delta_loop = { 3600.0 }; // ... for a residue in loop
161  // cutoff for acceptance
162  Real const rmsd_acceptance_cutoff = 1.5; // can be a little relaxed, since there will be a minimize afterwards.
163  // output for ccd_closure
164  Real forward_deviation, backward_deviation; // actually loop closure msd, both dirs
165  Real torsion_delta, rama_delta; // actually torsion and rama score changes, averaged by loop_size
166 
168  pose, mm_, loop_.start() , loop_.stop(), loop_.cut(), ccd_cycles,
169  ccd_tol, rama_check, max_rama_score_increase, max_total_delta_helix,
170  max_total_delta_strand, max_total_delta_loop, forward_deviation,
171  backward_deviation, torsion_delta, rama_delta
172  );
173 
174  pose_count_++;
175 
176 
177  TR << "CCD forward_dev: " << forward_deviation << " backward_dev: " << backward_deviation << " torsion_delta: " << torsion_delta << " rama_delta: " << rama_delta << std::endl;
178  if ( forward_deviation > rmsd_acceptance_cutoff || backward_deviation > rmsd_acceptance_cutoff ) return false;
179 
181 
182  return true;
183 
184  }
185 
186 
187  ///////////////////////////////////////////////////////////////////////////
188  void
190 
191  restore_phi_psi_over_loop_residues( pose ); // don't restore omega, since we'll be switching it around.
192 
193  //loop starts at position before cutpoint, ends after.
194  Size const omega_pos = loop_.start() + offset;
195 
196  if ( omega_pos == loop_.stop() ){
197 
198  CCD_loop_close( pose );
199 
200  } else {
201 
202  pose.set_omega( omega_pos, 180.0 );
203  CCD_loop_close_sample_omega_recursively( pose, offset + 1 );
204 
205  if ( is_pre_proline_[ omega_pos ] ){
206  pose.set_omega( omega_pos, 0.0 );
207  TR << "trying CIS omega! " << omega_pos << std::endl;
208  CCD_loop_close_sample_omega_recursively( pose, offset + 1 );
209  }
210 
211  }
212  }
213 
214 
215 
216  //////////////////////////////////////////////////////////////////////////////////////////////
217  // note 'loop' includes takeoff and end points
218  // movemap will ensure that we only sample psi of N-terminal takeoff, and phi of C-terminal landing.
219  void
221 
222  using namespace protocols::loops;
223  using namespace core::chemical;
224  using namespace core::id;
225 
226  Size loop_start( 0 ), loop_end( 0 ), cutpoint( 0 );
227 
228  Size const num_bridge_res = working_bridge_res_.size();
229 
230  if ( ccd_close_res_ > 0 ) {
231 
232  cutpoint = ccd_close_res_;
233  if ( !pose.residue_type( cutpoint ).has_variant_type( CUTPOINT_LOWER ) ||
234  !pose.residue_type( cutpoint+1 ).has_variant_type( CUTPOINT_UPPER ) ) utility_exit_with_message( "ccd_close_res needs to be specified as a cutpoint_closed!" );
235 
236  } else {
237 
238  // find the cutpoint...
239  for ( Size n = 1; n <= pose.total_residue() ; n++ ){
240 
241  if ( num_bridge_res > 0 && ( (n < working_bridge_res_[1]-1) || (n > working_bridge_res_[num_bridge_res] ) ) ) continue;
242 
243  if ( pose.residue_type( n ).has_variant_type( CUTPOINT_LOWER ) &&
245  if ( cutpoint > 0 ) utility_exit_with_message( "Cannot specify more than one closed cutpoint inside the bridge_residues in StepWiseProteinCCD_Closer! Consider using -ccd_close_res to specify, or else stick to one cutpoint_closed." );
246  cutpoint = n;
247  }
248  }
249 
250  }
251 
252  if ( cutpoint == 0 ) utility_exit_with_message( "Must specify one closed cutpoint within bridge_res in StepWiseProteinCCD_Closer!" );
253 
254  if ( num_bridge_res == 0 ) {
255  // could be just twiddling torsions at cutpoint.
256  loop_start = cutpoint;
257  loop_end = cutpoint+1;
258  } else {
259  loop_start = working_bridge_res_[1]-1;
260  loop_end = working_bridge_res_[num_bridge_res]+1;
261  }
262 
263  if ( cutpoint < loop_start || cutpoint >= loop_end ) utility_exit_with_message( "cutpoint must lie within loop" );
264 
265  loop_ = Loop( loop_start, loop_end, cutpoint );
266 
267  // set up movemap.
268  mm_.clear();
269  mm_.set( TorsionID( loop_start, id::BB, 2 ), true );
270  for ( Size n = loop_start+1; n <= loop_end-1; n++ ){
271  mm_.set( TorsionID( n, id::BB, 1 ), true );
272  mm_.set( TorsionID( n, id::BB, 2 ), true );
273  }
274  mm_.set( TorsionID( loop_end, id::BB, 1 ), true );
275 
276  }
277 
278 
279 
280  //////////////////////////////////////////////////////////////////////////////////////////////
281  void
283 
284  // Need to fill torsions for moving and bridge residues.
285 
286  using namespace core::id;
287 
288  utility::vector1< bool > is_moving_or_bridge_res( pose.total_residue(), false );
289 
290  for ( Size n = 1; n <= moving_residues_.size(); n++ ) {
291  is_moving_or_bridge_res[ moving_residues_[n] ] = true;
292  }
293 
294  for ( Size n = 1; n <= working_bridge_res_.size(); n++ ) {
295  is_moving_or_bridge_res[ working_bridge_res_[n] ] = true;
296  }
297 
298  which_torsions_.clear();
299  for ( Size n = 1; n <= pose.total_residue(); n++ ){
300 
301  if ( is_moving_or_bridge_res[ n ] ) {
302 
303  //save phi,psi,omega inside loop
304  for ( Size k = 1; k <= 3; k++ ) which_torsions_.push_back( TorsionID( n, BB, k ) );
305 
306  } else if ( n < pose.total_residue() && is_moving_or_bridge_res[ n+1 ] ) {
307 
308  //save psi,omega at 'takeoff' residue.
309  for ( Size k = 2; k <= 3; k++ ) which_torsions_.push_back( TorsionID( n, BB, k ) );
310 
311  } else if ( n > 1 && is_moving_or_bridge_res[ n-1 ] ) {
312 
313  //save phi at 'landing' residue.
314  for ( Size k = 1; k <= 1; k++ ) which_torsions_.push_back( TorsionID( n, BB, k ) );
315 
316  }
317 
318  }
319 
320  }
321 
322 
323  //////////////////////////////////////////////////////////////////////////
324  void
326 
327  utility::vector1< Real > main_chain_torsion_set_for_moving_residues;
328  for ( Size n = 1; n <= which_torsions_.size(); n++ ) {
329  main_chain_torsion_set_for_moving_residues.push_back( pose.torsion( which_torsions_[ n ] ) );
330  }
331  main_chain_torsion_sets_for_moving_residues_.push_back( main_chain_torsion_set_for_moving_residues );
332 
333  }
334 
335  //////////////////////////////////////////////////////////////////////////
338  {
340  }
341 
342  //////////////////////////////////////////////////////////////////////////
345  {
346  return which_torsions_;
347  }
348 
349 
350  //////////////////////////////////////////////////////////////////////////
351  void
353  {
354  for ( Size n = 1; n <= which_torsions_.size(); n++ ) {
356  }
357  }
358 
359  //////////////////////////////////////////////////////////////////////////
360  void
362  {
363  for ( Size n = 1; n <= which_torsions_.size(); n++ ) {
364  if ( which_torsions_[n].torsion() > 2 ) continue; // phi, psi, but not omega
366  }
367  }
368 
369  //////////////////////////////////////////////////////////////////////////
370  void
373  for ( Size n = 1; n <= which_torsions_.size(); n++ ) {
375  }
376  }
377 
378 
379 
380 }
381 }
382 }