Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PcsInputFile.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  //////////////////////////////////////////////
11  /// @begin
12  ///
13  /// @file protocols/scoring/methods/pcs2/PcsInputFile.cc
14  ///
15  /// @brief Read all input from a .npc input file, and hold the data in the class
16  /// One file per lanthanide data
17  ///
18  /// @detailed
19  ///
20  /// @param
21  ///
22  /// @return
23  ///
24  /// @remarks
25  ///
26  /// @references
27  ///
28  /// @authorsv Christophe Schmitz
29  ///
30  /// @last_modified February 2010
31  ////////////////////////////////////////////////
32 
33 
34 // Unit headers
36 
37 // Package headers
38 
39 // Project headers
40 #include <basic/Tracer.hh>
41 
42 // Utility headers
43 #include <utility/exit.hh>
44 
45 // Numeric headers
46 
47 // Objexx headers
48 
49 // C++ headers
50 #include <fstream>
51 #include <iostream>
52 
53 #include <utility/vector1.hh>
54 
55 
56 namespace protocols{
57 namespace scoring{
58 namespace methods{
59 namespace pcs2{
60 
61 basic::Tracer TR_PcsInputFile("protocols.scoring.methods.pcs.PcsInputFile");
62 
64  filename_(""), weight_(0)
65 {
66  utility_exit_with_message( "You shouldn't call the empty constructor for PcsInputFile class" );
67 }
68 
70 }
71 
73  filename_(other.filename_), weight_(other.weight_)
74 {
76 }
77 
80  if ( this != &other ) {
82  }
83  return *this;
84 }
85 
88  return(filename_);
89 }
90 
93  return(weight_);
94 }
95 
97  filename_(std::string(filename)), weight_(my_weight)
98 {
99  read_PCS_file();
100 }
101 
102 void
104  core::Size residue_num;
105  std::string atom_name;
106  core::Real PCS_experimental;
107  core::Real PCS_tolerance;
108  std::ifstream myfile;
109  std::string line;
110  core::Size line_number(0);
111 
112  TR_PcsInputFile << "Opening file '" << get_filename().c_str() << "'" << std::endl;
113  myfile.open (get_filename().c_str(), std::ios::in);
114  if (!myfile.is_open ()){
115  std::cerr << "Unable to open the file '" << get_filename().c_str() <<"'" << std::endl;
116  utility_exit();
117  }
118 
119  while( getline( myfile, line ) ) {
120  line_number++;
121  std::istringstream line_stream( line ,std::istringstream::in);
122  if( (line_stream >> residue_num >> atom_name >> PCS_experimental >> PCS_tolerance).fail()){
123  TR_PcsInputFile << "Ignoring line " <<line_number << ": `" << line << "` from file " << get_filename() <<std::endl;
124  continue;
125  }
126 
127  PcsInputLine_all_.push_back( PcsInputLine( residue_num, atom_name, PCS_experimental, PCS_tolerance ) );
128  }
129 
130  myfile.close();
131 }
132 
135  return (PcsInputLine_all_);
136 }
137 
138 std::ostream &
139 operator<<(std::ostream& out, const PcsInputFile &me){
142  pcs_i_l_a = me.PcsInputLine_all_;
143  core::Size i, n;
144 
145  i = 1;
146  n = pcs_i_l_a.size();
147  out<< "Found the following " << n << " PCS value in the file " << me.get_filename() << std::endl;
148  for ( it = pcs_i_l_a.begin(); it != pcs_i_l_a.end(); ++it){
149 
150  if( (i == 1) || (i == 2)){
151  out << *it;
152  i++;
153  continue;
154  }
155  if( i == (n-1) ){
156  out << std::endl;
157  out << *it;
158  i++;
159  continue;
160  }
161  if( i == (n) ){
162  out << *it;
163  i++;
164  continue;
165  }
166  out << ".";
167  i++;
168  }
169 
170  return out;
171 }
172 
173 }//namespace pcs2
174 }//namespace methods
175 }//namespace scoring
176 }//namespace protocols