Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GraftMoverBase.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/grafting/GraftMoverBase.cc
11 /// @brief Base class for GraftMovers
12 /// @author Jared Adolf-Bryfogle (jadolfbr@gmail.com)
13 
14 //Unit headers
16 #include <protocols/moves/Mover.hh>
17 
18 //Core headers
19 #include <core/pose/Pose.hh>
20 #include <core/pose/util.hh>
25 #include <core/scoring/rms_util.hh>
27 #include <core/id/AtomID_Map.hh>
28 #include <core/id/TorsionID.hh>
29 
34 
35 //Protocol Headers
38 #include <protocols/loops/Loop.hh>
39 #include <protocols/loops/util.hh>
40 
41 
42 //Basic Headers
43 #include <basic/Tracer.hh>
44 
45 //Utility Headers
46 #include <utility/PyAssert.hh>
48 
49 
50 
51 static basic::Tracer TR("protocols.grafting.GraftMoverBase");
52 
53 namespace protocols {
54 namespace grafting {
55 
56 using namespace core;
57 using namespace core::pose;
58 using namespace protocols::moves;
59 using namespace core::scoring;
60 using core::Size;
61 using core::id::AtomID;
67 
69  moves::Mover(mover_name),
70  start_(start),
71  end_(end),
72  original_end_(end)
73 
74 {
75 }
76 
77 ///@brief copy ctor
78 //GraftMoverBase::GraftMoverBase( GraftMoverBase const & rhs ) :
79 // Mover(rhs)
80 //{
81 // *this = rhs;
82 //}
83 
84 // Destructor
86 
87 
88 void
89 GraftMoverBase::set_piece(Pose & piece, Size Nter_overhang, Size Cter_overhang){
90  piece_ = piece;
91  Nter_overhang_ = Nter_overhang;
92  Cter_overhang_=Cter_overhang;
94 }
95 
96 void
98  start_=start;
99  end_=end;
101 }
102 
103 void
105  cen_scorefxn_=score->clone();
106 }
107 
108 void
110  //Just in case modifications are made to it.
111  fa_scorefxn_=score->clone();
112 }
113 
114 void
117 }
118 void
121 }
122 
123 void
125 
126  //Nter
127  for (core::Size i=1; i<=Nter_overhang_; ++i){
128  //piece_.conformation().delete_polymer_residue(piece_res_num);
130  }
131 
132  //Cter
133  core::Size res_num_start = (piece_.total_residue() - Cter_overhang_ + 1);
134  for (core::Size i=1; i<=Cter_overhang_; ++i){
135  //piece_.conformation().delete_polymer_residue(piece_res_num);
136  piece_.conformation().delete_residue_slow(res_num_start);
137  }
138  set_overhang(0, 0);
139 }
140 
141 void
142 GraftMoverBase::set_overhang(Size Nter_overhang, Size Cter_overhang){
143  Nter_overhang_=Nter_overhang;
144  Cter_overhang_=Cter_overhang;
145 }
146 
147 void
148 GraftMoverBase::superimpose_overhangs_heavy(Pose const & pose, bool ca_only, bool silence_rms){
149  AtomID_Map < AtomID > atoms_to_superimpose;
150  initialize_atomid_map( atoms_to_superimpose, piece_, core::id::BOGUS_ATOM_ID );
151  //Remove termini
154 
155  //Nter residues/atoms
156  for (core::Size piece_res_num=1; piece_res_num<=Nter_overhang_; ++piece_res_num){
157  core::Size pose_res_num = start_ - Nter_overhang_ + piece_res_num;
158  if (ca_only){
159  AtomID const atom_piece(piece_.residue(piece_res_num).atom_index("CA"), piece_res_num);
160  AtomID const atom_pose(pose.residue(pose_res_num).atom_index("CA"), pose_res_num);
161  atoms_to_superimpose[ atom_piece ]=atom_pose;
162  }
163  else{
164  for (core::Size atom_num=1; atom_num <=4; atom_num++){
165  AtomID const atom_piece(atom_num, piece_res_num);
166  AtomID const atom_pose(atom_num, pose_res_num);
167  atoms_to_superimpose[ atom_piece ]=atom_pose;
168  }
169  }
170  }
171 
172  //Cter residues/atoms
173  core::Size i = 0;
174  for (core::Size piece_res_num=(piece_.total_residue() - Cter_overhang_ + 1); piece_res_num<=piece_.total_residue(); ++piece_res_num){
175  core::Size pose_res_num = end_ + i;
176  if (ca_only){
177  AtomID const atom_piece(piece_.residue(piece_res_num).atom_index("CA"), piece_res_num);
178  AtomID const atom_pose(pose.residue(pose_res_num).atom_index("CA"), pose_res_num);
179  atoms_to_superimpose[ atom_piece ]=atom_pose;
180  }
181  else{
182  for (core::Size atom_num=1; atom_num <=4; ++atom_num){
183  AtomID const atom_piece(atom_num, piece_res_num);
184  AtomID const atom_pose( atom_num, pose_res_num);
185  atoms_to_superimpose[ atom_piece ]=atom_pose;
186  }
187  }
188  ++i;
189  }
190 
191  core::Real rms(superimpose_pose(piece_, pose, atoms_to_superimpose));
192 
193  if (!silence_rms){
194  TR << "RMS of piece from starting position to current: "<<rms<<std::endl;
195  }
196  return;
197 }
198 
199 MoveMapOP
200 GraftMoverBase::combine_movemaps(MoveMap const & scaffold_mm, MoveMap const & insert_mm){
201  using namespace core::kinematics;
202  MoveMapOP mm = new MoveMap();
203  TR<<"Combining movemaps"<<std::endl;
204  //First time with typedefs They are pretty narley!
205  typedef core::id::TorsionID TorsionID;
206  typedef std::pair< Size, core::id::TorsionType > MoveMapTorsionID;
207  typedef std::map< MoveMapTorsionID, bool > MoveMapTorsionID_Map;
208 
209  //Assert that a piece is set.
210 
211  //Copy Nterminal MoveMapTorsionIDs
212  for (MoveMapTorsionID_Map::const_iterator it=scaffold_mm.movemap_torsion_id_begin(), it_end=scaffold_mm.movemap_torsion_id_end(); it !=it_end; ++it){
213  //Scaffold to new MM
214  if (it->first.first<=start_){
215  MoveMapTorsionID new_id = MoveMapTorsionID(it->first.first, it->first.second);
216  mm->set(new_id, it->second);
217  }
218  }
219 
220  //Set insert residues
221  for (MoveMapTorsionID_Map::const_iterator it=insert_mm.movemap_torsion_id_begin(), it_end=insert_mm.movemap_torsion_id_end(); it !=it_end; ++it){
222  //Add from start_
223  Size new_resnum = start_ + it->first.first;
224  MoveMapTorsionID new_id = MoveMapTorsionID(new_resnum, it->first.second);
225  mm->set(new_id, it->second);
226  }
227 
228  //Set Cterminal residues after insert. We may have a deletion then an insertion that we need to change the numbers for.
229  Size deleted_residues = original_end_-start_-1;
230  for (MoveMapTorsionID_Map::const_iterator it=scaffold_mm.movemap_torsion_id_begin(), it_end=scaffold_mm.movemap_torsion_id_end(); it !=it_end; ++it){
231  //Check if residue exists in movemap. Copy that info no matter what it is to the new movemap.
232  if (it->first.first >=original_end_) {
233  //Add insertion length
234  Size new_resnum = it->first.first - deleted_residues+insertion_length_;
235  MoveMapTorsionID new_id = MoveMapTorsionID(new_resnum, it->first.second);
236  mm->set(new_id, it->second);
237  }
238  }
239  mm->show(TR);
240  return mm;
241 }
242 
243 Pose
245 
246  //Delete overhang if necessary.
248 
249  //strip termini variants from insert if necessary
252 
253  //Delete residues for pose.
254  Pose final_pose(pose);
255  delete_region(final_pose, start_+1, end_-1);
256  //Pose insert(piece_); Does the piece still exist afterward?
257  final_pose = insert_pose_into_pose(final_pose, piece_, start_, start_+1);
258 
259  //Update end residue number.
261  TR <<"Insertion complete."<<std::endl;
262  return final_pose;
263 
264 }
265 
266 
267 
270  Pose pre_test(pose);
271  TR <<"Randomizing residues in movemap." <<std::endl;
272  protocols::simple_moves::SmallMover randomize(mm, 10000, 500); //Huge KT to randomize the residues
273  randomize.angle_max( 'H', 180.0 );
274  randomize.angle_max( 'E', 180.0 );
275  randomize.angle_max( 'L', 180.0 );
276  randomize.apply(pose);
277 
278  Real RMS = core::scoring::bb_rmsd_including_O(pre_test, pose);
279  TR <<"All BB Heavy Atom RMSD "<< RMS <<std::endl;
280  return RMS;
281  }
282 
283 
284 //////////////////////////////////////////////////////////////////////////////////////////////////////
285 ///MOVEMAP and REGION SETUP
286 ///Note: Only these functions interact with class variables defined here. To be used optionally in apply.
287 //////////////////////////////////////////////////////////////////////////////////////////////////////
288 
289 void
291  if (!use_default_movemap_){
294 
295  }
296  else{
299  }
300 
301  PyAssert((Nter_loop_start_!=Cter_loop_end_), "Start and end of remodeling region the same. Please check movemap");
302 }
303 
304 void
306  TR <<"Setting default movemap"<<std::endl;
308  for (Size i=Nter_loop_start_; i<=Nter_loop_end_; ++i){
309  movemap_->set_bb(i, true);
310  movemap_->set_chi(i, true);
311  }
312  for (Size i=Cter_loop_start_; i<=Cter_loop_end_; ++i){
313  movemap_->set_bb(i, true);
314  movemap_->set_chi(i, true);
315  }
316 }
317 
318 void
320  Nter_loop_start_ = start_-Nter_scaffold_flexibility_+1;//(loop_start/insert_loop_start)First Flexible loop residue
322 
324  Cter_loop_end_ = start_+insertion_length_+Cter_scaffold_flexibility_;//(loop_end) Last Flexible loop residue
325 
326  //TR <<"Nter_loop_start: "<<Nter_loop_start_<<std::endl;
327  //TR <<"Nter_loop_end: "<<Nter_loop_end_<<std::endl;
328  //TR <<"Cter_loop_start: "<<Cter_loop_start_<<std::endl;
329  //TR <<"Cter_loop_end: "<<Cter_loop_end_<<std::endl;
330 }
331 
332 
333 void
335  //N terminal
336  for (Size i=1; i<=start_; ++i){
337  if (movemap_->get_bb(i)){
339  break;
340  }
341  }
342 
343  //C terminal end
344  for (Size i=pose.total_residue(); i>=Nter_loop_start_; --i){
345  if (movemap_->get_bb(i)){
346  TR <<i<<std::endl;
347  Cter_loop_end_=i;
348  break;
349  }
350  }
351 
352  //Insertion default flexiblity. Will not effect single_loop foldtrees.
354  for (Size i = start_+1; i<=start_+insertion_length_; ++i){
355  if (movemap_->get_bb(i)){
357  }
358  else{
360 
361  break;
362  }
363  }
364 
366  for (Size i = start_+insertion_length_; i>=1; --i){
367  if (movemap_->get_bb(i)){
369  }
370  else{
372  break;
373  }
374  }
375  //TR <<"Nter_insert_flex: "<<Nter_insert_flexibility_<<std::endl;
376  //TR <<"Nter_loop_start: "<<Nter_loop_start_<<std::endl;
377  //TR <<"Nter_loop_end: "<<Nter_loop_end_<<std::endl;
378  //TR <<"Cter_loop_start: "<<Cter_loop_start_<<std::endl;
379  //TR <<"Cter_loop_end: "<<Cter_loop_end_<<std::endl;
380 }
381 
382 
383 
384 
385 
386 /////////////////////////////////////////////////////////////////////////////////////////////////
387 ///FOLDTREE SETUP. options depending on how you want your graft algorithm to work!
388 ///---Indicates Flexible regions, | indicates cutpoint. Arrows are direction of ARMs used to close the loop in conjunction with algorithm. (CCD, KIC)
389 ///
390 /////////////////////////////////////////////////////////////////////////////////////////////////
391 
392 /////////////////////////////////////////////////////////////////
393 /// @brief ****Nter_loop_start---->Piece----> | Cter_loop_end****
394 /// Insert will move in cartesian space
395 /// @params lower_cutpoint for CCD and loops is Cter_loop_end-1
396 ///
397 void
398 GraftMoverBase::setup_single_loop_single_arm_remodeling_foldtree(Pose & pose, Size const Nter_loop_start, Size const Cter_loop_end, bool loop_modeling){
400 
401  //Setup the offset so the anchor of the loop is correct for either CCD loop closure or vanilla loop modeling.
402  Size anchor_offset = 1;
403  if (loop_modeling){anchor_offset=2;}
404 
405  core::Size const cutpoint_lower(Cter_loop_end-1); //cutpoint at the end of the loop
406  core::Size const cutpoint_upper(Cter_loop_end); //cutpoint at the end of the loop
407  core::Size const loop_start_foldtree_anchor(Nter_loop_start-anchor_offset); //this is the N-terminal jump anchor for the loop
408  core::Size const loop_end_foldtree_anchor(Cter_loop_end+anchor_offset); //C-terminal jump anchor
409 
410  TR << "loop_start_foldtree_anchor " << loop_start_foldtree_anchor << std::endl;
411  TR << "cutpoint_lower " << cutpoint_lower << std::endl;
412  TR << "cutpoint_upper " << cutpoint_upper << std::endl;
413  TR << "loop_end_foldtree_anchor " << loop_end_foldtree_anchor << std::endl;
414 
415  core::kinematics::FoldTree remodeling_tree(pose.total_residue());
416  remodeling_tree.clear();
417  remodeling_tree.add_edge(Edge(1, loop_start_foldtree_anchor, Edge::PEPTIDE));
418  remodeling_tree.add_edge(Edge(loop_start_foldtree_anchor, cutpoint_lower, Edge::PEPTIDE));
419  remodeling_tree.add_edge(Edge(cutpoint_upper, loop_end_foldtree_anchor, Edge::PEPTIDE));
420  remodeling_tree.add_edge(Edge(loop_end_foldtree_anchor, pose.total_residue(), Edge::PEPTIDE));
421  remodeling_tree.add_edge(Edge(loop_start_foldtree_anchor, loop_end_foldtree_anchor, 1));
422  remodeling_tree.reorder(1);
423  TR << remodeling_tree << std::endl;
424  pose.fold_tree(remodeling_tree);
425 }
426 
427 
428 //////////////////////////////////////////////////////////////////
429 /// @brief ****Nter_loop_start---->Piece | <----Nter_loop_end****
430 /// Insert will move in cartesian space
431 /// @params lower_cutpoint for CCD and loops is end_-1
432 ///
433 void
434 GraftMoverBase::setup_single_loop_double_arm_remodeling_foldtree(Pose & pose, Size const Nter_loop_start, Size const Cter_loop_end, bool loop_modeling){
435  //Note: Differs from single arm by moving the cutpoint.
436  TR <<"Setting up single loop, double arm remodeling foldtree"<<std::endl;
438  insertion_length_ = piece_.total_residue();//Double check.
439 
440  //Setup the offset so the anchor of the loop is correct for either CCD loop closure or vanilla loop modeling.
441  Size anchor_offset = 1;
442  if (loop_modeling){anchor_offset=2;}
443 
444  core::Size const cutpoint_lower(end_-1);//Cutpoint is at the end of the insert
445  core::Size const cutpoint_upper(end_);
446  core::Size const loop_start_foldtree_anchor(Nter_loop_start-anchor_offset); //this is the N-terminal jump anchor for the loop
447  core::Size const loop_end_foldtree_anchor(Cter_loop_end+anchor_offset); //C-terminal jump anchor
448 
449  TR << "loop_start_foldtree_anchor " << loop_start_foldtree_anchor << std::endl;
450  TR << "cutpoint_lower " << cutpoint_lower << std::endl;
451  TR << "cutpoint_upper " << cutpoint_upper << std::endl;
452  TR << "loop_end_foldtree_anchor " << loop_end_foldtree_anchor << std::endl;
453 
454  core::kinematics::FoldTree remodeling_tree(pose.total_residue());
455  remodeling_tree.clear();
456  remodeling_tree.add_edge(Edge(1, loop_start_foldtree_anchor, Edge::PEPTIDE));
457  remodeling_tree.add_edge(Edge(loop_start_foldtree_anchor, cutpoint_lower, Edge::PEPTIDE));
458  remodeling_tree.add_edge(Edge(cutpoint_upper, loop_end_foldtree_anchor, Edge::PEPTIDE));
459  remodeling_tree.add_edge(Edge(loop_end_foldtree_anchor, pose.total_residue(), Edge::PEPTIDE));
460  remodeling_tree.add_edge(Edge(loop_start_foldtree_anchor, loop_end_foldtree_anchor, 1));
461  remodeling_tree.reorder(1);
462  TR << remodeling_tree << std::endl;
463  pose.fold_tree(remodeling_tree);
464 }
465 
466 // Mover methods
469 {
470  return "GraftMoverBase";
471 }
472 
473 
474 
475 } // namespace grafting
476 } // namespace protocols