Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GenBornEnergy.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/GenBornEnergy.cc
11 /// @brief Statistically derived rotamer pair potential class implementation
12 /// @author Phil Bradley
13 /// @author Andrew Leaver-Fay
14 
15 
16 // Unit headers
19 
20 // Package headers
25 #include <core/scoring/Energies.hh>
26 // AUTO-REMOVED #include <core/scoring/EnergyGraph.hh>
27 // AUTO-REMOVED #include <core/scoring/TenANeighborGraph.hh>
29 
31 
32 // Project headers
33 #include <basic/datacache/CacheableData.hh>
34 #include <basic/prof.hh>
35 #include <core/pose/Pose.hh>
39 
40 #include <utility/vector1.hh>
41 
42 
43 // Utility headers
44 
45 
46 // C++
47 //////////////////////////////////////////////////////////////////////////////////
48 //////////////////////////////////////////////////////////////////////////////////
49 //////////////////////////////////////////////////////////////////////////////////
50 /**
51 
52  This is a reimplementation of Jim Havranek's original rosetta++ Gen Born code.
53  source files: rosetta++/gb_elec*
54 
55 **/
56 //////////////////////////////////////////////////////////////////////////////////
57 //////////////////////////////////////////////////////////////////////////////////
58 //////////////////////////////////////////////////////////////////////////////////
59 
60 
61 namespace core {
62 namespace scoring {
63 namespace methods {
64 
65 
66 /// @details This must return a fresh instance of the GenBornEnergy class,
67 /// never an instance already in use
70  methods::EnergyMethodOptions const & options
71 ) const {
72  return new GenBornEnergy( options );
73 }
74 
77  ScoreTypes sts;
78  sts.push_back( gb_elec );
79  return sts;
80 }
81 
82 
84  parent( src ),
85  potential_( src.potential_ ),
86  exclude_DNA_DNA_( src.exclude_DNA_DNA_ )
87 {}
88 
89 
92  potential_( ScoringManager::get_instance()->get_GenBornPotential() ),
93  exclude_DNA_DNA_( options.exclude_DNA_DNA() )
94 {}
95 
96 
97 /// clone
100 {
101  return new GenBornEnergy( *this );
102 }
103 
104 bool
106  pose::Pose const &,
107  Size,
108  Size
109 ) const
110 {
111  return true;
112 }
113 
114 
115 ///
116 void
118  pose::Pose & pose,
119  utility::vector1< bool > const & residues_repacking,
121 ) const
122 {
124 
125  /// build placeholders, compute template born radii, stash in Pose
126  potential_.setup_for_packing( pose, residues_repacking );
127 
128 }
129 
130 void
132  pose::Pose const & pose,
133  conformation::RotamerSetBase & rotamer_set
134 ) const
135 {
136  /// this will stash rotamer born radii in rotamer set
137  potential_.get_rotamers_born_radii( pose, rotamer_set );
138 
139 }
140 
141 
142 // void
143 // update_residue_for_packing(
144 // pose::Pose &,
145 // Size /*resid*/ ) const
146 // {}
147 void
149  pose::Pose & pose,
150  Size resid
151 ) const
152 {
153  /// update born radii for residue that has changed during packing, eg in rotamer trials
154  /// need to double-check the current logic on this...
155  potential_.update_residue_for_packing( pose, resid );
156 
157 }
158 
159 ///
160 void
162 {
163  LongRangeEnergyType const & lr_type( long_range_type() );
164 
166 
167  // create a container
168  Energies & energies( pose.energies() );
169  bool create_new_lre_container( false );
170 
171  if ( energies.long_range_container( lr_type ) == 0 ) {
172  create_new_lre_container = true;
173 
174  } else {
175  LREnergyContainerOP lrc = energies.nonconst_long_range_container( lr_type );
176  DenseEnergyContainerOP dec( static_cast< DenseEnergyContainer * > ( lrc.get() ) );
177  if ( dec->size() != pose.total_residue() ) {
178  create_new_lre_container = true;
179  }
180  }
181 
182  if ( create_new_lre_container ) {
184  energies.set_long_range_container( lr_type, new_dec );
185  }
186 
187 }
188 
189 
190 ///
191 void
193 {
195 }
196 
197 /////////////////////////////////////////////////////////////////////////////
198 // scoring
199 /////////////////////////////////////////////////////////////////////////////
200 
201 ///
202 void
204  conformation::Residue const & rsd1,
205  conformation::Residue const & rsd2,
206  pose::Pose const & pose,
207  ScoreFunction const &,
208  EnergyMap & emap
209 ) const
210 {
211  //using core::pose::datacache::CacheableDataType::GEN_BORN_POSE_INFO;
212  if ( exclude_DNA_DNA_ && rsd1.is_DNA() && rsd2.is_DNA() ) return;
213 
214  GenBornPoseInfo const & gb_info
215  ( static_cast< GenBornPoseInfo const & >( pose.data().get( core::pose::datacache::CacheableDataType::GEN_BORN_POSE_INFO ) ) ); // SHOULD BE FAST!
216 
217  emap[ gb_elec ] += potential_.get_res_res_elecE( rsd1, gb_info.residue_info( rsd1.seqpos() ),
218  rsd2, gb_info.residue_info( rsd2.seqpos() ) );
219 }
220 
221 void
223  conformation::RotamerSetBase const & set,
224  pose::Pose const & pose,
225  ScoreFunction const & sfxn,
227 ) const
228 {
229  using namespace conformation;
230  using namespace numeric;
232 
233  if ( exclude_DNA_DNA_ && pose.residue( set.resid() ).is_DNA() ) return;
234 
235 
236  GenBornRotamerSetInfo const & gb_info
238 
239  for ( Size ii = 1, ii_end = set.num_rotamers(); ii <= ii_end; ++ii ) {
240 
241  Real const elecE
242  ( potential_.get_res_res_elecE( *set.rotamer( ii ), gb_info.residue_info( ii ),
243  *set.rotamer( ii ), gb_info.residue_info( ii ) ) );
244 
245  energies[ ii ] += static_cast< core::PackerEnergy > ( sfxn[ gb_elec ] * elecE );
246  }
247 }
248 
249 void
251  conformation::RotamerSetBase const & set,
252  pose::Pose const & pose,
253  ScoreFunction const & ,
255 ) const
256 {
257  using namespace conformation;
258  using namespace numeric;
260 
261  if ( exclude_DNA_DNA_ && pose.residue( set.resid() ).is_DNA() ) return;
262 
263 // std::cout << "GenBorn rotamer_intrares_energies: " << set.resid() << std::endl;
264 
265  GenBornRotamerSetInfo const & gb_info
267 
268  for ( Size ii = 1, ii_end = set.num_rotamers(); ii <= ii_end; ++ii ) {
269 
270  Real const elecE
271  ( potential_.get_res_res_elecE( *set.rotamer( ii ), gb_info.residue_info( ii ),
272  *set.rotamer( ii ), gb_info.residue_info( ii ) ) );
273 
274  (emaps[ ii ])[ gb_elec ] += elecE ;
275  }
276 }
277 
278 void
280  conformation::RotamerSetBase const & set1,
281  conformation::RotamerSetBase const & set2,
282  pose::Pose const & pose,
283  ScoreFunction const &, // sfxn,
284  EnergyMap const & weights,
285  ObjexxFCL::FArray2D< core::PackerEnergy > & energy_table
286 ) const
287 {
288  using namespace conformation;
289  using namespace numeric;
291 
292  if ( exclude_DNA_DNA_ && pose.residue( set1.resid() ).is_DNA() && pose.residue( set2.resid() ).is_DNA() ) return;
293 
294  PROF_START( basic::GEN_BORN_ROTAMER_PAIR_ENERGIES );
295 
296  GenBornRotamerSetInfo const & gb_info1
298 
299  GenBornRotamerSetInfo const & gb_info2
301 
302 
303  for ( Size ii = 1; ii <= set1.get_n_residue_types(); ++ii ) {
304  Size const ii_offset = set1.get_residue_type_begin( ii );
305  Residue const & ii_example_rotamer( *set1.rotamer( ii_offset ));
306 
307  Vector const & ii_coord( ii_example_rotamer.nbr_atom_xyz() );
308  Real const ii_radius( ii_example_rotamer.nbr_radius() );
309 
310  for ( Size jj = 1; jj <= set2.get_n_residue_types(); ++jj ) {
311  Size const jj_offset = set2.get_residue_type_begin( jj );
312  Residue const & jj_example_rotamer( *set2.rotamer( jj_offset ));
313 
314  if ( exclude_DNA_DNA_ && ii_example_rotamer.is_DNA() && jj_example_rotamer.is_DNA() ) continue;
315 
316  Vector const & jj_coord( jj_example_rotamer.nbr_atom_xyz() );
317  Real const jj_radius( jj_example_rotamer.nbr_radius() );
318 
319  if ( ii_coord.distance_squared( jj_coord ) < std::pow(ii_radius+jj_radius+packing_interaction_cutoff(), 2 )) {
320  for ( Size kk = 1, kke = set1.get_n_rotamers_for_residue_type( ii ); kk <= kke; ++kk ) {
321  Size const kk_rot_id = ii_offset + kk - 1;
322  for ( Size ll = 1, lle = set2.get_n_rotamers_for_residue_type( jj ); ll <= lle; ++ll ) {
323  Size const ll_rot_id = jj_offset + ll - 1;
324 
325  Real const elecE(
326  potential_.get_res_res_elecE( *set1.rotamer( kk_rot_id ), gb_info1.residue_info( kk_rot_id ),
327  *set2.rotamer( ll_rot_id ), gb_info2.residue_info( ll_rot_id ) ) );
328 
329  energy_table( ll_rot_id, kk_rot_id ) += static_cast< core::PackerEnergy >( weights[ gb_elec ] * elecE );
330  }
331  }
332  }
333  }
334  }
335  PROF_START( basic::GEN_BORN_ROTAMER_PAIR_ENERGIES );
336 }
337 
338 void
340  conformation::RotamerSetBase const & set,
341  conformation::Residue const & rsd,
342  pose::Pose const & pose,
343  ScoreFunction const &, // sfxn,
344  EnergyMap const & weights,
346 ) const
347 {
348  PROF_START( basic::GEN_BORN_ROTAMER_BACKGROUND_ENERGIES );
349 
350  using conformation::Residue;
352  //using core::pose::datacache::CacheableDataType::GEN_BORN_POSE_INFO;
353 
354  GenBornResidueInfo const & gb_rsd_info
356  //GenBornResidueInfo const & gb_rsd_info( retrieve_gen_born_pose_info( pose ).residue_info( rsd.seqpos ) );
357 
358  GenBornRotamerSetInfo const & gb_set_info
360  //GenBornRotamersInfo const & gb_set_info( retrieve_gen_born_rotamers_info( set ) );
361 
362  for ( Size ii = 1; ii <= set.get_n_residue_types(); ++ii ) {
363  Size const ii_offset = set.get_residue_type_begin( ii );
364  Residue const & ii_example_rotamer( *set.rotamer( ii_offset ));
365 
366  Vector const & ii_coord( ii_example_rotamer.nbr_atom_xyz() );
367  Real const ii_radius( ii_example_rotamer.nbr_radius() );
368 
369  if ( exclude_DNA_DNA_ && ii_example_rotamer.is_DNA() && rsd.is_DNA() ) continue;
370 
371  Vector const & jj_coord( rsd.nbr_atom_xyz() );
372  Real const jj_radius( rsd.nbr_radius() );
373 
374  if ( ii_coord.distance_squared( jj_coord ) < std::pow(ii_radius+jj_radius+packing_interaction_cutoff(), 2 )) {
375  for ( Size kk = 1, kke = set.get_n_rotamers_for_residue_type( ii ); kk <= kke; ++kk ) {
376  Size const kk_rot_id = ii_offset + kk - 1;
377 
378  Real const elecE(
379  potential_.get_res_res_elecE( *set.rotamer( kk_rot_id ), gb_set_info.residue_info( kk_rot_id ),
380  rsd, gb_rsd_info ) );
381  energy_vector[ kk_rot_id ] += static_cast< core::PackerEnergy > (weights[ gb_elec ] * elecE );
382  } // kk - rotamers for residue types
383  } // nbrs
384  } // ii - residue types for rotamer set
385  PROF_STOP( basic::GEN_BORN_ROTAMER_BACKGROUND_ENERGIES );
386 }
387 
388 void
390  conformation::RotamerSetBase const & set,
391  conformation::Residue const & rsd,
392  pose::Pose const & pose,
393  ScoreFunction const &, // sfxn,
394  EnergyMap const & ,
396 ) const
397 {
398 // std::cout << "GenBornEnergy: rotamer background: " << set.resid() << ' ' << rsd.seqpos() << std::endl;
399 
400  using conformation::Residue;
402  //using core::pose::datacache::CacheableDataType::GEN_BORN_POSE_INFO;
403 
404  GenBornResidueInfo const & gb_rsd_info
406  //GenBornResidueInfo const & gb_rsd_info( retrieve_gen_born_pose_info( pose ).residue_info( rsd.seqpos ) );
407 
408  GenBornRotamerSetInfo const & gb_set_info
410  //GenBornRotamersInfo const & gb_set_info( retrieve_gen_born_rotamers_info( set ) );
411 
412  for ( Size ii = 1; ii <= set.get_n_residue_types(); ++ii ) {
413  Size const ii_offset = set.get_residue_type_begin( ii );
414  Residue const & ii_example_rotamer( *set.rotamer( ii_offset ));
415 
416  Vector const & ii_coord( ii_example_rotamer.nbr_atom_xyz() );
417  Real const ii_radius( ii_example_rotamer.nbr_radius() );
418 
419  if ( exclude_DNA_DNA_ && ii_example_rotamer.is_DNA() && rsd.is_DNA() ) continue;
420 
421  Vector const & jj_coord( rsd.nbr_atom_xyz() );
422  Real const jj_radius( rsd.nbr_radius() );
423 
424  if ( ii_coord.distance_squared( jj_coord ) < std::pow(ii_radius+jj_radius+packing_interaction_cutoff(), 2 )) {
425  for ( Size kk = 1, kke = set.get_n_rotamers_for_residue_type( ii ); kk <= kke; ++kk ) {
426  Size const kk_rot_id = ii_offset + kk - 1;
427 
428  Real const elecE
429  ( potential_.get_res_res_elecE( *set.rotamer( kk_rot_id ), gb_set_info.residue_info( kk_rot_id ),
430  rsd, gb_rsd_info ) );
431  (emaps[ kk_rot_id ])[ gb_elec ] += elecE;
432  } // kk - rotamers for residue types
433  } // nbrs
434  } // ii - residue types for rotamer set
435 }
436 
437 /////////////////////////////////////////////////////////////////////////////
438 ///
439 void
441  id::AtomID const & atom_id,
442  pose::Pose const & pose,
443  kinematics::DomainMap const & domain_map,
444  ScoreFunction const &,
445  EnergyMap const & weights,
446  Vector & F1,
447  Vector & F2
448 ) const
449 {
450  potential_.eval_atom_derivative( atom_id, weights[ gb_elec ], pose, domain_map, exclude_DNA_DNA_, F1, F2 );
451 }
452 
453 /// @brief GenBornEnergy distance cutoff set to the same cutoff used by EtableEnergy, for now
454 // Distance
455 // GenBornEnergy::atomic_interaction_cutoff() const
456 // {
457 // return 5.5; /// APL remove this magic number!
458 // }
459 
460 /// @brief GenBornEnergy requires no context graphs
461 void
463 {
464 }
465 
466 /// @brief GenBornEnergy does define intraresidue interactions
467 bool
469 {
470  return true;
471 }
472 
473 void
475  conformation::Residue const & rsd,
476  pose::Pose const & pose,
477  ScoreFunction const &,
478  EnergyMap & emap
479 ) const
480 {
481  //using core::pose::datacache::CacheableDataType::GEN_BORN_POSE_INFO;
482 
483  if ( exclude_DNA_DNA_ && rsd.is_DNA() ) return;
484 
485  GenBornResidueInfo const & gb
487 
488  emap[ gb_elec ] += potential_.get_res_res_elecE( rsd, gb, rsd, gb );
489 }
492 {
493  return 1; // Initial versioning
494 }
495 
496 }
497 }
498 }