Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Loop.hh
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.hh
11 /// @brief
12 /// @author Chu Wang
13 /// @author Mike Tyka
14 /// @author James Thompson
15 
16 #ifndef INCLUDED_protocols_loops_Loop_HH
17 #define INCLUDED_protocols_loops_Loop_HH
18 
19 // Unit headers
21 
22 // Project headers
23 #include <core/types.hh>
24 #include <core/id/types.hh>
26 #include <core/pose/Pose.fwd.hh>
27 
28 // Utility Headers
29 #include <utility/vector1.fwd.hh>
30 #include <utility/pointer/ReferenceCount.hh>
31 
32 // C++ headers
33 #ifdef WIN32
34 #include <functional>
35 #endif
36 
37 #include <ostream>
38 
39 ///////////////////////////////////////////////////////////////////////////////
40 namespace protocols {
41 namespace loops {
42 
43 /// @brief Bare-bones representation of a loop
49  bool extended;
50 };
51 
52 /// single loop definition
54 public:
55  ///@brief Automatically generated virtual destructor for class deriving directly from ReferenceCount
56  virtual ~Loop();
57  /// default constructor
58  Loop():
59  start_(0),
60  stop_(0),
61  cut_(0),
62  skip_rate_( 0.0 ),
63  extended_(false)
64  {}
65 
67  start_( loop.start ),
68  stop_( loop.stop ),
69  cut_( loop.cut ),
70  skip_rate_( loop.skip_rate ),
71  extended_( loop.extended )
72  {}
73 
74  /// input constructor
76  core::Size const start_in, core::Size const stop_in,
77  core::Size const cut_in = 0, core::Real skip_rate = 0.0,
78  bool const extended_in = false
79  ):
80  start_( start_in ),
81  stop_( stop_in ),
82  cut_( cut_in ),
84  extended_( extended_in )
85  {}
86 
87  inline bool is_extended() const { return extended_; }
88  inline core::Size start() const { return start_; }
89  inline core::Size stop() const { return stop_; }
90  inline core::Size cut() const { return cut_; }
91  inline core::Size size() const { return stop_ - start_ + 1; }
92  inline core::Real skip_rate() const { return skip_rate_; }
93 
94  inline void set_extended( bool input ) { extended_ = input; }
95  inline void set_start( core::Size input ) { start_ = input; }
96  inline void set_stop( core::Size input ) { stop_ = input; }
97  inline void set_cut( core::Size input ) { cut_ = input; }
98 
99  /// @brief Assuming that the loop represents a contiguous stretch of residues,
100  /// returns the length. Makes no assumptions about directionality. That is,
101  /// Loop(3,8).length() == Loop(8,3).length(). Constant time procedure.
102  core::Size length() const {
103  Size m = std::min(start(), stop());
104  Size n = std::max(start(), stop());
105  return n - m + 1;
106  }
107 
108  /// @brief Returns true if the loop's elements are increasing
109  bool increasing() const {
110  return start() <= stop();
111  }
112 
113  /// @brief Returns true if the loop's elements are decreasing
114  bool decreasing() const {
115  return !increasing();
116  }
117 
118  /// @brief Returns the midpoint of the loop
120  return increasing() ? start() + length() / 2 : stop() - length() / 2;
121  }
122 
123  bool operator< ( Loop const& larger ) const {
124  return ( size() < larger.size() ? true :
125  ( start() < larger.start() ? true : ( cut() < larger.cut() ) ) );
126  }
127  bool operator==( Loop const& other ) const {
128  return ( size() == other.size() &&
129  start() == other.start() && cut() == other.cut() );
130  }
131  bool operator!=( Loop const& other ) const {
132  return !(*this == other );
133  }
134 
135  ///@brief add all residues within this loop definition into selection
136  void get_residues( utility::vector1< Size>& selection ) const;
137 
138  /// @brief switch DOF_Type for residues in loop. id::CHI, id::BB --- don't
139  /// use with id::JUMP
140  void switch_movemap( core::kinematics::MoveMap& movemap, core::id::TorsionType, bool allow_moves = true ) const;
141 
142  // @brief Autochoose a cutpoint using the secondary structure of the pose.
143  void choose_cutpoint( core::pose::Pose const & pose );
144 
145  /// @brief Autochoose a cutpoint using the secondary structure of the pose
146  /// unless cutpoint is already set
148  if ( cut_ <= 0 ) choose_cutpoint ( pose );
149  }
150 
151  bool is_terminal( core::pose::Pose const & pose ) const;
152 
153  friend std::ostream & operator<<( std::ostream & os, const Loop & loop );
154 
155 private:
160  bool extended_;
161 }; // Loop
162 
163 //////////////////////////////////////////////////////////////////////
164 inline std::ostream & operator<<( std::ostream & os, const Loop & loop ) {
165  os << "LOOP " << loop.start_ << " " << loop.stop_ << " "
166  << loop.cut_ << " "
167  << loop.skip_rate_ << " " << loop.extended_;
168  return os;
169 }
170 
171 /// @brief Orders loops by start position
172 class RationalLoopComparator : public std::binary_function<double, double, bool> {
173 public:
174  bool operator()(Loop x, Loop y) {
175  return x.start() < y.start();
176  }
177 };
178 
179 
180 /// @brief used to sort Loops by start-res
181 class Loop_lt : public std::binary_function<double, double, bool> {
182 public:
183  bool operator()(Loop x, Loop y) {
184  return (x.start() < y.stop()); // so wrong...
185  }
186 };
187 
188 } //namespace loops
189 } //namespace protocols
190 
191 #endif //INCLUDED_protocols_loops_Loop_HH