Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Fa_MbsolvEnergy.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/Fa_MbsolvEnergy.hh
10 /// @author Patrick Barth
11 
12 
13 // Unit headers
16 
17 // Package headers
19 #include <core/scoring/Energies.hh> //pba
29 
30 // Project headers
31 #include <core/pose/Pose.hh>
33 //#include <ObjexxFCL/formatted.o.hh>
35 #include <core/id/AtomID.hh>
37 #include <basic/datacache/BasicDataCache.hh> //pba
38 // AUTO-REMOVED #include <core/scoring/constraints/AngleConstraint.hh>
39 
40 // AUTO-REMOVED #include <numeric/constants.hh>
41 // AUTO-REMOVED #include <numeric/xyz.functions.hh>
42 
43 #include <utility/vector1.hh>
44 
45 
46 namespace core {
47 namespace scoring {
48 namespace methods {
49 
50 /// @details This must return a fresh instance of the Fa_MbsolvEnergy class,
51 /// never an instance already in use
54  methods::EnergyMethodOptions const & options
55 ) const {
56  return new Fa_MbsolvEnergy( *( ScoringManager::get_instance()->etable( options.etable_type() )), *( ScoringManager::get_instance()->memb_etable( options.etable_type() )) );
57 }
58 
61  ScoreTypes sts;
62  sts.push_back( fa_mbsolv );
63  return sts;
64 }
65 
66 Fa_MbsolvEnergy::Fa_MbsolvEnergy( etable::Etable const & etable_in, etable::MembEtable const & memb_etable_in):
68  etable_(etable_in),
69  memb_etable_(memb_etable_in),
70  solv1_(memb_etable_in.solv1()),
71  solv2_(memb_etable_in.solv2()),
72  dsolv1_( memb_etable_in.dsolv1() ),
73  dsolv2_( memb_etable_in.dsolv2() ),
74  dsolv_( etable_in.dsolv() ),
75  memb_solv1_(memb_etable_in.memb_solv1()),
76  memb_solv2_(memb_etable_in.memb_solv2()),
77  memb_dsolv1_( memb_etable_in.memb_dsolv1() ),
78  memb_dsolv2_( memb_etable_in.memb_dsolv2() ),
79  safe_max_dis2_( etable_in.get_safe_max_dis2() ),
80  get_bins_per_A2_( etable_in.get_bins_per_A2()),
81  verbose_( false ),
82  potential_( ScoringManager::get_instance()->get_Membrane_FAPotential() )
83 {}
84 
87 {
88  return etable_.max_dis();
89 }
90 
91 /// clone
94 {
95  return new Fa_MbsolvEnergy( *this );
96 }
97 
98 /////////////////////////////////////////////////////////////////////////////
99 // scoring
100 /////////////////////////////////////////////////////////////////////////////
101 ///
102 void
104  pose::Pose & pose, ScoreFunction const &
105 ) const
106 {
108 }
109 
110 ///
111 void
113  conformation::Residue const & rsd1,
114  conformation::Residue const & rsd2,
115  pose::Pose const & pose,
116  ScoreFunction const &,
117  EnergyMap & emap
118 ) const
119 {
120  Real fa_mbsolv_score( 0.0 );
121 
122  get_residue_pair_energy( rsd1, rsd2, pose, fa_mbsolv_score);
123 
124  emap[ fa_mbsolv ] += fa_mbsolv_score;
125 }
126 
127 
128 ////////////////////////////////////////////////
129 void
131  conformation::Residue const & rsd1,
132  conformation::Residue const & rsd2,
133  pose::Pose const & pose,
134  Real & fa_mbsolv_score
135 ) const
136 {
137 
138  bool const same_res = ( rsd1.seqpos() == rsd2.seqpos() );
139  Real temp_score (0.0);
140 
141  using namespace etable::count_pair;
142  CountPairFunctionOP cpfxn( 0 );
143 
144  if( same_res ) {
145  cpfxn = CountPairFactory::create_intrares_count_pair_function( rsd1, CP_CROSSOVER_3 );
146  } else {
147  cpfxn = CountPairFactory::create_count_pair_function( rsd1, rsd2, CP_CROSSOVER_4 );
148  }
149 
150  for ( Size i = 1, i_end = rsd1.nheavyatoms(); i <= i_end; ++i ) {
151 
152  Vector const heavy_atom_i( rsd1.xyz( i ) );
153 
154  for ( Size j = 1, j_end = rsd2.nheavyatoms(); j <= j_end; ++j ) {
155 
156  Real cp_weight = 1.0; Size path_dist( 0 );
157  if ( cpfxn->count( i, j, cp_weight, path_dist ) ) {
158 
159  Vector const heavy_atom_j( rsd2.xyz( j ) );
160 
161  Vector const d_ij = heavy_atom_j - heavy_atom_i;
162  Real const d2 = d_ij.length_squared();
163 
164  if ( ( d2 >= safe_max_dis2_) || ( d2 == Real(0.0) ) ) continue;
165 
166  Real dummy_deriv( 0.0 );
167 
168  //pbadebug WARNING
169  bool debug(false);
170 
171  temp_score = cp_weight * eval_lk( rsd1.atom( i ), rsd2.atom( j ), d2, dummy_deriv,
172  Membrane_FAEmbed_from_pose( pose ).fa_proj(rsd1.seqpos(),i),
173  Membrane_FAEmbed_from_pose( pose ).fa_proj(rsd2.seqpos(),j),debug);
174 
175  if( same_res ) temp_score *= 0.5;
176 
177  fa_mbsolv_score += temp_score;
178 
179  /*if ( verbose_ && std::abs( fa_mbsolv_score ) > 0.1 )
180  std::cout << "fa_mbsolv_score: rsd1 " << rsd1.name1() << rsd1.seqpos() << " " << rsd1.atom_name( i ) << " rsd2 " << rsd2.name1() << rsd2.seqpos() << " " << rsd2.atom_name(j) << " ==> " << F(8,3,fa_mbsolv_score) << ' ' << std::
181 endl;*/
182 
183  } // cp
184 
185  } // j
186  } // i
187 
188 }
189 
190 /////////////////////////////////////////////////////////////////////////////
191 // derivatives
192 /////////////////////////////////////////////////////////////////////////////
193 void
195  pose::Pose & pose,
196  ScoreFunction const & scfxn
197 ) const
198 {
201  fa_mbsolv_weight_ = scfxn.weights()[ fa_mbsolv ];
202 }
203 
204 
205 ////////////////////////////////////////////////
206 Real
208  conformation::Atom const & atom1,
209  conformation::Atom const & atom2,
210  Real const & d2,
211  Real & deriv,
212  Real const & f1,
213  Real const & f2,
214  bool & debug ) const
215 {
216 
217  Real temp_score( 0.0 );
218  deriv = 0.0;
219  //Make this an input option for efficiency
220  bool const eval_deriv( true );
221 
222  if ( ( d2 < safe_max_dis2_) && ( d2 != Real(0.0) ) ) {
223 
224  Real const d2_bin = d2 * get_bins_per_A2_;
225  int disbin = static_cast< int >( d2_bin ) + 1;
226  Real frac = d2_bin - ( disbin - 1 );
227 
228  // l1 and l2 are FArray LINEAR INDICES for fast lookup:
229  // [ l1 ] == (disbin ,attype2,attype1)
230  // [ l2 ] == (disbin+1,attype2,attype1)
231 
232  int const l1 = solv1_.index( disbin, atom2.type(), atom1.type() );
233  int const l2 = l1 + 1;
234 
235  //pba Membrane specific solvation
236  //pba solvation of atom1 based on its distance from the membrane center on the membrane normal
237 
238  Real e11 = f1 * solv1_[ l1 ] + (1 - f1) * memb_solv1_[ l1 ];
239  Real e12 = f1 * solv1_[ l2 ] + (1 - f1) * memb_solv1_[ l2 ];
240 
241  //pba solvation of atom2 based on its distance from the membrane center on the membrane normal
242 
243  Real e21 = f2 * solv2_[ l1 ] + (1 - f2) * memb_solv2_[ l1 ];
244  Real e22 = f2 * solv2_[ l2 ] + (1 - f2) * memb_solv2_[ l2 ];
245 
246  Real e1 = e11 + e21;
247  Real e2 = e12 + e22;
248 
249  temp_score = e1 + frac * ( e2 - e1 ); //temp_score = weight * ( e1 + frac * ( e2 - e1 ) );
250 
251  if(debug) {
252  std::cout << "f1 s1l1 mbs1l1 s1l2 mbs1l2 " << f1 << " " << solv1_[ l1 ] << " " << memb_solv1_[ l1 ] << " " <<
253  solv1_[ l2 ] << " " << memb_solv1_[ l2 ] << std::endl;
254  std::cout << "f2 s2l1 mbs2l1 s2l2 mbs2l2 " << f2 << " " << solv2_[ l1 ] << " " << memb_solv2_[ l1 ] << " " <<
255  solv2_[ l2 ] << " " << memb_solv2_[ l2 ] << std::endl;
256  }
257 
258  if (eval_deriv) {
259  // int const l1 = dsolv1_.index( disbin, atom2.type(), atom1.type() ),
260  // l2 = l1 + 1;
261  // Real e1 = dsolv1_[ l1 ];
262  // deriv = ( e1 + frac * ( dsolv1_[ l2 ] - e1 ) );
263  e11 = f1 * dsolv1_[ l1 ] + (1 - f1) * memb_dsolv1_[ l1 ];
264  e12 = f1 * dsolv1_[ l2 ] + (1 - f1) * memb_dsolv1_[ l2 ];
265  e21 = f2 * dsolv2_[ l1 ] + (1 - f2) * memb_dsolv2_[ l1 ];
266  e22 = f2 * dsolv2_[ l2 ] + (1 - f2) * memb_dsolv2_[ l2 ];
267  e1 = e11 + e21;
268  e2 = e12 + e22;
269 
270  deriv = e1 + frac * ( e2 - e1 );
271  deriv = deriv / std::sqrt( d2 );
272  }
273 
274  }
275  return temp_score;
276 }
277 ////////////////////////////////////////////////////////////////////////////////////
278 Real
280  conformation::Atom const & atom1,
281  conformation::Atom const & atom2,
282  EnergyMap const & /*weights*/,
283  Vector & F1,
284  Vector & F2,
285  Real const & f1,
286  Real const & f2
287 ) const
288 {
289 
290  F1 = atom1.xyz().cross( atom2.xyz() );
291  F2 = atom1.xyz() - atom2.xyz();
292  Real d2,frac;
293  int disbin;
294 
295  d2 = atom1.xyz().distance_squared( atom2.xyz() );
296 
297  if ( ( d2 < safe_max_dis2_ ) && ( d2 != Real(0.0) ) ) {
298 
299  // bin by distance:
300  Real const d2_bin = d2 * get_bins_per_A2_;
301  disbin = static_cast< int >( d2_bin ) + 1;
302  frac = d2_bin - ( disbin - 1 );
303 
304  // l1 and l2 are FArray LINEAR INDICES for fast lookup:
305  // [ l1 ] == (disbin ,attype2,attype1)
306  // [ l2 ] == (disbin+1,attype2,attype1)
307 
308  Real deriv = 0.0;
309 
310  int const l1 = dsolv1_.index( disbin, atom1.type(), atom2.type()),
311  l2 = l1 + 1;
312 
313  Real e11 = f1 * dsolv1_[ l1 ] + (1 - f1) * memb_dsolv1_[ l1 ];
314  Real e12 = f1 * dsolv1_[ l2 ] + (1 - f1) * memb_dsolv1_[ l2 ];
315  Real e21 = f2 * dsolv2_[ l1 ] + (1 - f2) * memb_dsolv2_[ l1 ];
316  Real e22 = f2 * dsolv2_[ l2 ] + (1 - f2) * memb_dsolv2_[ l2 ];
317  Real e1 = e11 + e21;
318  Real e2 = e12 + e22;
319 
320  deriv = fa_mbsolv_weight_ * ( e1 + frac * ( e2 - e1 ) );
321 
322  return deriv / std::sqrt( d2 );
323  } else {
324  return 0.0;
325  }
326 }
327 
328 //////////////////////////////////////////////////////////////////////////////////////
329 void
331  id::AtomID const & atom_id,
332  pose::Pose const & pose,
333  kinematics::DomainMap const & domain_map,
334  ScoreFunction const &,// sfxn,
335  EnergyMap const & weights,
336  Vector & F1,
337  Vector & F2
338 ) const
339 {
340 
341  Size const i( atom_id.rsd() );
342  Size const m( atom_id.atomno() );
343  conformation::Residue const & rsd1( pose.residue( i ) );
344 
345  if ( m > rsd1.nheavyatoms() ) return;
346 
347  Vector const heavy_atom_i( rsd1.xyz( m ) );
348 
349  bool const pos1_fixed( domain_map( i ) != 0 );
350 
351  // cached energies object
352  Energies const & energies( pose.energies() );
353 
354  // the neighbor/energy links
355  EnergyGraph const & energy_graph( energies.energy_graph() );
356 
357  // Real deriv( 0.0 );
358 
360  iter = energy_graph.get_node( i )->const_edge_list_begin(),
361  itere = energy_graph.get_node( i )->const_edge_list_end();
362  iter != itere; ++iter ) {
363 
364  Size const j( (*iter)->get_other_ind( i ) );
365 
366  if ( pos1_fixed && domain_map(i) == domain_map(j) ) continue; //Fixed w.r.t. one another.
367 
368  conformation::Residue const & rsd2( pose.residue( j ) );
369  bool const same_res = ( rsd1.seqpos() == rsd2.seqpos() );
370 
371  using namespace etable::count_pair;
372  CountPairFunctionOP cpfxn( 0 );
373 
374  if( same_res ) {
375  cpfxn = CountPairFactory::create_intrares_count_pair_function( rsd1, CP_CROSSOVER_3 );
376  } else {
377  cpfxn = CountPairFactory::create_count_pair_function( rsd1, rsd2, CP_CROSSOVER_4 );
378  }
379 
380  for ( Size n = 1; n <= rsd2.nheavyatoms(); ++n ) {
381 
382  Real cp_weight = 1.0; Size path_dist(0);
383 
384  if ( cpfxn->count(m, n, cp_weight, path_dist ) ) {
385 
386  Vector const heavy_atom_j( rsd2.xyz( n ) );
387  Vector const d_ij = heavy_atom_j - heavy_atom_i;
388  Real const d2 = d_ij.length_squared();
389  // Real const d = std::sqrt( d2 );
390  Vector const d_ij_norm = d_ij.normalized();
391 
392  if ( ( d2 >= safe_max_dis2_) || ( d2 == Real(0.0) ) ) continue;
393 
394 
395  Vector f1( 0.0 ), f2( 0.0 );
396 
397  Real const dE_dR_over_r
398  ( eval_dE_dR_over_r( rsd1.atom(m), rsd2.atom(n), weights, f1, f2,
399  Membrane_FAEmbed_from_pose( pose ).fa_proj(rsd1.seqpos(),m),
400  Membrane_FAEmbed_from_pose( pose ).fa_proj(rsd2.seqpos(),n) ) );
401  if ( dE_dR_over_r != 0.0 ) {
402  if( same_res ) {
403  F1 += 0.5 * dE_dR_over_r * cp_weight * f1;
404  F2 += 0.5 * dE_dR_over_r * cp_weight * f2;
405  } else {
406  F1 += dE_dR_over_r * cp_weight * f1;
407  F2 += dE_dR_over_r * cp_weight * f2;
408  }
409  }
410  }
411  }
412  }
413 
414 }
415 
416 
417 ////////////////////////////////////////////////
418 void
420  utility::vector1< bool > & /* context_graphs_required */ ) const
421 {}
422 
423 ////////////////////////////////////////////////
424 void
426  conformation::Residue const & rsd,
427  pose::Pose const & pose,
428  ScoreFunction const &,
429  EnergyMap & emap
430 ) const
431 {
432 
433  Real fa_mbsolv_score( 0.0 );
434 
435  get_residue_pair_energy( rsd, rsd, pose, fa_mbsolv_score);
436 
437  emap[ fa_mbsolv ] += fa_mbsolv_score;
438 
439 }
440 
441 ////////////////////////////////////////////////
442 void
444  pose::Pose & /*pose*/,
445  ScoreFunction const &,
446  EnergyMap & /*emap*/
447 ) const
448 {
449  if (verbose_) std::cout << "DONE SCORING" << std::endl;
450 }
451 
452 
453 /// @details Pose must already contain a cenlist object or this method will fail.
454 Membrane_FAEmbed const &
456 {
457  //using core::pose::datacache::CacheableDataType::MEMBRANE_FAEMBED;
458  return *( static_cast< Membrane_FAEmbed const * >( pose.data().get_const_ptr( core::pose::datacache::CacheableDataType::MEMBRANE_FAEMBED )() ));
459 }
460 
461 MembraneTopology const &
463 {
464  //using core::pose::datacache::CacheableDataType::MEMBRANE_TOPOLOGY;
465  return *( static_cast< MembraneTopology const * >( pose.data().get_const_ptr( core::pose::datacache::CacheableDataType::MEMBRANE_TOPOLOGY )() ));
466 }
469 {
470  return 1; // Initial versioning
471 }
472 
473 
474 }
475 }
476 }
477 
478 
479