Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CoarseEtable.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/etable/CoarseEtable.cc
11 /// @brief
12 /// @author Oliver Lange
13 
14 // Unit headers
16 
17 /// Project Headers
20 #include <core/chemical/AA.hh>
21 
24 // AUTO-REMOVED #include <core/chemical/ChemicalManager.hh>
25 
26 #include <basic/database/open.hh>
27 
28 #include <basic/Tracer.hh>
29 
30 // C++ headers
31 #include <iostream>
32 #include <fstream>
33 
34 //Auto Headers
38 
39 
40 
41 using basic::T;
42 using basic::Error;
43 using basic::Warning;
44 
45 using namespace core;
46 using namespace coarse;
47 using namespace std;
48 
50  : atom_set_(atom_set) {
51  if ( tag == chemical::COARSE_TWO_BEAD )
52  {
53  read_files(
54  basic::database::full_name( "scoring/score_functions/etable/resolve_etable.twobead.txt" ),
55  basic::database::full_name( "scoring/score_functions/etable/etable.twobead.lj.dat" ),
56  basic::database::full_name( "etable.twobead.dlj.dat" )
57  );
58  } else {
59  std::string msg = "do not know how to load etable "+tag;
60  utility_exit_with_message( msg );
61  }
62 }
63 
64 
66  using namespace std;
67  chemical::AtomTypeSetCAP coarse = atom_set_; //our own copy of AtomSetCOP
68 
69  for (Size i=1;i<=normal->n_atomtypes();i++) {
70  string name = (*normal)[i].name();
71  Size ii=coarse->atom_type_index(name);
72  if (i!=ii) {
73  cerr << " --------------- WARNING --------------------- " << endl;
74  cerr << " incompatible atomtype indexes -- reorder coarse atomset or change program " << endl;
75  cerr << " if you go on, the wrong entries from the normal full-atom etable might be used " << endl;
76  cerr << " ------WARNING-----------------WARNING---------" << endl;
77  }
78  cerr << i << ' ' << ii << ' ' << name << endl;
79  }
80 }
81 
82 /// @brief setup before atom_pair functions can be called
85 }
86 
87 
89  T("coarse.scoring") << "prepare coarse scoring for " << rsd1.type().name() << " " << rsd2.type().name() << "\n";
90 
91 
92 }
93 
95  for (Size i=1;i<=atom_set_->n_atomtypes();++i) {
96  os << i << ' ' << (*atom_set_)[i].name() << endl;
97  }
98  const int nBeads = 2;
99  for (int aa = 1; aa<=20; aa++) {
100  for (int ibead = 1;ibead<=nBeads;ibead++) {
101  os << -((aa-1)*nBeads+ibead) << ' '
102  << rsd_set.aa_map(static_cast<chemical::AA>(aa)).front()->name3() << "_B" << ibead+1 << endl;
103  }
104  }
105 }
106 
107 struct Entry {
108  int type[2];
110  int ID;
111 };
112 typedef std::vector< Entry > Entries;
113 
114 void CoarseEtable::read_files(std::string fn_resolve,std::string fn_etable, std::string fn_dtable) {
115 
116  //the tables have this length
117  const int TABLE_LENGTH ( 721 );
118 
119  std::ifstream resolve( fn_resolve.c_str() ); // change to izstream!
120  // parse the header line
121  Entries entries;
122  maxID = 0;
123  maxType = 0;
124  maxDist = 0;
125  { // scope
126  std::string line, tag, tag2;
127  while (getline( resolve, line )) {
128  std::istringstream l( line );
129  Entry entry;
130 
131  //read entry from line
132  for (int i=0;i<2;i++) {
133  l >> tag;
134  if ( l.fail() ) goto error; // EVIL
135  entry.type[i] = atom_set_->atom_type_index( tag ); //fails if type not available
136  maxType = std::max(maxType,entry.type[i]);
137  };
138  l >> entry.seq_dist_;
139  if ( l.fail() ) goto error; //EVIL
140  l >> entry.ID;
141  if ( l.fail() ) goto error; //EVIL
142  entries.push_back(entry);
143  // cerr << "entry " << entry.type[0] << ' ' << entry.type[1] << ' ' << entry.seq_dist_ << ' ' << entry.ID << endl;
144  maxID = std::max(maxID,entry.ID);
145  maxDist= std::max(maxDist,entry.seq_dist_);
146  continue;
147  error:
148  utility_exit_with_message("CoarseEtable::read_file: bad line: "+ line );
149  };
150  cerr << "creating resolve_table with " << maxType << ' ' << maxDist+1 << endl;
151  resolve_.dimension(maxType,maxType,maxDist+1);
152  resolve_ = 0;
153  cerr << "fill resolve_table " << endl;
154  for (Entries::const_iterator it=entries.begin(), eit=entries.end(); it!=eit; ++it) {
155  resolve_(it->type[0],it->type[1],it->seq_dist_+1)=it->ID;
156  resolve_(it->type[1],it->type[0],it->seq_dist_+1)=it->ID;
157 
158  // std::cout << "resolve_( " << it->type[ 0 ] << ", " << it->type[ 1 ] << ", " << it->seq_dist_ + 1 << ") = " << it->ID << std::endl;
159  }
160 
161  cerr << "fill missing entries in resolve table ... " << endl;
162  //fix non-specific seq_dist_ances -- replace by default behaviour
163  for (int ti=1;ti<=maxType;ti++) {
164  for (int tj=1;tj<=maxType;tj++) {
165  for (int d=1;d<=maxDist;d++) {
166  // cerr << ti << ' ' << tj << ' ' << d << endl;
167  if (resolve_(ti,tj,d+1)==0) resolve_(ti,tj,d+1)=resolve_(ti,tj,1);
168  };
169  }
170  }
171 
172  etable_.dimension(TABLE_LENGTH,maxID);
173  dtable_.dimension(TABLE_LENGTH,maxID);
174  std::ifstream eet( fn_etable.c_str() ); // change to izstream!
175  std::ifstream det( fn_dtable.c_str() ); // change to izstream!
176 
177  cerr << "read etable data " << endl;
178  for (int i=1;i<=maxID;i++) {
179  for (int k=1;k<=TABLE_LENGTH;k++) {
180  // cerr << i << ' ' << k << ' ' << endl;
181  eet >> etable_(k,i);
182  det >> dtable_(k,i);
183  }
184  }
185 #if 0
186  cerr << "check table " << maxID << endl;
187  for (int k=1;k<TABLE_LENGTH;k++) {
188  cerr << etable_(5,k) << ' ';
189  }
190  cerr << endl;
191 #endif
192 
193  }
194 }
195 
196 
197 
198 bool
200  int disbin,
201  Real frac,
202  conformation::Atom const &atom1,
203  conformation::Atom const &atom2,
204  core::Energy &bb
205 ) const
206 {
207  int const eID = get_eID(atom1,atom2,seq_dist_);
208  bb = 0.0;
209  if (eID>0) {
210  // std::cerr << __FILE__<< ' ' << __LINE__ << ' ' << disbin << ' ' << eID << std::endl;
211  int const l1 = etable_.index( disbin, eID ), l2 = l1 + 1;
212  Real e1 = etable_[ l1 ];
213  bb = ( e1 + frac * ( etable_[ l2 ] - e1 ) );
214  return true;
215  }
216  return false;
217 }
218 
220  int disbin,
221  Real frac,
222  conformation::Atom const &atom1,
223  conformation::Atom const &atom2,
224  scoring::EnergyMap const &weights
225 ) const
226 {
227  Real deriv = 0.0;
228  int const eID = get_eID(atom1,atom2,seq_dist_);
229  //std::cout << "coarse dE_dR requested for " << (*atom_set_)[atom1.type()].name() << ' '<< (*atom_set_)[atom2.type()].name() << ' ' << eID << std::endl;
230 
231  if (eID>0) {
232  int const l1 = dtable_.index( disbin, eID), l2 = l1 + 1;
233  Real e1 = dtable_[ l1 ];
234  deriv = weights[ scoring::coarse_beadlj ] * ( e1 + frac * ( dtable_[ l2 ] - e1 ) );
235  }
236  return deriv;
237 }
238 
239 
240 
241