Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PairingsList.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 /// @brief
11 /// @detailed
12 ///
13 /// @author Oliver Lange
14 /// @author Christopher Miles (cmiles@uw.edu)
15 
16 // Unit Headers
18 
19 // ObjexxFCL Headers
20 #include <ObjexxFCL/format.hh>
21 #include <ObjexxFCL/FArray1A.hh>
22 
23 // Utility headers
24 #include <utility/vector1.fwd.hh>
25 #include <utility/io/izstream.hh>
26 #include <utility/exit.hh>
27 #include <basic/Tracer.hh>
28 
29 //// C++ headers
30 #include <core/types.hh>
31 #include <string>
32 
33 #include <utility/vector1.hh>
34 
35 
36 static basic::Tracer tr("core.scoring.dssp");
37 
38 namespace core {
39 namespace scoring {
40 namespace dssp {
41 
42 using core::Real;
43 using namespace basic;
44 using namespace ObjexxFCL;
45 
46 
47 Pairing::Pairing( ObjexxFCL::FArray1A_int data) {
48  pos1_ = data(1);
49  pos2_ = data(2);
50  orientation_ = data(3);
51  pleating_ = data(4);
52 }
53 
54 Pairing
56  Size tmp = pos2_;
57  pos2_ = pos1_;
58  pos1_ = tmp;
59 
60  if ( orientation_ == PARALLEL ) { // flip pleating
61  if ( pleating_ == 1 ) {
62  pleating_ = 2;
63  } else if ( pleating_ == 2 ) {
64  pleating_ = 1;
65  } else {
66  std::cout << "unrecognized pleating:" << fmt::SS( pleating_ ) << std::endl;
67  utility::exit( EXIT_FAILURE, __FILE__, __LINE__);
68  }
69  }
70  return *this;
71 }
72 
73 Pairing
75  Pairing p(*this);
76  p.reverse();
77  return p;
78 }
79 //static numeric::random::RandomGenerator RG(132238); // <- Magic number, do not change it, huaah hah ha!
80 void read_pairing_list( std::string pairing_file, PairingsList& pairings)
81 {
82  utility::io::izstream pairing_stream( pairing_file );
83  if ( !pairing_stream ) {
84  tr.Fatal << "can't open pairings file!!!" << pairing_file << std::endl;
85  pairing_stream.close();
86  utility::exit( EXIT_FAILURE, __FILE__, __LINE__);
87  }
88  read_pairing_list( pairing_stream, pairings );
89  pairing_stream.close();
90 }
91 
92 void read_pairing_list( std::istream& pairing_stream, PairingsList& pairings) {
93  std::string line;
94  Size a,b,c,d;
95  while ( getline( pairing_stream, line ) ) {
96  std::istringstream line_stream( line );
97  // a=i, b=j, c=orientation(1 or 2), d=pleating(1 or 2)
98  std::string o, pleat;
99  line_stream >> a >> b >> o >> pleat;
100  if ( line_stream.fail() || o.size() != 1 ) {
101  std::cout << "[ERROR] unable to parse " << line << std::endl;
102  continue;
103  }
104 
105  if ( o == "A" || o == "1" ) {
106  c = 1;
107  } else if ( o == "P" || o == "2") {
108  c = 2;
109  } else if ( o == "X" ) {
110  c = 0;
111  } else {
112  std::cout << "bad orientation: " << o << std::endl;
113  continue;
114  }
115 
116  if ( pleat == "O" || pleat== "1" ) {
117  d = 1;
118  } else if ( pleat == "I" || pleat == "2" ) {
119  d = 2;
120  } else if ( pleat == "X" ) {
121  d = 0;
122  } else {
123  std::cout << "bad pleating: " << pleat << std::endl;
124  }
125 
126  if ( ( a < 1 || b < 1 ) || ( a == b ) || ( c != 1 && c != 2 && c != 0 ) ||
127  ( d != 1 && d != 2 && d != 0 ) ) {
128  std::cout << "bad pairing:" <<
129  fmt::SS( a ) << fmt::SS( b ) << fmt::SS( c ) << fmt::SS( d ) << std::endl;
130  utility::exit( EXIT_FAILURE, __FILE__, __LINE__);
131  }
132 
133  Pairing p( a, b, c, d);
134  if ( a > b ) p.reverse();
135  pairings.push_back( p );
136 
137  }
138 } // read_pairings
139 
140 std::ostream& operator<< ( std::ostream& out, Pairing const& p) {
141  out << fmt::RJ(5, p.Pos1() ) << fmt::RJ(5, p.Pos2() ) << " "
142  << ( p.Orientation() ? ( p.is_parallel() ? "P" : "A") : "X" ) << " "
143  << ( p.Pleating() ? ( p.is_inwards() ? "I" : "O" ) : "X" );
144  return out;
145 }
146 
147 std::ostream& operator<< ( std::ostream& out, PairingsList const& p) {
148  for (PairingsList::const_iterator it= p.begin(),
149  eit = p.end(); it!=eit; ++it ) {
150  out << (*it) << "\n";
151  }
152  return out;
153 }
154 
156  for ( PairingsList::const_iterator it = pairings.begin(), eit = pairings.end();
157  it != eit; ++it ) {
158  if ( it->Orientation() == 0 || it->Pleating() == 0 ) return false;
159  }
160  return true;
161 }
162 
163 } // dssp
164 } // scoring
165 } // core