Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Loop.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/loops/Loop.cc
11 /// @brief
12 /// @author Chu Wang
13 /// @author Mike Tyka
14 /// @author James Thompson
15 
16 // Unit Headers
17 #include <protocols/loops/Loop.hh>
18 
19 // Project Headers
22 #include <core/pose/Pose.hh>
23 
24 // Utility Headers
25 #include <basic/Tracer.hh>
26 #include <numeric/random/random.hh>
27 #include <utility/exit.hh>
28 #include <utility/vector1.hh>
29 
30 // ObjexxFCL Headers
31 #include <ObjexxFCL/FArray1D.hh>
32 #include <ObjexxFCL/string.functions.hh>
33 
34 namespace protocols {
35 namespace loops {
36 
37 /// @details Auto-generated virtual destructor
39 
40 static basic::Tracer tr("protocols.loops.Loop");
41 static numeric::random::RandomGenerator RG(429); // <- Magic number, do not change it (and don't try and use it anywhere else)
42 
43 /// @brief switch DOF_Type for residues in loop. id::CHI, id::BB --- don't use
44 /// with id::JUMP
45 void
49  bool allow_moves
50 ) const {
51  for ( Size pos = start(); pos <= stop(); pos++ ) {
52  movemap.set( core::kinematics::MoveMap::MoveMapTorsionID( pos, id ), allow_moves );
53  }
54 }
55 
56 
57 /////////////////////////////////////////////////////////////////////
58 /// @details Choose a cutpoint for the loop if one is not specified.
59 /// Allow any residue to serve as the cutpoint, but prefer those to the center.
60 void
62  using core::Size;
63 
64  Size const loop_size ( stop_ - start_ + 1 );
65  Size const nres( pose.total_residue() );
66 
67  // Special case if we are extending the loop????
68 
69  // set up a weight-map for picking cut_s, we want the cut to be internal to
70  // the loop, so that the splice-rmsds are calculated between idealized atoms
71  // so also only use chainbreak_overlap = 1
72  Size const n_cut_s ( loop_size - 1 );
73  ObjexxFCL::FArray1D_float cut_weight( n_cut_s );
74  core::Real total_cut_weight( 0 );
75  for ( Size i = 1; i <= n_cut_s; ++i ) {
76  // eg: for a 7 rsd loop: 1 2 3 4 3 2 1
77  core::Real const weight ( std::max( i, n_cut_s-i + 1 ) );
78  total_cut_weight += weight;
79  cut_weight(i) = total_cut_weight;
80  }
81  // choose the cut_:
82  cut_ = 0;
83 
84  if ( start_ > 1 && stop_ < nres ){
85  char ss;
86  Size nfail( 0 );
87  do {
88  nfail++;
89  core::Real const weight ( numeric::random::uniform()*total_cut_weight );
90  for ( Size i = 1; i <= n_cut_s; ++i ) {
91  if ( weight <= cut_weight(i) ) {
92  cut_ = start_ + i - 1;
93  break;
94  }
95  }
96  ss = pose.secstruct( cut_ );
97 
98  // First try to put cutpoint outside of secondary structure
99  if( nfail < 20 ) if( ( ss == 'H' || ss == 'E' ) ) continue;
100  // later only insist that cutpoint is not infront of proline
101  if( nfail < 40 ) if( pose.residue(cut_+1).aa() == core::chemical::aa_pro ) continue;
102  if( nfail >= 40 ) tr.Error << "Cutpoint choice problem, setting cut_ = " << cut_ << std::endl;
103  }while(false);
104 
105  if ( cut_ == 0 ) {
106  cut_ = ( start_ + n_cut_s/2 );
107  tr.Warning << "Cutpoint choice problem, setting cut_ = " << cut_ << std::endl;
108  }
109  runtime_assert ( cut_ >= start_ && cut_ <= stop_ );
110  } else if( start_ == 1 ) {
111  cut_ = 1;
112  } else if ( stop_ == nres ){
113  cut_ = nres;
114  } else {
115  utility_exit_with_message(
116  "Somthing is wrong with the input loop: Pose has " +
117  ObjexxFCL::string_of( nres ) +
118  " residues, but loop definition runs from " +
119  ObjexxFCL::string_of( start_ ) + " to " +
120  ObjexxFCL::string_of( stop_ )
121  );
122  }
123 
124  tr.Info << "Autoset cut_ for loop " << start_ << " " << stop_
125  << " as " << cut_ << "." << std::endl;
126 }
127 
128 void Loop::get_residues( utility::vector1< Size>& selection ) const {
129  for ( core::Size i = start_; i<= stop_; i++ ) {
130  selection.push_back( i );
131  }
132 }
133 
134 
135 ///////////////////////////////////////////////////////////////////////
136 /// @details Detect a terminal loop, logic is more complicated for multi-chain
137 /// poses. Returns TRUE for terminal loops.
138 bool
139 Loop::is_terminal( core::pose::Pose const & pose ) const
140 {
141  if ( start() == 1 ) return true; // loop start at first residue
142  if ( stop() == pose.total_residue() ) return true; // loop end at last residue
143  if ( !pose.residue( start() -1 ).is_protein() ) return true; // residue before start is not protein
144  if ( !pose.residue( stop() +1 ).is_protein() ) return true; // residue after end is not protein
145  if ( pose.chain( start() -1 ) != pose.chain( start() ) ) return true; // residues before start is other chain
146  if ( pose.chain( stop() +1 ) != pose.chain( stop() ) ) return true; // residues before start is other chain
147  if ( pose.residue( start() ).is_lower_terminus() ) return true; // explicit terminus variant @ start of loop
148  if ( pose.residue( stop() ).is_upper_terminus() ) return true; // explicit terminus variant @ end of loop
149  return false;
150 }
151 
152 } // namespace loops
153 } // namespace protocols
154