Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RNA_FullAtomVDW_BasePhosphate.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/methods/RNA_SugarCloseEnergy.cc
11 /// @brief RNA_SugarClose energy method class implementation
12 /// @author Rhiju Das
13 
14 // Unit Headers
18 
19 // Package Headers
22 #include <core/scoring/types.hh>
23 
24 
25 // Project headers
26 #include <core/pose/Pose.hh>
27 
28 // Utility headers
29 #include <numeric/conversions.hh>
30 
31 //Auto Headers
34 
35 #include <core/pose/Pose.hh>
36 #include <core/scoring/Energies.hh>
38 #include <ObjexxFCL/format.hh>
39 // C++
40 
41 
42 
43 
44 namespace core {
45 namespace scoring {
46 namespace rna {
47 
48 
49 
50 /// @details This must return a fresh instance of the RNA_FullAtomVDW_BasePhosphateCreator class
51 /// never an instance already in use
54  methods::EnergyMethodOptions const & options
55 ) const {
56 
57 
58  etable::Etable const & etable_in= *( ScoringManager::get_instance()->etable( options.etable_type() ) );
59 
60  etable::TableLookupEtableEnergy etable_energy_in( etable_in, options );
61 
62  // [Note, previously created pointer to a regular object instead of OP -- energy leak.]
63  // etable::EtableEnergy & etable_energy_in= (*(new etable::EtableEnergy( etable_in, options ) ) );
64 
65  //RNA_FullAtomVDW_BasePhosphateCreator is friend of BaseEtableEnergy.hh and hence can access its private variables.
66  // No. Don't go around declaring other classes your friends. That's just pisses on everyone else's efforts to create
67  // an object oriented program.
68  etable_energy_in.intrares_evaluator().set_scoretypes(
72 
73  return new RNA_FullAtomVDW_BasePhosphate( etable_energy_in, etable_in);
74 }
75 
76 
79  ScoreTypes sts;
80  sts.push_back( fa_intra_RNA_base_phos_atr );
81  sts.push_back( fa_intra_RNA_base_phos_rep );
82  sts.push_back( fa_intra_RNA_base_phos_sol );
83  return sts;
84 }
85 
86 
87 /// constructor
89  etable::TableLookupEtableEnergy const & etable_energy_in,
90  etable::Etable const & etable_in
91 ):
93  etable_energy_( etable_energy_in), //Hacky thing, created the etable_energy_ energy_method to get access to its function.
94  //etable_energy_( *(new etable::EtableEnergy(etable_energy_in)) ),
95  //etable_energy_( *( new etable::EtableEnergy( etable_in, opts ) ) ),
96  etable_(etable_in)
97 {
98 
99  //etable_energy_.set_scoretypes( fa_intra_RNA_base_phos_atr, fa_intra_RNA_base_phos_rep, unfolded);
100  // etable_energy_( *( new etable::BaseEtableEnergy< etable::EtableEnergy >(new etable::EtableEnergyCreator, etable_in, options, fa_atr, fa_rep, fa_sol ) ) ),
101  // etable_energy_( etable::BaseEtableEnergy< etable::EtableEnergy > (new etable::EtableEnergyCreator, etable_in, options, unfolded, unfolded, unfolded ) )
102  //etable_energy_( etable::EtableEnergyCreator::create_energy_method(options) )
103 
104 }
105 
106 
108 
109 
110 /// clone
113 {
114 
115  return new RNA_FullAtomVDW_BasePhosphate( *this );
116 }
117 
118 
119 
120 
121 void
123  conformation::Residue const & res1,
124  int const atomno1,
125  conformation::Residue const & res2,
126  Size const atomno2,
127  Size const at1hbegin, //at1hbegin and at1hend define a range of hydrogen atom indices -- those h's bound to at1
128  Size const at1hend,
129  Size const at2hbegin,
130  Size const at2hend,
131  EnergyMap & emap
132 ) const
133 {
134  using conformation::Atom;
135 
136  Weight weight( 1.0 );
137 
138  Atom const & atom1( res1.atom( atomno1 ) );
139  Atom const & atom2( res2.atom( atomno2 ) );
140 
141 
142  // Heavy Atom in res1 to Hs in res2
143  for ( Size i = at2hbegin; i<= at2hend; ++i )
144  {
145  Atom const & H2( res2.atom( i ) );
146  weight = 1.0;
147  etable_energy_.pair_energy_H( atom1, H2, weight, emap );
148  }
149 
150 
151  // Hs in res1 to heavy Atom and Hs in res2
152  for ( Size i = at1hbegin; i<= at1hend; ++i )
153  {
154  Atom const & H1( res1.atom(i) );
155  weight = 1.0;
156  // H in res1 to heavy Atom in res2
157  etable_energy_.pair_energy_H( H1, atom2, weight, emap );
158 
159  // H in res1 to Hs in res2
160  for ( Size j = at2hbegin; j<= at2hend; ++j ) {
161  Atom const & H2( res2.atom(j) );
162  weight = 1.0f;
163  etable_energy_.pair_energy_H( H1, H2, weight, emap );
164  }
165  }
166 }
167 
168 ///////////////////////////////////////////////////////////////////////////////
169 
170 void
172  conformation::Residue const & rsd,
173  EnergyMap & emap ) const
174 {
175  using conformation::Atom;
176 
177  //runtime_assert(false);
178  //utility_exit_with_message("Why am I here?");
179 
180  if(rsd.is_RNA()==false) return;
181 
182 
183  DistanceSquared dsq;
184 
185  //Weight const weight=1.0;
186  Real const weight=1.0;
187 
188  // get hydrogen interaction cutoff
189  Real const Hydrogen_interaction_cutoff2=( etable_energy_.hydrogen_interaction_cutoff2() );
190 
191  EnergyMap mock_emap;
192 
193  typedef utility::vector1< Size > const & vect;
194 
195  vect rhbegin( rsd.attached_H_begin() );
196  vect rhend( rsd.attached_H_end() );
197 
198  Size const rsdnheavyatoms = rsd.nheavyatoms();
199 
200  // Atom pairs
201  for ( Size i=1; i <= rsdnheavyatoms; ++i ) {
202  Atom const & atom1( rsd.atom(i) );
203  for ( Size j=i+1; j <= rsdnheavyatoms; ++j ) {
204  Atom const & atom2( rsd.atom(j) );
205 
206  bool base_phosphate_atom_pair=false;
207 
208  if( rsd.RNA_type().atom_is_phosphate( i ) && rsd.RNA_type().is_RNA_base_atom( j ) ) base_phosphate_atom_pair=true;
209  if( rsd.RNA_type().atom_is_phosphate( j ) && rsd.RNA_type().is_RNA_base_atom( i ) ) base_phosphate_atom_pair=true;
210 
211  if(base_phosphate_atom_pair==false) continue;
212 
213  if(rsd.path_distance( i, j ) < 4){
214  std::cout << "rsd.name3()=" << rsd.name3() << " rsd.seqpos() = " << rsd.seqpos() << std::endl;
215  std::cout << "i= " << i << " j=" << j << std::endl;
216  std::cout << "rsd.atom_name(i)= " << rsd.atom_name(i) << " rsd.atom_name(j)=" << rsd.atom_name(j) << std::endl;
217  std::cout << "rsd.path_distance( i, j )=" << rsd.path_distance( i, j ) << std::endl;
218 
219  std::cout << "rsdnheavyatoms= " << rsdnheavyatoms << std::endl;
220  std::cout << "rsd.first_sidechain_atom()= " << rsd.first_sidechain_atom() << std::endl;
221  for ( Size atomno=1; atomno <= rsdnheavyatoms; ++atomno ) {
222  std::cout << "rsd.atom_name(" << atomno << " )= " << rsd.atom_name(atomno) << std::endl;
223  }
224 
225  std::cout << "rsd.nchi()=" << rsd.nchi() << std::endl;
226 
227  utility::vector1< utility::vector1< Size > > const & chi_atoms_list=rsd.type().chi_atoms();
228  utility::vector1< utility::vector1< Size > > const & all_chi_atoms_list=rsd.type().atoms_last_controlled_by_chi(); /*chi # 1 must be nucleic acid "chi"*/
229 
230 
231  for(Size chi_id=1; chi_id<=chi_atoms_list.size(); chi_id++){
232  std::cout << std::endl;
233  std::cout << "chi_atoms_list[" << chi_id<< "].size()=" << chi_atoms_list[chi_id].size() << std::endl;
234  for(Size n=1; n<=chi_atoms_list[chi_id].size(); n++){
235  Size const atomno=chi_atoms_list[chi_id][n];
236  std::cout << "rsd.atom_name(" << atomno << " )= " << rsd.atom_name(atomno) << std::endl;
237  }
238 
239  }
240  for(Size chi_id=1; chi_id<=chi_atoms_list.size(); chi_id++){
241  std::cout << std::endl;
242  std::cout << "all_chi_atoms_list[" << chi_id<< "].size()=" << all_chi_atoms_list[chi_id].size() << std::endl;
243  for(Size n=1; n<=all_chi_atoms_list[chi_id].size(); n++){
244  Size const atomno=all_chi_atoms_list[chi_id][n];
245  std::cout << "rsd.atom_name(" << atomno << " )= " << rsd.atom_name(atomno) << std::endl;
246  }
247 
248  }
249 
250  utility_exit_with_message("rsd.path_distance( i, j ) < 4");
251  }
252 
253  Real const START_fa_atr=mock_emap[fa_intra_RNA_base_phos_atr];
254  Real const START_fa_rep=mock_emap[fa_intra_RNA_base_phos_rep];
255 
256  etable_energy_.atom_pair_energy( atom1, atom2, weight, mock_emap, dsq );
257 
258  if(rsd.is_virtual(i) || rsd.is_virtual(j)){
259  Real const diff_fa_atr_E=mock_emap[fa_intra_RNA_base_phos_atr]-START_fa_atr;
260  Real const diff_fa_rep_E=mock_emap[fa_intra_RNA_base_phos_rep]-START_fa_rep;
261 
262  if(diff_fa_atr_E>0.001 || diff_fa_atr_E<-0.001){
263  std::cout << "At least one of the atoms in the pair " << i << "," << j << " | res= " << rsd.seqpos() << " is virtual";
264  std::cout << " but diff_fa_atr_E= " << diff_fa_atr_E << " is non-zero!" <<std::endl;
265  utility_exit_with_message("at least one of the atom in the pair is virtual BUT diff_fa_atr_E>0.001 || diff_fa_atr_E<-0.001");
266  }
267 
268 
269 
270  if(diff_fa_rep_E>0.001 || diff_fa_rep_E<-0.001){
271  std::cout << "At least one of the atoms in the pair " << i << "," << j << " | res= " << rsd.seqpos() << " is virtual";
272  std::cout << " but diff_fa_rep_E= " << diff_fa_rep_E << " is non-zero!" <<std::endl;
273  utility_exit_with_message("at least one of the atom in the pair is virtual BUT diff_fa_rep_E>0.001 || diff_fa_rep_E<-0.001");
274  }
275  }
276 
277  if ( dsq < Hydrogen_interaction_cutoff2 ) {
278  residue_fast_pair_energy_attached_H(rsd, i, rsd, j, rhbegin[ i ], rhend[ i ], rhbegin[ j ], rhend[ j ], mock_emap);
279  }
280  }
281  }
282 
283  emap[ fa_intra_RNA_base_phos_atr ] += mock_emap[ fa_intra_RNA_base_phos_atr ]; //Fix from = to += on Jan 10, 2012, since now emap is the total_energy, accumulated over all residues)
284  emap[ fa_intra_RNA_base_phos_rep ] += mock_emap[ fa_intra_RNA_base_phos_rep ]; //Fix from = to += on Jan 10, 2012, since now emap is the total_energy, accumulated over all residues)
285 
286  //Note that right now fa_intra_RNA_base_phos_sol is not include since it is not currently used in the RNA force-field. The term have also not yet been tested!//
287  //If you want to implement this term, please ensure your implementation works properly (i.e. perform numerical_derivative_check() and etc),
288  //before committing the code to TRUNK!)
289  //Parin S. (sripakpa@stanford.edu). Jan 11, 2012
290 
291 }
292 
293 
294 ///////////////////////////////////////////////////////////////////////////////
295 void
297  conformation::Residue const & rsd,
298  pose::Pose const &,
299  EnergyMap & emap ) const {
300 
301  return residue_energy( rsd, emap );
302 }
303 
304 
305 ///////////////////////////////////////////////////////////////////////////////
306 void
308  id::AtomID const & id,
309  pose::Pose const & pose,
310  kinematics::DomainMap const &, // domain_map,
311  ScoreFunction const & /*sfxn*/, // needed for non-nblist minimization
312  EnergyMap const & weights,
313  Vector & F1,
314  Vector & F2
315 ) const
316 {
317 
318  if(weights[ fa_intra_RNA_base_phos_sol] != 0.0){
319  //Please refer to paragraph at the end of RNA_FullAtomVDW_BasePhosphate::residue_energy for explanation.
320  //Again, if you want to implement this term, please ensure your implementation works properly (i.e. perform numerical_derivative_check() and etc),
321  //before committing the code to TRUNK!)
322  // Parin S. (sripakpa@stanford.edu). Jan 11, 2012
323  utility_exit_with_message("weights[ fa_intra_RNA_base_phos_sol ] != 0.0, but this term is not yet implemented!");
324  }
325 
326  Size const seq_num = id.rsd();
327 
328  if(pose.residue( seq_num ).is_RNA()==false) return;
329 
330  conformation::Residue const & rsd= pose.residue( seq_num );
331 
332  conformation::Atom const & atom1( rsd.atom( id.atomno() ) );
333 
334  Real const cp_weight=1.0;
335 
336  //std::cout << "eval_atom_deriv: seq_num=" << id.rsd() << " id.atomno()=" << id.atomno() << "[" << rsd.atom_name(id.atomno()) <<"]" << std::endl;
337 
338 
339  Vector f1,f2;
340  for ( Size nbr_atomno=1; nbr_atomno<=rsd.natoms(); nbr_atomno++ ) {
341 
342  if( rsd.is_virtual( id.atomno() ) ) continue; //Is this necessary?
343  if( rsd.is_virtual( nbr_atomno ) ) continue; //Is this necessary?
344 
345  bool base_phosphate_atom_pair=false;
346 
347  if( rsd.RNA_type().atom_is_phosphate( id.atomno() ) && rsd.RNA_type().is_RNA_base_atom( nbr_atomno ) ) base_phosphate_atom_pair=true;
348  if( rsd.RNA_type().atom_is_phosphate( nbr_atomno ) && rsd.RNA_type().is_RNA_base_atom( id.atomno() ) ) base_phosphate_atom_pair=true;
349 
350  if(base_phosphate_atom_pair==false) continue;
351 
352  if(rsd.path_distance( nbr_atomno, id.atomno() ) < 4) utility_exit_with_message("rsd.path_distance( nbr_atomno, id.atomno() ) < 4");
353 
354  conformation::Atom const & atom2( rsd.atom( nbr_atomno ) );
355 
356  Real const dE_dR_over_r= etable_energy_.intrares_evaluator().eval_dE_dR_over_r( atom1, atom2, weights, f1, f2 );
357 
358  if ( dE_dR_over_r != 0.0 ) {
359  F1 += dE_dR_over_r * cp_weight * f1;
360  F2 += dE_dR_over_r * cp_weight * f2;
361  }
362 
363  }
364 
365 }
366 
367 // check compatibility with atomtypeset
368 ///////////////////////////////////////////////////////////////////////////////
369 
370 void
372 {
373 
374 
375  if (pose.total_residue()>0) {
376  if ( pose.residue(1).type().atom_type_set_ptr() != etable_.atom_set() ) {
377  utility_exit_with_message( "Illegal attempt to score with non-identical atom set between pose and etable " );
378  }
379  }
380 
381 }
382 
383 
384 ///@details Make sure that the neighborlist is up-to-date before evaluating derivatives
385 void
387 {
388 
389  if (pose.total_residue()>0) {
390  if ( pose.residue(1).type().atom_type_set_ptr() != etable_.atom_set() ) {
391  utility_exit_with_message( "Illegal attempt to score with non-identical atom set between pose and etable " );
392  }
393  }
394 
395 }
396 
397 ///@details Make sure that the neighborlist is up-to-date before evaluating derivatives
398 /*
399 void
400 RNA_FullAtomVDW_BasePhosphate::setup_for_packing( pose::Pose & pose, pack::task::PackerTask const & ) const
401 {
402 
403  //NOT SURE IF THIS WORKS!
404 
405 
406  if (pose.total_residue()>0) {
407  if ( pose.residue(1).type().atom_type_set_ptr() != etable_.atom_set() ) {
408  utility_exit_with_message( "Illegal attempt to score with non-identical atom set between pose and etable " );
409  }
410  }
411 
412 }
413 */
414 
416 
417 
420 {
421  return 1; // First version, created by Parin Sripakdeevong (sripakpa@stanford.edu), Jan 2012.
422 }
423 
424 
425 
426 
427 } // rna
428 } // scoring
429 } // core
430