Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
compute_holes_score_res.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/packing/compute_holes_score_res.cc
11 /// @brief Packing Score
12 /// @author Will Sheffler
13 
14 //Unit headers
15 // AUTO-REMOVED #include <core/scoring/packing/HolesEnergyRes.hh>
16 
18 
19 //Package headers
20 
21 //#include <core/scoring/ScoringManager.hh>
22 // AUTO-REMOVED #include <core/scoring/EnergyGraph.hh>
23 #include <core/pose/Pose.hh>
24 // AUTO-REMOVED #include <core/id/AtomID_Map.Pose.hh>
25 // AUTO-REMOVED #include <basic/datacache/CacheableData.hh>
26 // AUTO-REMOVED #include <core/pose/datacache/CacheableDataType.hh>
27 #include <basic/options/option.hh>
28 
30 #include <utility/exit.hh>
31 
32 #include <basic/prof.hh>
33 
34 //numeric headers
35 #include <numeric/numeric.functions.hh>
36 #include <numeric/xyzMatrix.hh>
37 #include <numeric/xyzVector.hh>
38 // AUTO-REMOVED #include <numeric/xyz.functions.hh>
39 
40 //utility headers
41 #include <utility/vector1.hh>
42 
43 #ifdef __native_client__
44 #define WIN32
45 #endif
46 
47 #ifndef WIN32
48 #include <pstream.h>
49 #endif
50 
51 //C++ headers
52 #include <iostream>
53 #include <iomanip>
54 
55 // option key includes
56 
57 #include <basic/options/keys/holes.OptionKeys.gen.hh>
58 
60 
61 
62 
63 
64 
65 
66 namespace core {
67 namespace scoring {
68 namespace packing {
69 
70 
71 
72 Real
74  pose::Pose const & pose,
75  PoseBalls const & pb,
76  HolesParamsRes const & params
77 ) {
78  Real raw_score = 0;
79 
80 #ifndef WIN32
81 
82  using namespace core;
83 
84  PROF_START( basic::DALPHABALL );
85 
86  std::string cmd = basic::options::option[ basic::options::OptionKeys::holes::dalphaball ]();
87  redi::pstream proc( cmd );
88  proc.precision(20);
89  proc << "NPOINTS" << std::endl << pb.nballs() << std::endl << "COORDS" << std::endl;
90  for( Size i = 1; i <= pb.nballs(); i++ ) {
91  Ball b(pb.ball(i));
92  proc << b.x() << " " << b.y() << " " << b.z() << " " << b.r() << " " << std::endl;
93  }
94  proc << "WEIGHTS" << std::endl;
95  for( Size i = 1; i <= pb.nballs(); i++ ) {
96  core::Size res_num = pb.res_num(i);
97  std::string res_name = pb.res_name(i);
98  core::Size atom_num = pb.atom_num(i);
99  bool skip = false;
100  if( res_num <= pose.total_residue() && pose.residue(res_num).is_upper_terminus() ) skip = true;
101  if( res_num <= pose.total_residue() && pose.residue(res_num).is_lower_terminus() ) skip = true;
102  if( !params.have_params(res_name) ) skip = true;
103  if( skip ) {
104  proc << "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0" << std::endl;
105  } else {
106  for( Size j = (atom_num-1)*24+5; j <= atom_num*24; j++ ) {
107  proc << params.param(res_name)[j] / 12.56637 << " ";
108  }
109  proc << std::endl;
110  }
111  }
112  proc << "END" << std::endl << redi::peof;
113 
114  Size index,ialpha;
115  Real val;
116  // Real total_weight = 0;
117  for( Size a = 1; a <= 20; a++ ) {
118  for( Size i = 1; i <= pb.nballs(); i++ ) {
119  proc >> ialpha >> index >> val;
120  if( a != ialpha || i != index ) {
121  std::cerr << "DALPHABALL output indicies not matching! " << i << "!=" << index << " " << a << "!=" << ialpha << std::endl;
122  utility_exit_with_message( "DALPHABALL output indicies not matching!" );
123  }
124  core::Size res_num = pb. res_num(i);
125  core::Size atom_num = pb.atom_num(i);
126  std::string res_name = pb.res_name(i);
127  bool skip = false;
128  if( res_num <= pose.total_residue() && pose.residue(res_num).is_upper_terminus() ) skip = true;
129  if( res_num <= pose.total_residue() && pose.residue(res_num).is_lower_terminus() ) skip = true;
130  if( !params.have_params(res_name) ) skip = true;
131  if( !skip ) {
132  raw_score += val;
133  if( a==1 && atom_num==1 ) {
134  raw_score -= params.rho( pb.res_name(i) );
135  raw_score -= params.rho();
136  }
137  }
138  }
139  }
140 
141  PROF_STOP( basic::DALPHABALL );
142 
143  for( Size i = 1; i <= pb.nballs(); i++ ) {
144  std::string res_name = pb.res_name(i);
145  Size res_num = pb.res_num(i);
146  Size atom_num = pb.atom_num(i);
147  bool skip = false;
148  if( res_num <= pose.total_residue() && pose.residue(res_num).is_upper_terminus() ) skip = true;
149  if( res_num <= pose.total_residue() && pose.residue(res_num).is_lower_terminus() ) skip = true;
150  if( !params.have_params(res_name) ) skip = true;
151  if( !skip ) {
152  Real anb5=0,anb10=0,anb15=0,anb20=0;
153  for( Size j = 1; j < i; j++ ) {
154  Real dis2 = pb.ball(i).xyz().distance_squared(pb.ball(j).xyz());
155  if( 400 >= dis2 ) {
156  anb20++;
157  if( 225 >= dis2 ) anb15++;
158  if( 100 >= dis2 ) anb10++;
159  if( 25 >= dis2 ) anb5 ++;
160  }
161  }
162  raw_score += params.param(res_name)[24*(atom_num-1)+1] * anb5 / 14.61869 ;
163  raw_score += params.param(res_name)[24*(atom_num-1)+2] * anb10 / 116.94952;
164  raw_score += params.param(res_name)[24*(atom_num-1)+3] * anb15 / 394.70462;
165  raw_score += params.param(res_name)[24*(atom_num-1)+4] * anb20 / 935.59614;
166  }
167  }
168 
169 #endif
170 
171  return raw_score;
172 }
173 
174 Real
176  pose::Pose const & pose,
177  PoseBalls const & pb,
178  HolesParamsRes const & params,
180 ) {
181 
182  Real raw_score = 0;
183 
184 #ifndef WIN32
185 
186  using namespace core;
187  using namespace numeric;
188  using id::AtomID;
189 
190  PROF_START( basic::DALPHABALL_DERIV );
191 
192  for( Size ir = 1; ir <= derivs.size(); ir++ ) {
193  for( Size ia = 1; ia <= derivs.n_atom(ir); ia++ ) {
194  derivs[AtomID(ia,ir)] = xyzVector<Real>(0.0,0.0,0.0);
195  }
196  }
197  redi::pstream proc( std::string(basic::options::option[ basic::options::OptionKeys::holes::dalphaball ]()) + " DERIV" );
198  proc.precision(20);
199  proc << "NPOINTS" << std::endl << pb.nballs() << std::endl << "COORDS" << std::endl;
200  for( Size i = 1; i <= pb.nballs(); i++ ) {
201  Ball b(pb.ball(i));
202  proc << b.x() << " " << b.y() << " " << b.z() << " " << b.r() << " " << std::endl;
203  }
204  proc << "WEIGHTS" << std::endl;
205  for( Size i = 1; i <= pb.nballs(); i++ ) {
206  core::Size res_num = pb.res_num(i);
207  std::string res_name = pb.res_name(i);
208  core::Size atom_num = pb.atom_num(i);
209  bool skip = false;
210  if( res_num <= pose.total_residue() && pose.residue(res_num).is_upper_terminus() ) skip = true;
211  if( res_num <= pose.total_residue() && pose.residue(res_num).is_lower_terminus() ) skip = true;
212  if( !params.have_params(res_name) ) skip = true;
213  if( skip ) {
214  proc << "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0" << std::endl;
215  } else {
216  for( Size j = (atom_num-1)*24+5; j <= atom_num*24; j++ ) {
217  proc << params.param(res_name)[j] / 12.56637 << " ";
218  }
219  proc << std::endl;
220  }
221  }
222  proc << "END" << std::endl << redi::peof;
223 
224  Real dx,dy,dz,val;
225  for( Size a = 1; a <= 20; a++ ) {
226  for( Size i = 1; i <= pb.nballs(); i++ ) {
227  proc /*>> ialpha >> index*/ >> val >> dx >> dy >> dz;
228  core::Size res_num = pb. res_num(i);
229  core::Size atom_num = pb.atom_num(i);
230  std::string res_name = pb.res_name(i);
231  bool skip = false;
232  if( res_num <= pose.total_residue() && pose.residue(res_num).is_upper_terminus() ) skip = true;
233  if( res_num <= pose.total_residue() && pose.residue(res_num).is_lower_terminus() ) skip = true;
234  if( !params.have_params(res_name) ) skip = true;
235  if( !skip ) {
236  derivs[ id::AtomID(atom_num,res_num) ] += xyzVector<Real>(dx,dy,dz);
237  raw_score += val;
238  if( a==1 && atom_num==1 ) {
239  raw_score -= params.rho( pb.res_name(i) );
240  raw_score -= params.rho();
241  }
242  }
243  }
244  }
245 
246  // xyzVector<Real> mean(0,0,0);
247  // Real meanlen = 0.0;
248  // Real count = 0.0;
249  // for( Size ir = 1; ir <= derivs.size(); ir++ ) {
250  // for( Size ia = 1; ia <= derivs.n_atom(ir); ia++ ) {
251  // mean += derivs[AtomID(ia,ir)];
252  // meanlen += derivs[AtomID(ia,ir)].length();
253  // count++;
254  // }
255  // }
256  // mean /= count;
257  // meanlen /= count;
258  // // std::cerr << "meanlen " << meanlen << " mean grad " << mean.x() << " " << mean.y() << " " << mean.z() << std::endl;
259  //
260  // for( Size ir = 1; ir <= derivs.size(); ir++ ) {
261  // for( Size ia = 1; ia <= derivs.n_atom(ir); ia++ ) {
262  // derivs[AtomID(ia,ir)] -= mean;
263  // }
264  // }
265 
266  PROF_STOP( basic::DALPHABALL );
267 
268 #endif
269 
270  return raw_score;
271 }
272 
273 /// wrappers
274 Real
276  pose::Pose const & pose,
277  HolesParamsRes const & params
278 ) {
279  return compute_holes_score_res(pose,PoseBalls(pose),params);
280 }
281 
282 Real
284  pose::Pose const & pose,
285  HolesParamsRes const & params,
287 ) {
288  return compute_holes_deriv_res( pose, PoseBalls(pose), params, derivs );
289 }
290 
291 
292 
293 }
294 }
295 }