Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
VDW_Energy.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/VDW_Energy.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
21 #include <core/scoring/AtomVDW.hh>
23 #include <core/scoring/Energies.hh>
26 //#include <core/scoring/etable/count_pair/CountPair1BC4.hh>
30 
31 // Project headers
32 #include <core/pose/Pose.hh>
34 #include <basic/prof.hh>
35 
36 #include <core/id/AtomID.hh>
37 #include <utility/vector1.hh>
38 
39 
40 
41 namespace core {
42 namespace scoring {
43 namespace methods {
44 
45 
46 /// @details This must return a fresh instance of the VDW_Energy class,
47 /// never an instance already in use
50  methods::EnergyMethodOptions const & options
51 ) const {
52  return new VDW_Energy( options );
53 }
54 
57  ScoreTypes sts;
58  sts.push_back( vdw );
59  return sts;
60 }
61 
62 
63 /// @details C-TOR with method options object
66  atom_vdw_( ScoringManager::get_instance()->get_AtomVDW( options.atom_vdw_atom_type_set_name() ) ),
67  atom_type_set_name_( options.atom_vdw_atom_type_set_name() ),
68  vdw_scale_factor_( 0.8 ) // hack from rosetta++
69 {
70 }
71 
72 
73 /// clone
76 {
77  return new VDW_Energy( *this );
78 }
79 
80 /// @details copy c-tor
82  parent( src ),
83  atom_vdw_( src.atom_vdw_ ),
84  atom_type_set_name_( src.atom_type_set_name_ ),
85  vdw_scale_factor_( src.vdw_scale_factor_ )
86 {}
87 
88 
89 /////////////////////////////////////////////////////////////////////////////
90 // scoring
91 /////////////////////////////////////////////////////////////////////////////
92 
93 ///
94 void
96 {
98 }
99 
100 
101 ///
102 void
104 {
106 }
107 
108 
109 ///
110 void
112  conformation::Residue const & rsd1,
113  conformation::Residue const & rsd2,
114  pose::Pose const &,
115  ScoreFunction const &,
116  EnergyMap & emap
117 ) const
118 {
119  using namespace etable::count_pair;
120  Real score(0.0);
121  // basic::ProfileThis doit( basic::VDW_ENERGY );
122  if ( rsd1.is_bonded( rsd2 ) || rsd1.is_pseudo_bonded( rsd2 ) ) {
123  // assuming only a single bond right now -- generalizing to arbitrary topology
124  // also assuming crossover of 4, should be closest (?) to classic rosetta
125  CountPairFunctionOP cpfxn =
126  CountPairFactory::create_count_pair_function( rsd1, rsd2, CP_CROSSOVER_4 );
127 
128  for ( Size i = 1, i_end = rsd1.natoms(); i <= i_end; ++i ) {
129  Vector const & i_xyz( rsd1.xyz(i) );
130  Size const i_type( rsd1.atom_type_index(i) );
131  utility::vector1< Real > const & i_atom_vdw( atom_vdw_( i_type ) );
132  for ( Size j = 1, j_end = rsd2.natoms(); j <= j_end; ++j ) {
133  Real weight(1.0);
134  Size path_dist( 0 );
135  if ( cpfxn->count( i, j, weight, path_dist ) ) {
136  if ( weight < 0.99 ) continue; // don't count half-weight interxns in vdw_compute
137  if ( rsd2.atom_type_index(j) <= i_atom_vdw.size() ){
138  Real const bump_dsq( i_atom_vdw[ rsd2.atom_type_index(j) ] );
139  Real const clash( bump_dsq - i_xyz.distance_squared( rsd2.xyz(j) ) );
140  if ( clash > 0.0 ) {
141  score += ( clash * clash ) / bump_dsq;
142  }
143  }else{
144  std::cerr << "Etable: " << rsd2.atom_type_index(j) << " " << i_atom_vdw.size() << " " << i << " " << j << std::endl;
145  utility_exit_with_message( "Fatal Error in VDW_Energy" );
146  }
147  }
148  }
149  }
150  } else {
151  // no countpair!
152  for ( Size i = 1, i_end = rsd1.natoms(); i <= i_end; ++i ) {
153  Vector const & i_xyz( rsd1.xyz(i) );
154  Size const i_type( rsd1.atom_type_index(i) );
155  utility::vector1< Real > const & i_atom_vdw( atom_vdw_( i_type ) );
156  for ( Size j = 1, j_end = rsd2.natoms(); j <= j_end; ++j ) {
157  if ( rsd2.atom_type_index(j) <= i_atom_vdw.size() ){
158  Real const bump_dsq( i_atom_vdw[ rsd2.atom_type_index(j) ] );
159  Real const clash( bump_dsq - i_xyz.distance_squared( rsd2.xyz(j) ) );
160  if ( clash > 0.0 ) {
161  score += ( clash * clash ) / bump_dsq;
162 // std::cout << "BUMP: " << I(4,rsd1.seqpos() ) << I(4,rsd2.seqpos() )
163 // <<' ' << rsd1.atom_name(i) << ' ' << rsd2.atom_name(j) << ' '
164 // << ( clash * clash ) / bump_dsq * vdw_scale_factor_
165 // << ' ' << i_xyz.distance_squared( rsd2.xyz(j) ) << std::endl;
166  }
167  }else{
168  std::cerr << "Etable: " << rsd2.atom_type_index(j) << " " << i_atom_vdw.size() << " " << i << " " << j << std::endl;
169  utility_exit_with_message( "Fatal Error in VDW_Energy" );
170  }
171  }
172  }
173  }
174  emap[ vdw ] += score * vdw_scale_factor_; // vdw prefactor!
175 
176 // if ( score*0.8 > 0.001 && rsd1.seqpos() <= rsd2.seqpos() ) {
177 // using namespace ObjexxFCL::fmt;
178 // std::cout << "vdw_ij: " << I(4,rsd1.seqpos() ) << I(4,rsd2.seqpos() ) << F(9,3,score*0.8) << std::endl;
179 // }
180 }
181 
182 
183 void
185  id::AtomID const & atom_id,
186  pose::Pose const & pose,
187  kinematics::DomainMap const & domain_map,
188  ScoreFunction const &,
189  EnergyMap const & weights,
190  Vector & F1,
191  Vector & F2
192  ) const
193 {
194  using namespace etable::count_pair;
195  // basic::ProfileThis doit( basic::VDW_ENERGY );
196  // what is my charge?
197  Size const pos1( atom_id.rsd() );
198  Size const i ( atom_id.atomno() );
199  conformation::Residue const & rsd1( pose.residue( pos1 ) );
200 
201  int const pos1_map( domain_map( pos1 ) );
202  bool const pos1_fixed( pos1_map != 0 );
203 
204  Vector const & i_xyz( rsd1.xyz(i) );
205  Size const i_type( rsd1.atom_type_index(i) );
206  utility::vector1< Real > const & i_atom_vdw( atom_vdw_( i_type ) );
207 
208  // cached energies object
209  Energies const & energies( pose.energies() );
210 
211  // the neighbor/energy links
212  EnergyGraph const & energy_graph( energies.energy_graph() );
213 
214  // loop over *all* nbrs of rsd1 (not just upper or lower)
216  iru = energy_graph.get_node( pos1 )->const_edge_list_begin(),
217  irue = energy_graph.get_node( pos1 )->const_edge_list_end();
218  iru != irue; ++iru ) {
219  Size const pos2( (*iru)->get_other_ind( pos1 ) );
220 
221  if ( pos1_fixed && pos1_map == domain_map( pos2 ) ) continue; // fixed wrt one another
222 
223  conformation::Residue const & rsd2( pose.residue( pos2 ) );
224 
225  assert( pos2 != pos1 );
226 
227  if ( rsd1.is_bonded( rsd2 ) || rsd1.is_pseudo_bonded( rsd2 ) ) {
228  // generalizing to arbitrary topology
229  // also assuming crossover of 4, should be closest (?) to classic rosetta
230  CountPairFunctionOP cpfxn = CountPairFactory::create_count_pair_function( rsd1, rsd2, CP_CROSSOVER_4 );
231 
232  for ( Size j=1, j_end = rsd2.natoms(); j<= j_end; ++j ) {
233 
234  Real cp_weight(1.0);
235  Size path_dist( 0 );
236  if ( cpfxn->count( i, j, cp_weight, path_dist ) ) {
237  if ( cp_weight < 0.99 ) continue; // dont count half-weight interxns in vdw_compute
238  Vector const & j_xyz( rsd2.xyz(j) );
239  Vector const f2( i_xyz - j_xyz );
240  Real const dis2( f2.length_squared() );
241  Real const bump_dsq( i_atom_vdw[ rsd2.atom_type_index(j) ] );
242  if ( dis2 < bump_dsq ) {
243  // E += vdw_scale_factor_ * weights[vdw] * cp_weight * ( ( dis2 - bump_dsq ) **2 ) / bump_dsq
244  Real const dE_dr_over_r = vdw_scale_factor_ * weights[ vdw ] * cp_weight * 4.0 * ( dis2 - bump_dsq ) / bump_dsq;
245  Vector const f1( i_xyz.cross( j_xyz ) );
246  F1 += dE_dr_over_r * f1;
247  F2 += dE_dr_over_r * f2;
248  }
249  }
250  }
251  } else {
252  // no countpair!
253  for ( Size j=1, j_end = rsd2.natoms(); j<= j_end; ++j ) {
254 
255  Vector const & j_xyz( rsd2.xyz(j) );
256  Vector const f2( i_xyz - j_xyz );
257  Real const dis2( f2.length_squared() );
258  Real const bump_dsq( i_atom_vdw[ rsd2.atom_type_index(j) ] );
259  if ( dis2 < bump_dsq ) {
260  // E += vdw_scale_factor_ * weights[vdw] * ( ( dis2 - bump_dsq ) **2 ) / bump_dsq
261  Real const dE_dr_over_r = vdw_scale_factor_ * weights[ vdw ] * 4.0 * ( dis2 - bump_dsq ) / bump_dsq;
262  Vector const f1( i_xyz.cross( j_xyz ) );
263  F1 += dE_dr_over_r * f1;
264  F2 += dE_dr_over_r * f2;
265  }
266  }
267  } // are rsd1 and rsd2 bonded?
268 
269  } // loop over nbrs of rsd1
270 
271 }
272 
273 
274 
275 /// @brief VDW_Energy distance cutoff
276 Distance
278 {
279  return 6.0; /// now subtracted off 3.0 from cutoffs in centroid params files
280  //return 0.0; /// since all the cutoffs for centroid mode are rolled into the cendist check
281 }
282 
283 /// @brief VDW_Energy
284 void
286 {
287 }
290 {
291  return 1; // Initial versioning
292 }
293 
294 
295 
296 }
297 }
298 }