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_etable_BaseMembEtableEnergy_hh
28 #define INCLUDED_core_scoring_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  bool
461  {
462  return true;
463  }
464 
465  virtual
466  void indicate_required_context_graphs( utility::vector1< bool > & /*context_graphs_required*/ ) const;
467 
468  /// Inline Methods For Trie-vs-Trie Algorithm
469  inline
470  Energy sum_energies ( Real atr, Real rep, Real solv, Real bb ) const {
471  return weights_[ st_atr_ ] * atr
472  + weights_[ st_rep_ ] * rep
473  + weights_[ st_sol_ ] * solv
474  + weights_ [ coarse_beadlj ] * bb;
475  }
476 
477  inline
479  etrie::EtableAtom const & at1,
480  etrie::EtableAtom const & at2,
481  DistanceSquared & d2
482  ) const
483  {
484  Energy atr(0.0), rep(0.0), solv(0.0), bb(0.0);
485  atom_pair_energy( at1, at2, 1.0, atr, rep, solv, bb, d2 );
486  return sum_energies( atr, rep, solv, bb );
487  }
488 
489  inline
491  etrie::EtableAtom const & at1,
492  etrie::EtableAtom const & at2
493  ) const
494  {
495  Energy atr(0.0), rep(0.0), solv(0.0), bb(0.0);
496  pair_energy_H( at1, at2, 1.0, atr, rep, solv, bb );
497  return sum_energies( atr, rep, solv, bb );
498  }
499 
500  inline
502  etrie::EtableAtom const & at1,
503  etrie::EtableAtom const & at2
504  ) const
505  {
506  Energy atr(0.0), rep(0.0), solv(0.0), bb(0.0);
507  pair_energy_H( at1, at2, 1.0, atr, rep, solv, bb );
508  return sum_energies( atr, rep, solv, bb );
509  }
510 
511  inline
513  etrie::EtableAtom const & at1,
514  etrie::EtableAtom const & at2
515  ) const
516  {
517  Energy atr(0.0), rep(0.0), solv(0.0), bb(0.0);
518  pair_energy_H( at1, at2, 1.0, atr, rep, solv, bb );
519  return sum_energies( atr, rep, solv, bb );
520  }
521 
522 protected: //protected methods that may be used by derived classes
525  conformation::RotamerSetBase const & set1,
526  conformation::RotamerSetBase const & set2,
527  pose::Pose const & pose,
528  ScoreFunction const & sfxn
529  ) const;
530 
533  conformation::Residue const & res1,
534  conformation::Residue const & res2,
537  pose::Pose const & pose,
538  ScoreFunction const & sfxn
539  ) const;
540 
541  /*count_pair::CPResidueConnectionType
542  determine_residue_connection(
543  conformation::Residue const & res1,
544  conformation::Residue const & res2,
545  pose::Pose const &
546  ) const;*/
547 
550  conformation::Residue const & res1,
551  conformation::Residue const & res2,
552  pose::Pose const &,
553  ScoreFunction const & sfxn
554  ) const;
555 
558  conformation::RotamerSetBase const & rotset,
559  pose::Pose const & pose // will be need to create tries for disulfides
560  ) const;
561 
564  conformation::RotamerSetBase const & rotset
565  ) const;
566 
569  conformation::RotamerSetBase const & rotset,
570  Size connection_type // HACK: 1 for lower connect, 2 for upper connect. Replace this with an enum(?)
571  ) const;
572 
573 
574 protected:
575  // implementation for quasi-virtual functions
576  // rename this derived_atom_pair_energy
577  inline
578  void
580  conformation::Atom const & atom1,
581  conformation::Atom const & atom2,
582  Real const weight,
583  Real &atr,
584  Real &rep,
585  Real &solv,
586  Real &bb,
587  Real & dsq
588  ) const;
589 
590  //pba implementation for quasi-virtual functions
591  // rename this derived_atom_pair_energy
592  inline
593  void
595  conformation::Atom const & atom1,
596  conformation::Atom const & atom2,
597  Real const weight,
598  Real &atr,
599  Real &rep,
600  Real &solv,
601  Real &bb,
602  Real & dsq
603  ) const;
604 
605  //pba
606  inline
607  void
609  conformation::Atom const & atom1,
610  int const attype1,
611  Real & mbenvE
612  ) const;
613 
614  ///
615  inline
616  void
618  conformation::Atom const & atom1,
619  conformation::Atom const & atom2,
620  Real const weight,
621  Real &atr,
622  Real &rep,
623  Real &solv,
624  Real &bb
625  ) const;
626 
627  ///
628  inline
629  Real
631  conformation::Atom const & atom1,
632  conformation::Atom const & atom2,
633  EnergyMap const & weights,
634  Vector & f1,
635  Vector & f2
636  ) const;
637 
638  ///pba
639  inline
640  Real
642  conformation::Atom const & atom1,
643  conformation::Atom const & atom2,
644  EnergyMap const & weights,
645  Vector & f1,
646  Vector & f2
647  ) const;
648 
649  void
651  Size const res1,
652  Size const res2,
653  pose::Pose const &
654  ) const
655  { //do nothing if the derived class does not override this method
656  }
657 
658 
659  //little helper methods for interpolation:
660  bool interpolate_bins(
661  conformation::Atom const & atom1,
662  conformation::Atom const & atom2,
663  Real &d2,
664  int &disbin,
665  Real &frac
666  ) const;
667 
668  void
670  ScoreType atr_type,
671  ScoreType rep_type,
672  ScoreType sol_type
673  ) const;
674 
675  ScoreType
676  rep_scoretype() const;
677 
678  /////////////////////////////////////////////////////////////////////////////
679  // data
680  /////////////////////////////////////////////////////////////////////////////
681 protected:
682  Etable const & etable_; // shouldn't this be a pointer? Reference count information is (dangerously) lost when
683  //a reference is taken, instead of a smart pointer. There's the potential for a dangling reference with this.
684 
685 private:
686  /// these guys are taken from the etable
687  ObjexxFCL::FArray3D< Real > const & ljatr_;
688  ObjexxFCL::FArray3D< Real > const & ljrep_;
689  ObjexxFCL::FArray3D< Real > const & solv1_;
690  ObjexxFCL::FArray3D< Real > const & solv2_;
691  ObjexxFCL::FArray3D< Real > const & dljatr_;
692  ObjexxFCL::FArray3D< Real > const & dljrep_;
693  ObjexxFCL::FArray3D< Real > const & dsolv_;
694  ObjexxFCL::FArray3D< Real > const & memb_solv1_; //pba
695  ObjexxFCL::FArray3D< Real > const & memb_solv2_; //pba
696  ObjexxFCL::FArray3D< Real > const & memb_dsolv_; //pba
698 
700 
702 
706 
707  // For use in the trie-vs-trie algorithm
708  // written to at the beginning of the evaluate_rotamer_pair_energies call (which is const)
710 
711  // temporary hack -- make this configurable/cleaner, Phil
712  bool exclude_DNA_DNA;
713 
714  // not clear that we need these:
715  //chemical::AtomTypeSet const * atom_set_ptr_; // for atomtype info
716 };
717 
718 
719 ///////////////////////////////////////////////////////////////////////////////
720 // inline methods
721 ///////////////////////////////////////////////////////////////////////////////
722 
723 
724 ///////////////////////////////////////////////////////////////////////////////
725 // inline methods
726 ///////////////////////////////////////////////////////////////////////////////
727 template < class Derived >
728 inline
729 bool
731  conformation::Atom const & atom1,
732  conformation::Atom const & atom2,
733  Real &d2,
734  int &disbin,
735  Real &frac
736 ) const
737 {
738  d2 = atom1.xyz().distance_squared( atom2.xyz() );
739 
740  if ( ( d2 >= safe_max_dis2 ) || ( d2 == Real(0.0) ) ) {
741  return false;
742  }
743 
744  // bin by distance:
745  Real const d2_bin = d2 * etable_bins_per_A2;
746  disbin = static_cast< int >( d2_bin ) + 1;
747 // int const disbin2 = disbin + 1;
748  frac = d2_bin - ( disbin - 1 );
749  return true;
750 //ctsa
751 //ctsa tables have been hacked so that if disbin2 = lastbin, all values = 0.
752 //ctsa
753 }
754 
755 template <class Derived>
756 inline
757 void
759  conformation::Atom const & atom1,
760  conformation::Atom const & atom2,
761  Real const weight,
762  Real &atr,
763  Real &rep,
764  Real &solv,
765  Real &bb,
766  Real & d2
767 ) const
768 {
769  assert( ljatr_.active() );
770  bb = 0.0; //bead-bead interaction energy only in CoarseTable
771  int disbin; Real frac;
772  atr = rep = solv = bb = 0.0;
773  if (interpolate_bins(atom1,atom2,d2,disbin,frac)) {
774  // std::cerr << "atom_pair_energy... " << disbin << ' ' << d2 << ' ' << frac << ' ' << ljatr.size() << std::endl;
775  // l1 and l2 are FArray LINEAR INDICES for fast lookup:
776  // [ l1 ] == (disbin,attype2,attype1)
777  // [ l2 ] == (disbin2,attype2,attype1)
778 
779  int const l1 = ljatr_.index( disbin, atom1.type(), atom2.type()),
780  l2 = l1 + 1;
781 
782 
783  Real e1 = ljatr_[ l1 ];
784  atr = weight * ( e1 + frac * ( ljatr_[ l2 ] - e1 ) );
785 
786  e1 = ljrep_[ l1 ];
787  rep = weight * ( e1 + frac * ( ljrep_[ l2 ] - e1 ) );
788 
789  e1 = solv1_[ l1 ] + solv2_[ l1 ];
790  solv = weight * ( e1 + frac * ( solv1_[ l2 ] + solv2_[l2] - e1 ) );
791  // std::cout << "solv " << solv << std::endl;
792  // std::cerr << "finished evaluating atom _pair energy " << std::endl;
793  } //if within cutoff
794 }
795 
796 ///////////////////////////////////////////////////////////////////////////////
797 
798 //pba
799 template <class Derived>
800 inline
801 void
803  conformation::Atom const & atom1,
804  int const attype1,
805  Real & mbenvE
806 ) const
807 {
808 
809  Vector const normal(MembraneEmbed_from_pose( pose ).normal());
810  Vector const center(MembraneEmbed_from_pose( pose ).center());
811  Real const center_FA(MembraneEmbed_from_pose( pose ).center_FA);
812  Real const thickness(MembraneEmbed_from_pose( pose ).thickness);
813  Real const steepness(MembraneEmbed_from_pose( pose ).steepness);
814 
815  Real z = dot(atom1.xyz(),normal)+30;
816  z = fabs(z-center_FA);
817  z /= thickness;
818  Real zn = std::pow( z, steepness );
819  Real f = zn/(1 + zn);
820  mbenvE = (1 - f) * (memb_lk_dgrefce(attype1) - lk_dgrefce(attype1));
821 }
822 ///////////////////////////////////////////////////////////////////////////////
823 
824 //pba
825 template <class Derived>
826 inline
827 void
829  conformation::Atom const & atom1,
830  conformation::Atom const & atom2,
831  Real const weight,
832  Real &atr,
833  Real &rep,
834  Real &solv,
835  Real &bb,
836  Real & d2
837 ) const
838 {
839  assert( ljatr_.active() );
840  bb = 0.0; //bead-bead interaction energy only in CoarseTable
841  int disbin; Real frac;
842  atr = rep = solv = bb = 0.0;
843  if (interpolate_bins(atom1,atom2,d2,disbin,frac)) {
844  // std::cerr << "atom_pair_energy... " << disbin << ' ' << d2 << ' ' << frac << ' ' << ljatr.size() << std::endl;
845  // l1 and l2 are FArray LINEAR INDICES for fast lookup:
846  // [ l1 ] == (disbin,attype2,attype1)
847  // [ l2 ] == (disbin2,attype2,attype1)
848 
849  int const l1 = ljatr_.index( disbin, atom1.type(), atom2.type()),
850  l2 = l1 + 1;
851 
852 
853  Real e1 = ljatr_[ l1 ];
854  atr = weight * ( e1 + frac * ( ljatr_[ l2 ] - e1 ) );
855 
856  e1 = ljrep_[ l1 ];
857  rep = weight * ( e1 + frac * ( ljrep_[ l2 ] - e1 ) );
858 
859  //pba Membrane specific solvation
860 
861  Vector const normal(MembraneEmbed_from_pose( pose ).normal());
862  Vector const center(MembraneEmbed_from_pose( pose ).center());
863  Real const center_FA(MembraneEmbed_from_pose( pose ).center_FA);
864  Real const thickness(MembraneEmbed_from_pose( pose ).thickness);
865  Real const steepness(MembraneEmbed_from_pose( pose ).steepness);
866 
867  //pba solvation of atom1 based on its distance from the membrane center on the membrane normal
868 
869  Real z = dot(atom1.xyz(),normal)+30;
870  z = fabs(z-center_FA);
871  z /= thickness;
872  Real zn = std::pow( z, steepness );
873  Real f = zn/(1 + zn);
874 
875  e11 = f * solv1_[ l1 ] + (1 - f) * memb_solv1_[ l1 ];
876  e12 = f * solv1_[ l2 ] + (1 - f) * memb_solv1_[ l2 ];
877 
878  //pba solvation of atom2 based on its distance from the membrane center on the membrane normal
879 
880  z = dot(atom2.xyz(),normal)+30;
881  z = fabs(z-center_FA);
882  z /= thickness;
883  zn = std::pow( z, steepness );
884  f = zn/(1 + zn);
885 
886  e21 = f * solv2_[ l1 ] + (1 - f) * memb_solv2_[ l1 ];
887  e22 = f * solv2_[ l2 ] + (1 - f) * memb_solv2_[ l2 ];
888 
889  e1 = e11 + e21;
890  Real e2 = e12 + e22;
891 
892  solv = weight * ( e1 + frac * ( e2 - e1 ) );
893 
894  // std::cout << "solv " << solv << std::endl;
895  // std::cerr << "finished evaluating atom _pair energy " << std::endl;
896  } //if within cutoff
897 }
898 
899 ///////////////////////////////////////////////////////////////////////////////
900 template <class Derived>
901 inline
902 Real
904  conformation::Atom const & atom1,
905  conformation::Atom const & atom2,
906  EnergyMap const & weights,
907  Vector & f1,
908  Vector & f2
909 ) const
910 {
911  assert( dljatr_.active() );
912 
913  f1 = atom1.xyz().cross( atom2.xyz() );
914  f2 = atom1.xyz() - atom2.xyz();
915  Real d2,frac;
916  int disbin;
917 
918  if ( interpolate_bins(atom1,atom2,d2,disbin,frac) ) {
919  // l1 and l2 are FArray LINEAR INDICES for fast lookup:
920  // [ l1 ] == (disbin ,attype2,attype1)
921  // [ l2 ] == (disbin+1,attype2,attype1)
922 
923  Real deriv = 0.0;
924 
925  int const l1 = dljatr_.index( disbin, atom1.type(), atom2.type()),
926  l2 = l1 + 1;
927 
928  Real e1 = dljatr_[ l1 ];
929  deriv = weights[ st_atr_] * ( e1 + frac * ( dljatr_[ l2 ] - e1 ) );
930 
931  e1 = dljrep_[ l1 ];
932  deriv += weights[ st_rep_ ] * ( e1 + frac * ( dljrep_[ l2 ] - e1 ) );
933 
934  //pba Membrane specific solvation
935 
936  Vector const normal(MembraneEmbed_from_pose( pose ).normal());
937  Vector const center(MembraneEmbed_from_pose( pose ).center());
938  Real const center_FA(MembraneEmbed_from_pose( pose ).center_FA);
939  Real const thickness(MembraneEmbed_from_pose( pose ).thickness);
940  Real const steepness(MembraneEmbed_from_pose( pose ).steepness);
941 
942  //pba solvation of atom1 based on its distance from the membrane center on the membrane normal
943 
944  Real z = dot(atom1.xyz(),normal)+30;
945  z = fabs(z-center_FA);
946  z /= thickness;
947  Real zn = std::pow( z, steepness );
948  Real f = zn/(1 + zn);
949 
950  e1 = f * dsolv1_[ l1 ] + (1 - f) * memb_dsolv1_[ l1 ];
951 
952  //pba solvation of atom2 based on its distance from the membrane center on the membrane normal
953 
954  z = dot(atom2.xyz(),normal)+30;
955  z = fabs(z-center_FA);
956  z /= thickness;
957  zn = std::pow( z, steepness );
958  f = zn/(1 + zn);
959 
960  Real e2 = f * dsolv2_[ l2 ] + (1 - f) * memb_dsolv2_[ l2 ];
961 
962  deriv += weights[ st_sol_ ] * ( e1 + frac * ( e2 - e1 ) );
963 
964  return deriv / std::sqrt( d2 );
965  } else {
966  return 0.0;
967  }
968 }
969 
970 
971 ///////////////////////////////////////////////////////////////////////////////
972 template <class Derived>
973 inline
974 Real
976  conformation::Atom const & atom1,
977  conformation::Atom const & atom2,
978  EnergyMap const & weights,
979  Vector & f1,
980  Vector & f2
981 ) const
982 {
983  assert( dljatr_.active() );
984 
985  f1 = atom1.xyz().cross( atom2.xyz() );
986  f2 = atom1.xyz() - atom2.xyz();
987  Real d2,frac;
988  int disbin;
989 
990  if ( interpolate_bins(atom1,atom2,d2,disbin,frac) ) {
991  // l1 and l2 are FArray LINEAR INDICES for fast lookup:
992  // [ l1 ] == (disbin ,attype2,attype1)
993  // [ l2 ] == (disbin+1,attype2,attype1)
994 
995  Real deriv = 0.0;
996 
997  int const l1 = dljatr_.index( disbin, atom1.type(), atom2.type()),
998  l2 = l1 + 1;
999 
1000  Real e1 = dljatr_[ l1 ];
1001  deriv = weights[ st_atr_] * ( e1 + frac * ( dljatr_[ l2 ] - e1 ) );
1002 
1003  e1 = dljrep_[ l1 ];
1004  deriv += weights[ st_rep_ ] * ( e1 + frac * ( dljrep_[ l2 ] - e1 ) );
1005 
1006  e1 = dsolv_[ l1 ];
1007  deriv += weights[ st_sol_ ] * ( e1 + frac * ( dsolv_[ l2 ] - e1 ) );
1008 
1009 
1010  return deriv / std::sqrt( d2 );
1011  } else {
1012  return 0.0;
1013  }
1014 }
1015 
1016 
1017 template < class Derived >
1018 inline
1019 void
1021  conformation::Atom const & atom1,
1022  conformation::Atom const & atom2,
1023  Real weight,
1024  EnergyMap &emap
1025 ) const {
1026  Energy atr(0.0);
1027  Energy rep(0.0);
1028  Energy solv(0.0);
1029  Energy bb(0.0);
1030  pair_energy_H(atom1,atom2,weight,atr,rep,solv,bb);
1031  emap[st_atr_]+=atr;
1032  emap[st_rep_]+=rep;
1033  emap[st_sol_]+=solv;
1034  emap[ coarse_beadlj ]+=bb;
1035 }
1036 
1037 
1038 
1039 ///////////////////////////////////////////////////////////////////////////////
1040 template < class Derived >
1041 inline
1042 void
1044  conformation::Atom const & atom1,
1045  conformation::Atom const & atom2,
1046  Real const weight,
1047  Real &atr,
1048  Real &rep,
1049  Real &solv,
1050  Real &bb
1051 ) const
1052 {
1053  assert( ljrep_.active() );
1054  Real d2,frac;
1055  int disbin;
1056  atr = rep = solv = bb = 0.0;
1057  if (interpolate_bins(atom1,atom2,d2,disbin,frac)) {
1058 //ctsa
1059 //ctsa tables have been hacked so that if disbin2 = lastbin, all values = 0.
1060 //ctsa
1061 
1062  // l is an FArray LINEAR INDICES for fast lookup:
1063  // [ ll ] == (disbin,attype2,attype1)
1064 
1065  int l1 = ljrep_.index( disbin, atom1.type(), atom2.type() );
1066  int l2 = l1+1;
1067 
1068  Real const rep_e1( ljrep_[ l1 ] );
1069  rep = weight * ( rep_e1 + frac * ( ljrep_[ l2 ] - rep_e1 ) );
1070 
1071  Real const atr_e1 = ljatr_[ l1 ];
1072  atr = weight * ( atr_e1 + frac * ( ljatr_[ l2 ] - atr_e1 ) );
1073  // std::cerr << __FILE__<< ' ' << __LINE__ << std::endl;
1074  }
1075 }
1076 
1077 } // etable
1078 } // scoring
1079 } // core
1080 
1081 
1082 #endif // INCLUDED_core_scoring_EtableEnergy_HH