Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
StepWiseProteinResidueSampler.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 StepWiseProteinResidueSampler
11 /// @brief Not particularly fancy, just minimizes a list of poses.
12 /// @detailed
13 /// @author Rhiju Das
14 
15 
16 //////////////////////////////////
19 
20 //////////////////////////////////
21 // AUTO-REMOVED #include <core/kinematics/FoldTree.hh>
22 #include <core/kinematics/Jump.hh>
23 #include <core/kinematics/RT.hh>
24 #include <core/types.hh>
30 #include <core/pose/Pose.hh>
31 
32 #include <core/pose/util.hh>
33 // AUTO-REMOVED #include <core/scoring/rms_util.tmpl.hh>
37 // AUTO-REMOVED #include <core/scoring/Ramachandran.hh>
38 #include <core/scoring/Energies.hh>
39 #include <core/id/AtomID.hh>
40 #include <core/id/NamedAtomID.hh>
41 #include <core/id/DOF_ID.hh>
44 #include <basic/Tracer.hh>
45 
46 //GreenPacker
49 
50 // AUTO-REMOVED #include <numeric/angle.functions.hh>
51 
52 // AUTO-REMOVED #include <ObjexxFCL/format.hh>
53 #include <ObjexxFCL/string.functions.hh>
54 #include <ObjexxFCL/FArray1D.hh>
55 
56 #include <utility/exit.hh>
57 // AUTO-REMOVED #include <time.h>
58 
59 #include <string>
60 
61 //Auto Headers
62 #include <core/id/TorsionID.hh>
63 #include <utility/vector0.hh>
64 #include <utility/vector1.hh>
65 
66 //Auto using namespaces
67 namespace ObjexxFCL { } using namespace ObjexxFCL; // AUTO USING NS
68 //Auto using namespaces end
69 
70 
71 using namespace core;
72 using core::Real;
73 
74 //////////////////////////////////////////////////////////////////////////
75 //////////////////////////////////////////////////////////////////////////
76 // Core routine for stepwise sampling of proteins (and probably other
77 // biopolymers soon). Take a starting pose and a list of residues to sample,
78 // and comprehensively sample all backbone torsion angles by recursion.
79 //////////////////////////////////////////////////////////////////////////
80 //////////////////////////////////////////////////////////////////////////
81 //////////////////////////////////////////////////////////////////////////
82 
83 static basic::Tracer TR( "protocols.swa.stepwise_residue_sampler" ) ;
84 
85 namespace protocols {
86 namespace swa {
87 namespace protein {
88 
89  //////////////////////////////////////////////////////////////////////////
90  //constructor!
91  StepWiseProteinResidueSampler::StepWiseProteinResidueSampler(
92  utility::vector1< Size > const & moving_residues,
93  utility::vector1< core::id::TorsionID > const & which_torsions,
94  utility::vector1< utility::vector1< core::Real > > const & main_chain_torsion_set_lists ):
95  moving_residues_( moving_residues ),
96  which_torsions_( which_torsions ),
97  main_chain_torsion_set_lists_( main_chain_torsion_set_lists ),
98  scorefxn_( core::scoring::getScoreFunction() ),
99  green_packer_( new protocols::simple_moves::GreenPacker ),
100  use_green_packer_( false ),
101  use_packer_instead_of_rotamer_trials_( false ),
102  pack_at_neighbors_only_( true ),
103  do_prepack_( false ),
104  silent_file_( "" ),
105  sfd_( new core::io::silent::SilentFileData),
106  which_jump_( 0 )
107  {
108  }
109 
111  utility::vector1< Size > const & moving_residues,
112  utility::vector1< core::id::TorsionID > const & which_torsions,
113  utility::vector1< utility::vector1< core::Real > > const & main_chain_torsion_set_lists,
114  Size const which_jump,
116  moving_residues_( moving_residues ),
117  which_torsions_( which_torsions ),
118  main_chain_torsion_set_lists_( main_chain_torsion_set_lists ),
119  scorefxn_( core::scoring::getScoreFunction() ),
120  green_packer_( new protocols::simple_moves::GreenPacker ),
121  use_green_packer_( false ),
122  use_packer_instead_of_rotamer_trials_( false ),
123  pack_at_neighbors_only_( true ),
124  do_prepack_( false ),
125  silent_file_( "" ),
126  sfd_( new core::io::silent::SilentFileData),
127  which_jump_( which_jump ),
128  jumps_( jumps )
129  {
130  if ( which_torsions.size() == 0 ){
131  for ( Size n = 1; n <= jumps_.size(); n++ ) {
132  utility::vector1< core::Real > dummy_main_chain_torsion_set;
133  main_chain_torsion_set_lists_.push_back( dummy_main_chain_torsion_set );
134  }
135  }
136  }
137 
138  //////////////////////////////////////////////////////////////////////////
139  //destructor
141  {}
142 /////////////////////
145 return "StepWiseProteinResidueSampler";
146 }
147 
148 
149  //////////////////////////////////////////////////////////////////////////
150  //////////////////////////////////////////////////////////////////////
151  void
153  {
154 
155  //Size which_res( 1 );
156  // Size count( 1 );
157 
158  clock_t const time_start( clock() );
159 
160  if ( use_green_packer_ ) {
162  } else {
164  }
165 
166  sample_residues( pose );
167 
168  std::cout << "Total time in StepWiseProteinResidueSampler: " << static_cast<Real>( clock() - time_start ) / CLOCKS_PER_SEC << std::endl;
169 
170  }
171 
172 
173  ////////////////////////////////////////////////////////////////////////////
174  void
176  {
177 
178  using namespace core::chemical;
179  using namespace core::scoring;
180  using namespace core::pose;
181  using namespace core::kinematics;
182 
183  for ( Size k = 1; k <= main_chain_torsion_set_lists_.size(); k++ ) {
184 
185  utility::vector1< Real > const & main_chain_torsion_set_list( main_chain_torsion_set_lists_[ k ] );
186 
187  assert( main_chain_torsion_set_list.size() == which_torsions_.size() );
188 
189  for ( Size i = 1; i <= which_torsions_.size(); i++ ) {
190  pose.set_torsion( which_torsions_[ i ], main_chain_torsion_set_list[ i ] );
191  }
192 
193  if ( which_jump_ > 0 ) pose.set_jump( which_jump_, jumps_[ k ] );
194 
195  std::string const tag = "S_"+ lead_zero_string_of( k-1, 5 );
196  std::cout << " Decoy " << tag << " : " << k << " out of " << main_chain_torsion_set_lists_.size() << std::endl;
197 
198  if ( use_green_packer_ ) {
199  green_packer_->apply( pose );
200  } else {
201  apply_regular_packer( pose );
202  }
203 
204  (*scorefxn_)( pose );
205 
207  calc_rms_res_ );
208 
209  }
210 
211  if (sfd_->size() == 0 ){ //perhaps just did a prepack, no actual sampling. OK, save it.
212  assert( do_prepack_ );
213  output_silent_struct( pose, get_native_pose(), silent_file_, "S_PREPACK", sfd_,
214  calc_rms_res_ );
215  }
216 
217  }
218 
219 
220  ////////////////////////////////////////////////////////////////////////////////
221  void
223  {
224  using namespace protocols::moves;
225  using namespace core::pack;
226  using namespace core::pack::task;
227  using namespace core::pack::task::operation;
228 
230  utility::vector1< Size > group_ids;
231 
232  Size current_group = 0;
233  Size spectator_group = 0;
234  for (Size i = 1; i <= nres; i++ ) {
235  bool found_it( false );
236  for (Size k = 1; k <= moving_residues_.size(); k++ ) {
237  if ( i == moving_residues_[k] ) {
238  found_it = true;
239  break;
240  }
241  }
242  if (found_it ) {
243  current_group = 0;
244  TR << "GREENPACKER SAMPLER " << i << std::endl;
245  } else {
246  if ( current_group == 0 ) spectator_group++;
247  current_group = spectator_group;
248  TR << "GREENPACKER SPECTATOR " << i << " --> group " << spectator_group << std::endl;
249  }
250  group_ids.push_back( current_group );
251  }
252 
253  user_defined_group_discriminator->set_group_ids( group_ids );
254  green_packer_->set_scorefunction( *scorefxn_ );
255  green_packer_->set_group_discriminator( user_defined_group_discriminator );
256 
257  TaskFactoryOP initial_task_factory( new TaskFactory );
258  initial_task_factory->push_back( new InitializeFromCommandline );
259  initial_task_factory->push_back( new RestrictToRepacking );
260  green_packer_->set_reference_round_task_factory( initial_task_factory );
261 
262  TaskFactoryOP general_task_factory( new TaskFactory );
263  general_task_factory->push_back( new InitializeFromCommandline );
264  general_task_factory->push_back( new RestrictToRepacking );
265  green_packer_->set_task_factory( general_task_factory );
266 
267  //green_packer_->reset();
268  }
269 
270 
271  ////////////////////////////////////////////////////////////////////////////
272  void
274  using namespace core::id;
275 
276  /////////////////////////////////////////////////
277  // Need to do a full "prepack". Want all side-chains outside the loop
278  /// in their favorite states.
279  /////////////////////////////////////////////////
280 
281  /////////////////////////////////////////////////
282  // First space out the moving residues (will return them later)
283  /////////////////////////////////////////////////
284  DOF_ID dof_id;
285  utility::vector1< DOF_ID > dofs_to_reset;
286  utility::vector1< Real > dof_values;
287 
288  if ( do_prepack_ ){
289  for ( Size i = 1; i <= moving_residues_.size(); i++ ) {
290  dof_id = DOF_ID( named_atom_id_to_atom_id( NamedAtomID( " N ", moving_residues_[ i ]), pose ), D );
291  dofs_to_reset.push_back( dof_id );
292  dof_values.push_back( pose.dof( dof_id ) );
293  pose.set_dof( dof_id, 50.0 ); //dummy, extended value.
294 
295  dof_id = DOF_ID( named_atom_id_to_atom_id( NamedAtomID( " C ", moving_residues_[ i ]), pose ), D );
296  dofs_to_reset.push_back( dof_id );
297  dof_values.push_back( pose.dof( dof_id ) );
298  pose.set_dof( dof_id, 50.0 ); //dummy, extended value.
299  }
300  //pose.dump_pdb( "extended_before_pack.pdb" );
301  }
302 
303  /////////////////////////////////////////////////
304  // Then do the pack
305  /////////////////////////////////////////////////
306  pack_task_ = pack::task::TaskFactory::create_packer_task( pose );
307  pack_task_->restrict_to_repacking();
308  for (Size i = 1; i <= pose.total_residue(); i++) {
309  if ( !pose.residue(i).is_protein() ) continue;
310  pack_task_->nonconst_residue_task(i).and_extrachi_cutoff( 0 );
311  pack_task_->nonconst_residue_task(i).or_ex1( true );
312  pack_task_->nonconst_residue_task(i).or_ex2( true );
313  // pack_task_->nonconst_residue_task(i).or_ex3( true );
314  // pack_task_->nonconst_residue_task(i).or_ex4( true );
315  pack_task_->nonconst_residue_task(i).or_include_current( true );
316  }
317 
318  if ( do_prepack_ ){
319  Size const ntrials_prepack( 1 ); //is this necessary?
320  // each repack doesn't take very long -- best to do multiple trials
321  // and pick the lowest energy one.
322  pack::pack_rotamers_loop( pose, *scorefxn_, pack_task_, ntrials_prepack );
323  //pack::rotamer_trials( pose, *scorefxn_, pack_task_ );
324  }
325 
326  /////////////////////////////////////////////////
327  // Should we minimize the side chains too?
328  /////////////////////////////////////////////////
329 
330  /////////////////////////////////////////////////
331  // return spaced out moving residues.
332  /////////////////////////////////////////////////
333  if ( do_prepack_ ){
334  for ( Size n = 1; n <= dofs_to_reset.size(); n++ ) {
335  pose.set_dof( dofs_to_reset[ n ], dof_values[ n ] );
336  }
337  }
338 
339  // save this pose for later.
340  pose_prepack_ = new Pose;
341  *pose_prepack_ = pose;
342 
343  }
344 
345 
346  //////////////////////////////////////////////////////////////////////////
347  void
349  utility::vector1< bool > & residues_allowed_to_be_packed ){
350 
351  using namespace core::scoring;
352 
353  (*scorefxn_)( pose );
354  EnergyGraph const & energy_graph( pose.energies().energy_graph() );
355 
356  for ( Size n = 1; n <= moving_residues_.size(); n++ ) {
357 
358  Size const i = moving_residues_[ n ];
359  residues_allowed_to_be_packed[ i ] = true;
360 
362  iter = energy_graph.get_node( i )->const_edge_list_begin();
363  iter != energy_graph.get_node( i )->const_edge_list_end();
364  ++iter ){
365  Size j( (*iter)->get_other_ind( i ) );
366  residues_allowed_to_be_packed[ j ] = true;
367  }
368  }
369 
370  }
371 
372  //////////////////////////////////////////////////////////////////////////
373  void
374  reinstate_side_chain_angles( pose::Pose & pose, pose::Pose const & src_pose ){
375  for ( Size i = 1; i <= pose.total_residue(); i++ ) {
376  for ( Size n = 1; n <= pose.residue_type( i ).nchi(); n++ ) {
377  pose.set_chi( n, i, src_pose.chi( n, i ) );
378  }
379  }
380  }
381 
382  //////////////////////////////////////////////////////////////////////////
383  void
385  for ( Size i = 1; i <= pose.total_residue(); i++ ) {
386  for ( Size n = 1; n <= pose.residue_type( i ).nchi(); n++ ) {
387  pose.set_chi( n, i, src_pose.chi( n, i ) );
388  }
389  }
390  }
391 
392  //////////////////////////////////////////////////////////////////////////
393  void
395 
396  if ( pack_at_neighbors_only_ ) {
397 
398  // need to reinstate side-chain angles at all positions to "pre-packed values"
400 
401  // figure out neighbors
402  utility::vector1< bool > residues_allowed_to_be_packed( pose.total_residue(), false );
403  figure_out_neighbors( pose, residues_allowed_to_be_packed );
404 
405  //set up new task
406  pack_task_->restrict_to_repacking();
407 
408  // std::cout << "PACKING ==> ";
409  for (Size i = 1; i <= pose.total_residue(); i++) {
410  if ( pose.residue(i).is_protein() && residues_allowed_to_be_packed[ i ] ) {
411  // std::cout << i << " " ;
412  pack_task_->nonconst_residue_task(i).and_extrachi_cutoff( 0 );
413  pack_task_->nonconst_residue_task(i).or_ex1( true );
414  pack_task_->nonconst_residue_task(i).or_ex2( true );
415  pack_task_->nonconst_residue_task(i).or_include_current( true );
416  } else {
417  pack_task_->nonconst_residue_task(i).prevent_repacking();
418  }
419  }
420  // std::cout << std::endl;
421  }
422 
423 
424  // OK, pack!!
427  } else {
429  }
430 
431  }
432 
433  //////////////////////////////////////////////////////////////////////////
434  void
436  silent_file_ = silent_file;
437  }
438 
439  //////////////////////////////////////////////////////////////////////////
440  void
442  scorefxn_ = scorefxn;
443  }
444 
445  //////////////////////////////////////////////////////////////////////////
446  void
448  use_green_packer_ = setting;
449  }
450 
451  //////////////////////////////////////////////////////////////////////////
452  void
455  }
456 
457  //////////////////////////////////////////////////////////////////////////
458  void
460  do_prepack_ = setting;
461  }
462 
463  //////////////////////////////////////////////////////////////////////////
466  return sfd_;
467  }
468 
469  //////////////////////////////////////////////////////////////////////////
470  void
472  calc_rms_res_ = calc_rms_res;
473  }
474 
475 
476 }
477 }
478 }