Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Edge.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 core/kinematics/Edge.cc
11 /// @brief Fold tree edge class
12 /// @author Phil Bradley
13 
14 
15 // Unit headers
16 #include <core/kinematics/Edge.hh>
17 
18 // AUTO-REMOVED #include <utility/stream_util.hh>
19 #include <basic/Tracer.hh>
20 
21 // C++ headers
22 #include <iostream>
23 #include <sstream>
24 
25 
26 // will remove the following in a couple of weeks OL/ 8/4/2008
27 // just to have some backward compatibiliy for a transient time
28 #include <basic/options/option.hh>
29 
30 
31 // option key includes
32 
33 #include <basic/options/keys/in.OptionKeys.gen.hh>
34 
35 #include <utility/vector1.hh>
36 
37 
38 
39 namespace core {
40 namespace kinematics {
41 
42 static basic::Tracer tr("core.kinematics");
43 
44 // PHIL -- need to update these routines to include atom info?
45 // ANDREW -- made a stab at adding atom info to comparison operators and ostream operators; no guarantee
46 
47 /////////////////////////////////////////////////////////////////////////////
48 // these two should be inverses:
49 
50 std::ostream &
51 operator <<( std::ostream & os, const Edge & e )
52 {
53  std::string tag ( "EDGE" );
54  if ( e.is_jump() && e.has_atom_info() ) tag = "JEDGE";
55  os << " " << tag << " " << e.start() << ' ' << e.stop() << ' ' << e.label() << ' ';
56  if ( e.label() == Edge::CHEMICAL ) os << e.start_atom() << ' ' << e.stop_atom() << ' ';
57  if ( e.is_jump() ) {
58  if ( e.start_atom().size() ) {
59  os << e.start_atom() << ' ' << e.stop_atom() << ' ';
60  } else {
61  // os << " X X "; not-necessary with JEDGE tag //otherwise reading becomes difficult
62  }
63  }
64  if ( e.is_jump() && e.has_atom_info() ) {
65  if ( e.keep_stub_in_residue() ) {
66  os << " INTRA_RES_STUB ";
67  assert( e.start_atom().size() );
68  } else {
69  os << " END ";
70  }
71  }
72  return os;
73 }
74 
75 /////////////////////////////////////////////////////////////////////////////
76 std::istream &
77 operator >>( std::istream & is, Edge & e )
78 {
79  std::string tag;
80 
81 //============================================
82 // this is a temporary hack to allow read of the fold-tree format that existed for the weeks from revision 21447 30/3 -> 8/4 2008
83 // in a couple of weeks this support shall be removed
84  if ( basic::options::option[ basic::options::OptionKeys::in::use_stupid_foldtree_format ] ) {
85 
86  is >> tag;
87  if ( ! (tag == "EDGE" ) ) {
88  tr.Trace << "failed reading EDGE tag --- found instead: " << tag << std::endl;
89  is.setstate( std::ios_base::failbit );
90  return is;
91  }
92  is >> e.start_ >> e.stop_ >> e.label_;
93  if ( e.label() == Edge::CHEMICAL ) is >> e.start_atom_ >> e.stop_atom_;
94 
95  e.start_atom_ = ""; e.stop_atom_ = "";
96  if ( e.is_jump() ) {
97  is >> e.start_atom_;
98  is >> e.stop_atom_;
99  } else return is;
100  } else { // normal ( new ) format
101 //=================================================
102 // END OF TEMPORARY HACK
103 
104  is >> tag;
105  if ( ! (tag == "EDGE" || tag == "JEDGE") ) {
106  tr.Trace << "failed reading EDGE tag --- found instead: " << tag << std::endl;
107  is.setstate( std::ios_base::failbit );
108  return is;
109  }
110  is >> e.start_ >> e.stop_ >> e.label_;
111  if ( e.label() == Edge::CHEMICAL ) is >> e.start_atom_ >> e.stop_atom_;
112 
113  e.start_atom_ = ""; e.stop_atom_ = "";
114  if ( e.is_jump() && tag == "JEDGE" ) {
115  is >> e.start_atom_;
116  is >> e.stop_atom_;
117  } else return is;
118  } // from here both pathways are the same.
119  if ( e.start_atom_ == "X" ) e.start_atom_ = "";
120  if ( e.stop_atom_ == "X" ) e.stop_atom_ = "";
121 
122  // allow either both atoms set or both unset
123  assert( ( (e.start_atom_.size() && e.stop_atom_.size()) )
124  || (( e.start_atom_.size() == 0) && (e.stop_atom_.size() ==0 )));
125 
126  is >> tag;
127  e.bKeepStubInResidue_ = false;
128  if ( tag == "END" ) return is;
129  assert( tag == "INTRA_RES_STUB" ); //only allowed if also atoms are specified;
130  e.bKeepStubInResidue_ = true;
131  return is;
132 }
133 
134 
135 /////////////////////////////////////////////////////////////////////////////
136 /// @details compare start residue number first, then stop residue number, then label
137 /// index number, then start_atom, then stop_atom
138 bool
139 operator <( Edge const & a, Edge const & b )
140 {
141  //return ( a.start() < b.start() ||
142  // a.start() == b.start() && a.stop() < b.stop() ||
143  // a.start() == b.start() && a.stop() == b.stop() && a.label() < b.label() ||
144  // a.start() == b.start() && a.stop() == b.stop() && a.label() == b.label() && a.start_atom() < b.start_atom() ||
145  // a.start() == b.start() && a.stop() == b.stop() && a.label() == b.label() && a.start_atom() == b.start_atom() && a.stop_atom() < b.stop_atom() );
146  //);
147  return ( a.start() == b.start() ? ( a.stop() == b.stop() ? ( a.label() == b.label() ?
148  ( a.start_atom() == b.start_atom() ? a.stop_atom() < b.stop_atom() : a.start_atom() < b.start_atom() ) :
149  a.label() < b.label() ) : a.stop() < b.stop() ) : a.start() < b.start() );
150 }
151 
152 
153 /////////////////////////////////////////////////////////////////////////////
154 /// @details when start residue number, stop residue number and label index number are all equal
155 bool
156 operator ==( Edge const & a, Edge const & b )
157 {
158  return ( a.start() == b.start() && a.stop() == b.stop() && a.label() == b.label()
159  && a.start_atom() == b.start_atom() && a.stop_atom() == b.stop_atom() );
160 }
161 
162 
163 /////////////////////////////////////////////////////////////////////////////
164 /// @details when any of start residue number, stop residue number and label index number is not equal
165 bool
166 operator !=( Edge const & a, Edge const & b )
167 {
168  return ( a.start() != b.start() || a.stop() != b.stop() || a.label() != b.label() );
169 }
170 
171 
172 } // namespace kinematics
173 } // namespace core