Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RNA_LJ_BaseEnergy.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/methods/RNA_LJ_BaseEnergy.hh
10 /// @author Rhiju Das
11 
12 
13 // Unit headers
16 
17 // Package headers
19 #include <core/scoring/Energies.hh>
26 
27 // Project headers
28 #include <core/pose/Pose.hh>
29 // AUTO-REMOVED #include <core/scoring/ScoreFunction.hh>
31 
32 // AUTO-REMOVED #include <core/scoring/constraints/AngleConstraint.hh>
33 
34 // AUTO-REMOVED #include <numeric/constants.hh>
35 // AUTO-REMOVED #include <numeric/xyz.functions.hh>
36 
37 #include <core/id/AtomID.hh>
38 #include <utility/vector1.hh>
39 
40 
41 ////////////////////////////////////////////////////////////////////////////////
42 ////////////////////////////////////////////////////////////////////////////////
43 // June 2009. Quick hack to permit additional dispersional attraction between
44 // RNA bases. NOTE: It will be worthwhile at some point to make this generically
45 // compute rep and atr between all aromatic atoms, not just RNA bases!!
46 //
47 //
48 namespace core {
49 namespace scoring {
50 namespace rna {
51 
52 
53 /// @details This must return a fresh instance of the RNA_LJ_BaseEnergy class,
54 /// never an instance already in use
57  methods::EnergyMethodOptions const & options
58 ) const {
59  return new RNA_LJ_BaseEnergy( *ScoringManager::get_instance()->etable( options.etable_type() ) );
60 }
61 
64  ScoreTypes sts;
65  sts.push_back( rna_fa_atr_base );
66  sts.push_back( rna_fa_rep_base );
67  return sts;
68 }
69 
70 
73  etable_(etable_in),
74  ljatr_(etable_in.ljatr()),
75  ljrep_(etable_in.ljrep()),
76  dljatr_( etable_in.dljatr() ),
77  dljrep_( etable_in.dljrep() ),
78  safe_max_dis2_( etable_in.get_safe_max_dis2() ),
79  get_bins_per_A2_( etable_in.get_bins_per_A2()),
80  verbose_( false )
81 {}
82 
85 {
86  return etable_.max_dis();
87 }
88 
89 // clone
92 {
93  return new RNA_LJ_BaseEnergy( *this );
94 }
95 
96 ////////////////////////////////////////////////
98  parent( src ),
99  etable_(src.etable_),
100  ljatr_( src.ljatr_ ),
101  ljrep_( src.ljrep_ ),
102  dljatr_( src.dljatr_ ),
103  dljrep_( src.dljrep_ ),
104  safe_max_dis2_( src.safe_max_dis2_ ),
105  get_bins_per_A2_( src.get_bins_per_A2_ ),
106  verbose_( src.verbose_ )
107 {}
108 
109 
110 /////////////////////////////////////////////////////////////////////////////
111 // scoring
112 /////////////////////////////////////////////////////////////////////////////
113 
114 ///
115 void
117  conformation::Residue const & rsd1,
118  conformation::Residue const & rsd2,
119  pose::Pose const &,
120  ScoreFunction const &,
121  EnergyMap & emap
122 ) const
123 {
124 
125  //
126  // Currently only works for RNA bases!!!
127  // Could easily make it more general by checking for atoms that are *aromatic*
128  // This information could be kept in the Residue (and ResidueType) class, e.g., is_aromatic( atom_index ).
129  //
130  if (!rsd1.is_RNA()) return ;
131  if (!rsd2.is_RNA()) return ;
132 
133  Real fa_atr_score( 0.0 ), fa_rep_score( 0.0 );
134  // Basically just re-calculating lennard jones terms.
135  using namespace etable::count_pair;
136  CountPairFunctionOP cpfxn =
137  CountPairFactory::create_count_pair_function( rsd1, rsd2, CP_CROSSOVER_4 );
138 
139  //Real lj_aro_score = 0.0;
140 
141  for ( Size i = rsd1.first_sidechain_atom()+1, i_end = rsd1.nheavyatoms(); i <= i_end; ++i ) {
142 
143  Vector const heavy_atom_i( rsd1.xyz( i ) );
144 
145  for ( Size j = rsd2.first_sidechain_atom()+1, j_end = rsd2.nheavyatoms(); j <= j_end; ++j ) {
146 
147  Real cp_weight = 1.0;
148  Size path_dist( 0 );
149  if ( cpfxn->count( i, j, cp_weight, path_dist ) ) {
150 
151  Vector const heavy_atom_j( rsd2.xyz( j ) );
152 
153  Vector const d_ij = heavy_atom_j - heavy_atom_i;
154  Real const d2 = d_ij.length_squared();
155 
156  if ( ( d2 >= safe_max_dis2_) || ( d2 == Real(0.0) ) ) continue;
157 
158  //Real dotprod( 1.0 );
159  Real dummy_deriv( 0.0 );
160 
161  Real temp_atr_score( 0.0 ), temp_rep_score( 0.0 );
162 
163  eval_lj( rsd1.atom( i ), rsd2.atom( j ), d2,
164  temp_atr_score, temp_rep_score,
165  dummy_deriv, dummy_deriv);
166 
167  fa_atr_score += cp_weight * temp_atr_score;
168  fa_rep_score += cp_weight * temp_rep_score;
169 
170  } // cp
171 
172  } // j
173  } // i
174 
175  emap[ rna_fa_atr_base ] += fa_atr_score;
176  emap[ rna_fa_rep_base ] += fa_rep_score;
177 
178 }
179 
180 /////////////////////////////////////////////////////////////////////////////
181 // derivatives
182 /////////////////////////////////////////////////////////////////////////////
183 void
185  pose::Pose & pose,
186  ScoreFunction const &
187 ) const
188 {
190 }
191 
192 
193 ////////////////////////////////////////////////
194 void
196  conformation::Atom const & atom1,
197  conformation::Atom const & atom2,
198  Real const & d2,
199  Real & fa_atr_score,
200  Real & fa_rep_score,
201  Real & deriv_atr,
202  Real & deriv_rep
203 ) const
204 {
205 
206  // Real temp_score( 0.0 );
207  deriv_atr = 0.0;
208  deriv_rep = 0.0;
209 
210  //Make this an input option for efficiency
211  bool const eval_deriv( true );
212 
213  if ( ( d2 < safe_max_dis2_) && ( d2 != Real(0.0) ) ) {
214 
215  Real const d2_bin = d2 * get_bins_per_A2_;
216  int disbin = static_cast< int >( d2_bin ) + 1;
217  Real frac = d2_bin - ( disbin - 1 );
218 
219  // l1 and l2 are FArray LINEAR INDICES for fast lookup:
220  // [ l1 ] == (disbin ,attype2,attype1)
221  // [ l2 ] == (disbin+1,attype2,attype1)
222 
223  {
224  int const l1 = ljatr_.index( disbin, atom2.type(), atom1.type() );
225  int const l2 = l1 + 1;
226  fa_atr_score = ( (1.-frac)* ljatr_[ l1 ] + frac * ljatr_[ l2 ]);
227  if (eval_deriv) {
228  deriv_atr = ( ljatr_[ l2 ] - ljatr_[ l1 ] ) * get_bins_per_A2_ * std::sqrt( d2 ) * 2;
229  }
230  }
231 
232 
233  {
234  int const l1 = ljrep_.index( disbin, atom2.type(), atom1.type() );
235  int const l2 = l1 + 1;
236  fa_rep_score = ( (1.-frac)* ljrep_[ l1 ] + frac * ljrep_[ l2 ]);
237  if (eval_deriv) {
238  deriv_rep = ( ljrep_[ l2 ] - ljrep_[ l1 ] ) * get_bins_per_A2_ * std::sqrt( d2 ) * 2;
239  }
240  }
241 
242  }
243 
244 }
245 
246 //////////////////////////////////////////////////////////////////////////////////////
247 void
249  id::AtomID const & atom_id,
250  pose::Pose const & pose,
251  kinematics::DomainMap const & domain_map,
252  ScoreFunction const &,// sfxn,
253  EnergyMap const & weights,
254  Vector & F1,
255  Vector & F2
256 ) const
257 {
258 
259  Size const i( atom_id.rsd() );
260  Size const m( atom_id.atomno() );
261  conformation::Residue const & rsd1( pose.residue( i ) );
262 
263  // Currently extremely RNA specific.
264  if ( !rsd1.is_RNA() ) return;
265  if ( m > rsd1.nheavyatoms() ) return;
266  if ( m < rsd1.first_sidechain_atom()+1 ) return;
267 
268  Vector const heavy_atom_i( rsd1.xyz( m ) );
269 
270  bool const pos1_fixed( domain_map( i ) != 0 );
271 
272  // cached energies object
273  Energies const & energies( pose.energies() );
274 
275  // the neighbor/energy links
276  EnergyGraph const & energy_graph( energies.energy_graph() );
277 
278  // Real deriv( 0.0 );
279 
281  iter = energy_graph.get_node( i )->const_edge_list_begin(),
282  itere = energy_graph.get_node( i )->const_edge_list_end();
283  iter != itere; ++iter ) {
284 
285  Size const j( (*iter)->get_other_ind( i ) );
286 
287  if ( pos1_fixed && domain_map(i) == domain_map(j) ) continue; //Fixed w.r.t. one another.
288 
289  conformation::Residue const & rsd2( pose.residue( j ) );
290 
291  using namespace etable::count_pair;
292  CountPairFunctionOP cpfxn =
293  CountPairFactory::create_count_pair_function( rsd1, rsd2, CP_CROSSOVER_4 );
294 
295  for ( Size n = rsd2.first_sidechain_atom()+1; n <= rsd2.nheavyatoms(); ++n ) {
296 
297  Real cp_weight = 1.0;
298  Size path_dist( 0 );
299  if ( cpfxn->count(m, n, cp_weight,path_dist ) ) {
300 
301  Vector const heavy_atom_j( rsd2.xyz( n ) );
302  Vector const d_ij = heavy_atom_j - heavy_atom_i;
303  Real const d2 = d_ij.length_squared();
304  //Real const d = std::sqrt( d2 );
305  Vector const d_ij_norm = d_ij.normalized();
306 
307  if ( ( d2 >= safe_max_dis2_) || ( d2 == Real(0.0) ) ) continue;
308 
309  Real dummy( 0.0 ), fa_atr_deriv( 0.0 ), fa_rep_deriv( 0.0 );
310  eval_lj( rsd1.atom(m), rsd2.atom(n), d2, dummy, dummy, fa_atr_deriv, fa_rep_deriv );
311 
312  Vector const f2_fwd = -1.0 * cp_weight * d_ij_norm * ( fa_atr_deriv * weights[ rna_fa_atr_base ] +
313  fa_rep_deriv * weights[ rna_fa_rep_base ] );
314  Vector const f1_fwd = 1.0 * cross( f2_fwd, heavy_atom_j );
315 
316  F1 += f1_fwd;
317  F2 += f2_fwd;
318 
319  }
320 
321 
322  }
323  }
324 
325 }
326 
327 
328 
329 
330 //////////////////////////////////////////////////////////////////////////////////////
331 // hacky hacky.
332 Real
334  id::AtomID const & atom_id,
335  pose::Pose const & pose
336 ) const
337 {
338 
339  Size const i( atom_id.rsd() );
340  Size const m( atom_id.atomno() );
341  conformation::Residue const & rsd1( pose.residue( i ) );
342 
343  Real score( 0.0 );
344 
345  // Currently extremely RNA specific.
346  if ( !rsd1.is_RNA() ) return score;
347  if ( m > rsd1.nheavyatoms() ) return score;
348  if ( m < rsd1.first_sidechain_atom()+1 ) return score;
349 
350  Vector const heavy_atom_i( rsd1.xyz( m ) );
351 
352  for ( Size j = 1; j < pose.total_residue(); j ++ ) {
353 
354  if ( i == j ) continue;
355 
356  conformation::Residue const & rsd2( pose.residue( j ) );
357  if ( !rsd2.is_RNA() ) continue;
358 
359  using namespace etable::count_pair;
360  CountPairFunctionOP cpfxn =
361  CountPairFactory::create_count_pair_function( rsd1, rsd2, CP_CROSSOVER_4 );
362 
363  for ( Size n = rsd2.first_sidechain_atom()+1; n <= rsd2.nheavyatoms(); ++n ) {
364 
365  Real cp_weight = 1.0;
366  Size path_dist( 0 );
367  if ( cpfxn->count(m, n, cp_weight, path_dist ) ) {
368 
369  Vector const heavy_atom_j( rsd2.xyz( n ) );
370  Vector const d_ij = heavy_atom_j - heavy_atom_i;
371  Real const d2 = d_ij.length_squared();
372  //Real const d = std::sqrt( d2 );
373  Vector const d_ij_norm = d_ij.normalized();
374 
375  if ( ( d2 >= safe_max_dis2_) || ( d2 == Real(0.0) ) ) continue;
376 
377  Real dummy( 0.0 ), fa_atr( 0.0 ), fa_rep( 0.0 );
378  eval_lj( rsd1.atom(m), rsd2.atom(n), d2, fa_atr, fa_rep, dummy, dummy );
379 
380  // In principle could pass in an emap and weight the components
381  // by the Emap.
382  score += cp_weight * ( fa_atr + fa_rep );
383  }
384 
385 
386  }
387  }
388 
389  return score;
390 }
391 
392 
393 ////////////////////////////////////////////////
394 void
396  utility::vector1< bool > & /* context_graphs_required */ ) const
397 {}
398 
399 ////////////////////////////////////////////////
400 void
402  pose::Pose &,
403  ScoreFunction const &,
404  EnergyMap &
405 ) const
406 {
407  if (verbose_) std::cout << "DONE SCORING" << std::endl;
408 }
411 {
412  return 1; // Initial versioning
413 }
414 
415 }
416 }
417 }
418 
419 
420