Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
MembEtable.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 // This file is part of the Rosetta software suite and is made available under license.
5 // The Rosetta software is developed by the contributing members of the Rosetta Commons consortium.
6 // (C) 199x-2009 Rosetta Commons participating institutions and developers.
7 // For more information, see http://www.rosettacommons.org/.
8 
9 /// @file core/scoring/etable/Etable.cc
10 /// @brief
11 /// @author
12 
13 // Unit Headers
16 
17 #include <basic/options/option.hh>
18 #include <utility/exit.hh>
19 
20 #include <utility/vector1.hh>
21 #include <numeric/interpolation/spline/SplineGenerator.hh>
22 
23 // ObjexxFCL Headers
24 #include <ObjexxFCL/FArray1D.hh>
25 #include <ObjexxFCL/FArray2D.hh>
26 #include <ObjexxFCL/FArray3D.hh>
27 
28 // Utility Headers
29 
30 // C++ Headers
31 #include <iostream>
32 // AUTO-REMOVED #include <utility/io/izstream.hh>
33 #include <fstream>
34 
35 #include <basic/Tracer.hh>
36 
37 // option key includes
38 
39 #include <basic/options/keys/score.OptionKeys.gen.hh>
40 
42 
43 using basic::T;
44 using basic::Error;
45 using basic::Warning;
46 
47 using namespace ObjexxFCL;
48 
49 static basic::Tracer TR("core.scoring.etable");
50 
51 namespace core {
52 namespace scoring {
53 namespace etable {
54 
55 using namespace basic::options;
56 using namespace basic::options::OptionKeys;
57 
58 /// constructor
59 MembEtable::MembEtable(
60  chemical::AtomTypeSetCAP atom_set_in, // like etable namespace
61  EtableOptions const & options,
62  std::string const alternate_parameter_set // = ""
63 ):
64  //pba
65  Etable( atom_set_in, options, alternate_parameter_set ),
66 
67  // from atop_props_in:
68  atom_set_ ( atom_set_in ),
69  n_atomtypes ( atom_set_in->n_atomtypes() ),
70 
71  // from options
72  max_dis_ ( options.max_dis ),
73  bins_per_A2 ( options.bins_per_A2 ),
74  Wradius ( options.Wradius ), // global mod to radii
75  lj_switch_dis2sigma ( options.lj_switch_dis2sigma ),
76  max_dis2 ( max_dis_*max_dis_ ),
77  etable_disbins ( static_cast< int >( max_dis2 * bins_per_A2)+1),
78 
79  // hard-coded for now
80  lj_use_lj_deriv_slope ( true ),
81  lj_slope_intercept ( 0.0 ),
82  lj_use_hbond_radii ( true ),
83  lj_hbond_dis ( 3.0 ),
84  lj_hbond_hdis ( 1.95 ),
85  lj_hbond_accOch_dis ( 2.80 ), // unused
86  lj_hbond_accOch_hdis ( 1.75 ), // unused
87  lj_use_water_radii ( true ),
88  lj_water_dis ( 3.0 ),
89  lj_water_hdis ( 1.95 ),
90  lk_min_dis2sigma ( 0.89 ),
91  min_dis ( 0.01 ),
92  min_dis2 ( min_dis * min_dis ),
93  add_long_range_damping ( true ),
94  long_range_damping_length ( 0.5 ),
95  epsilon ( 0.0001 ),
96  safe_max_dis2 ( max_dis2 - epsilon ),
97  hydrogen_interaction_cutoff2_( option[ score::fa_Hatr ] ?
98  std::pow( max_dis_ + 2*chemical::MAX_CHEMICAL_BOND_TO_HYDROGEN_LENGTH, 2 ) :
99  std::pow(5.0,2) ),
100  nblist_dis2_cutoff_XX_ ((options.max_dis+1.5) * (options.max_dis+1.5) ),
101  nblist_dis2_cutoff_XH_ ( option[ score::fa_Hatr ] ?
102  nblist_dis2_cutoff_XX_ :
103  ((options.max_dis+0.5)/2.0+2.2) * ((options.max_dis+0.5)/2.0+2.2) ),
104  nblist_dis2_cutoff_HH_ ( option[ score::fa_Hatr ] ?
105  nblist_dis2_cutoff_XX_ :
106  4.4 * 4.4 ),
107  max_non_hydrogen_lj_radius_( 0.0 ),
108  max_hydrogen_lj_radius_( 0.0 )
109 
110 {
111 
112  // size the arrays
113  //ljatr_.dimension( etable_disbins, n_atomtypes, n_atomtypes );
114  //ljrep_.dimension( etable_disbins, n_atomtypes, n_atomtypes );
117  memb_solv1_.dimension( etable_disbins, n_atomtypes, n_atomtypes ); //pba
118  memb_solv2_.dimension( etable_disbins, n_atomtypes, n_atomtypes ); //pba
119  //dljatr_.dimension( etable_disbins, n_atomtypes, n_atomtypes );
120  //dljrep_.dimension( etable_disbins, n_atomtypes, n_atomtypes );
123  memb_dsolv2_.dimension( etable_disbins, n_atomtypes, n_atomtypes ); //pba
124  memb_dsolv1_.dimension( etable_disbins, n_atomtypes, n_atomtypes ); //pba
125 
126  lj_radius_.resize( n_atomtypes, 0.0 );
127  //lj_wdepth_.resize( n_atomtypes, 0.0 );
128  lk_dgfree_.resize( n_atomtypes, 0.0 );
129  lk_lambda_.resize( n_atomtypes, 0.0 );
130  lk_volume_.resize( n_atomtypes, 0.0 );
131  memb_lk_dgfree_.resize( n_atomtypes, 0.0 ); //pba
132  //lk_dgrefce_.resize( n_atomtypes, 0.0 ); //pba
133  //memb_lk_dgrefce_.resize( n_atomtypes, 0.0 ); //pba
134  lk_dgrefce_.dimension( n_atomtypes );
135  memb_lk_dgrefce_.dimension( n_atomtypes );
136 
137 
138  for ( int i=1; i<= n_atomtypes; ++i ) {
139  lj_radius_[i] = (*atom_set_in)[i].lj_radius();
140  //lj_wdepth_[i] = (*atom_set_in)[i].lj_wdepth();
141  //lk_dgfree_[i] = (*atom_set_in)[i].lk_dgfree();
142  lk_lambda_[i] = (*atom_set_in)[i].lk_lambda();
143  lk_volume_[i] = (*atom_set_in)[i].lk_volume();
144  //memb_lk_dgfree_[i] = (*atom_set_in)[i].memb_lk_dgfree(); //pba
145  //lk_dgrefce_[i] = (*atom_set_in)[i].lk_dgrefce(); //pba
146  //memb_lk_dgrefce_[i] = (*atom_set_in)[i].memb_lk_dgrefce(); //pba
147  //lk_dgrefce_(i) = (*atom_set_in)[i].lk_dgrefce(); //pba
148  //memb_lk_dgrefce_(i) = (*atom_set_in)[i].memb_lk_dgrefce(); //pba
149 
150 
151  if ( (*atom_set_in)[i].is_hydrogen() ) {
153  } else {
155  }
156  }
157 
158  //if ( alternate_parameter_set.size() ) {
159  /// uses alternate paramers
160  std::string param_name;
161  /*
162  param_name = "LJ_RADIUS_"+alternate_parameter_set;
163  if ( atom_set_in->has_extra_parameter( param_name ) ) {
164  TR << "Using alternate parameters: " << param_name << " in MembEtable construction." << std::endl;
165  Size const index( atom_set_in->extra_parameter_index( param_name ) );
166  for ( int i=1; i<= n_atomtypes; ++i ) lj_radius_[i] = (*atom_set_in)[i].extra_parameter( index );
167  }
168 
169  param_name = "LJ_WDEPTH_"+alternate_parameter_set;
170  if ( atom_set_in->has_extra_parameter( param_name ) ) {
171  TR << "Using alternate parameters: " << param_name << " in Etable construction."<<std::endl;
172  Size const index( atom_set_in->extra_parameter_index( param_name ) );
173  for ( int i=1; i<= n_atomtypes; ++i ) lj_wdepth_[i] = (*atom_set_in)[i].extra_parameter( index );
174  }
175 
176  param_name = "LK_DGFREE_"+alternate_parameter_set;
177  if ( atom_set_in->has_extra_parameter( param_name ) ) {
178  TR << "Using alternate parameters: " << param_name << " in Etable construction."<<std::endl;
179  Size const index( atom_set_in->extra_parameter_index( param_name ) );
180  for ( int i=1; i<= n_atomtypes; ++i ) lk_dgfree_[i] = (*atom_set_in)[i].extra_parameter( index );
181  }
182 
183  param_name = "LK_LAMBDA_"+alternate_parameter_set;
184  if ( atom_set_in->has_extra_parameter( param_name ) ) {
185  TR << "Using alternate parameters: " << param_name << " in MembEtable construction." << std::endl;
186  Size const index( atom_set_in->extra_parameter_index( param_name ) );
187  for ( int i=1; i<= n_atomtypes; ++i ) lk_lambda_[i] = (*atom_set_in)[i].extra_parameter( index );
188  }
189 
190  param_name = "LK_VOLUME_"+alternate_parameter_set;
191  if ( atom_set_in->has_extra_parameter( param_name ) ) {
192  TR << "Using alternate parameters: " << param_name << " in MembEtable construction." << std::endl;
193  Size const index( atom_set_in->extra_parameter_index( param_name ) );
194  for ( int i=1; i<= n_atomtypes; ++i ) lk_volume_[i] = (*atom_set_in)[i].extra_parameter( index );
195  }
196  */
197  //param_name = "WAT_LK_DGFREE_"+alternate_parameter_set; //pba
198  param_name = "LK_DGFREE"; //pba
199  //if ( atom_set_in->has_extra_parameter( param_name ) ) {
200  TR << "Using alternate parameters: " << param_name << " in MembEtable construction." << std::endl;
201  Size const lkfree_index( atom_set_in->extra_parameter_index( param_name ) );
202  for ( int i=1; i<= n_atomtypes; ++i ) lk_dgfree_[i] = (*atom_set_in)[i].extra_parameter( lkfree_index );
203  //}
204 
205  //param_name = "MEMB_LK_DGFREE_"+alternate_parameter_set; //pba
206  param_name = "MEMB_LK_DGFREE"; //pba
207  //if ( atom_set_in->has_extra_parameter( param_name ) ) {
208  TR << "Using alternate parameters: " << param_name << " in MembEtable construction." << std::endl;
209  Size const mb_lkfree_index( atom_set_in->extra_parameter_index( param_name ) );
210  for ( int i=1; i<= n_atomtypes; ++i ) memb_lk_dgfree_[i] = (*atom_set_in)[i].extra_parameter( mb_lkfree_index );
211  //}
212 
213  //param_name = "LK_DGREFCE_"+alternate_parameter_set; //pba
214  param_name = "LK_DGREFCE"; //pba
215  //if ( atom_set_in->has_extra_parameter( param_name ) ) {
216  TR << "Using alternate parameters: " << param_name << " in MembEtable construction." << std::endl;
217  Size const lkref_index( atom_set_in->extra_parameter_index( param_name ) );
218  //for ( int i=1; i<= n_atomtypes; ++i ) lk_dgrefce_[i] = (*atom_set_in)[i].extra_parameter( index );
219  for ( int i=1; i<= n_atomtypes; ++i ) lk_dgrefce_(i) = (*atom_set_in)[i].extra_parameter( lkref_index );
220  //}
221 
222  //param_name = "MEMB_LK_DGREFCE_"+alternate_parameter_set; //pba
223  param_name = "MEMB_LK_DGREFCE"; //pba
224  //if ( atom_set_in->has_extra_parameter( param_name ) ) {
225  TR << "Using alternate parameters: " << param_name << " in MembEtable construction." << std::endl;
226  Size const mb_lkref_index( atom_set_in->extra_parameter_index( param_name ) );
227  //for ( int i=1; i<= n_atomtypes; ++i ) memb_lk_dgrefce_[i] = (*atom_set_in)[i].extra_parameter( index );
228  for ( int i=1; i<= n_atomtypes; ++i ) memb_lk_dgrefce_(i) = (*atom_set_in)[i].extra_parameter( mb_lkref_index );
229  //}
230  //} if alternate param set
231 
232 
233  //pbadebug
234  /*for ( int i=1; i<= n_atomtypes; ++i ) {
235  std::cout << "atom " << i << " lj_rad " << lj_radius_[i] << " lk_vol " << lk_volume_[i] <<
236  " lk_free " << lk_dgfree_[i] << " lk_ref " << lk_dgrefce_(i) << " lambda " << lk_lambda_[i] <<
237  " mb_lk_ref " << memb_lk_dgrefce_(i) << " mb_lk_free " << memb_lk_dgfree_[i] << "\n";
238  }*/
239 
240 // Real const MAX_H_HEAVY_DISTANCE = 1.35; // FIX THIS SULFUR to hydrogen bond length.
241 
242 /* Real max_lj_rep_for_h = std::max(
243  2 * max_hydrogen_lj_radius_ + 2 * MAX_H_HEAVY_DISTANCE,
244  max_hydrogen_lj_radius_ + MAX_H_HEAVY_DISTANCE + max_non_hydrogen_lj_radius_ );
245 
246 
247  hydrogen_interaction_cutoff2_ = basic::options::option[ score::fa_Hatr ] ?
248  std::pow( 2 * MAX_H_HEAVY_DISTANCE + max_dis_, 2 ) : max_lj_rep_for_h * max_lj_rep_for_h;
249 */
251 }
252 
253 ////////////////////////////////////////////////////////////////////////////////
254 /*void
255 MembEtable::copy_from( Etable const * source )
256 {
257  assert( dynamic_cast< TenANeighborNode const * > (source) );
258  assert( static_cast< TenANeighborNode const * > (source) );
259  TenANeighborNode const * tAsource( static_cast< TenANeighborNode const * > (source) );
260  neighbor_mass_ = tAsource->neighbor_mass_;
261  sum_of_neighbors_masses_ = tAsource->sum_of_neighbors_masses_;
262  since_last_sonm_update_ = tAsource->since_last_sonm_update_;
263 }*/
264 
265 ////////////////////////////////////////////////////////////////////////////////
266 /// @begin MembEtable::make_pairenergy_table
267 ///
268 /// @brief calculate fast lookup arrays for vdw and solvation energy
269 ///
270 /// @detailed
271 ///
272 /// Several energies are precomputed when fullatom mode is initialized and
273 /// stored in lookup tables to speed fullatom calculation. Currently
274 /// pre-computed values are the Lennard-Jones van der Waals approximation
275 /// (lj) and the Lazaridis-Karplus implicit solvation function (lk). For
276 /// each of these energies the derivative w.r.t. atom pair separation distance is
277 /// calculated and stored as well. Note that the lj energy is artificially
278 /// divided into atractive and repulsive components.
279 ///
280 /// @global_read
281 ///
282 /// pdbstatistics_pack.h: several threshold distances
283 /// energy.h: just about everything should be used in the tree of
284 /// etable functions
285 ///
286 /// @global_write
287 ///
288 /// the etable: ljatr,dljatr,ljrep,dljrep,solvE
289 ///
290 /// @remarks
291 ///
292 /// @references
293 ///
294 /// @authors ctsa 10-2003
295 ///
296 /// @last_modified
297 /////////////////////////////////////////////////////////////////////////////////
298 void
300 {
301  using namespace basic::options;
302  using namespace basic::options::OptionKeys;
303 
304  // locals
305  Real dis2,dis,dis2_step;
306  //Real atrE,d_atrE,repE,d_repE;
307  Real solvE1,solvE2,dsolvE1,dsolvE2;
308  Real memb_solvE1,memb_solvE2,memb_dsolvE1,memb_dsolvE2; //pba
309 
310 
311  // pre-calculated coefficients for high-speed potential calculation
312  // computed in initialization function
313  // Note: +1 atom type is a disulfide-bonded cysteine
314  // (only if you are using the old disulfide hack)
315  FArray2D< Real > lj_sigma( n_atomtypes + 1, n_atomtypes + 1 );
316  //FArray2D< Real > lj_r6_coeff( n_atomtypes + 1, n_atomtypes + 1 );
317  //FArray2D< Real > lj_r12_coeff( n_atomtypes + 1, n_atomtypes + 1 );
318  //FArray2D< Real > lj_switch_intercept( n_atomtypes + 1, n_atomtypes + 1 );
319  //FArray2D< Real > lj_switch_slope( n_atomtypes + 1, n_atomtypes + 1 );
320  FArray1D< Real > lk_inv_lambda2( n_atomtypes );
321  FArray2D< Real > lk_coeff( n_atomtypes, n_atomtypes );
322  FArray2D< Real > lk_min_dis2sigma_value( n_atomtypes + 1, n_atomtypes + 1 );
323  FArray2D< Real > memb_lk_coeff( n_atomtypes, n_atomtypes ); //pba
324  FArray2D< Real > memb_lk_min_dis2sigma_value( n_atomtypes + 1, n_atomtypes + 1 ); //pba
325 
326  // parameters to calculate the damping at max_dis range
327  Real damping_thresh_dis2;
328  int damping_disbins, normal_disbins;
329  //Real dljatr_damp, dljrep_damp, dsolv1_damp, dsolv2_damp;
330  //Real intercept_ljatr_damp, intercept_ljrep_damp;
331  Real dsolv1_damp, dsolv2_damp, intercept_solv1_damp, intercept_solv2_damp;
332  Real memb_dsolv1_damp, memb_dsolv2_damp, intercept_memb_solv1_damp, intercept_memb_solv2_damp; //pba
333 
334  // etable parameters
335  TR << "Starting membrane specific energy table calculation" << std::endl;
336 
337 // std::TR << "Energy table parameter set: " << etable_label << ' ' <<
338 // etable_revision.substr( 1, etable_revision.length() - 3 ) << ' ' <<
339 // etable_date.substr( 1, etable_date.length() - 3 ) << std::endl;
340 
341  // ctsa - values precomputed from etable parameters:
342  // these were all originally constants but need
343  // to be calculated here b/c the switch value:
344  // lj_switch_dis2sigma
345  // is set at runtime
346  //lj_switch_sigma2dis = 1.0/lj_switch_dis2sigma;
347 
348  // ctsa - value of the lennard-jones potential at the linear
349  // switch point divided by the wdepth (note that this
350  // coefficient is independent of atomtype)
351  //lj_switch_value2wdepth = std::pow( lj_switch_sigma2dis, 12 ) -
352  // 2.0 * std::pow( lj_switch_sigma2dis, 6 );
353 
354  // ctsa - slope of the lennard-jones potential at the linear
355  // switch point times sigma divided by wdepth (note that this
356  // coefficient is independent of atomtype)
357  //lj_switch_slope_sigma2wdepth = -12.0 * (
358  // std::pow( lj_switch_sigma2dis, 13 ) -
359  // std::pow( lj_switch_sigma2dis, 7 ) );
360 
361  // initialize non-distance dependent coefficients
362  /*precalc_etable_coefficients(lj_sigma, lj_r6_coeff, lj_r12_coeff,
363  lj_switch_intercept, lj_switch_slope, lk_inv_lambda2, lk_coeff,
364  memb_lk_coeff, lk_min_dis2sigma_value, memb_lk_min_dis2sigma_value );*/
365 
366  precalc_etable_coefficients(lj_sigma,lk_inv_lambda2,lk_coeff,memb_lk_coeff,lk_min_dis2sigma_value,memb_lk_min_dis2sigma_value); //pba
367 
368  // calc distance**2 step per bin
369  dis2_step = 1.0 / bins_per_A2;
370 
371  // get the number of damping disbins
372  if ( add_long_range_damping ) {
374  damping_thresh_dis2 = max_dis2 - ( dif * dif );
375  damping_disbins = static_cast< int >( damping_thresh_dis2*bins_per_A2 );
376  normal_disbins = etable_disbins-damping_disbins;
377  } else {
378  normal_disbins = etable_disbins;
379  }
380 
381  // ctsa - step through distance**2 bins and calculate potential
382  for ( int atype1 = 1, atype_end = n_atomtypes; atype1 <= atype_end; ++atype1 ) {
383  for ( int atype2 = 1; atype2 <= atype_end; ++atype2 ) {
384  // ctsa - normal bins have their lj and lk values
385  // calculated analytically
386  for ( int disbin = 1; disbin <= normal_disbins; ++disbin ) {
387  dis2 = ( disbin - 1 ) * dis2_step;
388 
389  /*calc_etable_value(dis2,atype1,atype2,atrE,d_atrE,repE,d_repE,solvE1,
390  solvE2,dsolvE1,dsolvE2,lj_sigma, lj_r6_coeff,lj_r12_coeff,
391  lj_switch_intercept,lj_switch_slope, lk_inv_lambda2,
392  lk_coeff, lk_min_dis2sigma_value, memb_solvE1, memb_solvE2,
393  memb_lk_coeff, memb_lk_min_dis2sigma_value, memb_dsolvE); //pba */
394 
395  calc_etable_value(dis2,atype1,atype2,solvE1,solvE2,dsolvE1,dsolvE2,lj_sigma,lk_inv_lambda2,
396  lk_coeff, lk_min_dis2sigma_value,memb_solvE1, memb_solvE2,
397  memb_lk_coeff, memb_lk_min_dis2sigma_value, memb_dsolvE1, memb_dsolvE2); //pba
398 
399  //ljatr_(disbin,atype2,atype1) = atrE;
400  //dljatr_(disbin,atype2,atype1) = d_atrE;
401  //ljrep_(disbin,atype2,atype1) = repE;
402  //dljrep_(disbin,atype2,atype1) = d_repE;
403  solv1_(disbin,atype2,atype1) = solvE1;
404  solv2_(disbin,atype2,atype1) = solvE2;
405  dsolv2_(disbin,atype2,atype1) = dsolvE2;
406  dsolv1_(disbin,atype2,atype1) = dsolvE1;
407  memb_solv1_(disbin,atype2,atype1) = memb_solvE1; //pba
408  memb_solv2_(disbin,atype2,atype1) = memb_solvE2; //pba
409  memb_dsolv2_(disbin,atype2,atype1) = memb_dsolvE2; //pba
410  memb_dsolv1_(disbin,atype2,atype1) = memb_dsolvE1; //pba
411  //pbadebug WARNING
412  //if(atype1==18 && atype2==19)
413  // std::cout << "bin s1 s2 " << disbin << " " << solv1_(disbin,atype2,atype1) << " " << solv2_(disbin,atype2,atype1) << std::endl;
414 
415  }
416 
417  if ( !add_long_range_damping ) goto L456;
418 
419  // ctsa - remaining bins damp to 0. on a linear path
420  /*dljatr_damp = -ljatr_(normal_disbins,atype2,atype1) /
421  long_range_damping_length;
422  dljrep_damp = -ljrep_(normal_disbins,atype2,atype1) /
423  long_range_damping_length;*/
424  dsolv1_damp = -solv1_(normal_disbins,atype2,atype1) /
426  dsolv2_damp = -solv2_(normal_disbins,atype2,atype1) /
428  //pba
429  memb_dsolv1_damp = -memb_solv1_(normal_disbins,atype2,atype1) /
431  memb_dsolv2_damp = -memb_solv2_(normal_disbins,atype2,atype1) /
433 
434  /*intercept_ljatr_damp = -dljatr_damp*max_dis_;
435  intercept_ljrep_damp = -dljrep_damp*max_dis_;*/
436  intercept_solv1_damp = -dsolv1_damp*max_dis_;
437  intercept_solv2_damp = -dsolv2_damp*max_dis_;
438  //pba
439  intercept_memb_solv1_damp = -memb_dsolv1_damp*max_dis_;
440  intercept_memb_solv2_damp = -memb_dsolv2_damp*max_dis_;
441 
442  for ( int disbin = normal_disbins+1; disbin <= etable_disbins; ++disbin ) {
443  dis2 = ( disbin - 1 ) * dis2_step;
444  dis = std::sqrt(dis2);
445 
446  /*ljatr_(disbin,atype2,atype1) = intercept_ljatr_damp + dis *dljatr_damp;
447  ljrep_(disbin,atype2,atype1) = intercept_ljrep_damp + dis *dljrep_damp;*/
448  solv1_(disbin,atype2,atype1) = intercept_solv1_damp + dis *dsolv1_damp;
449  solv2_(disbin,atype2,atype1) = intercept_solv2_damp + dis *dsolv2_damp;
450  //pba
451  memb_solv1_(disbin,atype2,atype1) = intercept_memb_solv1_damp + dis * memb_dsolv1_damp;
452  memb_solv2_(disbin,atype2,atype1) = intercept_memb_solv2_damp + dis * memb_dsolv2_damp;
453 
454  /*dljatr_(disbin,atype2,atype1) = dljatr_damp;
455  dljrep_(disbin,atype2,atype1) = dljrep_damp;*/
456  dsolv1_(disbin,atype2,atype1) = dsolv1_damp;
457  dsolv2_(disbin,atype2,atype1) = dsolv2_damp;
458  //pba
459  memb_dsolv2_(disbin,atype2,atype1) = memb_dsolv2_damp;
460  memb_dsolv1_(disbin,atype2,atype1) = memb_dsolv1_damp;
461 
462  //pbadebug WARNING
463  //if(atype1==18 && atype2==19)
464  // std::cout << "bin s1 s2 " << disbin << " " << solv1_(disbin,atype2,atype1) << " " << solv2_(disbin,atype2,atype1) << std::endl;
465 
466  }
467 
468 L456:
469 
470  // ctsa - set last bin of all values to zero
471  /*ljatr_(etable_disbins,atype2,atype1) = 0.0;
472  ljrep_(etable_disbins,atype2,atype1) = 0.0;*/
473  solv1_(etable_disbins,atype2,atype1) = 0.0;
474  solv2_(etable_disbins,atype2,atype1) = 0.0;
475  memb_solv1_(etable_disbins,atype2,atype1) = 0.0; //pba
476  memb_solv2_(etable_disbins,atype2,atype1) = 0.0; //pba
477  }
478  }
479 
480  //db the following function call modifies the potential in three ways:
481  //db (1) the solvation energy for nonpolar atoms is held constant below
482  //db 4.2A to avoid shifting the minimum in the LJ potential.
483  //db (2) a short range repulsion is added between backbone oxygens which are
484  //db otherwise brought too close together by the LJatr.
485  //db (3) the range of the repulsive interaction between non polar hydrogens is
486  //db increased slightly. (this is currently commented out because the effects
487  //db on design have not been tested)
488 
489  //db all three modifications are based on inspection of the atom pair distributions
490  //db after extensive refinement.
491  //pbadebug WARNING
492  modify_pot();
493 
494  if( !option[ score::no_smooth_etables ] ) smooth_etables();
495 
496  // sheffler changed this to happen after modify_pot so that
497  // etable smoothing of Hydrogens and Waters will work properly
498  //if ( !option[ score::fa_Hatr ] ) zero_hydrogen_and_water_ljatr();
499 
500 
501  ////////////////////////////////////////////////////////
502  // etable I/O stuff
503  ////////////////////////////////////////////////////////
504  using namespace std;
505  using namespace ObjexxFCL;
506 
507  // just for convenience in input/output_etables
508  map< string, FArray3D<Real>* > etables;
509  /*etables[ "ljatr"] = & ljatr_; etables[ "ljrep"] = & ljrep_;
510  etables["dljatr"] = & dljatr_; etables["dljrep"] = & dljrep_;*/
511  etables[ "solv1"] = & solv1_; etables[ "solv2"] = & solv2_;
512  etables["dsolv1"] = & dsolv1_;
513  etables["dsolv2"] = & dsolv2_;
514  etables[ "memb_solv1"] = & memb_solv1_; etables[ "memb_solv2"] = & memb_solv2_; //pba
515  etables["memb_dsolv2"] = & memb_dsolv2_; etables["memb_dsolv1"] = & memb_dsolv1_; //pba
516 
517  if ( option[ score::input_etables ].user() ) {
518  string tag = option[ score::input_etables ];
519  TR << "INPUT ETABLES " << tag << std::endl;
520  for (map<string,FArray3D<Real>*>::iterator i = etables.begin(); i != etables.end(); i++) {
521  string ename = i->first;
522  string fname = tag+"."+ename+".etable";
523  std::ifstream input( fname.c_str() ); // TODO sheffler: figure out how to do this the right way
524  input_etable(*(i->second),ename,input);
525  input.close();
526  }
527  }
528 
529  if ( option[ score::output_etables ].user() ) {
530  string header = option[ score::output_etables ];
531  TR << "OUTPUT ETABLES " << header << std::endl;
532  for (map<string,FArray3D<Real>*>::iterator i = etables.begin(); i != etables.end(); i++) {
533  string ename = i->first;
534  string fname = header+"."+ename+".etable";
535  TR << "output_etable: writing etable: " << ename << " to " << fname << std::endl;
536  ofstream out(fname.c_str());
537  output_etable(*(i->second),ename,out);
538  out.close();
539  }
540  }
541 
542  TR << "Finished calculating membrane specific energy tables." << std::endl;
543 }
544 
545 
546 ////////////////////////////////////////////////////////////////////////////////
547 /// @begin modify_pot
548 ///
549 /// @brief modify Etable to better treat 0-0, C-C, and H-H interactions
550 ///
551 /// @detailed
552 ///$$$ the Etables are modified in three ways:
553 ///$$$ (1) the LK solvation energy is set to a constant below 4.2A to avoid shifting the position
554 ///$$$ of the minimum on the LJatr potential. in refined decoys the peak in the C C pair
555 ///$$$ distribution function shifts to around 3.8 A from ~4.0A in native structures; the LJatr
556 ///$$$ potential has a minimum at 4.0A but this shifts towards smaller values because of the LK
557 ///$$$ solvation term, which became increasingly favorable at shorter distances
558 ///$$$ (2) the backbone carbonyl oxygen-carbonyl oxygen LJrep term has been modified to become
559 ///$$$ moderately repulsive at distances less than 3.6A. this is to counteract the favorable
560 ///$$$ LJatr between the atoms (which have radii of ~1.4A and so a minimum at ~2.8A; very few
561 ///$$$ counts are observed in the pdb until around 3.2A) which leads to a significant shift in the
562 ///$$$ O O pair distribution function towards smaller values in refined decoys. the repulsion is
563 ///$$$ a temporary proxy for the lack of explicit electrostatic repulsion in the current force
564 ///$$$ field.
565 ///$$$ (3) a third soft repulsion between non polar hydrogens that was also based on comparison of
566 ///$$$ refined decoy to native pdf's is currently commented out as the effects on packing have not
567 ///$$$ been tested. it was observed that the protons tend to pile up at just beyond the point
568 ///$$$ where the repulsion becomes strong, perhaps due to a general tendency to overcontraction
569 ///$$$ because of long range LJatr interactions not compensated by interactions with solvent
570 ///$$$ (which are of course missing)
571 ///
572 /// @global_read
573 /// pdbstatistics_pack.h: ljatr,dljatr,ljrep, dljrep, solv1,solv2,dsolv
574 ///
575 /// @global_write
576 /// pdbstatistics_pack.h: ljatr,dljatr,ljrep, dljrep, solv1,solv2,dsolv
577 ///
578 /// @remarks
579 ///
580 /// @references
581 ///
582 /// @authors ctsa 10-2003
583 ///
584 /// @last_modified
585 /////////////////////////////////////////////////////////////////////////////////
586 void
588 {
589 
590  using namespace std;
591 
592  bool mod_hhrep = false; //truefalseoption("mod_hhrep");
593  Real const h = 0.0;// fullatom_setup_ns::mod_hhrep_height;
594  Real const c = 0.0;// fullatom_setup_ns::mod_hhrep_center;
595  Real const w = 0.0;// fullatom_setup_ns::mod_hhrep_width;
596  Real const e = 0.0;// fullatom_setup_ns::mod_hhrep_exponent;
597 
598 
599  if(mod_hhrep) {
600  TR << "fullatom_setup: modifying h-h repulsion "
601  << " hhrep center " << c
602  << " hhrep height " << h
603  << " hhrep width " << w
604  << " hhrep exponent " << e
605  << std::endl;
606  }
607 
608  {
609 
610  Real const bin = ( 4.2 * 4.2 / .05 ) + 1.0; //SGM Off-by-1 bug fix: Add + 1.0: Index 1 is at distance^2==0
611  int const ibin( static_cast< int >( bin ) );
612  for ( int k = 1; k <= etable_disbins; ++k ) {
613  Real const dis = std::sqrt( ( k - 1 ) * .05f ); //SGM Off-by-1 bug fix: k -> ( k - 1 )
614 
615 
616  // if( !SMOOTH_ETABLES ) {
618  carbon_types.push_back( atom_set_->atom_type_index("CH1") );
619  carbon_types.push_back( atom_set_->atom_type_index("CH2") );
620  carbon_types.push_back( atom_set_->atom_type_index("CH3") );
621  carbon_types.push_back( atom_set_->atom_type_index("aroC") );
622  if ( dis < 4.2 ) {
623  for ( int i = 1, i_end = carbon_types.size(); i <= i_end; ++i ) {
624  for ( int j = 1, j_end = carbon_types.size(); j <= j_end; ++j ) {
625  int const ii = carbon_types[i];
626  int const jj = carbon_types[j];
627  solv1_(k,jj,ii) = solv1_(ibin,jj,ii);
628  solv1_(k,ii,jj) = solv1_(ibin,ii,jj); // Why is this duplicated?
629  solv2_(k,jj,ii) = solv2_(ibin,jj,ii);
630  solv2_(k,ii,jj) = solv2_(ibin,ii,jj); // Why is this duplicated?
631  dsolv2_(k,jj,ii) = 0.0;
632  dsolv2_(k,ii,jj) = 0.0; // Why is this duplicated?
633  dsolv1_(k,ii,jj) = 0.0;
634  dsolv1_(k,jj,ii) = 0.0; // Why is this duplicated?
635  memb_solv1_(k,jj,ii) = memb_solv1_(ibin,jj,ii);
636  memb_solv1_(k,ii,jj) = memb_solv1_(ibin,ii,jj); // Why is this duplicated?
637  memb_solv2_(k,jj,ii) = memb_solv2_(ibin,jj,ii);
638  memb_solv2_(k,ii,jj) = memb_solv2_(ibin,ii,jj); // Why is this duplicated?
639  memb_dsolv2_(k,jj,ii) = 0.0;
640  memb_dsolv2_(k,ii,jj) = 0.0; // Why is this duplicated?
641  memb_dsolv1_(k,ii,jj) = 0.0;
642  memb_dsolv1_(k,jj,ii) = 0.0; // Why is this duplicated?
643  }
644  }
645  }
646  // }
647 
648 // push carbonyl oxygens (in beta sheets) apart. a proxy for the missing
649 // electrostatic repulsion needed to counteract the LJatr which pulls the oxyens
650 // together
651  //mjo commenting out 'OCbb_idx' because it is unused and causes a warning
652  //int const OCbb_idx = atom_set_->atom_type_index("OCbb");
653  if ( dis <= 3.6 ) {
654  //mjo commenting out 'fac' because it is unused and causes a warning
655  //Real const fac = std::max( dis - 3.6, -1.5 );
656 // Real const fac = std::max( dis - 3.6f, -1.5f );
657 // ljrep_(k,OCbb_idx,OCbb_idx) += 2 * ( fac * fac );
658 // dljrep_(k,OCbb_idx,OCbb_idx) += 4 * fac;
659  }
660 // the following gives peak at 2.4 in 22 and 23 interactions. maybe push out a
661 // bit further. (this is commented out because effects on design have not been
662 // tested)
663 
664  // use one half of a single term polynomial
665  // as the repulsive term for apolar hydrogens (types 23 & 24)
666 
667 // if( mod_hhrep ) {
668 // if( dis < c ) {
669 // for ( int j = 23; j <= 24; ++j ) {
670 // for ( int kk = 23; kk <= 24; ++kk ) {
671 // ljrep_(k,j,kk) = h * pow( min(0.0f, (dis-c)/w ), e );// +
672 // dljrep_(k,j,kk) = h * e / w * pow( min(0.0f, dis-c)/w, e-1 ) ;// +
673 // }
674 // }
675 // }
676 // }
677 
678  } // end for ( int k = 1; k <= etable_disbins; ++k ) {
679 
680 
681  } //Objexx:SGM Extra {} scope is a VC++ work-around
682 
683 
684 }
685 
686 void
688 {
689  using namespace numeric::interpolation;
690  using namespace basic::options;
691  using namespace basic::options::OptionKeys;
692 
693  FArray1D<Real> dis(etable_disbins);
694  for(int i = 1; i <= etable_disbins; ++i) {
695  dis(i) = sqrt( ( i - 1 ) * 1.0 / bins_per_A2 );
696  }
697  FArray1D<int> bin_of_dis(100);
698  for(int i = 1; i <= 100; ++i) {
699  float d = ((float)i)/10.0;
700  bin_of_dis(i) = (int)( d*d * bins_per_A2 + 1 );
701  }
702  /*
703  //////////////////////////////////////////////////////////////////
704  // 1) change ljatr / ljrep split so that scaling is smooth
705  //////////////////////////////////////////////////////////////////
706  TR << "smooth_etable: changing atr/rep split to bottom of energy well" << std::endl;
707  for( int at1 = 1; at1 <= n_atomtypes; ++at1 ) {
708  for( int at2 = 1; at2 <= n_atomtypes; ++at2 ) {
709 
710  // find ljatr min
711  core::Real min_atr = 0.0;
712  int which_min = -1;
713  for(int i = 1; i <= etable_disbins; ++i) {
714  if ( ljatr_(i,at1,at2) < min_atr ) {
715  min_atr = ljatr_(i,at1,at2);
716  which_min = i;
717  }
718  }
719  // for dis below ljatr min, transfer ljatr to ljrep
720  if( min_atr < 0.0 ) {
721  for( int i = 1; i <= which_min; ++i ) {
722  ljrep_(i,at1,at2) += ljatr_(i,at1,at2) - min_atr;
723  ljatr_(i,at1,at2) -= ljatr_(i,at1,at2) - min_atr; // = min_atr;
724  dljrep_(i,at1,at2) += dljatr_(i,at1,at2);
725  dljatr_(i,at1,at2) -= dljatr_(i,at1,at2); // = 0;
726  }
727  }
728 
729  }
730  }
731 
732  using namespace numeric::interpolation::spline;
733  ///////////////////////////////////////////////////////////////////
734  // 2) spline smooth ljatr/ljrep at fa_max_dis cut
735  //////////////////////////////////////////////////////////////////
736  TR << "smooth_etable: spline smoothing lj etables (maxdis = " << max_dis_ << ")" << std::endl;
737  for( int at1 = 1; at1 <= n_atomtypes; ++at1 ) {
738  for( int at2 = 1; at2 <= n_atomtypes; ++at2 ) {
739 
740  int start = bin_of_dis( (int)((max_dis_-1.5)*10.0) );//arg_max_first(dljatr_(1,at1,at2),1,600);
741 
742  Real lbx = dis(start);
743  Real lby = ljatr_(start,at1,at2);
744  Real lbdy = dljatr_(start,at1,at2);
745  Real ubx = dis(etable_disbins);
746  Real uby = 0.0;
747  Real ubdy = 0.0;
748  SplineGenerator gen( lbx, lby, lbdy, ubx, uby, ubdy );
749 
750  if( option[ score::etable_lr ].user() ) {
751  Real modx = option[ score::etable_lr ]();
752  Real mody = lbx * 0.5;
753  gen.add_known_value( modx, mody );
754  }
755 
756  InterpolatorOP interp( gen.get_interpolator() );
757  for( int i = start; i <= etable_disbins; ++i ) {
758  interp->interpolate( dis(i), ljatr_(i,at1,at2), dljatr_(i,at1,at2) );
759  }
760 
761  }
762  }
763  */
764  /////////////////////////////////////////////////////////////////////////////
765  // 2) spline smooth solv1/solv2 at fa_max_dis cut && and first switchpoint
766  /////////////////////////////////////////////////////////////////////////////
767  using namespace numeric::interpolation::spline;
768  TR << "smooth_etable: spline smoothing solvation etables (max_dis = " << max_dis_ << ")" << std::endl;
769  for( int at1 = 1; at1 <= n_atomtypes; ++at1 ) {
770  for( int at2 = 1; at2 <= n_atomtypes; ++at2 ) {
771 
772  int SWTCH = 1;
773  for( SWTCH=1; SWTCH <= etable_disbins; ++SWTCH) {
774  // std::cerr << SWTCH << "," << at1 << "," << at2 << "," << solv1_(SWTCH,at1,at2) << " ";
775  if( (solv1_(SWTCH,at1,at2) != solv1_(1,at1,at2)) ||
776  (solv2_(SWTCH,at1,at2) != solv2_(1,at1,at2)) ||
777  (memb_solv1_(SWTCH,at1,at2) != memb_solv1_(1,at1,at2)) ||
778  (memb_solv2_(SWTCH,at1,at2) != memb_solv2_(1,at1,at2)) ) {
779  break;
780  }
781  }
782  if ( SWTCH > etable_disbins ) continue;
783 
784  int const S1 = std::max(1,SWTCH - 30);
785  int const E1 = std::min(SWTCH + 20,406);
786  int const S2 = bin_of_dis( (int)((max_dis_-1.5)*10.0) );
787  int const E2 = etable_disbins;
788  // std::cerr << "smooth solv " << S1 << " " << E1 << " " << S2 << " " << E2 << std::endl;
789 
790  Real dsolv1e1 = (solv1_(E1+1,at1,at2)-solv1_(E1 ,at1,at2))/(dis(E1+1)-dis(E1 ));
791  Real dsolv1s2 = (solv1_(S2 ,at1,at2)-solv1_(S2-1,at1,at2))/(dis(S2 )-dis(S2-1));
792  Real dsolv2e1 = (solv2_(E1+1,at1,at2)-solv2_(E1 ,at1,at2))/(dis(E1+1)-dis(E1 ));
793  Real dsolv2s2 = (solv2_(S2 ,at1,at2)-solv2_(S2-1,at1,at2))/(dis(S2 )-dis(S2-1));
794 
795  Real mdsolv1e1 = (memb_solv1_(E1+1,at1,at2)-memb_solv1_(E1 ,at1,at2))/(dis(E1+1)-dis(E1 ));
796  Real mdsolv1s2 = (memb_solv1_(S2 ,at1,at2)-memb_solv1_(S2-1,at1,at2))/(dis(S2 )-dis(S2-1));
797  Real mdsolv2e1 = (memb_solv2_(E1+1,at1,at2)-memb_solv2_(E1 ,at1,at2))/(dis(E1+1)-dis(E1 ));
798  Real mdsolv2s2 = (memb_solv2_(S2 ,at1,at2)-memb_solv2_(S2-1,at1,at2))/(dis(S2 )-dis(S2-1));
799 
800  SplineGenerator gen11( dis(S1), solv1_(S1,at1,at2), 0.0 , dis(E1), solv1_(E1,at1,at2), dsolv1e1 );
801  SplineGenerator gen21( dis(S1), solv2_(S1,at1,at2), 0.0 , dis(E1), solv2_(E1,at1,at2), dsolv2e1 );
802  SplineGenerator gen12( dis(S2), solv1_(S2,at1,at2), dsolv1s2, dis(E2), solv1_(E2,at1,at2), 0.0 );
803  SplineGenerator gen22( dis(S2), solv2_(S2,at1,at2), dsolv2s2, dis(E2), solv2_(E2,at1,at2), 0.0 );
804 
805  SplineGenerator mgen11( dis(S1), memb_solv1_(S1,at1,at2), 0.0 , dis(E1), memb_solv1_(E1,at1,at2), mdsolv1e1 );
806  SplineGenerator mgen21( dis(S1), memb_solv2_(S1,at1,at2), 0.0 , dis(E1), memb_solv2_(E1,at1,at2), mdsolv2e1 );
807  SplineGenerator mgen12( dis(S2), memb_solv1_(S2,at1,at2), mdsolv1s2, dis(E2), memb_solv1_(E2,at1,at2), 0.0 );
808  SplineGenerator mgen22( dis(S2), memb_solv2_(S2,at1,at2), mdsolv2s2, dis(E2), memb_solv2_(E2,at1,at2), 0.0 );
809 
810  InterpolatorOP interp11( gen11.get_interpolator() );
811  InterpolatorOP interp21( gen21.get_interpolator() );
812 
813  InterpolatorOP minterp11( mgen11.get_interpolator() );
814  InterpolatorOP minterp21( mgen21.get_interpolator() );
815 
816  for( int i = S1; i <= E1; ++i ) {
817  Real d1,d2;
818  interp11->interpolate( dis(i), solv1_(i,at1,at2), d1 );
819  interp21->interpolate( dis(i), solv2_(i,at1,at2), d2 );
820  dsolv2_(i,at1,at2) = d2;
821  dsolv1_(i,at1,at2) = d1;
822  minterp11->interpolate( dis(i), memb_solv1_(i,at1,at2), d1 );
823  minterp21->interpolate( dis(i), memb_solv2_(i,at1,at2), d2 );
824  memb_dsolv2_(i,at1,at2) = d2;
825  memb_dsolv1_(i,at1,at2) = d1;
826  }
827 
828  InterpolatorOP interp12( gen12.get_interpolator() );
829  InterpolatorOP interp22( gen22.get_interpolator() );
830 
831  InterpolatorOP minterp12( mgen12.get_interpolator() );
832  InterpolatorOP minterp22( mgen22.get_interpolator() );
833 
834  for( int i = S2; i <= E2; ++i ) {
835  Real d1,d2;
836  interp12->interpolate( dis(i), solv1_(i,at1,at2), d1 );
837  interp22->interpolate( dis(i), solv2_(i,at1,at2), d2 );
838  dsolv2_(i,at1,at2) = d2;
839  dsolv1_(i,at1,at2) = d1;
840  minterp12->interpolate( dis(i), memb_solv1_(i,at1,at2), d1 );
841  minterp22->interpolate( dis(i), memb_solv2_(i,at1,at2), d2 );
842  memb_dsolv2_(i,at1,at2) = d2;
843  memb_dsolv1_(i,at1,at2) = d1;
844  }
845 
846  }
847  }
848 
849 }
850 
851 
852 ////////////////////////////////////////////////////////////////////////////////
853 /// @begin output_etable
854 ///
855 /// @brief output an etable data file in the same format used in input_etable
856 ///
857 /// @detailed
858 ///$$$ file first line is <etable> <etable_disbins>
859 ///$$$ other lines are <atom type 1> <atomtype 1> <eval bin 1> <eval bin 2>...
860 ///
861 /// @global_read
862 /// pdbstatistics_pack.h: ljatr, dljatr, ljrep, dljrep, solv1,solv2,dsolv
863 ///
864 ///
865 /// @remarks
866 ///
867 /// @references
868 ///
869 /// @authors sheffler mar 19 2006
870 ///
871 /// @last_modified
872 /////////////////////////////////////////////////////////////////////////////////
873 void
875  ObjexxFCL::FArray3D<Real> & etable,
876  std::string label,
877  std::ostream & out
878 ) {
879  using namespace std;
880  using namespace ObjexxFCL;
881 
882  out << label << " " << etable_disbins << endl;
883  for(int at1 = 1; at1 <= n_atomtypes; at1++) {
884  for(int at2 = 1; at2 <= n_atomtypes; at2++) {
885  out << at1 << " "
886  << at2 << " ";
887  for(int bin = 1; bin <= etable_disbins; bin++) {
888  float evalue = etable(bin,at1,at2);
889  out << evalue << ' ';
890  }
891  out << endl;
892  }
893  }
894 
895 }
896 
897 
898 ////////////////////////////////////////////////////////////////////////////////
899 /// @begin input_etable
900 ///
901 /// @brief read in etable from a datafile
902 ///
903 /// @detailed
904 ///$$$ file first line is <etable> <etable_disbins>
905 ///$$$ other lines are <atom type 1> <atomtype 1> <eval bin 1> <eval bin 2>...
906 ///
907 /// @global_read
908 /// pdbstatistics_pack.h: ljatr, dljatr, ljrep, dljrep, solv1,solv2,dsolv
909 ///
910 /// @global_write
911 /// pdbstatistics_pack.h: ljatr, dljatr, ljrep, dljrep, solv1,solv2,dsolv
912 ///
913 /// @remarks
914 ///
915 /// @references
916 ///
917 /// @authors sheffler mar 19 2006
918 ///
919 /// @last_modified
920 /////////////////////////////////////////////////////////////////////////////////
921 void
923  ObjexxFCL::FArray3D<Real> & etable,
924  const std::string label,
925  std::istream & in
926 ) {
927  using namespace std;
928 
929  TR << "input_etable: reading etable... " << label << endl;
930  istringstream intmp;
931  string lblin;
932  int numdisbin;
933  char buf[100000];
934 
935  // check header
936  in.getline(buf,100000);
937  intmp.str(buf);
938  if( !(intmp >> lblin >> numdisbin) ) {
939  TR << "input_etable: WARNING bad etable header " << buf << endl;
940  return;
941  }
942  if( lblin != label || etable_disbins != numdisbin ) {
943  TR << "input_etable: WARNING etable types don't match! "<< endl;
944  TR << " expected " << label << "," << etable_disbins
945  << " got " << lblin << ',' << numdisbin<< endl;
946  utility_exit_with_message( "input_etable: WARNING etable types don't match! " );
947  } else {
948  TR << "input_etable expected etable " << label << " of size " << etable_disbins
949  << ", got " << lblin << ',' << numdisbin<< endl;
950 
951  }
952 
953  // read in etable
954  int at1,at2,count=0,scount=0;
955  float evalue;
956  while( in.getline(buf,100000) ) {
957  //TR << "ASDFF buf " << buf << endl;
958  count++;
959  intmp.clear();
960  intmp.str(buf);
961  if( ! (intmp >> at1 >> at2 ) ) {
962  TR << "input_etable: error reading etable line: " << buf << endl;
963  } else {
964  for(int bin = 1; bin <=numdisbin; bin++) {
965  if( !(intmp >> evalue) ) {
966  TR << "input_etable: not enough bins on etable line: " << buf << endl;
967  utility_exit_with_message( "input_etable: not enough bins on etable line: " );
968  }
969  //TR << "ASDFF read " << lblin << ' ' << at1 << ' ' << at2 << ' ' << bin << ' ' << evalue << endl;
970  //TR << "ASDFF " << lblin << at1 << at2 << evalue;
971  etable(bin,at1,at2) = evalue;
972  etable(bin,at2,at1) = evalue;
973  }
974  scount++;
975  }
976  }
977  TR << " read " << scount << " of " << count << " lines" << endl;
978 }
979 
980 
981 
982 
983 ////////////////////////////////////////////////////////////////////////////////
984 /// @begin precalc_etable_coefficients
985 ///
986 /// @brief precalculate non-distance dependent coefficients of energy functions
987 ///
988 /// @detailed
989 ///
990 /// @param[out] lj_sigma - out - for atomtypes i and j: (radius_i+radius_j)
991 /// @param[out] lj_r6_coeff - out - precalced coefficient on the (1/dis)**6 term in lj
992 /// @param[out] lj_r12_coeff - out - precalced coefficient on the (1/dis)**12 term in lj
993 /// @param[out] lj_switch_intercept - out -
994 /// for close contacts calculate lj from a line with this intercept
995 /// @param[out] lj_switch_slope - out -
996 /// for close contacts calculate lj from a line with this slope
997 /// @param[out] lk_inv_lambda2 - out -
998 /// surprise! it's the 1/(lambda)**2 term in the lk equation
999 /// @param[out] lk_coeff - out - precalculation of all non-distance dependent terms
1000 /// outside of the exponential in the lk equation
1001 /// @param[out] lk_min_dis2sigma_value - out - below the min dis2sigma ratio for lk,
1002 /// this value is assigned to the solvation
1003 ///
1004 /// @global_read
1005 ///
1006 /// @global_write
1007 ///
1008 /// @remarks
1009 ///
1010 /// @references
1011 ///
1012 /// @authors ctsa 10-2003
1013 ///
1014 /// @last_modified
1015 /////////////////////////////////////////////////////////////////////////////////
1016 void
1018  FArray2< Real > & lj_sigma,
1019  /*FArray2< Real > & lj_r6_coeff,
1020  FArray2< Real > & lj_r12_coeff,
1021  FArray2< Real > & lj_switch_intercept,
1022  FArray2< Real > & lj_switch_slope,*/
1023  FArray1< Real > & lk_inv_lambda2,
1024  FArray2< Real > & lk_coeff,
1025  FArray2< Real > & memb_lk_coeff, //pba
1026  FArray2< Real > & lk_min_dis2sigma_value,
1027  FArray2< Real > & memb_lk_min_dis2sigma_value //pba
1028 )
1029 {
1030 
1031 // using namespace etable;
1032 // using namespace param;
1033 // using namespace water;
1034 // using namespace hbonds;
1035 
1036  // locals
1037  Real sigma; //sigma6,sigma12,wdepth;
1038  Real inv_lambda;
1039  FArray1D< Real > lk_coeff_tmp( n_atomtypes );
1040  FArray1D< Real > memb_lk_coeff_tmp( n_atomtypes ); //pba
1041  Real thresh_dis,inv_thresh_dis2,x_thresh;
1042  //int dstype;
1043  //int const atype_sulfur = { 16 };
1044  Real const inv_neg2_tms_pi_sqrt_pi = { -0.089793561062583294 };
1045  // coefficient for lk solvation
1046 
1047  // include follows locals so that data statements can initialize included arrays
1048  for ( int i = 1, e = n_atomtypes; i <= e; ++i ) {
1049  inv_lambda = 1.0/lk_lambda(i);
1050  //inv_lambda = 1.0/atom_type(i).lk_lambda();
1051  lk_inv_lambda2(i) = inv_lambda * inv_lambda;
1052  lk_coeff_tmp(i) = inv_neg2_tms_pi_sqrt_pi * lk_dgfree(i) * inv_lambda;
1053  memb_lk_coeff_tmp(i) = inv_neg2_tms_pi_sqrt_pi * memb_lk_dgfree(i) * inv_lambda; //pba
1054  }
1055 
1056  for ( int i = 1, e = n_atomtypes; i <= e; ++i ) {
1057  for ( int j = i; j <= e; ++j ) {
1058 
1059  sigma = Wradius * ( lj_radius(i) + lj_radius(j) );
1060  //sigma = Wradius * ( atom_type(i).lj_radius() + atom_type(j).lj_radius() );
1061 //jjh temporary fix to prevent division by zero below
1062  sigma = ( sigma < 1.0e-9 ? 1.0e-9 : sigma );
1063 
1064  // (bk) modify sigma for hbond donors and acceptors
1065  // ctsa -- should these scale down by Wradius as well?
1066 
1067  // pb specific sigma correction for pairs between charged oxygen acceptors (15)
1068  // pb and hydroxyl oxygen donors (13). sigma correction for all polar H and charged oxygen
1069  // pb acceptor. Combinations of these corrections allow better prediction of both
1070  // pb hydroxyl O donor/charged O acceptor and charged NH donor/charged O acceptor
1071  // pb distances.
1072 
1073  if ( lj_use_hbond_radii ) {
1074  if ( ( atom_type(i).is_acceptor() && atom_type(j).is_donor() ) ||
1075  ( atom_type(i).is_donor() && atom_type(j).is_acceptor() ) ) {
1076  sigma = lj_hbond_dis;
1077 // if (tight_hb && ((i == 15 && j == 13) || (j == 15 && i == 13)))
1078 // sigma = lj_hbond_accOch_dis;
1079  } else if ( ( atom_type(i).is_acceptor() && atom_type(j).is_polar_hydrogen() ) ||
1080  ( atom_type(i).is_polar_hydrogen() && atom_type(j).is_acceptor() ) ) {
1081  sigma = lj_hbond_hdis;
1082 // if (tight_hb && ((i == 15 && j == 22) || (j == 15 && i == 22)))
1083 // sigma = lj_hbond_accOch_hdis;
1084  }
1085  }
1086 
1087 //lin modify sigma for water and hbond donors/acceptors
1088  if ( lj_use_water_radii ) {
1089  if ( ( ( atom_type(i).is_acceptor() ||
1090  atom_type(i).is_donor() ) &&
1091  atom_type(j).is_h2o() ) ||
1092  ( ( atom_type(j).is_acceptor() ||
1093  atom_type(j).is_donor() ) &&
1094  atom_type(i).is_h2o() ) ) {
1095  sigma = lj_water_dis;
1096  } else if ( ( atom_type(i).is_polar_hydrogen() &&
1097  atom_type(j).is_h2o() ) ||
1098  ( atom_type(j).is_polar_hydrogen() &&
1099  atom_type(i).is_h2o() ) ) {
1100  sigma = lj_water_hdis;
1101  }
1102  }
1103 /*
1104  sigma6 = std::pow( sigma, 6 );
1105  sigma12 = sigma6 * sigma6;
1106  wdepth = std::sqrt(lj_wdepth(i)*lj_wdepth(j));
1107  //wdepth = std::sqrt(atom_type(i).lj_wdepth()*atom_type(j).lj_wdepth());
1108 */
1109  lj_sigma(i,j) = sigma;
1110  lj_sigma(j,i) = lj_sigma(i,j);
1111 /*
1112  lj_r6_coeff(i,j) = -2. * wdepth * sigma6;
1113  lj_r6_coeff(j,i) = lj_r6_coeff(i,j);
1114 
1115  lj_r12_coeff(i,j) = wdepth * sigma12;
1116  lj_r12_coeff(j,i) = lj_r12_coeff(i,j);
1117 
1118  // ctsa - create coefficients for linear projection of lj repulsive used
1119  // for low distance values
1120  if ( lj_use_lj_deriv_slope ) {
1121 
1122  // ctsa - use the slope of the true lj repulsive at the
1123  // linear switch point to create a linear projection of
1124  // lj for low distances
1125 
1126  // slope = wdepth/sigma *
1127  // (slope@switch_point*sigma/wdepth)
1128  lj_switch_slope(i,j) = (wdepth/sigma)*
1129  lj_switch_slope_sigma2wdepth;
1130  lj_switch_slope(j,i) = lj_switch_slope(i,j);
1131 
1132  // intercept = wdepth*(lj@switch_point/wdepth)
1133  // - slope*switch_point_distance
1134  lj_switch_intercept(i,j) = wdepth*lj_switch_value2wdepth -
1135  lj_switch_slope(i,j)*sigma*lj_switch_dis2sigma;
1136  lj_switch_intercept(j,i) = lj_switch_intercept(i,j);
1137  } else {
1138 
1139  // ctsa - create a linear projection of lj for low distances which
1140  // is defined by a constant y intercept and the true lj repulsive
1141  // value at the linear switch point
1142  lj_switch_slope(i,j) = -(1./sigma)*lj_switch_sigma2dis*
1143  (lj_slope_intercept-wdepth*lj_switch_value2wdepth);
1144  lj_switch_slope(j,i) = lj_switch_slope(i,j);
1145 
1146  lj_switch_intercept(i,j) = lj_slope_intercept;
1147  lj_switch_intercept(j,i) = lj_switch_intercept(i,j);
1148  }
1149 */
1150  // ctsa - precalculated lk solvation coefficients
1151  lk_coeff(i,j) = lk_coeff_tmp(i) * lk_volume(j);
1152  //lk_coeff(i,j) = lk_coeff_tmp(i) * atom_type(j).lk_volume();
1153  lk_coeff(j,i) = lk_coeff_tmp(j) * lk_volume(i);
1154  //lk_coeff(j,i) = lk_coeff_tmp(j) * atom_type(i).lk_volume();
1155  memb_lk_coeff(i,j) = memb_lk_coeff_tmp(i) * lk_volume(j); //pba
1156  memb_lk_coeff(j,i) = memb_lk_coeff_tmp(j) * lk_volume(i); //pba
1157 
1158  // ctsa - when dis/sigma drops below lk_min_dis2sigma,
1159  // a constant lk solvation value equal to the value at the
1160  // switchover point is used. That switchover-point value
1161  // is calculated here and stored in lk_min_dis2sigma_value
1162  thresh_dis = lk_min_dis2sigma*sigma;
1163  inv_thresh_dis2 = 1./( thresh_dis * thresh_dis );
1164  Real dis_rad = thresh_dis - lj_radius(i);
1165  //Real dis_rad = thresh_dis - atom_type(i).lj_radius();
1166  x_thresh = ( dis_rad * dis_rad ) * lk_inv_lambda2(i);
1167  lk_min_dis2sigma_value(i,j) = std::exp(-x_thresh) * lk_coeff(i,j) *
1168  inv_thresh_dis2;
1169  memb_lk_min_dis2sigma_value(i,j) = std::exp(-x_thresh) * memb_lk_coeff(i,j) *
1170  inv_thresh_dis2; //pba
1171 
1172  dis_rad = thresh_dis - lj_radius(j);
1173  //dis_rad = thresh_dis - atom_type(j).lj_radius();
1174  x_thresh = ( dis_rad * dis_rad ) * lk_inv_lambda2(j);
1175  lk_min_dis2sigma_value(j,i) = std::exp(-x_thresh) * lk_coeff(j,i) *
1176  inv_thresh_dis2;
1177  memb_lk_min_dis2sigma_value(j,i) = std::exp(-x_thresh) * memb_lk_coeff(j,i) *
1178  inv_thresh_dis2; //pba
1179  //pbadebug WARNING
1180  //if(i==18 && j==19)
1181  //std::cout << "lk_min_ij lk_min_ji " << lk_min_dis2sigma_value(i,j) << " " << lk_min_dis2sigma_value(j,i) << std::endl;
1182 
1183  }
1184  }
1185 
1186  // ctsa - calculate disulfide coefficients
1187  // pb -- killed this
1188 
1189 }
1190 
1191 
1192 ////////////////////////////////////////////////////////////////////////////////
1193 /// @begin calc_etable_value
1194 ///
1195 /// @brief calc all etable values given a distance and atom-type pair
1196 ///
1197 /// @detailed
1198 ///
1199 /// given a pair of atom types and the squared inter-atomic separation
1200 /// distance (and a whole bunch of pre-computed coeffecients), this returns
1201 /// the value of the lennard-jones and lk solvation potentials and
1202 /// their derivatives w.r.t. the separation distance
1203 ///
1204 ///
1205 /// @param[in] dis2 - in - atomic separation distance squared
1206 /// @param[in] atype1 - in - chemical type of atom 1
1207 /// @param[in] atype2 - in - chemical type of atom 2
1208 /// @param[out] atrE - out - atractive lj energy
1209 /// @param[out] d_atrE - out - d(atrE)/d(dis)
1210 /// @param[out] repE - out - repulsive lj energy
1211 /// @param[out] d_repE - out - d(repE)/d(dis)
1212 /// @param[out] solvE1 - out - lk solvation energy
1213 /// @param[out] solvE2 - out - lk solvation energy
1214 /// @param[out] dsolvE - out - d(solvE1+solvE2)/d(dis)
1215 /// @param[in] lj_sigma - in - for atomtypes i and j: (radius_i+radius_j)
1216 /// @param[in] lj_r6_coeff - in - precalced coefficient on the (1/dis)**6 term in lj
1217 /// @param[in] lj_r12_coeff - in - precalced coefficient on the (1/dis)**12 term in lj
1218 /// @param[in] lj_switch_intercept - in -
1219 /// for close contacts calculate lj from a line with this intercept
1220 /// @param[in] lj_switch_slope - in -
1221 /// for close contacts calculate lj from a line with this slope
1222 /// @param[in] lk_inv_lambda2 - in -
1223 /// surprise! it's the 1/(lambda)**2 term in the lk equation
1224 /// @param[in] lk_coeff - in - precalculation of all non-distance dependent terms
1225 /// outside of the exponential in the lk equation
1226 /// @param[in] lk_min_dis2sigma_value - in - below the min dis2sigma ratio for lk,
1227 /// this value is assigned to the solvation
1228 ///
1229 /// @global_read
1230 ///
1231 /// pdbstatistics_pack.h
1232 /// etable.h
1233 ///
1234 /// @global_write
1235 ///
1236 /// @remarks
1237 ///
1238 /// @references
1239 ///
1240 /// @authors ctsa 10-2003
1241 ///
1242 /// @last_modified
1243 /////////////////////////////////////////////////////////////////////////////////
1244 void
1246  Real & dis2,
1247  int & atype1,
1248  int & atype2,
1249  /*Real & atrE,
1250  Real & d_atrE,
1251  Real & repE,
1252  Real & d_repE,*/
1253  Real & solvE1,
1254  Real & solvE2,
1255  Real & dsolvE1,
1256  Real & dsolvE2,
1257  FArray2< Real > & lj_sigma,
1258  /*FArray2< Real > & lj_r6_coeff,
1259  FArray2< Real > & lj_r12_coeff,
1260  FArray2< Real > & lj_switch_intercept,
1261  FArray2< Real > & lj_switch_slope,*/
1262  FArray1< Real > & lk_inv_lambda2,
1263  FArray2< Real > & lk_coeff,
1264  FArray2< Real > & lk_min_dis2sigma_value,
1265  Real & memb_solvE1, //pba
1266  Real & memb_solvE2,
1267  FArray2< Real > & memb_lk_coeff,
1268  FArray2< Real > & memb_lk_min_dis2sigma_value,
1269  Real & memb_dsolvE1,
1270  Real & memb_dsolvE2
1271 )
1272 {
1273 // using namespace etable;
1274 // using namespace param;
1275 // using namespace pdbstatistics_pack;
1276 
1277  // locals
1278  //Real ljE,d_ljE,
1279  Real x1,x2;
1280  Real dis;
1281  Real inv_dis,inv_dis2; //,inv_dis6,inv_dis7,inv_dis12,inv_dis13;
1282  Real dis2sigma;
1283  int xtra_atype1,xtra_atype2;
1284  //int const atype_sulfur = { 16 };
1285 
1286  // include after local variables to allow data statements to initialize
1287  /*atrE = 0.;
1288  d_atrE = 0.;
1289  repE = 0.;
1290  d_repE = 0.;*/
1291  solvE1 = 0.;
1292  solvE2 = 0.;
1293  dsolvE1 = 0.;
1294  dsolvE2 = 0.;
1295  memb_solvE1 = 0.; //pba
1296  memb_solvE2 = 0.;
1297  memb_dsolvE1 = 0.;
1298  memb_dsolvE2 = 0.;
1299 
1300  // ctsa - epsilon allows final bin value to be calculated
1301  if ( dis2 > max_dis2 + epsilon ) return;
1302 
1303  if ( dis2 < min_dis2 ) dis2 = min_dis2;
1304 
1305  dis = std::sqrt(dis2);
1306  inv_dis = 1.0/dis;
1307  inv_dis2 = inv_dis * inv_dis;
1308 
1309 
1310 
1311  // ctsa - switch to disulfide bonded atom types
1312  // when conditions are met
1313 // if ( ( atype1 == atype_sulfur && atype2 == atype_sulfur ) &&
1314 // dis < disulfide_dis_thresh ) {
1315 // xtra_atype1 = n_atomtypes + 1;
1316 // xtra_atype2 = n_atomtypes + 1;
1317 // } else {
1318  xtra_atype1 = atype1;
1319  xtra_atype2 = atype2;
1320  //}
1321 
1322 
1323  dis2sigma = dis / lj_sigma(xtra_atype1,xtra_atype2);
1324 
1325 /*
1326  if ( dis2sigma < lj_switch_dis2sigma ) {
1327  // ctsa - use linear ramp instead of lj when the dis/sigma
1328  // ratio drops below theshold
1329  d_ljE = lj_switch_slope(xtra_atype1,xtra_atype2);
1330  ljE = dis*d_ljE + lj_switch_intercept(xtra_atype1,xtra_atype2);
1331  } else {
1332  // ctsa - calc regular lennard-jones
1333  inv_dis6 = inv_dis2 * inv_dis2 * inv_dis2;
1334  inv_dis7 = inv_dis6 * inv_dis;
1335  inv_dis12 = inv_dis6 * inv_dis6;
1336  inv_dis13 = inv_dis12 * inv_dis;
1337 
1338  ljE = lj_r12_coeff(xtra_atype1,xtra_atype2) * inv_dis12 +
1339  lj_r6_coeff(xtra_atype1,xtra_atype2) * inv_dis6;
1340 
1341  d_ljE = -12.*lj_r12_coeff(xtra_atype1,xtra_atype2) * inv_dis13-6. *
1342  lj_r6_coeff(xtra_atype1,xtra_atype2) * inv_dis7;
1343  }
1344 
1345  if ( ljE < 0. ) {
1346  atrE = ljE;
1347  d_atrE = d_ljE;
1348  } else {
1349  repE = ljE;
1350  d_repE = d_ljE;
1351  }
1352 */
1353  //pbadebug WARNING
1354  //if(atype1==18 && atype2==19)
1355  // std::cout << "d lj d2s lkmin " << dis << " " << lj_sigma(xtra_atype1,xtra_atype2) << " " << dis2sigma << " " << lk_min_dis2sigma << std::endl;
1356  // ctsa - calc lk
1357  if ( dis2sigma < lk_min_dis2sigma ) {
1358  // ctsa - solvation is constant when the dis/sigma ratio
1359  // falls below minimum threshold
1360  solvE1 = lk_min_dis2sigma_value(xtra_atype1,xtra_atype2);
1361  solvE2 = lk_min_dis2sigma_value(xtra_atype2,xtra_atype1);
1362  dsolvE1 = 0.0;
1363  dsolvE2 = 0.0;
1364  memb_solvE1 = memb_lk_min_dis2sigma_value(xtra_atype1,xtra_atype2); //pba
1365  memb_solvE2 = memb_lk_min_dis2sigma_value(xtra_atype2,xtra_atype1);
1366  memb_dsolvE1 = memb_dsolvE2 = 0.0;
1367 
1368  } else {
1369 
1370  Real dis_rad = dis - lj_radius(atype1);
1371  //Real dis_rad = dis - atom_type(atype1).lj_radius();
1372  x1 = ( dis_rad * dis_rad ) * lk_inv_lambda2(atype1);
1373  dis_rad = dis - lj_radius(atype2);
1374  //dis_rad = dis - atom_type(atype2).lj_radius();
1375  x2 = ( dis_rad * dis_rad ) * lk_inv_lambda2(atype2);
1376 
1377  solvE1 = std::exp(-x1) * lk_coeff(atype1,atype2) * inv_dis2;
1378  solvE2 = std::exp(-x2) * lk_coeff(atype2,atype1) * inv_dis2;
1379  memb_solvE1 = std::exp(-x1) * memb_lk_coeff(atype1,atype2) * inv_dis2; //pba
1380  memb_solvE2 = std::exp(-x2) * memb_lk_coeff(atype2,atype1) * inv_dis2;
1381 
1382  //pbadebug WARNING
1383  //if(atype1==18 && atype2==19)
1384  // std::cout << "d x1 x2 lk1 lk2 s1 s2 " << dis << " " << x1 << " " << x2 << " " << lk_coeff(atype1,atype2) << " " << lk_coeff(atype2,atype1) << " " << solvE1 << " " << solvE2 << std::endl;
1385 
1386  // ctsa - get d(lk_E)/dr
1387  dsolvE1 = -2.0 * solvE1 *
1388  (((dis-lj_radius(atype1))*lk_inv_lambda2(atype1))+inv_dis);
1389  //(((dis-atom_type(atype1).lj_radius())*lk_inv_lambda2(atype1))+inv_dis);
1390  dsolvE2 = -2.0 * solvE2 *
1391  (((dis-lj_radius(atype2))*lk_inv_lambda2(atype2))+inv_dis);
1392  //(((dis-atom_type(atype2).lj_radius())*lk_inv_lambda2(atype2))+inv_dis);
1393 
1394  // pba - get d(memblk_E)/dr
1395  memb_dsolvE1 = -2.0 * memb_solvE1 *
1396  (((dis-lj_radius(atype1))*lk_inv_lambda2(atype1))+inv_dis);
1397  memb_dsolvE2 = -2.0 * memb_solvE2 *
1398  (((dis-lj_radius(atype2))*lk_inv_lambda2(atype2))+inv_dis);
1399 
1400  }
1401 
1402 }
1403 
1404 /*
1405 void
1406 Etable::zero_hydrogen_and_water_ljatr()
1407 {
1408  int const HOH = atom_set_->atom_type_index("HOH");
1409  for( int at1 = 1; at1 <= n_atomtypes; ++at1 ) {
1410  for( int at2 = 1; at2 <= n_atomtypes; ++at2 ) {
1411 
1412  // cbk don't give hydrogens or water attractive lennard-jones
1413  // cbk this is so very short range cut-offs can be used
1414  //if ( ( at1 >= 22 && at2 <= 26 ) || ( at2 >= 22 && at2 <= 26 ) ) { // BUG! introduced in r19802
1415  if( atom_type(at1).is_hydrogen() || atom_type(at2).is_hydrogen() || at1 == HOH || at2 == HOH ) {
1416  for( int i = 1; i <= etable_disbins; ++i ) {
1417  ljatr_(i,at1,at2) = 0.0;
1418  dljatr_(i,at1,at2) = 0.0;
1419  }
1420  }
1421 
1422  }
1423  }
1424 
1425 }
1426 */
1427 /// @brief Returns the maximum lj radius for any non-hydrogen
1428 /// atom as defined by the atom-type-set used to create this Etable.
1429 Real
1431 {
1433 }
1434 
1435 /// @brief Returns the maximum lj radius for any hydrogen atom as
1436 /// defined by the input atom-type-set used to create this Etable.
1437 Real
1439 {
1440  return max_hydrogen_lj_radius_;
1441 }
1442 
1443 
1444 
1445 } // etable
1446 } // scoring
1447 } // core