Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
StepWiseProteinPacker.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 StepWiseProteinPacker
11 /// @brief Not particularly fancy, just minimizes a list of poses.
12 /// @detailed
13 /// @author Rhiju Das
14 
15 
16 //////////////////////////////////
21 
22 //////////////////////////////////
23 // AUTO-REMOVED #include <core/kinematics/FoldTree.hh>
24 #include <core/kinematics/Jump.hh>
25 #include <core/kinematics/RT.hh>
26 #include <core/types.hh>
27 #include <core/graph/Graph.hh>
33 #include <core/pose/Pose.hh>
34 
35 // AUTO-REMOVED #include <core/pose/util.hh>
36 // AUTO-REMOVED #include <core/scoring/rms_util.tmpl.hh>
40 // AUTO-REMOVED #include <core/scoring/Ramachandran.hh>
41 #include <core/scoring/Energies.hh>
42 // AUTO-REMOVED #include <core/id/AtomID.hh>
43 // AUTO-REMOVED #include <core/id/NamedAtomID.hh>
44 // AUTO-REMOVED #include <core/id/DOF_ID.hh>
47 #include <basic/Tracer.hh>
48 
49 //GreenPacker
52 
53 // AUTO-REMOVED #include <numeric/angle.functions.hh>
54 
55 // AUTO-REMOVED #include <ObjexxFCL/format.hh>
56 #include <ObjexxFCL/string.functions.hh>
57 #include <ObjexxFCL/FArray1D.hh>
58 
59 #include <utility/exit.hh>
60 // AUTO-REMOVED #include <time.h>
61 
62 #include <string>
63 
64 //Auto Headers
66 #include <utility/vector0.hh>
67 #include <utility/vector1.hh>
68 
69 //Auto using namespaces
70 namespace ObjexxFCL { } using namespace ObjexxFCL; // AUTO USING NS
71 //Auto using namespaces end
72 
73 
74 using namespace core;
75 using core::Real;
76 
77 //////////////////////////////////////////////////////////////////////////
78 //////////////////////////////////////////////////////////////////////////
79 // Core routine for stepwise sampling of proteins (and probably other
80 // biopolymers soon). Take a starting pose and a list of residues to sample,
81 // and comprehensively sample all backbone torsion angles by recursion.
82 //////////////////////////////////////////////////////////////////////////
83 //////////////////////////////////////////////////////////////////////////
84 //////////////////////////////////////////////////////////////////////////
85 
86 static basic::Tracer TR( "protocols.swa.stepwise_residue_sampler" ) ;
87 
88 namespace protocols {
89 namespace swa {
90 namespace protein {
91 
92  //////////////////////////////////////////////////////////////////////////
93  //constructor!
94  StepWiseProteinPacker::StepWiseProteinPacker(
95  utility::vector1< Size > const & moving_residues,
97  moving_residues_( moving_residues ),
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  rescore_only_( false ),
104  silent_file_( "" ),
105  sfd_( new core::io::silent::SilentFileData),
106  sample_generator_( sample_generator )
107  {
108  }
109 
110  //////////////////////////////////////////////////////////////////////////
111  //destructor
113  {}
114 /////////////////////
117 return "StepWiseProteinPacker";
118 }
119 
120 
121  //////////////////////////////////////////////////////////////////////////
122  //////////////////////////////////////////////////////////////////////
123  void
125  {
126 
127  //Size which_res( 1 );
128  // Size count( 1 );
129 
130  clock_t const time_start( clock() );
131 
132  if ( pose.is_fullatom() ){
133  if ( use_green_packer_ ) {
135  } else {
137  }
138  }
139 
140  sample_residues( pose );
141 
142  std::cout << "Total time in StepWiseProteinPacker: " << static_cast<Real>( clock() - time_start ) / CLOCKS_PER_SEC << std::endl;
143 
144  }
145 
146 
147  ////////////////////////////////////////////////////////////////////////////
148  void
150  {
151 
152  using namespace core::chemical;
153  using namespace core::scoring;
154  using namespace core::pose;
155  using namespace core::kinematics;
156  using namespace protocols::swa;
157 
158  sample_generator_->reset();
159 
160  Size k( 0 );
161 
162  while( sample_generator_->has_another_sample() ){
163 
164  sample_generator_->get_next_sample( pose );
165  k++;
166 
167  if ( pose_filter_ && !pose_filter_->passes_filter( pose ) ) continue;
168 
169  std::string const tag = "S_"+ lead_zero_string_of( k-1, 5 );
170 
171  if ( pose.is_fullatom() || ( k % 100 == 0 ) ) print_tag( tag, k );
172 
173  if ( pose.is_fullatom() && !rescore_only_ ){
174  if ( use_green_packer_ ) {
175  green_packer_->apply( pose );
176  } else {
177  apply_regular_packer( pose );
178  }
179  }
180 
181  (*scorefxn_)( pose );
182 
184  calc_rms_res_ );
185 
186  }
187 
188  //Nothing found? At least produce one pose...
189  if ( sfd_->size() == 0 ) {
190  TR << "Warning -- nothing passed filter -- outputting a placeholder pose." << std::endl;;
191  std::string const tag = "S_"+ lead_zero_string_of( k-1, 5 );
193  calc_rms_res_ );
194  }
195 
196 
197  }
198 
199  ////////////////////////////////////////////////////////////////////////////////
200  void
202  std::cout << " Decoy " << tag << " : ";
203  std::string const pack_or_trials = use_packer_instead_of_rotamer_trials_ ? "PACK" : "ROT_TRIALS" ;
204  std::cout << pack_or_trials;
205  std::cout << " Number " << k;
206  if ( sample_generator_->size() > 0 ) std::cout << " out of " << sample_generator_->size();
207  std::cout << std::endl;
208  }
209 
210  ////////////////////////////////////////////////////////////////////////////////
211  void
213  {
214  using namespace protocols::moves;
215  using namespace core::pack;
216  using namespace core::pack::task;
217  using namespace core::pack::task::operation;
218 
220  utility::vector1< Size > group_ids;
221 
222  Size current_group = 0;
223  Size spectator_group = 0;
224  for (Size i = 1; i <= nres; i++ ) {
225  bool found_it( false );
226  for (Size k = 1; k <= moving_residues_.size(); k++ ) {
227  if ( i == moving_residues_[k] ) {
228  found_it = true;
229  break;
230  }
231  }
232  if (found_it ) {
233  current_group = 0;
234  TR << "GREENPACKER SAMPLER " << i << std::endl;
235  } else {
236  if ( current_group == 0 ) spectator_group++;
237  current_group = spectator_group;
238  TR << "GREENPACKER SPECTATOR " << i << " --> group " << spectator_group << std::endl;
239  }
240  group_ids.push_back( current_group );
241  }
242 
243  user_defined_group_discriminator->set_group_ids( group_ids );
244  green_packer_->set_scorefunction( *scorefxn_ );
245  green_packer_->set_group_discriminator( user_defined_group_discriminator );
246 
247  TaskFactoryOP initial_task_factory( new TaskFactory );
248  initial_task_factory->push_back( new InitializeFromCommandline );
249  initial_task_factory->push_back( new RestrictToRepacking );
250  green_packer_->set_reference_round_task_factory( initial_task_factory );
251 
252  TaskFactoryOP general_task_factory( new TaskFactory );
253  general_task_factory->push_back( new InitializeFromCommandline );
254  general_task_factory->push_back( new RestrictToRepacking );
255  green_packer_->set_task_factory( general_task_factory );
256 
257  //green_packer_->reset();
258  }
259 
260 
261  ////////////////////////////////////////////////////////////////////////////
262  void
264  using namespace core::id;
265 
266  pack_task_ = pack::task::TaskFactory::create_packer_task( pose );
267  pack_task_->restrict_to_repacking();
268  for (Size i = 1; i <= pose.total_residue(); i++) {
269 
270  pack_task_->nonconst_residue_task(i).and_extrachi_cutoff( 0 );
271  pack_task_->nonconst_residue_task(i).or_include_current( true );
272 
273  if ( pose.residue(i).is_protein() ) {
274  pack_task_->nonconst_residue_task(i).or_ex1( true );
275  pack_task_->nonconst_residue_task(i).or_ex2( true );
276  // pack_task_->nonconst_residue_task(i).or_ex3( true );
277  // pack_task_->nonconst_residue_task(i).or_ex4( true );
278  } else if ( pose.residue(i).is_RNA() ) {
279  // Following could be useful...
280  pack_task_->nonconst_residue_task(i).or_ex4( true ); //extra rotamers?? Parin S. Jan 28, 2010
281  // new -- in case RNA backbone only is input?
282  //pack_task_->nonconst_residue_task(i).sample_rna_chi( true );
283  }
284 
285  if ( pose.residue(i).has_variant_type( "VIRTUAL_RESIDUE" ) ) pack_task_->nonconst_residue_task(i).prevent_repacking();
286  }
287 
288  // save this pose for later.
289  pose_init_ = new Pose;
290  *pose_init_ = pose;
291 
292  }
293 
294 
295  //////////////////////////////////////////////////////////////////////////
296  void
298  utility::vector1< bool > & residues_allowed_to_be_packed ){
299 
300  using namespace core::scoring;
301 
302  (*scorefxn_)( pose );
303  EnergyGraph const & energy_graph( pose.energies().energy_graph() );
304 
305  for ( Size n = 1; n <= moving_residues_.size(); n++ ) {
306 
307  Size const i = moving_residues_[ n ];
308  residues_allowed_to_be_packed[ i ] = true;
309 
311  iter = energy_graph.get_node( i )->const_edge_list_begin();
312  iter != energy_graph.get_node( i )->const_edge_list_end();
313  ++iter ){
314  Size j( (*iter)->get_other_ind( i ) );
315  residues_allowed_to_be_packed[ j ] = true;
316  }
317  }
318 
319  }
320 
321  //////////////////////////////////////////////////////////////////////////
322  void
324  for ( Size i = 1; i <= pose.total_residue(); i++ ) {
325  for ( Size n = 1; n <= pose.residue_type( i ).nchi(); n++ ) {
326  pose.set_chi( n, i, src_pose.chi( n, i ) );
327  }
328  }
329  }
330 
331  //////////////////////////////////////////////////////////////////////////
332  void
334 
335  if ( pack_at_neighbors_only_ ) {
336 
337  // need to reinstate side-chain angles at all positions to "pre-packed values"
339 
340  // figure out neighbors
341  utility::vector1< bool > residues_allowed_to_be_packed( pose.total_residue(), false );
342  figure_out_neighbors( pose, residues_allowed_to_be_packed );
343 
344  //set up new task
345  pack_task_->restrict_to_repacking();
346 
347  // std::cout << "PACKING ==> ";
348  for (Size i = 1; i <= pose.total_residue(); i++) {
349  if ( residues_allowed_to_be_packed[ i ] ) {
350  pack_task_->nonconst_residue_task(i).and_extrachi_cutoff( 0 );
351  pack_task_->nonconst_residue_task(i).or_include_current( true );
352  if ( pose.residue(i).is_protein() ) {
353  pack_task_->nonconst_residue_task(i).or_ex1( true );
354  pack_task_->nonconst_residue_task(i).or_ex2( true );
355  } else if ( pose.residue(i).is_RNA() ){
356  pack_task_->nonconst_residue_task(i).or_ex4( true ); //extra rotamers?? Parin S. Jan 28, 2010
357  // new -- in case RNA backbone only is input?
358  //pack_task_->nonconst_residue_task(i).sample_rna_chi( true );
359  }
360  } else {
361  pack_task_->nonconst_residue_task(i).prevent_repacking();
362  }
363  }
364 
365  // NEW -- more rotamers at moving residues...
366  // for ( Size n = 1; n <= moving_residues_.size(); n++ ) {
367  // Size const i = moving_residues_[ n ];
368  //std::cout << "MORE ROTAMERS TO " << i << std::endl;
369  // pack_task_->nonconst_residue_task(i).or_ex1_sample_level( core::pack::task::EX_SIX_QUARTER_STEP_STDDEVS );
370  // pack_task_->nonconst_residue_task(i).or_ex2_sample_level( core::pack::task::EX_SIX_QUARTER_STEP_STDDEVS );
371  // }
372 
373  // std::cout << std::endl;
374  }
375 
376 
377  // OK, pack!!
380  } else {
382  }
383 
384  }
385 
386  //////////////////////////////////////////////////////////////////////////
387  void
389  silent_file_ = silent_file;
390  }
391 
392  //////////////////////////////////////////////////////////////////////////
393  void
395  scorefxn_ = scorefxn;
396  }
397 
398  //////////////////////////////////////////////////////////////////////////
399  void
401  use_green_packer_ = setting;
402  }
403 
404  //////////////////////////////////////////////////////////////////////////
405  void
408  }
409 
410  //////////////////////////////////////////////////////////////////////////
413  return sfd_;
414  }
415 
416  //////////////////////////////////////////////////////////////////////////
417  void
419  calc_rms_res_ = calc_rms_res;
420  }
421 
422  //////////////////////////////////////////////////////////////////////////
423  void
425  pose_filter_ = pose_filter;
426  }
427 
428 }
429 }
430 }