Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PositionDdGInfo.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
11 /// @brief
12 /// @author Liz Kellogg ekellogg@u.washington.edu
13 
14 // libRosetta headers
15 
16 #include <core/types.hh>
17 
18 #include <core/chemical/AA.hh>
19 // AUTO-REMOVED #include <core/conformation/Residue.hh>
20 // AUTO-REMOVED #include <core/conformation/ResidueMatcher.hh>
21 // AUTO-REMOVED #include <core/chemical/ResidueTypeSet.hh>
23 
24 // AUTO-REMOVED #include <core/scoring/ScoreFunction.hh>
25 // AUTO-REMOVED #include <core/scoring/ScoreFunctionFactory.hh>
26 // AUTO-REMOVED #include <protocols/jd2/ScoreMap.hh>
27 
28 #include <core/pose/Pose.hh>
29 // AUTO-REMOVED #include <core/io/pdb/pose_io.hh>
32 
33 // AUTO-REMOVED #include <basic/options/util.hh>
34 // AUTO-REMOVED #include <basic/options/after_opts.hh>
35 // AUTO-REMOVED #include <basic/options/keys/OptionKeys.hh>
36 
37 
38 #include <numeric/random/random.hh>
39 
41 
42 #include <utility/exit.hh>
43 #include <utility/file/FileName.hh>
44 #include <utility/io/izstream.hh>
45 #include <utility/string_util.hh>
46 
47 // C++ headers
48 #include <cstdlib>
49 #include <fstream>
50 #include <iostream>
51 #include <string>
52 
53 #include <utility/vector1.hh>
54 
55 
56 
57 
58 static numeric::random::RandomGenerator RG(86979347); // <- Magic number, do not change it!!!
59 
60 
61 namespace core {
62 namespace io {
63 namespace PositionDdGInfo{
64 
65 
67  core::Size seqpos,
68  core::chemical::AA wt_aa
69  )
70  : seqpos_(seqpos),
71  wt_aa_(wt_aa)
72  {}
73 
74  PositionDdGInfo::~PositionDdGInfo(){}
75 
76  /// @details doesn't check whether something for this mutation already exists,
77  /// so previously added stuff will be overwritten
78  void
79  PositionDdGInfo::add_mutation_ddG(
81  core::Real ddG
82  )
83  {
84  std::map< core::chemical::AA, core::Real >::iterator map_it = mutation_ddGs_.find( aa );
85  if( map_it == mutation_ddGs_.end() ){
86  mutation_ddGs_.insert( std::pair< core::chemical::AA, core::Real >(aa, ddG) );
87  }
88  else map_it->second = ddG;
89  }
90 
91  const std::map< core::Size, PositionDdGInfoOP >
93  {
94 
95  utility::io::izstream data( filename.c_str() );
96  if ( !data ) utility_exit_with_message("File "+filename+"could not be opened.");
97  std::map< core::Size, PositionDdGInfoOP > to_return;
98 
99  while( !data.eof() ) {
100 
101  std::string line;
102  getline(data,line);
103  utility::vector1< std::string > tokens; tokens.push_back("");
104  tokens = utility::split(line);
105  if( tokens.size() < 2 ) continue; //ddg predictions output file has empty lines :(
106  std::string mutstring( tokens[2] );
107  core::Size mutaaloc( mutstring.length() - 1 );
108  std::string wt_res = mutstring.substr(0,1);
109  std::string mut_res = mutstring.substr(mutaaloc, 1 );
110  std::string string_seqpos( mutstring.substr(1, mutaaloc - 1 ) );
111  core::Size mut_seqpos( atoi( string_seqpos.c_str() ));
112  core::Real ddG( atof(tokens[3].c_str() ) );
113 
114  //std::cerr << "Reading ddg out file, at pos " << mut_seqpos << " wt " << wt_res << " turned to " << mut_res << " with ddG of " << ddG << std::endl;
115 
118 
119  std::map< core::Size, PositionDdGInfoOP >::iterator muts_it( to_return.find( mut_seqpos ));
120  if( muts_it == to_return.end() ){
121  PositionDdGInfoOP pos_info = new PositionDdGInfo( mut_seqpos, wt_aa );
122  to_return.insert( std::pair< core::Size, PositionDdGInfoOP >( mut_seqpos, pos_info ) );
123  muts_it = to_return.find( mut_seqpos );
124  }
125  muts_it->second->add_mutation_ddG( mut_aa, ddG );
126  }
127  data.close();
128  return to_return;
129  }
130 
131 } //namespace ddG
132 } //namespace io
133 } //namespace core