Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ConstrainToIdealMover.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/simple_moves/ConstrainToIdealMover.cc
11 /// @brief Adds to your pose constraints suitable for idealization of bond lengths and angles
12 /// @author Steven Lewis (smlewi@gmail.com); Rhiju Das
13 
14 
15 // Unit Headers
17 //#include <protocols/simple_moves/ConstrainToIdealMoverCreator.hh>
18 
19 // Project Headers
20 #include <core/pose/Pose.hh>
22 
25 #include <protocols/toolbox/AllowInsert.hh> //need to move AllowInsert to toolbox XRW2
26 
28 
30 //#include <core/chemical/util.hh>
31 
32 //#include <core/id/AtomID_Map.hh>
33 //TRANSCLUDED in MoveMap #include <core/id/AtomID.hh>
34 //#include <core/id/NamedAtomID.hh>
35 //TRANSCLUDED in MoveMap #include <core/id/DOF_ID.hh>
36 //#include <core/id/TorsionID.hh>
37 
41 
42 //#include <core/pose/util.hh>
44 
49 
50 // Utility Headers
51 #include <basic/Tracer.hh>
52 //#include <core/types.hh>
53 //#include <utility/exit.hh>
54 
55 #include <numeric/conversions.hh>
56 #include <numeric/xyz.functions.hh>
57 
58 // AUTO-REMOVED #include <core/chemical/AtomType.hh>
59 #include <utility/vector1.hh>
60 
61 
62 using basic::T;
63 using basic::Error;
64 using basic::Warning;
65 
66 static basic::Tracer TR( "protocols.simple_moves.ConstrainToIdealMover" );
67 
68 namespace protocols {
69 namespace simple_moves {
70 
71 /*std::string
72 ConstrainToIdealMoverCreator::keyname() const
73 {
74  return ConstrainToIdealMoverCreator::mover_name();
75 }
76 
77 protocols::moves::MoverOP
78 ConstrainToIdealMoverCreator::create_mover() const {
79  return new ConstrainToIdealMover;
80 }
81 
82 std::string
83 ConstrainToIdealMoverCreator::mover_name()
84 {
85  return "ConstrainToIdealMover";
86 }
87 */
88 
89 ///@brief parse XML (specifically in the context of the parser/scripting scheme)
90 // void
91 // ConstrainToIdealMover::parse_my_tag(
92 // TagPtr const tag,
93 // protocols::moves::DataMap & datamap,
94 // Filters_map const & filters,
95 // protocols::moves::Movers_map const & movers,
96 // Pose const & pose
97 // )
98 // {
99 // if ( tag->getName() != "ConstrainToIdealMover" ) {
100 // TR << " received incompatible Tag " << tag << std::endl;
101 // assert(false);
102 // return;
103 // }
104 //}
105 
107  : protocols::moves::Mover("ConstrainToIdealMover"),
108  allow_insert_(NULL), //requires pose to initialize
109  mm_(new core::kinematics::MoveMap()),
110  supplied_movemap_(false)
111 {}
112 
114 
116  *this = rhs;
117  return;
118 }
119 
121 
122  //abort self-assignment
123  if (this == &rhs) return *this;
124 
125  // allow_insert_ = rhs.get_AllowInsert(); //would prefer to clone, but that class author offered no way to do it
126  allow_insert_ = rhs.get_AllowInsert()->clone(); //OK stephen, I did it. --Rhiju
127  mm_ = rhs.get_movemap()->clone();
129  return *this;
130 }
131 
134  return "ConstrainToIdealMover"; //ConstrainToIdealMoverCreator::mover_name();
135 }
136 
139 
140 ///@details supply a MoveMap to be further modified by this mover; otherwise it will modify a blank one; notice it sets a boolean flag to mark the source of the movemap
142  mm_ = movemap;
143  supplied_movemap_ = true;
144 }
145 
146 ///@brief get the MoveMap last created during apply(); it has the bond and angles free for minimization
148 
149 ///@brief setter for AllowInsert; shallow copy
151 
152 ///@brief getter for AllowInsert
154 
155 ///@details This code will modify your input pose by adding constraints which will trend bond lengths and angles towards ideal. If you input a movemap via set_movemap, that movemap will be modified to free the same set of bond lengths and angles (needs some testing) and will be available from get_movemap.
159 
160  //handle mm - if we don't have a freshly externally supplied one, throw the old one out.
161  //this is not a clear() operation in case someone is still sharing the old pointer
164 
165  core::pose::Pose pose_reference;
166  create_pose_reference(pose, pose_reference);
167 
168  vary_bond_geometry(pose, pose_reference);
169 
170  //the movemap in mm_ is now modified and cannot be reused
171  supplied_movemap_ = false;
172  return;
173 }//apply
174 
175 //////////////////////////////////START MOVED CODE/////////////////////////////
176 //Most of the code for this mover was moved from Rhiju's RNA_Minimizer. It was
177 //copied from src/protocols/rna/RNA_Minimizer.cc, SVN #44771
178 ///////////////////////////////////////////////////////////////////////////////
179 
180 //copied from src/protocols/rna/RNA_Minimizer.cc, SVN #44771
181 bool
183  core::id::AtomID const & atom_id1,
184  core::id::AtomID const & atom_id2,
185  utility::vector1< std::pair< core::id::AtomID, core::id::AtomID > > & bonded_atom_list ) {
186 
187  for (core::Size n = 1; n <= bonded_atom_list.size(); n++ ) {
188  if( atom_id1 == bonded_atom_list[ n ].first && atom_id2 == bonded_atom_list[ n ].second ) return true;
189  if( atom_id2 == bonded_atom_list[ n ].first && atom_id1 == bonded_atom_list[ n ].second ) return true;
190  }
191  return false;
192 }
193 
194 //copied from src/protocols/rna/RNA_Minimizer.cc, SVN #44771
195 bool
197  core::id::AtomID const & atom_id1,
198  core::id::AtomID const & atom_id2,
199  core::id::AtomID const & atom_id3,
200  utility::vector1< std::pair< core::id::AtomID, std::pair< core::id::AtomID, core::id::AtomID > > > & bond_angle_list ) {
201 
202  for (core::Size n = 1; n <= bond_angle_list.size(); n++ ) {
203  if( atom_id1 == bond_angle_list[ n ].first ) {
204  if( atom_id2 == bond_angle_list[ n ].second.first && atom_id3 == bond_angle_list[ n ].second.second ) return true;
205  if( atom_id3 == bond_angle_list[ n ].second.first && atom_id2 == bond_angle_list[ n ].second.second ) return true;
206  }
207  }
208  return false;
209 }
210 
211 //copied from src/protocols/rna/RNA_Minimizer.cc, SVN #44771
212 void
214  core::id::AtomID const & atom_id1,
215  core::id::AtomID const & atom_id2,
216  utility::vector1< std::pair< core::id::AtomID, core::id::AtomID > > & bonded_atom_list,
217  core::pose::Pose const & pose,
218  core::pose::Pose const & pose_reference,
220 {
221 
222  using namespace core::scoring;
223  using namespace core::scoring::constraints;
224 
225  std::string const & atom_name1 = pose.residue( atom_id1.rsd() ).atom_name( atom_id1.atomno() );
226  std::string const & atom_name2 = pose.residue( atom_id2.rsd() ).atom_name( atom_id2.atomno() );
227 
228  if ( !pose_reference.residue( atom_id1.rsd() ).has( atom_name1 ) ) return;
229  if ( !pose_reference.residue( atom_id2.rsd() ).has( atom_name2 ) ) return;
230 
231  if ( !check_in_bonded_list( atom_id1, atom_id2, bonded_atom_list ) ) {
232  bonded_atom_list.push_back( std::make_pair( atom_id1, atom_id2 ) );
233 
234  core::Real const bond_length_sd_( 0.05 );
235 
236  core::Real const bond_length = ( pose_reference.residue( atom_id1.rsd() ).xyz( atom_name1 ) -
237  pose_reference.residue( atom_id2.rsd() ).xyz( atom_name2 ) ).length();
238 
239 
240  FuncOP dist_harm_func_( new HarmonicFunc( bond_length, bond_length_sd_ ));
241 
242  cst_set->add_constraint( new AtomPairConstraint( atom_id1 ,
243  atom_id2,
244  dist_harm_func_,
245  rna_bond_geometry ) );
246  if ( false ) {
247  TR << "PUTTING CONSTRAINT ON DISTANCE: " <<
248  atom_id2.rsd() << " " << atom_name1 << "; " <<
249  atom_id1.rsd() << " " << atom_name2 << " " <<
250  bond_length <<
251  std::endl;
252  }
253  }
254 
255 }
256 
257 
258 //copied from src/protocols/rna/RNA_Minimizer.cc, SVN #44771
259 void
261  core::id::AtomID const & atom_id1,
262  core::id::AtomID const & atom_id2,
263  core::id::AtomID const & atom_id3,
264  utility::vector1< std::pair < core::id::AtomID, std::pair< core::id::AtomID, core::id::AtomID > > > & bond_angle_list,
265  core::pose::Pose const & pose,
266  core::pose::Pose const & pose_reference,
268 {
269 
270  using namespace core::scoring;
271  using namespace core::scoring::constraints;
272  using namespace numeric::conversions;
273 
274  if (atom_id2 == atom_id3) return;
275 
276  std::string const & atom_name1 = pose.residue( atom_id1.rsd() ).atom_name( atom_id1.atomno() );
277  std::string const & atom_name2 = pose.residue( atom_id2.rsd() ).atom_name( atom_id2.atomno() );
278  std::string const & atom_name3 = pose.residue( atom_id3.rsd() ).atom_name( atom_id3.atomno() );
279 
280  if ( !pose_reference.residue( atom_id1.rsd() ).has( atom_name1 ) ) return;
281  if ( !pose_reference.residue( atom_id2.rsd() ).has( atom_name2 ) ) return;
282  if ( !pose_reference.residue( atom_id3.rsd() ).has( atom_name3 ) ) return;
283 
284  if ( !check_in_bond_angle_list( atom_id1, atom_id2, atom_id3, bond_angle_list ) ) {
285  bond_angle_list.push_back( std::make_pair( atom_id1, std::make_pair( atom_id2, atom_id3 ) ) );
286 
287 
288  core::Real const bond_angle_sd_( radians( 5.0 ) );
289 
290  core::Real const bond_angle = angle_radians(
291  pose_reference.residue( atom_id2.rsd() ).xyz( atom_name2 ) ,
292  pose_reference.residue( atom_id1.rsd() ).xyz( atom_name1 ) ,
293  pose_reference.residue( atom_id3.rsd() ).xyz( atom_name3 )
294  );
295 
296  if (bond_angle < 0.001 ) TR << "WHAT THE HELL????????? " << std::endl;
297 
298  FuncOP angle_harm_func_( new HarmonicFunc( bond_angle, bond_angle_sd_ ));
299  cst_set->add_constraint( new AngleConstraint(
300  atom_id2 , atom_id1, atom_id3, angle_harm_func_, rna_bond_geometry ) );
301 
302  if ( false ) {
303  TR << "PUTTING CONSTRAINT ON ANGLE: " <<
304  atom_id2.rsd() << " " << pose_reference.residue( atom_id2.rsd() ).atom_name( atom_id2.atomno() ) << "; " <<
305  atom_id1.rsd() << " " << pose_reference.residue( atom_id1.rsd() ).atom_name( atom_id1.atomno() ) << "; " <<
306  atom_id3.rsd() << " " << pose_reference.residue( atom_id3.rsd() ).atom_name( atom_id3.atomno() ) << " ==> " << degrees( bond_angle ) << " " << degrees( bond_angle_sd_ ) <<
307  std::endl;
308  }
309 
310  }
311 
312 }
313 
314 //copied from src/protocols/rna/RNA_Minimizer.cc, SVN #44771
315 bool
317  core::pose::Pose const & pose,
318  core::id::AtomID const & atom_id1,
319  core::id::AtomID const & atom_id2)
320 {
321  if ( atom_id1.rsd() == atom_id2.rsd() ) return true;
322 
323 
324  core::kinematics::tree::AtomCOP atom1 ( & pose.atom_tree().atom( atom_id1 ) );
325  core::kinematics::tree::AtomCOP atom2 ( & pose.atom_tree().atom( atom_id2 ) );
326 
327  if ( atom1->parent() == atom2 ) return true;
328  if ( atom2->parent() == atom1 ) return true;
329 
330  return false;
331 }
332 
333 //copied from src/protocols/rna/RNA_Minimizer.cc, SVN #44771
334 bool
336 {
337 
338  if (k > residue2.first_sidechain_atom() &&
339  k != core::scoring::rna::first_base_atom_index( residue2 ) ) return false;
340 
341  if ( residue2.is_virtual( k ) ) {
342  // std::cout << "Is this virtual? " << residue2.atom_name( k ) << std::endl;
343  return false;
344  }
345 
346  return true;
347 
348 }
349 
350 //copied from src/protocols/rna/RNA_Minimizer.cc, SVN #44771
351 bool
353 {
354 
355  return i_want_this_atom_to_move( pose.residue( atom_id.rsd() ) ,
356  atom_id.atomno() );
357 
358 }
359 //////////////////////////////////////////////////////////////////////////////
360 // Following has not (yet) been carefully debugged. --Rhiju
361 //copied from src/protocols/rna/RNA_Minimizer.cc, SVN #44771
362 void
364  //core::kinematics::MoveMap & mm,
365  core::pose::Pose & pose,
366  core::pose::Pose const & pose_reference ) {
367 
368  using namespace core::id;
369  using namespace core::scoring;
370  using namespace core::scoring::constraints;
371  using namespace core::kinematics;
372  using namespace numeric::conversions;
373 
374  ConstraintSetOP cst_set = pose.constraint_set()->clone();
375  pose.constraint_set( cst_set );
376 
377  core::Size const nres( pose.total_residue() );
378 
379  std::map< AtomID, utility::vector1< AtomID > > lists_of_angle_bonded_atoms;
380 
381  for (core::Size i = 1; i <= nres; i++ ) {
382 
383  if ( !allow_insert_->get( i ) ) continue;
384 
385  core::conformation::Residue const & residue( pose.residue( i ) );
386 
387  for (core::Size j = 1; j <= residue.natoms(); j++ ) {
388 
389  if ( !i_want_this_atom_to_move( residue, j ) ) continue;
390 
391  core::kinematics::tree::AtomCOP current_atom ( & pose.atom_tree().atom( AtomID(j,i) ) );
392  if ( current_atom->is_jump() ) continue;
393 
394  ///////////////////
395  core::kinematics::tree::AtomCOP input_stub_atom1( current_atom->input_stub_atom1() );
396  if ( !input_stub_atom1 ) continue;
397  if ( !i_want_this_atom_to_move( pose, input_stub_atom1->id() ) ) continue;
398  mm_->set( DOF_ID( AtomID( j, i ), D ), true );
399  if ( input_stub_atom1->is_jump() ) continue;
400 
401  core::kinematics::tree::AtomCOP input_stub_atom2( current_atom->input_stub_atom2() );
402 
403  ///////////////////
404  if ( !input_stub_atom2 ) continue;
405  if ( input_stub_atom2 == current_atom ) continue;
406  if ( !i_want_this_atom_to_move( pose, input_stub_atom2->id() ) ) continue;
407  mm_->set( DOF_ID( AtomID( j, i ), THETA ), true );
408  if ( input_stub_atom2->is_jump() ) continue;
409 
410  ///////////////////
411  core::kinematics::tree::AtomCOP input_stub_atom3( current_atom->input_stub_atom3() );
412  if ( !input_stub_atom3 ) continue;
413  if ( !i_want_this_atom_to_move( pose, input_stub_atom3->id() ) ) continue;
414  if ( input_stub_atom3 == current_atom ) continue;
415  mm_->set( DOF_ID( AtomID( j, i ), PHI ), true );
416 
417  }
418  }
419 
422 
423  for (core::Size i = 1; i <= nres; i++ ) {
424 
425  //Go through all bonds in pose...
426  if ( !allow_insert_->get( i ) ) continue;
427 
428  core::conformation::Residue const & residue( pose.residue( i ) );
429 
430  for (core::Size j = 1; j <= residue.natoms(); j++ ) {
431 
432  if ( !i_want_this_atom_to_move( residue, j ) ) continue;
433 
434  AtomID atom_id1( j, i );
435 
437 
438  // Bond lengths.
439  for ( core::Size n = 1; n <= nbrs.size(); n++ ) {
440 
441  AtomID const & atom_id2( nbrs[ n ] );
442 
443  core::conformation::Residue const & residue2( pose.residue( atom_id2.rsd() ) ) ;
444  core::Size const & k( atom_id2.atomno() ) ;
445 
446  if ( ! check_if_really_connected( pose, atom_id1, atom_id2) ) continue;
447 
448  if ( i_want_this_atom_to_move( residue2, k ) ) {
449  add_bond_constraint( atom_id1, atom_id2,
450  bond_list,
451  pose, pose_reference, cst_set );
452  }
453 
454  }
455 
456  // Bond angles
457  for ( core::Size m = 1; m <= nbrs.size(); m++ ) {
458  AtomID const & atom_id2( nbrs[ m ] );
459 
460  core::conformation::Residue const & residue2( pose.residue( atom_id2.rsd() ) ) ;
461  if ( ! check_if_really_connected( pose, atom_id1, atom_id2) ) continue;
462 
463  core::Size const & k( atom_id2.atomno() ) ;
464 
465  for ( core::Size n = 1; n <= nbrs.size(); n++ ) {
466  AtomID const & atom_id3( nbrs[ n ] );
467 
468  core::conformation::Residue const & residue3( pose.residue( atom_id3.rsd() ) ) ;
469  if ( ! check_if_really_connected( pose, atom_id1, atom_id3) ) continue;
470 
471  core::Size const & q( atom_id3.atomno() ) ;
472 
473  if ( i_want_this_atom_to_move( residue2, k ) &&
474  i_want_this_atom_to_move( residue3, q ) ) {
475  add_bond_angle_constraint( atom_id1, atom_id2, atom_id3, bond_angle_list,
476  pose, pose_reference, cst_set );
477  }
478 
479  }
480  }
481 
482 
483  }
484 
485  }
486 
487  pose.constraint_set( cst_set );
488 
489 }
490 
491 
492 ///////////////////////////////////////////////////
493 //copied from src/protocols/rna/RNA_Minimizer.cc, SVN #44771
494 void
496 {
497 
498  using namespace core::scoring::rna;
499  RNA_FittedTorsionInfo const rna_fitted_torsion_info;
500 
501  core::Real const DELTA_CUTOFF( rna_fitted_torsion_info.delta_cutoff() );
502 
503  for (core::Size n = 1; n <= pose.total_residue(); n++ ) {
504  core::Real const delta = pose.residue( n ).mainchain_torsion( DELTA );
505  if ( delta > DELTA_CUTOFF ) {
506  //apply_ideal_c2endo_sugar_coords( pose_reference, pose_reference, n );
507  apply_ideal_c2endo_sugar_coords( pose_reference, n );
508  }
509  }
510 
511 }
512 
513 ///////////////////////////////////////////////////
514 //copied from src/protocols/rna/RNA_Minimizer.cc, SVN #44771
515 void
517  core::pose::Pose const & pose,
518  core::pose::Pose & pose_reference )
519 {
520  using namespace core::chemical;
521  ResidueTypeSetCAP rsd_set;
523  make_pose_from_sequence( pose_reference, pose.sequence(), *rsd_set );
524  apply_ideal_coordinates_for_alternative_pucker( pose, pose_reference );
525 }
526 
527 } // namespace moves
528 } // namespace protocols