Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
StepWiseProteinPoseMinimizer.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 StepWiseProteinPoseMinimizer
11 /// @brief Not particularly fancy, just minimizes a list of poses.
12 /// @detailed
13 /// @author Rhiju Das
14 
15 
16 //////////////////////////////////
20 
21 //////////////////////////////////
24 #include <core/types.hh>
29 #include <core/id/TorsionID.hh>
30 #include <core/pose/Pose.hh>
31 #include <core/pose/util.hh>
33 #include <core/scoring/Energies.hh>
41 #include <ObjexxFCL/format.hh>
42 
43 
44 #include <string>
45 
46 //Auto Headers
47 #include <utility/vector1.hh>
48 using namespace core;
49 using core::Real;
50 using ObjexxFCL::fmt::F;
51 
52 namespace protocols {
53 namespace swa {
54 namespace protein {
55 
56 
57  //////////////////////////////////////////////////////////////////////////
58  //constructor!
59  StepWiseProteinPoseMinimizer::StepWiseProteinPoseMinimizer( core::io::silent::SilentFileDataOP const sfd, utility::vector1< Size > const & moving_residues ):
60  Mover(),
61  moving_residues_( moving_residues )
62  {
65  }
66 
67  //////////////////////////////////////////////////////////////////////////
69  Mover(),
70  moving_residues_( moving_residues )
71  {
74  }
75 
76  //////////////////////////////////////////////////////////////////////////
77  //destructor
79  {}
80 
81  /////////////////////
84  return "StepWiseProteinPoseMinimizer";
85  }
86 
87  //////////////////////////////////////////////////////////////////////////
88  void
90  Mover::type( "StepWiseProteinPoseMinimizer" );
92  rescore_only_ = false;
94  silent_file_ = "";
96  min_type_ = "dfpmin_armijo_nonmonotone"; // used to be dfpmin
97  min_tolerance_ = 0.000025 ; // used to be 0.00000025
98  }
99 
100 
101  //////////////////////////////////////////////////////////////////////////
103  using namespace core::pose;
104  using namespace core::io::silent;
105 
106  input_silent_file_data_->clear();
107  for ( PoseList::iterator iter = pose_list_.begin(); iter != pose_list_.end(); iter++ ) {
108  PoseOP & pose_op( iter->second );
109  BinaryProteinSilentStruct s( *pose_op, iter->first /*tag*/ );
110  input_silent_file_data_->add_structure( s );
111  }
112  }
113 
114  //////////////////////////////////////////////////////////////////////////
115  void
117  {
118  using namespace core::optimization;
119  using namespace core::scoring;
120  using namespace core::scoring::constraints;
121  using namespace core::pose;
122  using namespace core::io::silent;
123 
124  clock_t const time_start( clock() );
125 
126  ConstraintSetOP cst_set = pose.constraint_set()->clone();
127 
130 
131  AtomTreeMinimizer minimizer;
132  bool const use_nblist( true );
133  MinimizerOptions options( min_type_, min_tolerance_, use_nblist, false, false );
134  options.nblist_auto_update( true );
135 
136  kinematics::MoveMap mm_start, mm;
137  std::cout << "MOVE TAKEOFF TORSIONS: " << move_takeoff_torsions_ << std::endl;
139  mm = mm_start;
140 
141  // using namespace core::id;
142  // for ( Size i = 1; i <= pose.total_residue(); i++ ){
143  // std::cout << " MM: " << i << ' ' << mm.get( TorsionID( i, BB, 1 ) ) << ' ' << mm.get( TorsionID( i, BB, 2 ) ) << ' ' << mm.get( TorsionID( i, BB, 3 ) ) << std::endl;
144  // }
145 
146  Size count( 1 );
147  Real const original_coordinate_cst_weight = fa_scorefxn_->get_weight( coordinate_constraint );
148 
149  sfd_ = new SilentFileData;
152 
153  while ( input.has_another_pose() ) {
154 
155  std::cout << "Minimizing decoy " << count++ << " out of " << input_silent_file_data_->size() << std::endl;
156 
157  input.fill_pose( pose );
158 
159  // Following are necessary because poses from clustering went thorugh silent struct and lost their constraints & disulfide information.
160  pose.constraint_set( cst_set );
161  pose.conformation().fix_disulfides( disulfides );
162 
163  Real const score_original = (*fa_scorefxn_)( pose );
164 
165  // The movemap has all dofs for "non-fixed residues" free to move.
166  // We can also let sidechains minimize in fixed-residues -- for
167  // speed only look at neighbors of moving residues.
168  mm = mm_start;
169  let_neighboring_chis_minimize( mm, pose );
170 
171  if ( !rescore_only_ ){
172 
173  // One minimize with loose coordinate tethers to make sure the pose doesn't blow up.
175  if ( fa_scorefxn_->has_zero_weight( coordinate_constraint) ) fa_scorefxn_->set_weight( coordinate_constraint, 1.0 );
176  minimizer.run( pose, mm, *fa_scorefxn_, options );
177 
178  // Now a regular minimize.
179  pose.constraint_set( cst_set ); // return original constraints (no added coordinate constraints)
180  fa_scorefxn_->set_weight( coordinate_constraint, original_coordinate_cst_weight );
181 
182  // for poses with chainbreaks, do an initial minimization with a weak linear_chainbreak term. (anneal it in.)
183  if ( pose_has_chainbreak( pose ) ){
184 
185  Real const linear_chainbreak_weight_original = fa_scorefxn_->get_weight( linear_chainbreak );
186  if ( linear_chainbreak_weight_original < 20.0 ) std::cout << "WARNING!! Your linear_chainbreak weight is " << F(8,3,linear_chainbreak_weight_original ) << ", which is less than recommended (20.0) " << std::endl;
187 
188  fa_scorefxn_->set_weight( linear_chainbreak, linear_chainbreak_weight_original * 0.25 );
189  minimizer.run( pose, mm, *fa_scorefxn_, options );
190  fa_scorefxn_->set_weight( linear_chainbreak, linear_chainbreak_weight_original );
191  }
192 
193 
194  minimizer.run( pose, mm, *fa_scorefxn_, options );
195 
196  }
197 
198  setPoseExtraScores( pose, "score_orig", score_original );
199  std::string const & tag( tag_from_pose( pose ) );
201 
202  std::cout << "Score minimized from " <<F(8,3, score_original) << " to " << F(8,3,(*fa_scorefxn_)( pose )) << std::endl;
203 
204  // Running into file locking issues
205  // utility::sys_sleep( 0.5 );
206  //exit( 0 );
207 
208  // Might was well replace pose in original list.
209  //*pose_op = pose;
210 
211  }
212 
213  std::cout << "Total time in StepWiseProteinPoseMinimizer: " <<
214  static_cast<Real>(clock() - time_start) / CLOCKS_PER_SEC << std::endl;
215 
216  }
217 
218  //////////////////////////////////////////////////////////////////////////
219  void
222  core::pose::Pose & pose ){
223 
224  using namespace core::scoring;
225 
226  (*fa_scorefxn_)( pose );
227  EnergyGraph const & energy_graph( pose.energies().energy_graph() );
228 
229  for ( Size n = 1; n <= moving_residues_.size(); n++ ) {
230 
231  Size const i = moving_residues_[ n ];
232 
234  iter = energy_graph.get_node( i )->const_edge_list_begin();
235  iter != energy_graph.get_node( i )->const_edge_list_end();
236  ++iter ){
237 
238  Size j( (*iter)->get_other_ind( i ) );
239  if ( pose.residue(j).has_variant_type( "VIRTUAL_RESIDUE" ) ) continue;
240 
241  if ( pose.residue(j).is_protein() ){
242  mm.set_chi( j, true );
243  } else if ( pose.residue(j).is_RNA() ){
244  mm.set( id::TorsionID( j, id::CHI, 4), true ); // 2'-OH.
245  }
246 
247  }
248  }
249 
250  }
251 
252  //////////////////////////////////////////////////////////////////////////
253  bool
255  // this is pretty conservative -- actually there might be
256  // cases where the pose has a chainbreak but the minimized dofs would
257  // not affect the relative positions of the chainbreak residues.
258  for ( Size i = 1; i <= pose.total_residue(); i++ ){
259  if ( pose.residue_type(i).has_variant_type( "CUTPOINT_UPPER" ) ) return true;
260  if ( pose.residue_type(i).has_variant_type( "CUTPOINT_LOWER" ) ) return true;
261  }
262  return false;
263  }
264 
265  //////////////////////////////////////////////////////////////////////////
266  void
268  silent_file_ = silent_file;
269  }
270 
271  //////////////////////////////////////////////////////////////////////////
272  void
274  min_type_ = min_type;
275  }
276 
277  //////////////////////////////////////////////////////////////////////////
278  void
280  min_tolerance_ = min_tolerance;
281  }
282 
283  //////////////////////////////////////////////////////////////////////////
284  void
286  fa_scorefxn_ = scorefxn;
287  }
288 
289  //////////////////////////////////////////////////////////////////////////
290  void
292  fixed_res_ = fixed_res;
293  }
294 
295  //////////////////////////////////////////////////////////////////////////
296  void
298  calc_rms_res_ = calc_rms_res;
299  }
300 
301  //////////////////////////////////////////////////////////////////////////
304  return sfd_;
305  }
306 
307  // void
308  // StepWiseProteinPoseMinimizer::set_constraint_set( core::scoring::constraints::ConstraintSetOP const & cst_set ){
309  // cst_set_ = cst_set;
310  // }
311 
312 
313 }
314 }
315 }