Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CarbonHBondEnergy.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/carbon_hbonds/CarbonHBondEnergy.fwd.hh
11 /// @brief Hydrogen bond energy method forward declaration
12 /// @author Phil Bradley
13 /// @author Andrew Leaver-Fay
14 /// @author Rhiju Das
15 /// @author Parin Sripakdeevong (sripakpa@stanford.edu)
16 
17 // Unit Headers
20 
21 // Package headers
22 // AUTO-REMOVED #include <core/scoring/Energies.hh>
23 // AUTO-REMOVED #include <core/scoring/EnergyGraph.hh>
24 // AUTO-REMOVED #include <core/scoring/ScoreFunction.hh>
27 // AUTO-REMOVED #include <core/scoring/hbonds/HBondSet.hh>
28 // AUTO-REMOVED #include <core/scoring/hbonds/types.hh>
29 
30 // Project headers
31 #include <ObjexxFCL/format.hh>
32 
34 
35 #include <basic/options/option.hh>
36 #include <basic/options/keys/score.OptionKeys.gen.hh>
37 
39 
40 // AUTO-REMOVED #include <core/pose/Pose.hh>
41 #include <basic/Tracer.hh>
42 // AUTO-REMOVED #include <basic/prof.hh>
43 
44 #include <numeric/xyzVector.hh>
45 #include <numeric/conversions.hh>
46 #include <numeric/xyz.functions.hh>
47 
49 #include <utility/vector1.hh>
50 #include <boost/bind.hpp>
51 
52 //Auto Headers
54 
55 
56 static basic::Tracer tr( "core.scoring.carbon_hbonds.CarbonHBondEnergy" );
57 
58 
59 namespace core {
60 namespace scoring {
61 namespace carbon_hbonds {
62 
63 using namespace ObjexxFCL::fmt;
64 
65 /// @details This must return a fresh instance of the CarbonHBondEnergy class,
66 /// never an instance already in use
70 ) const {
71  return new CarbonHBondEnergy;
72 }
73 
76  ScoreTypes sts;
77  sts.push_back( ch_bond );
78  sts.push_back( ch_bond_sc_sc );
79  sts.push_back( ch_bond_bb_sc );
80  sts.push_back( ch_bond_bb_bb );
81  return sts;
82 }
83 
84 
85 ///@brief copy c-tor
88  carbon_hbond_potential_( ScoringManager::get_instance()->get_CarbonHBondPotential() ),
89  max_dis_( carbon_hbond_potential_.max_dis() ),
90  max_dis2_( max_dis_*max_dis_ ),
91  path_dist_cutoff_( 4 ),
92  orientation_dep_rna_ch_o_bonds_( ! basic::options::option[ basic::options::OptionKeys::score::disable_orientation_dependent_rna_ch_o_bonds ]),
93  verbose_( false )
94 {}
95 
96 /// copy ctor
98  parent( src ),
99  carbon_hbond_potential_( ScoringManager::get_instance()->get_CarbonHBondPotential() ),
100  max_dis_( carbon_hbond_potential_.max_dis() ),
101  max_dis2_( max_dis_*max_dis_ ),
102  path_dist_cutoff_( src.path_dist_cutoff_ ),
103  orientation_dep_rna_ch_o_bonds_( src.orientation_dep_rna_ch_o_bonds_ ),
104  verbose_( src.verbose_ )
105 {}
106 
107 /// clone
110 {
111  return new CarbonHBondEnergy( *this );
112 }
113 
114 ///
115 void
117 {
118  // nothing for now.
119 }
120 
121 /////////////////////////////////////////////////////////////////////////////
122 // scoring
123 /////////////////////////////////////////////////////////////////////////////
124 
125 /// Everything in here.
126 void
128  conformation::Residue const & rsd1,
129  conformation::Residue const & rsd2,
130  pose::Pose const &,
131  ScoreFunction const &,
132  EnergyMap & emap
133 ) const
134 {
135 
136  Real bb_bb(0.0);
137  Real bb_sc(0.0);
138  Real sc_sc(0.0);
139  Real ch_bond_E =
140  res_res_carbon_hbond_one_way( rsd1, rsd2, bb_bb, bb_sc, sc_sc) +
141  res_res_carbon_hbond_one_way( rsd2, rsd1, bb_bb, bb_sc, sc_sc ) ;
142  emap[ ch_bond_bb_bb ] += bb_bb;
143  emap[ ch_bond_bb_sc ] += bb_sc;
144  emap[ ch_bond_sc_sc ] += sc_sc;
145  // store the energies
146  emap[ ch_bond ] += ch_bond_E;
147  // std::cout << "RUNNING SUM: " << rsd1.seqpos() << " " << rsd2.seqpos() << " " << ch_bond_E << " " << emap[ ch_bond ] << std::endl;
148 
149 }
150 
151 bool
153 
154 void
156  conformation::Residue const & rsd1,
157  conformation::Residue const & rsd2,
158  pose::Pose const &,
159  ScoreFunction const &,
160  EnergyMap & emap
161 ) const
162 {
163  Real ch_bond_E =
164  bb_bb_carbon_hbond_one_way( rsd1, rsd2 ) +
165  bb_bb_carbon_hbond_one_way( rsd2, rsd1 ) ;
166 
167  // store the energies
168  emap[ ch_bond ] += ch_bond_E;
169  emap[ ch_bond_bb_bb ] += ch_bond_E;
170  // std::cout << "RUNNING SUM: " << rsd1.seqpos() << " " << rsd2.seqpos() << " " << ch_bond_E << " " << emap[ ch_bond ] << std::endl;
171 }
172 
173 
174 void
176  conformation::Residue const & rsd1,
177  conformation::Residue const & rsd2,
178  pose::Pose const &,
179  ScoreFunction const &,
180  EnergyMap & emap
181 ) const
182 {
183  Real ch_bond_E =
184  bb_sc_carbon_hbond_one_way( rsd1, rsd2 ) +
185  sc_bb_carbon_hbond_one_way( rsd2, rsd1 ) ;
186 
187  // store the energies
188  emap[ ch_bond ] += ch_bond_E;
189  emap[ ch_bond_bb_sc ] += ch_bond_E;
190 
191  // std::cout << "RUNNING SUM: " << rsd1.seqpos() << " " << rsd2.seqpos() << " " << ch_bond_E << " " << emap[ ch_bond ] << std::endl;
192 }
193 
194 
195 void
197  conformation::Residue const & rsd1,
198  conformation::Residue const & rsd2,
199  pose::Pose const & ,
200  ScoreFunction const & ,
201  EnergyMap & emap
202 ) const
203 {
204  Real ch_bond_E =
205  sc_sc_carbon_hbond_one_way( rsd1, rsd2 ) +
206  sc_sc_carbon_hbond_one_way( rsd2, rsd1 ) ;
207 
208  // store the energies
209  emap[ ch_bond ] += ch_bond_E;
210  emap[ ch_bond_sc_sc ] += ch_bond_E;
211  // std::cout << "RUNNING SUM: " << rsd1.seqpos() << " " << rsd2.seqpos() << " " << ch_bond_E << " " << emap[ ch_bond ] << std::endl;
212 }
213 
214 
215 ///////////////////////////////////////////////////////////////////////////////
216 // Look more than four atoms away.
217 bool
219  conformation::Residue const & rsd1,
220  conformation::Residue const & rsd2,
221  Size const ii,
222  Size const jj
223 ) const
224 {
225  Size const & i( rsd1.seqpos() );
226  Size const & j( rsd2.seqpos() );
227  // std::cout << i << " " << j << " " << ii << " " << jj << std::endl;
228  if ( i == j && Size( rsd1.path_distance(ii,jj) ) <= path_dist_cutoff_) return false;
229  else if ( rsd1.is_bonded( rsd2 ) ) {
230  Size const path_size =
231  rsd1.path_distance( ii, rsd1.connect_atom( rsd2 ) ) +
232  rsd2.path_distance( jj, rsd2.connect_atom( rsd1 ) ) + 1;
233  if ( path_size <= path_dist_cutoff_ ) return false;
234  }
235  return true;
236 }
237 
238 
239 /////////////////////////////////////////////////////////////////////
240 Real
242  conformation::Residue const & don_rsd,
243  conformation::Residue const & acc_rsd,
244  Real & bb_bb,
245  Real & bb_sc,
246  Real & sc_sc
247 ) const
248 {
249 
250  Real res_res_energy( 0.0 ), energy( 0.0 );
251 
252 
253  // Here we go -- cycle through non-polar hydrogens in don_aa, and all acceptors.
254  for ( chemical::AtomIndices::const_iterator
255  hnum = don_rsd.Hpos_apolar().begin(),
256  hnume = don_rsd.Hpos_apolar().end(); hnum != hnume; ++hnum ) {
257  Size const don_h_atm( *hnum );
258 
259  // std::cout << "Apolar hydrogen: " << don_rsd.atom_name( don_h_atm ) << " in " << don_rsd.name1() << don_rsd.seqpos() << std::endl;
260 
261  for ( chemical::AtomIndices::const_iterator
262  anum = acc_rsd.accpt_pos().begin(),
263  anume = acc_rsd.accpt_pos().end(); anum != anume; ++anum ) {
264 
265  //check here whether is backbone
266  Size const acc_atm( *anum );
267 
268  /// square-distance check outside the call to get_atom_atom_carbon_hbond_energy
269  if ( don_rsd.xyz( don_h_atm ).distance_squared( acc_rsd.xyz( acc_atm ) ) > max_dis2_ ) continue;
270 
271  if ( get_atom_atom_carbon_hbond_energy( don_h_atm, don_rsd,
272  acc_atm, acc_rsd, energy ) ) {
273  if (don_rsd.atom_is_backbone(don_h_atm) && acc_rsd.atom_is_backbone(acc_atm)){
274  //emap[ch_bond_bb_bb]+=energy;
275  bb_bb +=energy;
276  } else if (!don_rsd.atom_is_backbone(don_h_atm) && !acc_rsd.atom_is_backbone(acc_atm)){
277  //emap[ch_bond_sc_sc]+=energy;
278  sc_sc +=energy;
279  } else {
280  //emap[ch_bond_bb_sc]+=energy;
281  bb_sc +=energy;
282  }
283  res_res_energy += energy;
284  }
285  }
286  }
287 
288  return res_res_energy;
289 }
290 
291 Real
293  conformation::Residue const & don_rsd,
294  conformation::Residue const & acc_rsd
295 ) const
296 {
297 
298  Real res_res_energy( 0.0 ), energy( 0.0 );
299 
300  // Here we go -- cycle through non-polar hydrogens in don_aa, and all acceptors.
301  for ( chemical::AtomIndices::const_iterator
302  hnum = don_rsd.Hpos_apolar().begin(),
303  hnume = don_rsd.Hpos_apolar().end(); hnum != hnume; ++hnum ) {
304  Size const don_h_atm( *hnum );
305  if ( don_h_atm >= don_rsd.first_sidechain_hydrogen() ) continue;
306  // std::cout << "Apolar hydrogen: " << don_rsd.atom_name( don_h_atm ) << " in " << don_rsd.name1() << don_rsd.seqpos() << std::endl;
307 
308  for ( chemical::AtomIndices::const_iterator
309  anum = acc_rsd.accpt_pos().begin(),
310  anume = acc_rsd.accpt_pos().end(); anum != anume; ++anum ) {
311 
312  Size const acc_atm( *anum );
313  if ( acc_atm > acc_rsd.last_backbone_atom() ) continue;
314 
315  /// square-distance check outside the call to get_atom_atom_carbon_hbond_energy
316  if ( don_rsd.xyz( don_h_atm ).distance_squared( acc_rsd.xyz( acc_atm ) ) > max_dis2_ ) continue;
317 
318  get_atom_atom_carbon_hbond_energy( don_h_atm, don_rsd,
319  acc_atm, acc_rsd,
320  energy );
321  res_res_energy += energy;
322  }
323  }
324 
325  return res_res_energy;
326 }
327 
328 Real
330  conformation::Residue const & don_rsd, // sidechain atoms on donor
331  conformation::Residue const & acc_rsd // backbone atoms on acceptor
332 ) const
333 {
334 
335  Real res_res_energy( 0.0 ), energy( 0.0 );
336 
337  // Here we go -- cycle through non-polar hydrogens in don_aa, and all acceptors.
338  for ( chemical::AtomIndices::const_iterator
339  hnum = don_rsd.Hpos_apolar().begin(),
340  hnume = don_rsd.Hpos_apolar().end(); hnum != hnume; ++hnum ) {
341  Size const don_h_atm( *hnum );
342  if ( don_h_atm < don_rsd.first_sidechain_hydrogen() ) continue;
343  // std::cout << "Apolar hydrogen: " << don_rsd.atom_name( don_h_atm ) << " in " << don_rsd.name1() << don_rsd.seqpos() << std::endl;
344 
345  for ( chemical::AtomIndices::const_iterator
346  anum = acc_rsd.accpt_pos().begin(),
347  anume = acc_rsd.accpt_pos().end(); anum != anume; ++anum ) {
348 
349  Size const acc_atm( *anum );
350  if ( acc_atm > acc_rsd.last_backbone_atom() ) continue;
351 
352  /// square-distance check outside the call to get_atom_atom_carbon_hbond_energy
353  if ( don_rsd.xyz( don_h_atm ).distance_squared( acc_rsd.xyz( acc_atm ) ) > max_dis2_ ) continue;
354 
355  get_atom_atom_carbon_hbond_energy( don_h_atm, don_rsd,
356  acc_atm, acc_rsd,
357  energy );
358  res_res_energy += energy;
359  }
360  }
361 
362  return res_res_energy;
363 }
364 
365 Real
367  conformation::Residue const & don_rsd, // backbone atoms on donor
368  conformation::Residue const & acc_rsd // sidechain atoms on acceptor
369 ) const
370 {
371 
372  Real res_res_energy( 0.0 ), energy( 0.0 );
373 
374  // Here we go -- cycle through non-polar hydrogens in don_aa, and all acceptors.
375  for ( chemical::AtomIndices::const_iterator
376  hnum = don_rsd.Hpos_apolar().begin(),
377  hnume = don_rsd.Hpos_apolar().end(); hnum != hnume; ++hnum ) {
378  Size const don_h_atm( *hnum );
379  if ( don_h_atm >= don_rsd.first_sidechain_hydrogen() ) continue;
380  // std::cout << "Apolar hydrogen: " << don_rsd.atom_name( don_h_atm ) << " in " << don_rsd.name1() << don_rsd.seqpos() << std::endl;
381 
382  for ( chemical::AtomIndices::const_iterator
383  anum = acc_rsd.accpt_pos().begin(),
384  anume = acc_rsd.accpt_pos().end(); anum != anume; ++anum ) {
385 
386  Size const acc_atm( *anum );
387  if ( acc_atm <= acc_rsd.last_backbone_atom() ) continue;
388 
389  /// square-distance check outside the call to get_atom_atom_carbon_hbond_energy
390  if ( don_rsd.xyz( don_h_atm ).distance_squared( acc_rsd.xyz( acc_atm ) ) > max_dis2_ ) continue;
391 
392  get_atom_atom_carbon_hbond_energy( don_h_atm, don_rsd,
393  acc_atm, acc_rsd,
394  energy );
395  res_res_energy += energy;
396  }
397  }
398 
399  return res_res_energy;
400 }
401 
402 Real
404  conformation::Residue const & don_rsd,
405  conformation::Residue const & acc_rsd
406 ) const
407 {
408 
409  Real res_res_energy( 0.0 ), energy( 0.0 );
410 
411  // Here we go -- cycle through non-polar hydrogens in don_aa, and all acceptors.
412  for ( chemical::AtomIndices::const_iterator
413  hnum = don_rsd.Hpos_apolar().begin(),
414  hnume = don_rsd.Hpos_apolar().end(); hnum != hnume; ++hnum ) {
415  Size const don_h_atm( *hnum );
416  if ( don_h_atm < don_rsd.first_sidechain_hydrogen() ) continue;
417  // std::cout << "Apolar hydrogen: " << don_rsd.atom_name( don_h_atm ) << " in " << don_rsd.name1() << don_rsd.seqpos() << std::endl;
418 
419  for ( chemical::AtomIndices::const_iterator
420  anum = acc_rsd.accpt_pos().begin(),
421  anume = acc_rsd.accpt_pos().end(); anum != anume; ++anum ) {
422 
423  Size const acc_atm( *anum );
424  if ( acc_atm <= acc_rsd.last_backbone_atom() ) continue;
425 
426  /// square-distance check outside the call to get_atom_atom_carbon_hbond_energy
427  if ( don_rsd.xyz( don_h_atm ).distance_squared( acc_rsd.xyz( acc_atm ) ) > max_dis2_ ) continue;
428 
429  get_atom_atom_carbon_hbond_energy( don_h_atm, don_rsd, acc_atm, acc_rsd, energy );
430  res_res_energy += energy;
431  }
432  }
433 
434  return res_res_energy;
435 }
436 
437 
438 void
440  conformation::Residue const & don_rsd,
441  conformation::Residue const & acc_rsd,
442  EnergyMap const & weights,
443  utility::vector1< DerivVectorPair > & don_atom_derivs,
444  utility::vector1< DerivVectorPair > & acc_atom_derivs
445 ) const
446 {
447  bool const eval_bbbb( weights[ ch_bond ] != 0.0 || weights[ ch_bond_bb_bb ] != 0.0 );
448  bool const eval_bbsc( weights[ ch_bond ] != 0.0 || weights[ ch_bond_bb_sc ] != 0.0 );
449  bool const eval_scsc( weights[ ch_bond ] != 0.0 || weights[ ch_bond_bb_sc ] != 0.0 ); //Mistake on this line? Parin S. (sripakpa@stanford.edu) Jan 11, 2012
450  bool const eval_bb( eval_bbsc || eval_bbbb );
451  bool const eval_sc( eval_bbsc || eval_scsc );
452 
453  // Here we go -- cycle through non-polar hydrogens in don_aa, and all acceptors.
454  for ( chemical::AtomIndices::const_iterator
455  hnum = don_rsd.Hpos_apolar().begin(),
456  hnume = don_rsd.Hpos_apolar().end(); hnum != hnume; ++hnum ) {
457  Size const don_h_atm( *hnum );
458  bool const don_h_bb( don_rsd.atom_is_backbone( don_h_atm ) );
459  if ( don_h_bb ) {
460  if ( ! eval_bb ) continue;
461  } else {
462  if ( ! eval_sc ) continue;
463  }
464 
465  // std::cout << "Apolar hydrogen: " << don_rsd.atom_name( don_h_atm ) << " in " << don_rsd.name1() << don_rsd.seqpos() << std::endl;
466 
467  for ( chemical::AtomIndices::const_iterator
468  anum = acc_rsd.accpt_pos().begin(),
469  anume = acc_rsd.accpt_pos().end(); anum != anume; ++anum ) {
470 
471  Size const acc_atm( *anum );
472  bool const acc_bb( acc_rsd.atom_is_backbone( acc_atm ) );
473 
474  /// skip the derivative evaluation if we have a zero weight for the interaction we're examining
475  if ( acc_bb ) {
476  if ( ! eval_bb ) continue;
477  if ( don_h_bb ) {
478  if ( ! eval_bbbb ) continue;
479  } else {
480  if ( ! eval_bbsc ) continue;
481  }
482  } else { // acceptor is sidechain
483  if ( ! eval_sc ) continue;
484  if ( don_h_bb ) {
485  if ( ! eval_bbsc ) continue;
486  } else {
487  if ( ! eval_scsc ) continue;
488  }
489  }
490 
491  /// square-distance check outside the call to get_atom_atom_carbon_hbond_energy
492  if ( don_rsd.xyz( don_h_atm ).distance_squared( acc_rsd.xyz( acc_atm ) ) > max_dis2_ ) continue;
493 
494  Vector f2; Real energy;
495  if ( get_atom_atom_carbon_hbond_energy( don_h_atm, don_rsd,
496  acc_atm, acc_rsd, energy, true, f2 ) ) {
497  //// 1. scale the f2 vector by the weight that applies to this interaction
498  if ( don_h_bb && acc_bb ) {
499  f2 *= weights[ ch_bond ] + weights[ ch_bond_bb_bb ];
500  } else if ( ! don_h_bb && ! acc_bb ) {
501  f2 *= weights[ ch_bond ] + weights[ ch_bond_sc_sc ];
502  } else {
503  f2 *= weights[ ch_bond ] + weights[ ch_bond_bb_sc ];
504  }
505 
506  if( use_orientation_dep_rna_ch_o_bonds(don_rsd, acc_rsd) ){
507  //The standard code doesn't appear to work properly for the RNA case (i.e. fail the numerical_derivative_check() test)
508  //I am including a special version for RNA. Parin S. (sripakpa@stanford.edu). Jan 11, 2012
509 
510  Vector const f1 = cross( f2, acc_rsd.xyz( acc_atm ) );
511 
512  don_atom_derivs[ don_h_atm ].f2() += f2;
513  don_atom_derivs[ don_h_atm ].f1() += f1 ;
514 
515  acc_atom_derivs[ acc_atm ].f2() -= f2;
516  acc_atom_derivs[ acc_atm ].f1() -= f1;
517 
518  }else{
519 
520  /// 2. f2 is the force vector on the hydrogen; compute f1 by taking the cross product
521  /// with the coordinate of the acceptor atom
522  don_atom_derivs[ don_h_atm ].f2() += f2;
523  Vector f1_H = cross( f2, acc_rsd.xyz( acc_atm ) );
524  don_atom_derivs[ don_h_atm ].f1() += f1_H;
525 
526  /// 3. Since f2 is the force vector on the hydrogen, negate it to get the force
527  /// vector on the acceptor; compute f1 by taking the cross product
528  /// with the coordinate of the hydrogen atom
529  f2 *= -1;
530  acc_atom_derivs[ acc_atm ].f2() += f2;
531  Vector f1_Acc = cross( f2, don_rsd.xyz( don_h_atm ) );
532  acc_atom_derivs[ acc_atm ].f1() += f1_Acc;
533  }
534 
535  /*std::cout << " chbond deriv: " << energy << " " << don_rsd.seqpos() << " " << don_h_atm << " " << don_rsd.atom_name(don_h_atm) << " "
536  << acc_rsd.seqpos() << " " << acc_atm << " " << acc_rsd.atom_name( acc_atm ) << " " << don_h_bb << " " << acc_bb << std::endl;
537  std::cout << " don f1: " << don_atom_derivs[ don_h_atm ].f1().x() << " " << don_atom_derivs[ don_h_atm ].f1().y() << " " << don_atom_derivs[ don_h_atm ].f1().z() << std::endl;
538  std::cout << " don f2: " << don_atom_derivs[ don_h_atm ].f2().x() << " " << don_atom_derivs[ don_h_atm ].f2().y() << " " << don_atom_derivs[ don_h_atm ].f2().z() << std::endl;
539  std::cout << " acc f1: " << acc_atom_derivs[ acc_atm ].f1().x() << " " << acc_atom_derivs[ acc_atm ].f1().y() << " " << acc_atom_derivs[ acc_atm ].f1().z() << std::endl;
540  std::cout << " acc f2: " << acc_atom_derivs[ acc_atm ].f2().x() << " " << acc_atom_derivs[ acc_atm ].f2().y() << " " << acc_atom_derivs[ acc_atm ].f2().z() << std::endl;*/
541 
542  }
543  }
544  }
545 }
546 
547 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
548 bool
550  Size const don_h_atm,
551  conformation::Residue const & don_rsd,
552  Size const acc_atm,
553  conformation::Residue const & acc_rsd,
554  Real & energy,
555  bool const update_deriv /*= false*/,
556  Vector & f2 /*=ZERO_VECTOR*/ // Only computes the force vector between don and acceptor -- calling code must compute f1
557 ) const
558 {
559 
560  energy = 0.0;
561  f2 = 0.0;
562 
563  Size const don_atm( don_rsd.atom_base( don_h_atm ) );
564  Size const base_atm( acc_rsd.atom_base( acc_atm ) );
565 
566  if ( !path_distance_OK( don_rsd, acc_rsd, don_atm, acc_atm ) ) return false; // Look more than four atoms away.
567 
568 
569  ////////////////////////////////////////////////////////////////////////////////////////////////////////////
570  //No virtual atom seem to reach to point, probably becuase virtual_atom is neither Hpos_apolar nor accpt_atom.
571  //But should still have these checks here just to be safe. [Parin S. (sripakpa@stanford.edu) Jan 11, 2012]
572  if( acc_rsd.is_virtual( acc_atm ) ) return false;
573 
574  if( don_rsd.is_virtual( don_atm ) ) return false;
575 
576  if( don_rsd.is_virtual( don_h_atm) ) return false;
577 
578 
579 
580 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
581 
582  Vector const & don_h_atm_xyz( don_rsd.atom( don_h_atm ).xyz() );
583  Vector const & don_atm_xyz( don_rsd.atom( don_atm ).xyz() );
584  Vector const & acc_atm_xyz( acc_rsd.atom( acc_atm ).xyz() );
585  Vector const & base_atm_xyz( acc_rsd.atom( base_atm ).xyz() );
586 
587 
588  Vector H_A_vector = acc_atm_xyz - don_h_atm_xyz;
589  Vector D_H_vector = don_h_atm_xyz - don_atm_xyz;
590  Vector B_A_vector = acc_atm_xyz - base_atm_xyz;
591 
592 
593  if( use_orientation_dep_rna_ch_o_bonds(don_rsd, acc_rsd) ){
594 
595  Vector const r_H_A( acc_atm_xyz - don_h_atm_xyz );
596  Vector const z_D_H( ( don_h_atm_xyz - don_atm_xyz ).normalize() );
597 
598  energy = carbon_hbond_potential_.get_potential_RNA( r_H_A, z_D_H, update_deriv, f2 );
599  // for some reason, get_potential_RNA() returns the derivative for the acceptor,
600  // whereas get_potential() returns the derivative for the hydrogen. Since this function
601  // should return the derivative for the hydrogen, multiply f2 by -1.
602  f2 *= -1;
603 
604  if ( verbose_ && energy < -0.05 ) {
605  Real const angle_DH_A = numeric::conversions::degrees( angle_radians( don_atm_xyz, don_h_atm_xyz, acc_atm_xyz ) );
606  tr <<"CHbond [RNA]: "<< don_rsd.name1() << I(3,don_rsd.seqpos())<<
607  " atom "<< don_rsd.atom_name( don_h_atm )<< " [ " <<
608  don_rsd.atom_name( don_atm) <<
609  " ] bonded to acc_res " <<
610  acc_rsd.name1()<< I(3, acc_rsd.seqpos()) <<
611  " atom "<< acc_rsd.atom_name( acc_atm ) <<
612  " with energy "<< F(8,3,energy) << " [" << F(8,3,H_A_vector.length()) << " Angstroms; "
613  << angle_DH_A << " degrees ]" << std::endl;
614  }
615 
616 
617  } else {
618 
620  don_rsd.atom_type_index( don_atm ), H_A_vector, D_H_vector, B_A_vector, update_deriv, f2);
621 
622  if ( verbose_ && energy < -0.05 ) {
623  tr <<"CHbond: "<< don_rsd.name1() << I(3,don_rsd.seqpos())<<
624  " atom "<< don_rsd.atom_name( don_h_atm )<< " [ " <<
625  don_rsd.atom_name( don_atm) <<
626  " ] bonded to acc_res " <<
627  acc_rsd.name1()<< I(3, acc_rsd.seqpos()) <<
628  " atom "<< acc_rsd.atom_name( acc_atm ) <<
629  " with energy "<< F(8,3,energy) << " [" << F(8,3,H_A_vector.length()) << "]" << std::endl;
630  }
631 
632  }
633 
634 
635  return true;
636 }
637 
638 //////////////////////////////////////////////////////////////////////////////////////
639 // Stupid helper function
640 // These should probably live inside conformation::Residue.
641 //
642 bool
644 {
645  for ( chemical::AtomIndices::const_iterator
646  hnum = rsd.Hpos_apolar().begin(),
647  hnume = rsd.Hpos_apolar().end(); hnum != hnume; ++hnum ) {
648  Size const don_h_atm( *hnum );
649  if ( don_h_atm == atm ) return true;
650  }
651  return false;
652 }
653 //////////////////////////////////////////////////////////////////////////////
654 // Stupid helper function
655 // These should probably live inside conformation::Residue.
656 bool
658 {
659  for ( chemical::AtomIndices::const_iterator
660  anum = rsd.accpt_pos().begin(),
661  anume = rsd.accpt_pos().end(); anum != anume; ++anum ) {
662  Size const acc_atm( *anum );
663  if ( acc_atm == atm ) return true;
664  }
665  return false;
666 }
667 
668 
669 
670 //////////////////////////////////////////////////////////////////////////////
671 /*void
672 CarbonHBondEnergy::get_deriv_acceptor(
673  conformation::Residue const & current_rsd,
674  Size const current_atm,
675  conformation::Residue const & other_rsd,
676  Vector & F1,
677  Vector & F2
678 ) const
679 {
680 
681  Real dummy_energy( 0.0 );
682  Vector f1( 0.0 ), f2( 0.0 );
683  for ( chemical::AtomIndices::const_iterator
684  anum = other_rsd.accpt_pos().begin(),
685  anume = other_rsd.accpt_pos().end(); anum != anume; ++anum ) {
686  Size const acc_atm ( *anum );
687  get_atom_atom_carbon_hbond_energy( current_atm, current_rsd,
688  acc_atm, other_rsd,
689  dummy_energy, true, false, f1, f2 );
690  Real w = get_deriv_weight_for_atom_pair( current_rsd, current_atm, other_rsd, acc_atm );
691  F1 += w * f1;
692  F2 += w * f2;
693  }
694 }*/
695 
696 
697 //////////////////////////////////////////////////////////////////////////////
698 /*void
699 CarbonHBondEnergy::get_deriv_donor(
700  conformation::Residue const & current_rsd,
701  Size const current_atm,
702  conformation::Residue const & other_rsd,
703  Vector & F1,
704  Vector & F2
705 ) const
706 {
707 
708  Real dummy_energy( 0.0 );
709  Vector f1( 0.0 ), f2( 0.0 );
710  for ( chemical::AtomIndices::const_iterator
711  hnum = other_rsd.Hpos_apolar().begin(),
712  hnume = other_rsd.Hpos_apolar().end(); hnum != hnume; ++hnum ) {
713 
714  Size const don_h_atm( *hnum );
715 
716  get_atom_atom_carbon_hbond_energy( don_h_atm, other_rsd,
717  current_atm, current_rsd,
718  dummy_energy, true, true, f1, f2 );
719  Real w = get_deriv_weight_for_atom_pair( current_rsd, current_atm, other_rsd, don_h_atm );
720 
721  F1 -= w*f1;
722  F2 -= w*f2;
723  }
724 
725 }*/
726 
727 /*Real
728 CarbonHBondEnergy::get_deriv_weight_for_atom_pair(
729  conformation::Residue const & rsd1,
730  Size const at1,
731  conformation::Residue const & rsd2,
732  Size const at2
733 ) const
734 {
735  if ( rsd1.atom_is_backbone( at1 ) ) {
736  if ( rsd2.atom_is_backbone( at2 ) ) {
737  return wbb_bb_;
738  } else {
739  return wbb_sc_;
740  }
741  } else if ( rsd2.atom_is_backbone(at2) ) {
742  return wbb_sc_;
743  } else {
744  return wsc_sc_;
745  }
746 }*/
747 
748 
749 //////////////////////////////////////////////////////////////////////////////
750 // Note that this computes every interaction *twice* -- three times if you
751 // note that the score calculation above does most of the computation already.
752 // Oh well -- we currently assume derivative calculation doesn't happen too often!
753 //
754 /*void
755 CarbonHBondEnergy::eval_atom_derivative(
756  id::AtomID const & atom_id,
757  pose::Pose const & pose,
758  kinematics::DomainMap const &,
759  ScoreFunction const &,
760  EnergyMap const &,
761  Vector & F1,
762  Vector & F2
763 ) const
764 {
765  // Real energy( 0.0 ); //not actually returned.
766  //hbonds::Deriv deriv;
767 
768  EnergyGraph const & energy_graph( pose.energies().energy_graph() );
769 
770  Size const i( atom_id.rsd() );
771  conformation::Residue const & current_rsd( pose.residue( i ) );
772  Size const current_atm( atom_id.atomno() );
773 
774  // Size const nres = pose.total_residue();
775  // static bool const update_deriv( true );
776 
777  Vector f1( 0.0 ),f2( 0.0 ); // Accumulates!
778 
779  if ( atom_is_apolar_h( current_rsd, current_atm ) ){
780 
781  // Loop over all potential acceptors in the pose -- go over neighbors.
782  for( graph::Graph::EdgeListConstIter
783  iter = energy_graph.get_node( i )->const_edge_list_begin();
784  iter != energy_graph.get_node( i )->const_edge_list_end();
785  ++iter ){
786  Size j( (*iter)->get_other_ind( i ) );
787  get_deriv_acceptor( current_rsd, current_atm, pose.residue(j), f1, f2 );
788  }
789 
790  //Intra residue...
791  get_deriv_acceptor( current_rsd, current_atm, pose.residue(i), f1, f2 );
792 
793  } else if ( atom_is_acceptor( current_rsd, current_atm ) ) {
794 
795  // Loop over all potential carbon hydrogen-bond donors in the pose -- including within the same residue.
796  for( graph::Graph::EdgeListConstIter
797  iter = energy_graph.get_node( i )->const_edge_list_begin();
798  iter != energy_graph.get_node( i )->const_edge_list_end();
799  ++iter ){
800  Size j( (*iter)->get_other_ind( i ) );
801  get_deriv_donor( current_rsd, current_atm, pose.residue(j), f1, f2 );
802  }
803 
804  //Intra residue...
805  get_deriv_donor( current_rsd, current_atm, pose.residue(i), f1, f2 );
806 
807  }
808 
809 
810  F1 += f1; // already weighted
811  F2 += f2; // already weighted
812 
813 }*/
814 
815 void
817  conformation::Residue const & rsd1,
818  conformation::Residue const & rsd2,
821  ResPairMinimizationData const &,
822  pose::Pose const &, // provides context
823  EnergyMap const & weights,
824  utility::vector1< DerivVectorPair > & r1_atom_derivs,
825  utility::vector1< DerivVectorPair > & r2_atom_derivs
826 ) const
827 {
828  res_res_carbon_hbond_derivs_one_way( rsd1, rsd2, weights, r1_atom_derivs, r2_atom_derivs );
829  res_res_carbon_hbond_derivs_one_way( rsd2, rsd1, weights, r2_atom_derivs, r1_atom_derivs );
830 }
831 
832 void
834  conformation::Residue const & rsd,
836  pose::Pose const &,
837  EnergyMap const & weights,
839 ) const
840 {
841  /// intra-residue carbon hbond derivatives; one call to
842  res_res_carbon_hbond_derivs_one_way( rsd, rsd, weights, atom_derivs, atom_derivs );
843 }
844 
845 
846 ////////////////////////////////////////////////////////////////////////////////////////////
847 Distance
849 {
850  //return hbonds::MAX_R + 1.35; // MAGIC NUMBER
851  return 4.35; //MAX_R is no longer a constant
852 }
853 
854 ////////////////////////////////////////////////////////////////////////////////////////////
855 bool
857 {
858  return true;
859 }
860 
861 void
863  conformation::Residue const & rsd,
864  pose::Pose const & ,
865  ScoreFunction const & ,
866  EnergyMap & emap
867 ) const
868 {
869 
870  Real bb_bb(0.0);
871  Real bb_sc(0.0);
872  Real sc_sc(0.0);
873  Real const res_energy = res_res_carbon_hbond_one_way( rsd, rsd, bb_bb, bb_sc, sc_sc );
874  emap[ ch_bond ] += res_energy;
875  emap[ ch_bond_bb_bb ] += bb_bb;
876  emap[ ch_bond_bb_sc ] += bb_sc;
877  emap[ ch_bond_sc_sc ] += sc_sc;
878 
879  // std::cout << "INTRARES" << rsd.seqpos() << " " << res_energy << " " << emap[ch_bond] << std::endl;
880 
881 }
882 
883 ///@brief CarbonHBondEnergy is not context sensitive
884 void
886  utility::vector1< bool > & /*context_graphs_required*/
887 ) const
888 {
889  /*nothing*/
890 }
893 {
894  return 1; // Initial versioning
895 }
896 
897 ////////////////////////////////////////////////////////////////////////////////////////////
898 bool
900 {
901 
902  return ( orientation_dep_rna_ch_o_bonds_ && don_rsd.is_RNA() && acc_rsd.is_RNA() );
903 
904 }
905 ////////////////////////////////////////////////////////////////////////////////////////////
906 
907 } // carbon_hbonds
908 } // scoring
909 } // core