Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
BaseMembEtableEnergy.hh
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/etable/EtableEnergy.hh
10 /// @brief Etable energy method class declaration
11 /// @author Phil Bradley
12 /// @author Andrew Leaver-Fay
13 /// @author Oliver Lange
14 
15 /***********************************************************************
16 ++++++++++++++++++++++++++++ WARNING +++++++++++++++++++++++++++++++++++
17 
18 the CoarseEtable is currently not threadsafe, since it has the
19 "mutable" element seq_dist...
20 
21 could move seq_dist into CoarseEtableEnergy --> then at least the
22 CoarseEtable can be shared between threads
23 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
24 ************************************************************************/
25 
26 
27 #ifndef INCLUDED_core_scoring_memb_etable_BaseMembEtableEnergy_hh
28 #define INCLUDED_core_scoring_memb_etable_BaseMembEtableEnergy_hh
29 
30 // Unit headers
32 
33 // Package headers
39 
45 
48 // Project headers
50 #include <core/pose/Pose.fwd.hh>
51 
52 
53 #include <ObjexxFCL/FArray3D.hh>
54 
55 namespace core {
56 namespace scoring {
57 namespace etable {
58 
59 template < class Derived >
60 class BaseEtableEnergy : public methods::ContextIndependentTwoBodyEnergy
61 {
62 
63 public:
65 
66 public:
67 
68  /// construction with an etable
70  Etable const & etable_in,
71  methods::EnergyMethodOptions const & options,
72  ScoreType st_atr,
73  ScoreType st_rep,
74  ScoreType st_sol
75  );
76 
77 
78  /////////////////////////////////////////////////////////////////////////////
79  // methods for ContextIndependentTwoBodyEnergies
80  /////////////////////////////////////////////////////////////////////////////
81 
82  /// stashes nblist if use_nblist is true
83  virtual
84  void
86  pose::Pose & pose,
87  ScoreFunction const & sfxn,
88  kinematics::MinimizerMapBase const & min_map
89  ) const;
90 
91  /// @brief check compatibility with atomtypeset
92  virtual
93  void
94  setup_for_scoring( pose::Pose &pose, ScoreFunction const &scfxn ) const;
95 
96  virtual
97  void
99  pose::Pose &pose,
100  ScoreFunction const &scfxn
101  ) const;
102 
103  // The EtableEnergy method stores a vector of rotamer trie objects in the Energies
104  // object for use in rapid rotamer/background energy calculations. Overrides default
105  // do-nothing behavior.
106  virtual
107  void
109 
110  // Creates a rotamer trie for the input set of rotamers and stores the trie
111  // in the rotamer set.
112  virtual
113  void
115  pose::Pose const & pose,
116  conformation::RotamerSetBase & set
117  ) const;
118 
119  // Updates the cached rotamer trie for a residue if it has changed during the course of
120  // a repacking
121  virtual
122  void
123  update_residue_for_packing( pose::Pose & pose, Size resid ) const;
124 
125 
128  Size res1,
129  Size res2,
130  pose::Pose const & pose,
131  ScoreFunction const & sfxn
132  ) const;
133 
136  conformation::Residue const & res1,
137  conformation::Residue const & res2,
138  pose::Pose const & pose,
139  ScoreFunction const & sfxn
140  ) const;
141 
144  conformation::Residue const & res,
145  pose::Pose const & pose,
146  ScoreFunction const & sfxn
147  ) const;
148 
149  ///
150  virtual
151  void
153  conformation::Residue const & rsd1,
154  conformation::Residue const & rsd2,
155  pose::Pose const & pose,
156  ScoreFunction const & sfxn,
157  EnergyMap & emap
158  ) const;
159 
160  ///@brief Evaluates the interaction between the backbone of rsd1 and the
161  /// backbone of rsd2 and accumulates the unweighted energy.
162  virtual
163  void
165  conformation::Residue const & rsd1,
166  conformation::Residue const & rsd2,
167  pose::Pose const & pose,
168  ScoreFunction const & sfxn,
169  EnergyMap & emap
170  ) const;
171 
172 
173  ///@brief Evaluates the interaction between the backbone of rsd1 and the
174  /// sidechain of rsd2 and accumulates the unweighted energy.
175  virtual
176  void
178  conformation::Residue const & rsd1,
179  conformation::Residue const & rsd2,
180  pose::Pose const & pose,
181  ScoreFunction const & sfxn,
182  EnergyMap & emap
183  ) const;
184 
185  ///@brief Evaluates the interaction between the sidechain of rsd1 and the
186  /// sidechain of rsd2 and accumulates the unweighted energy.
187  virtual
188  void
190  conformation::Residue const & rsd1,
191  conformation::Residue const & rsd2,
192  pose::Pose const & pose,
193  ScoreFunction const & sfxn,
194  EnergyMap & emap
195  ) const;
196 
197  virtual
198  void
200  conformation::RotamerSetBase const & set1,
201  conformation::RotamerSetBase const & set2,
202  pose::Pose const & pose,
203  ScoreFunction const & sfxn,
204  EnergyMap const & weights,
205  ObjexxFCL::FArray2D< core::PackerEnergy > & energy_table
206  ) const;
207 
208 
209  //@brief overrides default rotamer/background energy calculation and uses
210  // the trie-vs-trie algorithm instead
211  virtual
212  void
214  conformation::RotamerSetBase const & set,
215  conformation::Residue const & residue,
216  pose::Pose const & pose,
217  ScoreFunction const & sfxn,
218  EnergyMap const & weights,
220  ) const;
221 
222  virtual
223  void
225  conformation::Residue const & rsd1,
226  conformation::Residue const & rsd2,
227  pose::Pose const & pose,
228  ScoreFunction const & sfxn,
229  EnergyMap & emap
230  ) const;
231 
232  virtual
233  void
235  conformation::Residue const & rsd1,
236  conformation::Residue const & rsd2,
237  pose::Pose const & pose,
238  ScoreFunction const & sfxn,
239  EnergyMap & emap
240  ) const;
241 
242  /// called at the end of energy evaluation
243  virtual
244  void
246  pose::Pose & pose,
247  ScoreFunction const &,
248  EnergyMap & totals
249  ) const;
250 
251 
252  /// called during gradient-based minimization inside dfunc
253  /**
254  F1 and F2 are not zeroed -- contributions from this atom are
255  just summed in
256  **/
257  virtual
258  void
260  id::AtomID const & id,
261  pose::Pose const & pose,
262  kinematics::DomainMap const &, // domain_map,
263  ScoreFunction const & sfxn,
264  EnergyMap const & weights,
265  Vector & F1,
266  Vector & F2
267  ) const;
268 
269 
270  /////////////////////////////////////////////////////////////////////////////
271  // methods specific to EtableEnergy:
272  /////////////////////////////////////////////////////////////////////////////
273  /// Should/Could these inlined" in a separate .inline.hh?
274 
275  // for some reason the virtual-function call to residue_pair_energy does not get passed thru to
276  // CoarseEnergyEtable... Use template based call instead...
277  ///
278  inline
279  void
281  Size const res1,
282  Size const res2,
283  pose::Pose const & pose
284  ) const {
285  static_cast< Derived const* > (this) -> derived_prepare_for_residue_pair(res1,res2,pose);
286  }
287 
288 
289  ///
290  inline
291  void
293  conformation::Atom const & atom1,
294  conformation::Atom const & atom2,
295  Real const weight,
296  EnergyMap & emap,
297  Real & dsq
298  ) const {
299  Energy atr, rep, solv, bb;
300  atr = rep = solv = bb = 0;
301  // std::cerr << __FILE__<< ' ' << __LINE__ << std::endl;
302  atom_pair_energy(atom1,atom2,weight,atr,rep,solv,bb,dsq);
303  // std::cerr << __FILE__<< ' ' << __LINE__ << "sol " << solv << std::endl;
304  emap[st_atr_]+=atr;
305  emap[st_rep_]+=rep;
306  emap[st_sol_]+=solv;
307  // std::cerr << __FILE__<< ' ' << __LINE__ << "total " << emap[st_sol_] << std::endl;
308  emap[coarse_beadlj]+=bb;
309  }
310 
311  ///pba
312  inline
313  void
315  conformation::Atom const & atom1,
316  conformation::Atom const & atom2,
317  Real const weight,
318  EnergyMap & emap,
319  Real & dsq
320  ) const {
321  Energy atr, rep, solv, bb;
322  atr = rep = solv = bb = 0;
323  // std::cerr << __FILE__<< ' ' << __LINE__ << std::endl;
324  memb_atom_pair_energy(atom1,atom2,weight,atr,rep,solv,bb,dsq);
325  // std::cerr << __FILE__<< ' ' << __LINE__ << "sol " << solv << std::endl;
326  emap[st_atr_]+=atr;
327  emap[st_rep_]+=rep;
328  emap[st_sol_]+=solv;
329  // std::cerr << __FILE__<< ' ' << __LINE__ << "total " << emap[st_sol_] << std::endl;
330  emap[coarse_beadlj]+=bb;
331  }
332 
333  ///pba
334  inline
335  void
337  conformation::Atom const & atom1,
338  int const attype1,
339  Real & mbenvE
340  ) const {
341  fast_memb_env_energy(atom1,attype1,mbenvE);
342  }
343 
344  /// @brief for the trie-vs-trie algorithm; could test if the other
345  /// atom pair energy function could inline this function to avoid
346  /// the table reading code duplication.
347  inline
348  void
350  conformation::Atom const & atom1,
351  conformation::Atom const & atom2,
352  Real const weight,
353  Energy & atr,
354  Energy & rep,
355  Energy & solv,
356  Energy & bb,
357  Real & dsq
358  ) const {
359  // std::cerr << __FILE__<< ' ' << __LINE__ << std::endl;
360  static_cast< Derived const* > (this) -> atom_pair_energy_(atom1,atom2,weight,atr,rep,solv,bb,dsq);
361  }
362 
363  /// pba @brief for the trie-vs-trie algorithm; could test if the other
364  /// atom pair energy function could inline this function to avoid
365  /// the table reading code duplication.
366  inline
367  void
369  conformation::Atom const & atom1,
370  conformation::Atom const & atom2,
371  Real const weight,
372  Energy & atr,
373  Energy & rep,
374  Energy & solv,
375  Energy & bb,
376  Real & dsq
377  ) const {
378  // std::cerr << __FILE__<< ' ' << __LINE__ << std::endl;
379  static_cast< Derived const* > (this) -> memb_atom_pair_energy_(atom1,atom2,weight,atr,rep,solv,bb,dsq);
380  }
381 
382  //pba
383  inline
384  void
386  conformation::Atom const & atom1,
387  int const attype1,
388  Real & mbenvE
389  ) const {
390  static_cast< Derived const* > (this) -> fast_memb_env_energy_(atom1,attype1,mbenvE);
391  }
392 
393  ///
394  inline
395  void
397  conformation::Atom const & atom1,
398  conformation::Atom const & atom2,
399  Real weight,
400  Energy & atr,
401  Energy & rep,
402  Energy & solv,
403  Energy & bb
404  ) const {
405  return static_cast< Derived const* > (this) -> pair_energy_H_(atom1,atom2,weight,atr,rep,solv,bb);
406  };
407 
408  ///
409  inline
410  void
412  conformation::Atom const & atom1,
413  conformation::Atom const & atom2,
414  Real weight,
415  EnergyMap &emap
416  ) const;
417 
418 
419 
420  ///
421  inline
422  Real
424  conformation::Atom const & atom1,
425  conformation::Atom const & atom2,
426  EnergyMap const & weights,
427  Vector & f1,
428  Vector & f2
429  ) const {
430  return static_cast< Derived const* > (this) -> eval_dE_dR_over_r_(atom1,atom2,weights,f1,f2);
431  };
432 
433  ///pba
434  inline
435  Real
437  conformation::Atom const & atom1,
438  conformation::Atom const & atom2,
439  EnergyMap const & weights,
440  Vector & f1,
441  Vector & f2
442  ) const {
443  return static_cast< Derived const* > (this) -> memb_eval_dE_dR_over_r_(atom1,atom2,weights,f1,f2);
444  };
445 
446  ///
447  Real
449  {
451  }
452 
453  /// @brief Etable atomic distance cutoff is 5.5 A
454  virtual
455  Distance
457 
458  virtual
459  void indicate_required_context_graphs( utility::vector1< bool > & /*context_graphs_required*/ ) const;
460 
461  /// Inline Methods For Trie-vs-Trie Algorithm
462  inline
463  Energy sum_energies ( Real atr, Real rep, Real solv, Real bb ) const {
464  return weights_[ st_atr_ ] * atr
465  + weights_[ st_rep_ ] * rep
466  + weights_[ st_sol_ ] * solv
467  + weights_ [ coarse_beadlj ] * bb;
468  }
469 
470  inline
472  etrie::EtableAtom const & at1,
473  etrie::EtableAtom const & at2,
474  DistanceSquared & d2
475  ) const
476  {
477  Energy atr(0.0), rep(0.0), solv(0.0), bb(0.0);
478  atom_pair_energy( at1, at2, 1.0, atr, rep, solv, bb, d2 );
479  return sum_energies( atr, rep, solv, bb );
480  }
481 
482  inline
484  etrie::EtableAtom const & at1,
485  etrie::EtableAtom const & at2
486  ) const
487  {
488  Energy atr(0.0), rep(0.0), solv(0.0), bb(0.0);
489  pair_energy_H( at1, at2, 1.0, atr, rep, solv, bb );
490  return sum_energies( atr, rep, solv, bb );
491  }
492 
493  inline
495  etrie::EtableAtom const & at1,
496  etrie::EtableAtom const & at2
497  ) const
498  {
499  Energy atr(0.0), rep(0.0), solv(0.0), bb(0.0);
500  pair_energy_H( at1, at2, 1.0, atr, rep, solv, bb );
501  return sum_energies( atr, rep, solv, bb );
502  }
503 
504  inline
506  etrie::EtableAtom const & at1,
507  etrie::EtableAtom const & at2
508  ) const
509  {
510  Energy atr(0.0), rep(0.0), solv(0.0), bb(0.0);
511  pair_energy_H( at1, at2, 1.0, atr, rep, solv, bb );
512  return sum_energies( atr, rep, solv, bb );
513  }
514 
515 protected: //protected methods that may be used by derived classes
518  conformation::RotamerSetBase const & set1,
519  conformation::RotamerSetBase const & set2,
520  pose::Pose const & pose,
521  ScoreFunction const & sfxn
522  ) const;
523 
526  conformation::Residue const & res1,
527  conformation::Residue const & res2,
530  pose::Pose const & pose,
531  ScoreFunction const & sfxn
532  ) const;
533 
534  /*count_pair::CPResidueConnectionType
535  determine_residue_connection(
536  conformation::Residue const & res1,
537  conformation::Residue const & res2,
538  pose::Pose const &
539  ) const;*/
540 
543  conformation::Residue const & res1,
544  conformation::Residue const & res2,
545  pose::Pose const &,
546  ScoreFunction const & sfxn
547  ) const;
548 
551  conformation::RotamerSetBase const & rotset,
552  pose::Pose const & pose // will be need to create tries for disulfides
553  ) const;
554 
557  conformation::RotamerSetBase const & rotset
558  ) const;
559 
562  conformation::RotamerSetBase const & rotset,
563  Size connection_type // HACK: 1 for lower connect, 2 for upper connect. Replace this with an enum(?)
564  ) const;
565 
566 
567 protected:
568  // implementation for quasi-virtual functions
569  // rename this derived_atom_pair_energy
570  inline
571  void
573  conformation::Atom const & atom1,
574  conformation::Atom const & atom2,
575  Real const weight,
576  Real &atr,
577  Real &rep,
578  Real &solv,
579  Real &bb,
580  Real & dsq
581  ) const;
582 
583  //pba implementation for quasi-virtual functions
584  // rename this derived_atom_pair_energy
585  inline
586  void
588  conformation::Atom const & atom1,
589  conformation::Atom const & atom2,
590  Real const weight,
591  Real &atr,
592  Real &rep,
593  Real &solv,
594  Real &bb,
595  Real & dsq
596  ) const;
597 
598  //pba
599  inline
600  void
602  conformation::Atom const & atom1,
603  int const attype1,
604  Real & mbenvE
605  ) const;
606 
607  ///
608  inline
609  void
611  conformation::Atom const & atom1,
612  conformation::Atom const & atom2,
613  Real const weight,
614  Real &atr,
615  Real &rep,
616  Real &solv,
617  Real &bb
618  ) const;
619 
620  ///
621  inline
622  Real
624  conformation::Atom const & atom1,
625  conformation::Atom const & atom2,
626  EnergyMap const & weights,
627  Vector & f1,
628  Vector & f2
629  ) const;
630 
631  ///pba
632  inline
633  Real
635  conformation::Atom const & atom1,
636  conformation::Atom const & atom2,
637  EnergyMap const & weights,
638  Vector & f1,
639  Vector & f2
640  ) const;
641 
642  void
644  Size const res1,
645  Size const res2,
646  pose::Pose const &
647  ) const
648  { //do nothing if the derived class does not override this method
649  }
650 
651 
652  //little helper methods for interpolation:
653  bool interpolate_bins(
654  conformation::Atom const & atom1,
655  conformation::Atom const & atom2,
656  Real &d2,
657  int &disbin,
658  Real &frac
659  ) const;
660 
661  void
663  ScoreType atr_type,
664  ScoreType rep_type,
665  ScoreType sol_type
666  ) const;
667 
668  ScoreType
669  rep_scoretype() const;
670 
671  /////////////////////////////////////////////////////////////////////////////
672  // data
673  /////////////////////////////////////////////////////////////////////////////
674 protected:
675  Etable const & etable_; // shouldn't this be a pointer? Reference count information is (dangerously) lost when
676  //a reference is taken, instead of a smart pointer. There's the potential for a dangling reference with this.
677 
678 private:
679  /// these guys are taken from the etable
680  ObjexxFCL::FArray3D< Real > const & ljatr_;
681  ObjexxFCL::FArray3D< Real > const & ljrep_;
682  ObjexxFCL::FArray3D< Real > const & solv1_;
683  ObjexxFCL::FArray3D< Real > const & solv2_;
684  ObjexxFCL::FArray3D< Real > const & dljatr_;
685  ObjexxFCL::FArray3D< Real > const & dljrep_;
686  ObjexxFCL::FArray3D< Real > const & dsolv_;
687  ObjexxFCL::FArray3D< Real > const & memb_solv1_; //pba
688  ObjexxFCL::FArray3D< Real > const & memb_solv2_; //pba
689  ObjexxFCL::FArray3D< Real > const & memb_dsolv_; //pba
691 
692  int etable_bins_per_A2;
693 
695 
696  mutable ScoreType st_rep_;
697  mutable ScoreType st_atr_;
698  mutable ScoreType st_sol_;
699 
700  // For use in the trie-vs-trie algorithm
701  // written to at the beginning of the evaluate_rotamer_pair_energies call (which is const)
702  mutable EnergyMap weights_;
703 
704  // temporary hack -- make this configurable/cleaner, Phil
705  bool exclude_DNA_DNA;
706 
707  // not clear that we need these:
708  //chemical::AtomTypeSet const * atom_set_ptr_; // for atomtype info
709 };
710 
711 
712 ///////////////////////////////////////////////////////////////////////////////
713 // inline methods
714 ///////////////////////////////////////////////////////////////////////////////
715 
716 
717 ///////////////////////////////////////////////////////////////////////////////
718 // inline methods
719 ///////////////////////////////////////////////////////////////////////////////
720 template < class Derived >
721 inline
722 bool
724  conformation::Atom const & atom1,
725  conformation::Atom const & atom2,
726  Real &d2,
727  int &disbin,
728  Real &frac
729 ) const
730 {
731  d2 = atom1.xyz().distance_squared( atom2.xyz() );
732 
733  if ( ( d2 >= safe_max_dis2 ) || ( d2 == Real(0.0) ) ) {
734  return false;
735  }
736 
737  // bin by distance:
738  Real const d2_bin = d2 * etable_bins_per_A2;
739  disbin = static_cast< int >( d2_bin ) + 1;
740 // int const disbin2 = disbin + 1;
741  frac = d2_bin - ( disbin - 1 );
742  return true;
743 //ctsa
744 //ctsa tables have been hacked so that if disbin2 = lastbin, all values = 0.
745 //ctsa
746 }
747 
748 template <class Derived>
749 inline
750 void
752  conformation::Atom const & atom1,
753  conformation::Atom const & atom2,
754  Real const weight,
755  Real &atr,
756  Real &rep,
757  Real &solv,
758  Real &bb,
759  Real & d2
760 ) const
761 {
762  assert( ljatr_.active() );
763  bb = 0.0; //bead-bead interaction energy only in CoarseTable
764  int disbin; Real frac;
765  atr = rep = solv = bb = 0.0;
766  if (interpolate_bins(atom1,atom2,d2,disbin,frac)) {
767  // std::cerr << "atom_pair_energy... " << disbin << ' ' << d2 << ' ' << frac << ' ' << ljatr.size() << std::endl;
768  // l1 and l2 are FArray LINEAR INDICES for fast lookup:
769  // [ l1 ] == (disbin,attype2,attype1)
770  // [ l2 ] == (disbin2,attype2,attype1)
771 
772  int const l1 = ljatr_.index( disbin, atom1.type(), atom2.type()),
773  l2 = l1 + 1;
774 
775 
776  Real e1 = ljatr_[ l1 ];
777  atr = weight * ( e1 + frac * ( ljatr_[ l2 ] - e1 ) );
778 
779  e1 = ljrep_[ l1 ];
780  rep = weight * ( e1 + frac * ( ljrep_[ l2 ] - e1 ) );
781 
782  e1 = solv1_[ l1 ] + solv2_[ l1 ];
783  solv = weight * ( e1 + frac * ( solv1_[ l2 ] + solv2_[l2] - e1 ) );
784  // std::cout << "solv " << solv << std::endl;
785  // std::cerr << "finished evaluating atom _pair energy " << std::endl;
786  } //if within cutoff
787 }
788 
789 ///////////////////////////////////////////////////////////////////////////////
790 
791 //pba
792 template <class Derived>
793 inline
794 void
795 BaseEtableEnergy< Derived>::fast_memb_env_energy_(
796  conformation::Atom const & atom1,
797  int const attype1,
798  Real & mbenvE
799 ) const
800 {
801 
802  Vector const normal(MembraneEmbed_from_pose( pose ).normal());
803  Vector const center(MembraneEmbed_from_pose( pose ).center());
804  Real const center_FA(MembraneEmbed_from_pose( pose ).center_FA);
805  Real const thickness(MembraneEmbed_from_pose( pose ).thickness);
806  Real const steepness(MembraneEmbed_from_pose( pose ).steepness);
807 
808  Real z = dot(atom1.xyz(),normal)+30;
809  z = fabs(z-center_FA);
810  z /= thickness;
811  Real zn = std::pow( z, steepness );
812  Real f = zn/(1 + zn);
813  mbenvE = (1 - f) * (memb_lk_dgrefce(attype1) - lk_dgrefce(attype1));
814 }
815 ///////////////////////////////////////////////////////////////////////////////
816 
817 //pba
818 template <class Derived>
819 inline
820 void
822  conformation::Atom const & atom1,
823  conformation::Atom const & atom2,
824  Real const weight,
825  Real &atr,
826  Real &rep,
827  Real &solv,
828  Real &bb,
829  Real & d2
830 ) const
831 {
832  assert( ljatr_.active() );
833  bb = 0.0; //bead-bead interaction energy only in CoarseTable
834  int disbin; Real frac;
835  atr = rep = solv = bb = 0.0;
836  if (interpolate_bins(atom1,atom2,d2,disbin,frac)) {
837  // std::cerr << "atom_pair_energy... " << disbin << ' ' << d2 << ' ' << frac << ' ' << ljatr.size() << std::endl;
838  // l1 and l2 are FArray LINEAR INDICES for fast lookup:
839  // [ l1 ] == (disbin,attype2,attype1)
840  // [ l2 ] == (disbin2,attype2,attype1)
841 
842  int const l1 = ljatr_.index( disbin, atom1.type(), atom2.type()),
843  l2 = l1 + 1;
844 
845 
846  Real e1 = ljatr_[ l1 ];
847  atr = weight * ( e1 + frac * ( ljatr_[ l2 ] - e1 ) );
848 
849  e1 = ljrep_[ l1 ];
850  rep = weight * ( e1 + frac * ( ljrep_[ l2 ] - e1 ) );
851 
852  //pba Membrane specific solvation
853 
854  Vector const normal(MembraneEmbed_from_pose( pose ).normal());
855  Vector const center(MembraneEmbed_from_pose( pose ).center());
856  Real const center_FA(MembraneEmbed_from_pose( pose ).center_FA);
857  Real const thickness(MembraneEmbed_from_pose( pose ).thickness);
858  Real const steepness(MembraneEmbed_from_pose( pose ).steepness);
859 
860  //pba solvation of atom1 based on its distance from the membrane center on the membrane normal
861 
862  Real z = dot(atom1.xyz(),normal)+30;
863  z = fabs(z-center_FA);
864  z /= thickness;
865  Real zn = std::pow( z, steepness );
866  Real f = zn/(1 + zn);
867 
868  e11 = f * solv1_[ l1 ] + (1 - f) * memb_solv1_[ l1 ];
869  e12 = f * solv1_[ l2 ] + (1 - f) * memb_solv1_[ l2 ];
870 
871  //pba solvation of atom2 based on its distance from the membrane center on the membrane normal
872 
873  z = dot(atom2.xyz(),normal)+30;
874  z = fabs(z-center_FA);
875  z /= thickness;
876  zn = std::pow( z, steepness );
877  f = zn/(1 + zn);
878 
879  e21 = f * solv2_[ l1 ] + (1 - f) * memb_solv2_[ l1 ];
880  e22 = f * solv2_[ l2 ] + (1 - f) * memb_solv2_[ l2 ];
881 
882  e1 = e11 + e21;
883  Real e2 = e12 + e22;
884 
885  solv = weight * ( e1 + frac * ( e2 - e1 ) );
886 
887  // std::cout << "solv " << solv << std::endl;
888  // std::cerr << "finished evaluating atom _pair energy " << std::endl;
889  } //if within cutoff
890 }
891 
892 ///////////////////////////////////////////////////////////////////////////////
893 template <class Derived>
894 inline
895 Real
897  conformation::Atom const & atom1,
898  conformation::Atom const & atom2,
899  EnergyMap const & weights,
900  Vector & f1,
901  Vector & f2
902 ) const
903 {
904  assert( dljatr_.active() );
905 
906  f1 = atom1.xyz().cross( atom2.xyz() );
907  f2 = atom1.xyz() - atom2.xyz();
908  Real d2,frac;
909  int disbin;
910 
911  if ( interpolate_bins(atom1,atom2,d2,disbin,frac) ) {
912  // l1 and l2 are FArray LINEAR INDICES for fast lookup:
913  // [ l1 ] == (disbin ,attype2,attype1)
914  // [ l2 ] == (disbin+1,attype2,attype1)
915 
916  Real deriv = 0.0;
917 
918  int const l1 = dljatr_.index( disbin, atom1.type(), atom2.type()),
919  l2 = l1 + 1;
920 
921  Real e1 = dljatr_[ l1 ];
922  deriv = weights[ st_atr_] * ( e1 + frac * ( dljatr_[ l2 ] - e1 ) );
923 
924  e1 = dljrep_[ l1 ];
925  deriv += weights[ st_rep_ ] * ( e1 + frac * ( dljrep_[ l2 ] - e1 ) );
926 
927  //pba Membrane specific solvation
928 
929  Vector const normal(MembraneEmbed_from_pose( pose ).normal());
930  Vector const center(MembraneEmbed_from_pose( pose ).center());
931  Real const center_FA(MembraneEmbed_from_pose( pose ).center_FA);
932  Real const thickness(MembraneEmbed_from_pose( pose ).thickness);
933  Real const steepness(MembraneEmbed_from_pose( pose ).steepness);
934 
935  //pba solvation of atom1 based on its distance from the membrane center on the membrane normal
936 
937  Real z = dot(atom1.xyz(),normal)+30;
938  z = fabs(z-center_FA);
939  z /= thickness;
940  Real zn = std::pow( z, steepness );
941  Real f = zn/(1 + zn);
942 
943  e1 = f * dsolv1_[ l1 ] + (1 - f) * memb_dsolv1_[ l1 ];
944 
945  //pba solvation of atom2 based on its distance from the membrane center on the membrane normal
946 
947  z = dot(atom2.xyz(),normal)+30;
948  z = fabs(z-center_FA);
949  z /= thickness;
950  zn = std::pow( z, steepness );
951  f = zn/(1 + zn);
952 
953  Real e2 = f * dsolv2_[ l2 ] + (1 - f) * memb_dsolv2_[ l2 ];
954 
955  deriv += weights[ st_sol_ ] * ( e1 + frac * ( e2 - e1 ) );
956 
957  return deriv / std::sqrt( d2 );
958  } else {
959  return 0.0;
960  }
961 }
962 
963 
964 ///////////////////////////////////////////////////////////////////////////////
965 template <class Derived>
966 inline
967 Real
969  conformation::Atom const & atom1,
970  conformation::Atom const & atom2,
971  EnergyMap const & weights,
972  Vector & f1,
973  Vector & f2
974 ) const
975 {
976  assert( dljatr_.active() );
977 
978  f1 = atom1.xyz().cross( atom2.xyz() );
979  f2 = atom1.xyz() - atom2.xyz();
980  Real d2,frac;
981  int disbin;
982 
983  if ( interpolate_bins(atom1,atom2,d2,disbin,frac) ) {
984  // l1 and l2 are FArray LINEAR INDICES for fast lookup:
985  // [ l1 ] == (disbin ,attype2,attype1)
986  // [ l2 ] == (disbin+1,attype2,attype1)
987 
988  Real deriv = 0.0;
989 
990  int const l1 = dljatr_.index( disbin, atom1.type(), atom2.type()),
991  l2 = l1 + 1;
992 
993  Real e1 = dljatr_[ l1 ];
994  deriv = weights[ st_atr_] * ( e1 + frac * ( dljatr_[ l2 ] - e1 ) );
995 
996  e1 = dljrep_[ l1 ];
997  deriv += weights[ st_rep_ ] * ( e1 + frac * ( dljrep_[ l2 ] - e1 ) );
998 
999  e1 = dsolv_[ l1 ];
1000  deriv += weights[ st_sol_ ] * ( e1 + frac * ( dsolv_[ l2 ] - e1 ) );
1001 
1002 
1003  return deriv / std::sqrt( d2 );
1004  } else {
1005  return 0.0;
1006  }
1007 }
1008 
1009 
1010 template < class Derived >
1011 inline
1012 void
1014  conformation::Atom const & atom1,
1015  conformation::Atom const & atom2,
1016  Real weight,
1017  EnergyMap &emap
1018 ) const {
1019  Energy atr(0.0);
1020  Energy rep(0.0);
1021  Energy solv(0.0);
1022  Energy bb(0.0);
1023  pair_energy_H(atom1,atom2,weight,atr,rep,solv,bb);
1024  emap[st_atr_]+=atr;
1025  emap[st_rep_]+=rep;
1026  emap[st_sol_]+=solv;
1027  emap[ coarse_beadlj ]+=bb;
1028 }
1029 
1030 
1031 
1032 ///////////////////////////////////////////////////////////////////////////////
1033 template < class Derived >
1034 inline
1035 void
1037  conformation::Atom const & atom1,
1038  conformation::Atom const & atom2,
1039  Real const weight,
1040  Real &atr,
1041  Real &rep,
1042  Real &solv,
1043  Real &bb
1044 ) const
1045 {
1046  assert( ljrep_.active() );
1047  Real d2,frac;
1048  int disbin;
1049  atr = rep = solv = bb = 0.0;
1050  if (interpolate_bins(atom1,atom2,d2,disbin,frac)) {
1051 //ctsa
1052 //ctsa tables have been hacked so that if disbin2 = lastbin, all values = 0.
1053 //ctsa
1054 
1055  // l is an FArray LINEAR INDICES for fast lookup:
1056  // [ ll ] == (disbin,attype2,attype1)
1057 
1058  int l1 = ljrep_.index( disbin, atom1.type(), atom2.type() );
1059  int l2 = l1+1;
1060 
1061  Real const rep_e1( ljrep_[ l1 ] );
1062  rep = weight * ( rep_e1 + frac * ( ljrep_[ l2 ] - rep_e1 ) );
1063 
1064  Real const atr_e1 = ljatr_[ l1 ];
1065  atr = weight * ( atr_e1 + frac * ( ljatr_[ l2 ] - atr_e1 ) );
1066  // std::cerr << __FILE__<< ' ' << __LINE__ << std::endl;
1067  }
1068 }
1069 
1070 } // etable
1071 } // scoring
1072 } // core
1073 
1074 
1075 #endif // INCLUDED_core_scoring_EtableEnergy_HH