Rosetta
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
StepWiseProteinMinimizer.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 StepWiseProteinMinimizer
11 /// @brief Not particularly fancy, just minimizes a list of poses.
12 /// @details
13 /// @author Rhiju Das
14 
15 
16 //////////////////////////////////
22 
23 //////////////////////////////////
26 #include <core/id/TorsionID.hh>
27 #include <core/pose/Pose.hh>
28 #include <core/pose/util.hh>
30 #include <core/scoring/Energies.hh>
39 #include <ObjexxFCL/format.hh>
40 
41 #include <basic/Tracer.hh>
42 
43 #include <string>
44 
45 //Auto Headers
46 #include <utility/vector1.hh>
47 using namespace core;
48 using core::Real;
50 
51 static THREAD_LOCAL basic::Tracer TR( "protocols.stepwise.legacy.modeler.protein.StepWiseProteinMinimizer" );
52 
53 using namespace protocols::stepwise::modeler;
54 using namespace protocols::stepwise::modeler::protein;
55 using namespace protocols::stepwise::modeler::movemap;
56 
57 namespace protocols {
58 namespace stepwise {
59 namespace legacy {
60 namespace modeler {
61 namespace protein {
62 
63 
64 //////////////////////////////////////////////////////////////////////////
65 StepWiseProteinMinimizer::StepWiseProteinMinimizer( utility::vector1< pose::PoseOP > const & pose_list,
66  utility::vector1< Size > const & moving_residues ):
67  Mover(),
68  moving_residues_( moving_residues ),
69  pose_list_( pose_list )
70 {
72 }
73 
74 //////////////////////////////////////////////////////////////////////////
75 //destructor
77 {}
78 
79 /////////////////////
82  return "StepWiseProteinMinimizer";
83 }
84 
85 //////////////////////////////////////////////////////////////////////////
86 void
88  Mover::type( "StepWiseProteinMinimizer" );
90  rescore_only_ = false;
92  //fa_scorefxn_ = core::scoring::get_score_function();
93  min_type_ = "dfpmin_armijo_nonmonotone"; // used to be dfpmin
94  cartesian_ = true;
95  min_tolerance_ = 0.000025 ; // used to be 0.00000025
97  num_pose_minimize_ = 0; // signal to minimize all
98 }
99 
100 //////////////////////////////////////////////////////////////////////////
101 void
103 {
104  using namespace core::optimization;
105  using namespace core::scoring;
106  using namespace core::scoring::constraints;
107  using namespace core::pose;
108 
109  clock_t const time_start( clock() );
110 
111  ConstraintSetOP cst_set;
112  if ( use_coordinate_constraints_ ) cst_set = pose.constraint_set()->clone();
113 
114  utility::vector1< std::pair<core::Size,core::Size> > disulfides;
116  runtime_assert( fa_scorefxn_ != 0 );
117 
118  CartesianMinimizer cart_minimizer;
119  AtomTreeMinimizer minimizer;
120  bool const use_nblist( true );
121  MinimizerOptions options( min_type_, min_tolerance_, use_nblist, false, false );
122  options.nblist_auto_update( true );
123 
124  kinematics::MoveMap mm_start, mm;
125  // figure_out_moving_residues( mm_start, pose, fixed_res_, move_takeoff_torsions_, move_jumps_between_chains_ );
126  // output_movemap( mm_start, pose, TR );
127 
128  // testing unification...
129  utility::vector1< Size > working_minimize_res;
130  for ( Size n = 1; n <= pose.total_residue(); n++ ) { if ( !fixed_res_.has_value( n ) ) working_minimize_res.push_back( n );}
131  figure_out_stepwise_movemap( mm_start, pose, working_minimize_res, move_takeoff_torsions_ );
132  // output_movemap( mm_start, pose, TR );
133 
134  mm = mm_start;
135  Real const original_coordinate_cst_weight = fa_scorefxn_->get_weight( coordinate_constraint );
136 
137  utility::vector1< PoseOP > output_pose_list;
138  for ( Size n = 1; n <= pose_list_.size(); n++ ) {
139 
140  if ( num_pose_minimize_ > 0 && n > num_pose_minimize_ ) break;
141 
142  pose = *pose_list_[ n ];
143 
144  // Following are necessary because poses from clustering went thorugh silent struct and lost their constraints & disulfide information.
145  if ( cst_set ) pose.constraint_set( cst_set );
146  pose.conformation().fix_disulfides( disulfides );
147 
148  Real const score_original = (*fa_scorefxn_)( pose );
149 
150  // The movemap has all dofs for "non-fixed residues" free to move.
151  // We can also let sidechains minimize in fixed-residues -- for
152  // speed only look at neighbors of moving residues.
153  mm = mm_start;
154  let_neighboring_chis_minimize( mm, pose );
155 
156  if ( !rescore_only_ ) {
157 
159  // One minimize with loose coordinate tethers to make sure the pose doesn't blow up.
161  if ( fa_scorefxn_->has_zero_weight( coordinate_constraint) ) fa_scorefxn_->set_weight( coordinate_constraint, 1.0 );
162  minimizer.run( pose, mm, *fa_scorefxn_, options );
163  // Now a regular minimize.
164  pose.constraint_set( cst_set ); // return original constraints (no added coordinate constraints)
165  fa_scorefxn_->set_weight( coordinate_constraint, original_coordinate_cst_weight );
166  }
167 
168  // for poses with chainbreaks, do an initial minimization with a weak linear_chainbreak term. (anneal it in.)
169  if ( pose_has_chainbreak( pose ) ) {
170 
171  Real const linear_chainbreak_weight_original = fa_scorefxn_->get_weight( linear_chainbreak );
172  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;
173 
174  fa_scorefxn_->set_weight( linear_chainbreak, linear_chainbreak_weight_original * 0.25 );
175  if ( !cartesian_ ) {
176  minimizer.run( pose, mm, *fa_scorefxn_, options );
177  }
178  fa_scorefxn_->set_weight( linear_chainbreak, linear_chainbreak_weight_original );
179  }
180 
181  if ( cartesian_ ) {
182  cart_minimizer.run( pose, mm, *fa_scorefxn_, options );
183  } else {
184  minimizer.run( pose, mm, *fa_scorefxn_, options );
185  }
186 
187  }
188 
189  output_pose_list.push_back( pose.clone() );
190  TR.Debug << "Score minimized from " << F(8,3, score_original) << " to " << F(8,3,(*fa_scorefxn_)( pose )) << std::endl;
191  }
192 
194 
195  TR.Debug << "Total time in StepWiseProteinMinimizer: " <<
196  static_cast<Real>(clock() - time_start) / CLOCKS_PER_SEC << std::endl;
197 
198 }
199 
200 //////////////////////////////////////////////////////////////////////////
201 void
204  core::pose::Pose & pose ){
205 
206  using namespace core::scoring;
207 
208  (*fa_scorefxn_)( pose );
209  EnergyGraph const & energy_graph( pose.energies().energy_graph() );
210 
211  for ( Size n = 1; n <= moving_residues_.size(); n++ ) {
212  Size const i = moving_residues_[ n ];
213  if ( pose.residue(i).is_protein() ) { // these should be activated, but make sure . VIRTUAL_SIDE_CHAIN issue!
214  mm.set_chi( i, true );
215  }
216  }
217 
218  for ( Size n = 1; n <= moving_residues_.size(); n++ ) {
219 
220  Size const i = moving_residues_[ n ];
221 
223  iter = energy_graph.get_node( i )->const_edge_list_begin();
224  iter != energy_graph.get_node( i )->const_edge_list_end();
225  ++iter ) {
226 
227  Size j( (*iter)->get_other_ind( i ) );
228  if ( pose.residue(j).has_variant_type( core::chemical::VIRTUAL_RESIDUE_VARIANT ) ) continue;
229 
230  if ( pose.residue(j).is_protein() ) {
231  mm.set_chi( j, true );
232  } else if ( pose.residue(j).is_RNA() ) {
233  mm.set( id::TorsionID( j, id::CHI, 4), true ); // 2'-OH.
234  }
235 
236  }
237  }
238 
239 }
240 
241 //////////////////////////////////////////////////////////////////////////
242 bool
244  // this is pretty conservative -- actually there might be
245  // cases where the pose has a chainbreak but the minimized dofs would
246  // not affect the relative positions of the chainbreak residues.
247  for ( Size i = 1; i <= pose.total_residue(); i++ ) {
248  if ( pose.residue_type(i).has_variant_type( "CUTPOINT_UPPER" ) ) return true;
249  if ( pose.residue_type(i).has_variant_type( "CUTPOINT_LOWER" ) ) return true;
250  }
251  return false;
252 }
253 
254 //////////////////////////////////////////////////////////////////////////
255 void
257  min_type_ = min_type;
258 }
259 
260 //////////////////////////////////////////////////////////////////////////
261 void
263  min_tolerance_ = min_tolerance;
264 }
265 
266 //////////////////////////////////////////////////////////////////////////
267 void
269  fa_scorefxn_ = scorefxn;
270 }
271 
272 //////////////////////////////////////////////////////////////////////////
273 void
274 StepWiseProteinMinimizer::set_fixed_res( utility::vector1< core::Size > const & fixed_res ){
275  fixed_res_ = fixed_res;
276 }
277 
278 //////////////////////////////////////////////////////////////////////////
279 void
280 StepWiseProteinMinimizer::set_calc_rms_res( utility::vector1< core::Size > const & calc_rms_res ){
281  calc_rms_res_ = calc_rms_res;
282 }
283 
284 //////////////////////////////////////////////////////////////////////////
285 void
287  cartesian_ = setting;
288  if ( cartesian_ ) min_type_ = "lbfgs_armijo_nonmonotone";
289 }
290 
291 
292 } //protein
293 } //modeler
294 } //legacy
295 } //stepwise
296 } //protocols
utility::pointer::shared_ptr< ScoreFunction > ScoreFunctionOP
void let_neighboring_chis_minimize(core::kinematics::MoveMap &mm, core::pose::Pose &pose)
Minimizer options class.
Declarations for the MoveMap class.
static THREAD_LOCAL basic::Tracer TR("protocols.stepwise.legacy.modeler.protein.StepWiseProteinMinimizer")
EnergyGraph const & energy_graph() const
Read access to the EnergyGraph.
Definition: Energies.cc:255
High-level atom tree minimizer class.
A molecular system including residues, kinematics, and energies.
Definition: Pose.hh:151
Score function class.
virtual void apply(core::pose::Pose &pose_to_visualize)
Apply the minimizer to one pose.
A class specifying DOFs to be flexible or fixed.
Definition: MoveMap.hh:87
void set_fixed_res(utility::vector1< core::Size > const &fixed_res)
virtual std::string get_name() const
Each derived class must specify its name. The class name.
High-level atom tree minimizer class.
chemical::ResidueType const & residue_type(Size const seqpos) const
Returns the ResidueType at position (read access) Note: this method NOT will trigger a refol...
Definition: Pose.cc:875
Utility functions for defining and using constraints.
void set(TorsionType const &t, bool const setting)
set a specific TorsionType movable: currently BB, CHI, NU, BRANCH, or JUMP
Definition: MoveMap.cc:102
Conformation const & conformation() const
Returns the pose Conformation (const-access)
Definition: Pose.hh:236
utility::pointer::shared_ptr< ConstraintSet > ConstraintSetOP
EdgeListConstIter const_edge_list_end() const
returns a const iterator to the end of its edge list
Definition: Graph.hh:451
High-level atom tree minimizer class.
platform::Size Size
Definition: types.hh:30
PoseOP clone() const
clone the conformation
Definition: Pose.cc:282
Size total_residue() const
Returns the number of residues in the pose conformation.
Definition: Pose.cc:732
bool has_variant_type(VariantType const variant_type) const
Generic variant access.
Node const * get_node(platform::Size index) const
get a const * to one node that this edge is incident upon uses c-style index-from-0 for these two nod...
Definition: Graph.hh:627
void set_chi(bool const setting)
Sets whether or not CHI TorsionType is movable.
Definition: MoveMap.hh:233
void add_coordinate_constraints(pose::Pose &pose, Real const coord_sdev, bool include_sc)
handy function for tethering pose to starting coordinates.
Definition: util.cc:364
Torsion identifier class.
Definition: TorsionID.hh:50
void fix_disulfides(utility::vector1< std::pair< Size, Size > > disulf_bonds)
Assigns disulfide bonds based on a pre-determined list.
void set_calc_rms_res(utility::vector1< core::Size > const &calc_rms_res)
void output_pose_list(utility::vector1< core::pose::PoseOP > pose_list, core::pose::PoseCOP native_pose, std::string const &silent_file, utility::vector1< Size > const &working_calc_rms_res, bool const overwrite)
Definition: util.cc:94
platform::Real Real
Definition: types.hh:35
void figure_out_stepwise_movemap(core::kinematics::MoveMap &mm, core::pose::Pose const &pose, utility::vector1< Size > const &working_minimize_res, bool const move_takeoff_torsions)
Definition: util.cc:57
Energies class.
Pose utilities.
Class to hold the component energies between pairs of residues. Each node represents a residue in its...
Definition: EnergyGraph.hh:177
void disulfide_bonds(conformation::Conformation const &conformation, utility::vector1< std::pair< Size, Size > > &disulfides)
Generate a list of all disulfide bonds in the conformation.
Definition: util.cc:2198
Residue const & residue(Size const seqpos) const
Returns the Residue at position (read access) Note: this method will trigger a refold if eit...
Definition: Pose.cc:866
conformation container
Energy graph class declaration.
bool is_RNA() const
Returns true if this residue is a RNA residue.
Definition: Residue.hh:1707
bool has_variant_type(chemical::VariantType const variant_type) const
Generic variant access.
Definition: Residue.hh:1870
bool is_protein() const
Returns true if this residue is an amino acid.
Definition: Residue.hh:1673
Custom Edge list const iterator class, which returns only const Edge pointers. This iterator cannot b...
Definition: Graph.hh:228
scoring::Energies const & energies() const
Returns the pose Energies (const-access)
Definition: Pose.hh:339
static THREAD_LOCAL basic::Tracer TR("protocols.looprelax_protocols")
ConstraintSetCOP constraint_set() const
Definition: Pose.cc:1624
Pose class.