Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
DFIRE_Potential.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/scoring/methods/DFIRE_Potential.cc
11 /// @author James Thompson
12 
13 #include <basic/Tracer.hh>
14 #include <basic/database/open.hh>
16 
19 
20 #include <utility/pointer/ReferenceCount.hh>
21 #include <utility/exit.hh>
22 #include <utility/io/izstream.hh>
23 
24 // AUTO-REMOVED #include <numeric/xyz.functions.hh>
25 #include <numeric/xyzVector.hh>
26 #include <boost/algorithm/string/trim.hpp>
27 
28 #include <utility/vector1.hh>
29 
30 
31 namespace core {
32 namespace scoring {
33 namespace methods {
34 namespace dfire {
35 
36 // @brief Auto-generated virtual destructor
38 
39 static basic::Tracer TR("core.scoring.methods.DFIRE_Potential");
40 
41 static Size const INVALID(999);
42 
44  : potential_is_loaded_(false)
45 {}
46 
48  std::string const & res1,
49  std::string const & atom1,
50  std::string const & res2,
51  std::string const & atom2
52 ) {
53  std::string atom1_trimmed(atom1);
54  std::string atom2_trimmed(atom2);
55  boost::algorithm::trim(atom1_trimmed);
56  boost::algorithm::trim(atom2_trimmed);
57  using std::string;
58  if ( res1 < res2 ) {
59  string const joint_id1( res1 + " " + atom1_trimmed + " " + res2 + " " + atom2_trimmed);
60  return joint_id1;
61  }
62  string const joint_id2( res2 + " " + atom2_trimmed + " " + res1 + " " + atom1_trimmed );
63  return joint_id2;
64 }
65 
66 void
68  using core::Size;
69  using core::Real;
70  using std::string;
71  using utility::vector1;
72 
73  //std::cout << "reading potential!" << std::endl;
74 
75  utility::io::izstream input;
76  basic::database::open( input, fn );
77  if ( !input.good() ) {
78  std::string const msg( "Error opening file: " + fn );
79  utility_exit_with_message( msg );
80  }
81  string line;
82  while (getline(input,line) ) {
83  if ( line.substr(0,1) != "#" ) {
84  std::istringstream ss(line);
85  string res1(""), atom1(""), res2(""), atom2("");
86  ss >> res1 >> atom1 >> res2 >> atom2;
87 
88  //Size const res_idx1(res_index(res1)), res_idx2(res_index(res2));
89  //Size const atom_idx1(atom_index(atom1)), atom_idx2(atom_index(atom2));
90 
91  //std::cout << "line = " << line << std::endl;
92  //if ( res_idx1 != INVALID && res_idx2 != INVALID && atom_idx1 != INVALID && atom_idx2 != INVALID ) {
93  vector1< Real > pair_potential; // for (res1,atom1,res2,atom2)
94  Real value(-999);
95  ss >> value;
96  while ( !ss.fail() ) {
97  pair_potential.push_back(value);
98  ss >> value;
99  //std::cout << "value = " << value << std::endl;
100  }
101 
102  potential_.push_back( pair_potential );
103  string const joint_id(get_joint_id(res1,atom1,res2,atom2));
104  atom_res_idx_[joint_id] = potential_.size();
105  //std::cout << "joint_id = (" << joint_id << ")" << std::endl;
106  //std::cout << "potential size = " << potential_.size() << std::endl;
107  //std::cout << "pair_potential size = " << pair_potential.size() << std::endl;
108  //std::cout << joint_id;
109  //for ( Size ii = 1; ii <= pair_potential.size(); ++ii ) {
110  // std::cout << " " << pair_potential[ii];
111  //}
112  //std::cout << std::endl;
113  //}
114  }
115  } // getline
116 
117  potential_is_loaded_ = true;
118 } // read_potential
119 
120 
122  std::string const & input
123 ) const {
124  std::string res_name(input);
125  boost::algorithm::trim(res_name);
126  if ( res_name == "ASP" ) return 1;
127  else if ( res_name == "PRO" ) return 2;
128  else if ( res_name == "LYS" ) return 3;
129  else if ( res_name == "ILE" ) return 4;
130  else if ( res_name == "TRP" ) return 5;
131  else if ( res_name == "CYS" ) return 6;
132  else if ( res_name == "GLY" ) return 7;
133  else if ( res_name == "PHE" ) return 8;
134  else if ( res_name == "GLN" ) return 9;
135  else if ( res_name == "SER" ) return 10;
136  else if ( res_name == "ASN" ) return 11;
137  else if ( res_name == "LEU" ) return 12;
138  else if ( res_name == "VAL" ) return 13;
139  else if ( res_name == "TYR" ) return 14;
140  else if ( res_name == "GLU" ) return 15;
141  else if ( res_name == "ARG" ) return 16;
142  else if ( res_name == "THR" ) return 17;
143  else if ( res_name == "ALA" ) return 18;
144  else if ( res_name == "MET" ) return 19;
145  else if ( res_name == "HIS" ) return 20;
146 
147  return INVALID;
148 }
149 
151  std::string const & atom_name
152 ) const {
153  if ( atom_name == "N" ) return 1;
154  else if ( atom_name == "CA" ) return 2;
155  else if ( atom_name == "C" ) return 3;
156  else if ( atom_name == "O" ) return 4;
157  else if ( atom_name == "CB" ) return 5;
158 
159  return INVALID;
160 }
161 
164  core::conformation::Residue const & rsd1,
165  core::conformation::Residue const & rsd2
166 ) const {
167 
168  if ( rsd1.seqpos() == rsd2.seqpos() ) return 0.0;
169 
170  using core::Size;
171  using std::string;
172  Size const natoms1( rsd1.natoms() );
173  Size const natoms2( rsd2.natoms() );
174 
175  Real score = 0;
176  //std::cout << "calling score with " << natoms1 << "," << natoms2 << std::endl;
177  for ( Size ii = 1; ii <= natoms1; ++ii ) {
178  for ( Size jj = 1; jj <= natoms2; ++jj ) {
179  Real const dist = rsd1.xyz(ii).distance( rsd2.xyz(jj) );
180  Size const dist_bin_idx = (Size) (2*dist + 0.5);
181  //std::cout << "bin(" << dist << ") = " << dist_bin_idx << std::endl;
182  if ( dist_bin_idx < 30 ) {
183  string const atom_id1( rsd1.type().atom_name(ii) );
184  string const atom_id2( rsd2.type().atom_name(jj) );
185  string const res_id1 ( rsd1.type().name3() );
186  string const res_id2 ( rsd2.type().name3() );
187  string const joint_bin_id( get_joint_id( res_id1, atom_id1, res_id2, atom_id2 ) );
188  boost::unordered_map< string, Size >::const_iterator it = atom_res_idx_.find(joint_bin_id);
189  utility::vector1< Real > const & scores( potential_[it->second] );;
190  if ( it != atom_res_idx_.end() && dist_bin_idx <= scores.size() ) {
191  score += scores[dist_bin_idx];
192  //for ( Size kk = 1; kk <= scores.size(); ++kk ) {
193  // std::cout << " " << scores[kk];
194  //}
195  //std::cout << std::endl;
196  //std::cout << "score(" << joint_bin_id << "," << dist << "," << dist_bin_idx << ") = " << score << std::endl;
197  }
198  }
199  }
200  }
201  return score/100;
202 }
203 
205  return potential_is_loaded_;
206 }
207 
209  static DFIRE_Potential potential;
210  if (!potential.is_loaded()) {
211  potential.read_potential("scoring/dfire/dfire_pair.lib.txt");
212  }
213  return potential;
214 }
215 
216 } // database
217 } // methods
218 } // scoring
219 } // core