Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FlexPacker.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/flexpack/FlexPacker.cc
11 /// @brief
12 /// @author Florian Richter (floric@u.washington.edu), oct 08
13 
14 
15 // Unit Headers
17 
18 // Package headers
22 // AUTO-REMOVED #include <protocols/flexpack/interaction_graph/OTFFlexbbInteractionGraph.hh>
23 // AUTO-REMOVED #include <protocols/flexpack/interaction_graph/PrecomputedFlexbbInteractionGraph.hh>
26 #include <core/fragment/Frame.hh>
27 
28 
29 // Project headers
31 #include <core/graph/Graph.hh>
34 #include <core/pose/Pose.hh>
36 #include <core/scoring/Energies.hh>
39 
40 // tracer
41 #include <basic/Tracer.hh>
42 
43 // ObjexxFCL
44 #include <ObjexxFCL/FArray1D.hh>
45 
46 #include <utility/vector1.hh>
47 
48 
49 
50 namespace protocols {
51 namespace flexpack {
52 
53 static basic::Tracer tr("protocols.flexpack.FlexPacker");
54 
56 
57 
59  core::pack::task::PackerTaskCOP task, // SHOULD TAKE A TASK FACTORY, NOT A TASK COP!
62 ) : task_(task), scorefxn_(scorefxn)
63 {
64  this->set_frames( frames );
65 }
66 
68 
69 void
71  scorefxn_ = sfxn;
72 }
73 
74 void
76  task_ = task;
77 }
78 
79 void
81  factory_ = factory;
82 }
83 
84 
85 void
87  core::pose::Pose & pose
88 )
89 {
90  using namespace ObjexxFCL;
91 
92  //std::cout << "Flexpacker start score: " << (*scorefxn_)( pose ) << std::endl;
93 
94  scorefxn_->setup_for_packing( pose, task_->repacking_residues(), task_->designing_residues() );
95 
97 
98  flex_rotsets->set_frames( pose, frames_ );
99 
100  /// DEBUG HACK!
101  core::scoring::methods::EnergyMethodOptions opts = scorefxn_->energy_method_options();
102  opts.hbond_options().decompose_bb_hb_into_pair_energies( true );
103  (const_cast< core::scoring::ScoreFunction & > (*scorefxn_)).set_energy_method_options( opts );
104 
105 
106  core::graph::GraphOP flex_neighbor_graph = flex_rotsets->flexpack_neighbor_graph( pose, *scorefxn_, task_ );
107 
108  flex_rotsets->build_rotamers( pose, *scorefxn_, *flex_neighbor_graph );
109  tr << "Flexxbb RotamerSet contains a total of " << flex_rotsets->nrotamers() << " rotamers." << std::endl;
110 
113 
114  flex_ig->initialize( *flex_rotsets );
115  flex_rotsets->precompute_energies( pose, *scorefxn_, flex_neighbor_graph, *flex_ig );
116 
117  FArray1D_int bestrotamer_at_seqpos( pose.total_residue(), 0 );
118  FArray1D< PackerEnergy > rot_freq( flex_rotsets->nrotamers() );
119  FArray1D_int current_rot_index( pose.total_residue(), 1 );
120  //for ( Size ii = 1; ii <= flex_rotsets->nmoltenres(); ++ii ) {
121  // current_rot_index( flex_rotsets->moltenres_2_resid( ii ) ) = 1 + flex_rotsets->nrotamer_offset_for_moltenres( ii );
122  //}
123  tr << "Current rot index: ";
124  for ( Size ii = 1; ii <= flex_rotsets->nmoltenres(); ++ii ) {
125  tr << current_rot_index( ii ) << " ";
126  }
127  tr << std::endl;
128  PackerEnergy bestE (0);
129 
131  bestrotamer_at_seqpos, bestE, false /*start_with_current*/, flex_ig,
132  flex_rotsets, current_rot_index, false, rot_freq);
133 
134  tr << "FlexbbIG Memory Use: " << flex_ig->getTotalMemoryUsage() << " bytes " << std::endl;
135  OtherContextScoreFunction oc_sfxn( pose );
136  using namespace core::scoring;
137  oc_sfxn.set_energy_method_options( scorefxn_->energy_method_options() );
138  for ( Size ii = 1; ii <= n_score_types; ++ii ) {
139  ScoreType iist = (ScoreType) ii;
140  if ( scorefxn_->weights()[ iist ] != 0.0 ) {
141  oc_sfxn.set_weight( iist, scorefxn_->weights()[ iist ] );
142  }
143  }
144 
145  pose.energies().clear();
146  oc_sfxn.pre_scoring();
147  tr << "Other Context Score: " << oc_sfxn( pose ) << std::endl;
148  pose.energies().total_energies().show_weighted( tr, oc_sfxn.weights() );
149  tr << "OC weights: ";
150  oc_sfxn.weights().show_nonzero( tr );
151  tr << std::endl;
152  pose.energies().clear();
153  tr << std::endl << "Correct Context Score: " << (*scorefxn_)( pose ) << std::endl;
154  pose.energies().total_energies().show_weighted( tr, scorefxn_->weights() );
155  tr << std::endl;
156  tr << "scorefxn_ weights: ";
157  scorefxn_->weights().show_nonzero( tr );
158  tr << std::endl;
159 
160 
161  std::cerr << "Start score: " << oc_sfxn( pose ) << std::endl;
162  annealer->run();
163 
164  tr << "Final energy: " << bestE << std::endl;
165  for ( Size ii = 1; ii <= flex_rotsets->nmoltenres(); ++ii ) {
166  Size iiresid =flex_rotsets->moltenres_2_resid( ii );
167  //tr << "Replacing residue " << iiresid << " mres: " << ii << std::endl;
168  pose.replace_residue(
169  iiresid,
170  *(flex_rotsets->rotamer( bestrotamer_at_seqpos( iiresid ))),
171  false
172  );
173  }
174 
175  tr << "The final assigned backbone fragments are: ";
176  for( Size jj = 1; jj<= flex_rotsets->nflexible_segments(); ++jj){
177  Size representative_seqpos = flex_rotsets->flexsegment_start_resid( jj );
178  Size representative_moltenres = flex_rotsets->resid_2_moltenres( representative_seqpos );
179  Size rep_rotamer = bestrotamer_at_seqpos( representative_seqpos ) - flex_rotsets->nrotamer_offset_for_moltenres( representative_moltenres );
180 
181  tr << "for segment " << jj << " is " << flex_ig->get_bb_for_state( representative_moltenres , rep_rotamer ) ;
182  tr << "; ";
183  }
184  tr << std::endl;
185 
186 
187  pose.energies().clear();
188  tr << "Other Context Score: " << oc_sfxn( pose ) << std::endl;
189  pose.energies().total_energies().show_weighted( tr, oc_sfxn.weights() );
190  tr << "OC weights: ";
191  oc_sfxn.weights().show_nonzero( tr );
192  tr << std::endl;
193  pose.energies().clear();
194  tr << std::endl << "Correct Context Score: " << (*scorefxn_)( pose ) << std::endl;
195  pose.energies().total_energies().show_weighted( tr, scorefxn_->weights() );
196  tr << std::endl;
197  tr << "scorefxn_ weights: ";
198  scorefxn_->weights().show_nonzero( tr );
199  tr << std::endl;
200 
201  //pose.dump_pdb( "flexpacked.pdb" );
202 
203 
204 
205 } //apply function
206 
209  return "FlexPacker";
210 }
211 
212 void
215 )
216 {
217 
218  for( utility::vector1< core::fragment::FrameOP >::const_iterator frame_it = frames.begin(); frame_it != frames.end(); ++frame_it ){
219 
220  frames_.push_back( *frame_it );
221  }
222 
223 } //set_frames
224 
225 } //namespace flexpack
226 } //namespace protocols