Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PseudocontactShiftInput.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/PseudocontactShiftInput.cc
14  ///
15  /// @brief Read input .npc input file
16  ///
17  /// @detailed The following classes are responsable to read / parse the PCS input file (.npc format)
18  ///
19  /// @param
20  ///
21  /// @return
22  ///
23  /// @remarks
24  ///
25  /// @references
26  ///
27  /// @authorsv Christophe Schmitz
28  ///
29  /// @last_modified June 2009
30  ////////////////////////////////////////////////
31 
32 
33 // Unit headers
35 
36 // Package headers
37 
38 // Project headers
39 #include <basic/Tracer.hh>
40 
41 // Utility headers
42 #include <utility/exit.hh>
43 // AUTO-REMOVED #include <utility/vector1.hh>
44 
45 // Numeric headers
46 
47 // Objexx headers
48 
49 // C++ headers
50 #include <sstream>
51 #include <fstream>
52 #include <iostream>
53 #include <iomanip>
54 
55 namespace protocols{
56 namespace scoring{
57 namespace methods{
58 namespace pcs{
59 
60 basic::Tracer TR_PCS_d_i("protocols.scoring.methods.pcs.PCS_data_input");
61 
63  residue_num_(0),
64  atom_name_(""),
65  PCS_experimental_(0),
66  PCS_tolerance_(0)
67 {
68  utility_exit_with_message( "You shouldn't call the empty constructor for PCS_line_data class" );
69 }
70 
72  residue_num_(other.residue_num_),
73  atom_name_(other.atom_name_),
74  PCS_experimental_(other.PCS_experimental_),
75  PCS_tolerance_(other.PCS_tolerance_)
76 {
77 }
78 
81 {
82  if ( this != &other ) {
83  //All data member are const, nothing to copy
84  }
85  return *this;
86 }
87 
89 }
90 
92  filename_(""), weight_(0)
93 {
94  utility_exit_with_message( "You shouldn't call the empty constructor for PCS_file_data class" );
95 }
96 
98 }
99 
101  filename_(other.filename_), weight_(other.weight_)
102 {
104 }
105 
108  if ( this != &other ) {
110  }
111  return *this;
112 }
113 
114 
116  utility_exit_with_message( "You shouldn't call the empty constructor for PCS_data_input class" );
117 }
118 
120 }
121 
124 }
125 
128  if ( this != &other ) {
130  }
131  return *this;
132 }
133 
136  return residue_num_;
137 }
138 
141  return atom_name_;
142 }
143 
146  return PCS_experimental_;
147 }
148 
149 
152  return PCS_tolerance_;
153 }
154 
156  std::string atom_name,
157  core::Real PCS_experimental,
158  core::Real PCS_tolerance
159  ) :
160  residue_num_( residue_num ),
161  atom_name_(atom_name),
162  PCS_experimental_(PCS_experimental),
163  PCS_tolerance_(PCS_tolerance)
164 {
165 }
166 
167 std::map< std::string, PCS_file_data > &
169  return PCS_filename_and_data_;
170 }
171 
174  return(filename_);
175 }
176 
179  return(weight_);
180 }
181 
183  filename_(std::string(filename)), weight_(my_weight)
184 {
185  read_PCS_file();
186 }
187 
189  // utility::vector1<std::string>::const_iterator it;
190  core::Real weight_sum;
191  core::Size i;
192 
193  weight_sum = 0;
194  for (i = 1; i <= filenames.size(); i++){
195  weight_sum += weight[i];
196  }
197 
198  for (i = 1; i <= filenames.size(); i++){
199  //core::Real my_weight(weight[i]/weight_sum);
200  //TODO correct the weighting scheme. For the moment it is one automatically
201  core::Real my_weight(weight[i]);
202  PCS_file_data pcs_f_d_temp(filenames[i], my_weight);
203  PCS_filename_and_data_.insert ( std::pair< std::string, PCS_file_data >(filenames[i], pcs_f_d_temp) );
204  }
205 }
206 
207 void
209  core::Size residue_num;
210  std::string atom_name;
211  core::Real PCS_experimental;
212  core::Real PCS_tolerance;
213  std::ifstream myfile;
214  std::string line;
215  core::Size line_number(0);
216 
217  TR_PCS_d_i << "Opening file '" << get_filename().c_str() << "'" << std::endl;
218  myfile.open (get_filename().c_str(), std::ios::in);
219  if (!myfile.is_open ()){
220  std::cerr << "Unable to open the file '" << get_filename().c_str() <<"'" << std::endl;
221  utility_exit();
222  }
223 
224  while( getline( myfile, line ) ) {
225  line_number++;
226  std::istringstream line_stream( line ,std::istringstream::in);
227  if( (line_stream >> residue_num >> atom_name >> PCS_experimental >> PCS_tolerance).fail()){
228  TR_PCS_d_i << "Ignoring line " <<line_number << ": `" << line << "` from file " << get_filename() <<std::endl;
229  continue;
230  }
231 
232  PCS_data_line_all_.push_back( PCS_line_data( residue_num, atom_name, PCS_experimental, PCS_tolerance ) );
233  }
234 
235  myfile.close();
236 }
237 
240  return (PCS_data_line_all_);
241 }
242 
243 std::ostream &
244 operator<<(std::ostream& out, const PCS_line_data &PCS_l_d){
245  out << "Residue: " << std::setw(4) << PCS_l_d.residue_num();
246  out << " Atom: " << std::setw(4) << PCS_l_d.atom_name();
247  out << " PCS: " << std::setw(7) << PCS_l_d.PCS_experimental();
248  out << " Tolerance: " << std::setw(7) << PCS_l_d.PCS_tolerance()<< std::endl;
249  return out;
250 }
251 
252 std::ostream &
253 operator<<(std::ostream& out, const PCS_file_data &PCS_f_d){
256  PCS_d_l_a = PCS_f_d.PCS_data_line_all_;
257 
258  for ( it = PCS_d_l_a.begin(); it != PCS_d_l_a.end(); ++it){
259  out << *it;
260  }
261  out<< PCS_d_l_a.size() << " PCS in total for this file" << std::endl;
262  return out;
263 }
264 
265 std::ostream &
266  operator<<(std::ostream & out, const PCS_data_input &PCS_d_i ){
267 
268  std::map< std::string, PCS_file_data >::iterator it;
269  std::map< std::string, PCS_file_data > mymap;
270  mymap = PCS_d_i.PCS_filename_and_data_;
271 
272  for ( it = mymap.begin(); it != mymap.end(); ++it ) {
273  out << "For the file '" << it->first <<"' the PCS are:" << std::endl;
274  out << it->second;// << std::endl;
275  out << "The relative weight is " << (it->second).get_weight() << std::endl;
276  }
277  return out;
278 }
279 
280 
282 
283 }
284 
287  if ( instance_ == 0 ){
289  }
290  return instance_;
291 }
292 
295  std::string id;
296  core::Size i;
297 
298  for(i = 1; i <= filenames.size(); ++i){
299  id += filenames[i];
300  }
301 
302  std::map< std::string, PCS_data_input >::iterator it;
303 
304  for ( it = file_2_data_map_.begin(); it != file_2_data_map_.end(); ++it ) {
305  if(it->first == id){
306  return(it->second);
307  }
308  }
309 
310  PCS_data_input pcs_d_i(filenames, weight);
311  it = file_2_data_map_.begin();
312  file_2_data_map_.insert(it, std::pair< std::string , PCS_data_input >( id ,pcs_d_i));
313 
314  TR_PCS_d_i << pcs_d_i << std::endl;
315 
316  return(pcs_d_i);
317 }
318 
320 
321 }//namespace pcs
322 }//namespace methods
323 }//namespace scoring
324 }//namespace protocols