Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
EtableEnergy.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 // (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/ScoreFunction.hh
11 /// @brief Score function class
12 /// @author Phil Bradley
13 
14 
15 #ifndef INCLUDED_core_scoring_etable_EtableEnergy_hh
16 #define INCLUDED_core_scoring_etable_EtableEnergy_hh
17 
18 // Unit headers
20 
22 
23 
24 // Package headers
27 
29 
30 #include <utility/vector1.hh>
31 
32 
33 
34 namespace core {
35 namespace scoring {
36 namespace etable {
37 
38 
39 //////////////////// Evaluators ///////////////////////////////
40 
41 
43 {
44 public:
45  EtableEvaluator( Etable const & etable );
47 
48  void
50  EnergyMap const & weights
51  ) {
52  atr_weight_ = weights[ st_atr_ ];
53  rep_weight_ = weights[ st_rep_ ];
54  sol_weight_ = weights[ st_sol_ ];
55  }
56 
57  void
59  ScoreType st_atr_in,
60  ScoreType st_rep_in,
61  ScoreType st_sol_in
62  )
63  {
64  st_atr_ = st_atr_in;
65  st_rep_ = st_rep_in;
66  st_sol_ = st_sol_in;
67  }
68 
69 
70  inline Real atr_weight() const { return atr_weight_; }
71  inline Real rep_weight() const { return rep_weight_; }
72  inline Real sol_weight() const { return sol_weight_; }
73 
74  inline ScoreType st_atr() const { return st_atr_; }
75  inline ScoreType st_rep() const { return st_rep_; }
76  inline ScoreType st_sol() const { return st_sol_; }
77 
78  inline
79  Energy
80  sum_energies( Real atr, Real rep, Real solv ) const {
81  return
82  atr_weight_ * atr +
83  rep_weight_ * rep +
84  sol_weight_ * solv;
85  }
86  inline
87  Real
89  {
91  }
92 
93 private:
94 
98 
99  /// score types: could be either fa_atr/fa_atr_intra, etc.
103 
105 };
106 
107 
108 
110 {
111 public:
112  AnalyticEtableEvaluator( Etable const & etable );
114 
115  /// Atom pair energy inline type resolution functions
116  void
118  conformation::Residue const & rsd1,
119  conformation::Residue const & rsd2,
121  EnergyMap & emap
122  ) const;
123 
124  void
126  conformation::Residue const & rsd1,
127  conformation::Residue const & rsd2,
129  EnergyMap & emap
130  ) const;
131 
132  void
134  conformation::Residue const & rsd1,
135  conformation::Residue const & rsd2,
137  EnergyMap & emap
138  ) const;
139 
140  void
142  conformation::Residue const & rsd1,
143  conformation::Residue const & rsd2,
145  EnergyMap & emap
146  ) const;
147 
148  void
150  conformation::Residue const & rsd1,
151  conformation::Residue const & rsd2,
153  EnergyMap & emap
154  ) const;
155 
156  /// Trie vs trie / trie vs path type resolution functions
157 
158  void
159  trie_vs_trie(
160  trie::RotamerTrieBase const & trie1,
161  trie::RotamerTrieBase const & trie2,
163  ObjexxFCL::FArray2D< core::PackerEnergy > & pair_energy_table,
164  ObjexxFCL::FArray2D< core::PackerEnergy > & temp_table
165  ) const;
166 
167  void
168  trie_vs_path(
169  trie::RotamerTrieBase const & trie1,
170  trie::RotamerTrieBase const & trie2,
172  utility::vector1< core::PackerEnergy > & pair_energy_vector,
174  ) const;
175 
176 // void
177 // atom_pair_energy_v(
178 // conformation::Atom const & atom1,
179 // conformation::Atom const & atom2,
180 // Real const weight,
181 // EnergyMap & emap,
182 // Real & d2
183 // ) const
184 // {
185 // atom_pair_energy( atom1, atom2, weight, emap, d2 );
186 // }
187 
188  inline
189  void
191  conformation::Atom const & atom1,
192  conformation::Atom const & atom2,
193  Real const weight,
194  EnergyMap & emap,
195  Real & d2
196  ) const
197  {
198  Real atr(0),rep(0),solv(0);
199  atom_pair_energy( atom1, atom2, weight, atr, rep, solv, d2 );
200  emap[st_atr()]+=atr;
201  emap[st_rep()]+=rep;
202  emap[st_sol()]+=solv;
203  }
204 
205  virtual
206  void
208  conformation::Atom const & atom1,
209  conformation::Atom const & atom2,
210  Real const weight,
211  Real & atrE,
212  Real & repE,
213  Real & solE,
214  Real & d2
215  ) const {
216  atom_pair_energy( atom1, atom2, weight, atrE, repE, solE, d2 );
217  }
218 
219 
220  inline
221  void
223  conformation::Atom const & atom1,
224  conformation::Atom const & atom2,
225  Real const weight,
226  Real &atr,
227  Real &rep,
228  Real &solv,
229  Real & d2
230  ) const;
231 
232  inline
233  void
235  conformation::Atom const & atom1,
236  conformation::Atom const & atom2,
237  Real const weight,
238  EnergyMap & emap
239  ) const
240  {
241  Real atr(0), rep(0), sol(0), d2(0);
242  atom_pair_energy( atom1, atom2, weight, atr, rep, sol, d2 );
243  emap[ st_atr() ] += atr;
244  emap[ st_rep() ] += rep;
245  emap[ st_sol() ] += sol;
246  }
247 
248  inline
249  Real
251  conformation::Atom const & atom1,
252  conformation::Atom const & atom2,
253  EnergyMap const & weights,
254  Vector & f1,
255  Vector & f2
256  ) const;
257 
258  /// Inline Methods For Trie-vs-Trie Algorithm
259  inline
261  etrie::EtableAtom const & at1,
262  etrie::EtableAtom const & at2,
263  DistanceSquared & d2,
264  Size & /*path_dist*/
265  ) const
266  {
267  Energy atr(0.0), rep(0.0), solv(0.0);
268  atom_pair_energy( at1, at2, 1.0, atr, rep, solv, d2 );
269  return sum_energies( atr, rep, solv );
270  }
271 
272  inline
274  etrie::EtableAtom const & at1,
275  etrie::EtableAtom const & at2,
276  Size & /*path_dist*/
277  ) const
278  {
279  Energy atr(0.0), rep(0.0), solv(0.0), d2dummy(0.0);
280  atom_pair_energy( at1, at2, 1.0, atr, rep, solv, d2dummy );
281  return sum_energies( atr, rep, solv );
282  }
283 
284  inline
286  etrie::EtableAtom const & at1,
287  etrie::EtableAtom const & at2,
288  Size & /*path_dist*/
289  ) const
290  {
291  Energy atr(0.0), rep(0.0), solv(0.0), d2dummy(0.0);
292  atom_pair_energy( at1, at2, 1.0, atr, rep, solv, d2dummy );
293  return sum_energies( atr, rep, solv );
294  }
295 
296  inline
298  etrie::EtableAtom const & at1,
299  etrie::EtableAtom const & at2,
300  Size & /*path_dist*/
301  ) const
302  {
303  Energy atr(0.0), rep(0.0), solv(0.0), d2dummy(0.0);
304  atom_pair_energy( at1, at2, 1.0, atr, rep, solv, d2dummy );
305  return sum_energies( atr, rep, solv );
306  }
307 
308 
309 private:
310 
311  Etable const & etable_;
313 
314 };
315 
316 
318 {
319 public:
320  TableLookupEvaluator( Etable const & etable_in );
322 
323  /// Atom pair energy inline type resolution functions
324  void
326  conformation::Residue const & rsd1,
327  conformation::Residue const & rsd2,
329  EnergyMap & emap
330  ) const;
331 
332  void
334  conformation::Residue const & rsd1,
335  conformation::Residue const & rsd2,
337  EnergyMap & emap
338  ) const;
339 
340  void
342  conformation::Residue const & rsd1,
343  conformation::Residue const & rsd2,
345  EnergyMap & emap
346  ) const;
347 
348  void
350  conformation::Residue const & rsd1,
351  conformation::Residue const & rsd2,
353  EnergyMap & emap
354  ) const;
355 
356  void
358  conformation::Residue const & rsd1,
359  conformation::Residue const & rsd2,
361  EnergyMap & emap
362  ) const;
363 
364  /// Trie vs trie / trie vs path type resolution functions
365  void
366  trie_vs_trie(
367  trie::RotamerTrieBase const & trie1,
368  trie::RotamerTrieBase const & trie2,
370  ObjexxFCL::FArray2D< core::PackerEnergy > & pair_energy_table,
371  ObjexxFCL::FArray2D< core::PackerEnergy > & temp_table
372  ) const;
373 
374  void
375  trie_vs_path(
376  trie::RotamerTrieBase const & trie1,
377  trie::RotamerTrieBase const & trie2,
379  utility::vector1< core::PackerEnergy > & pair_energy_vector,
381  ) const;
382 
383  void
385  conformation::Atom const & atom1,
386  conformation::Atom const & atom2,
387  Real const weight,
388  EnergyMap & emap,
389  Real & d2
390  ) const
391  {
392  atom_pair_energy( atom1, atom2, weight, emap, d2 );
393  }
394 
395  inline
396  void
398  conformation::Atom const & atom1,
399  conformation::Atom const & atom2,
400  Real const weight,
401  EnergyMap & emap,
402  Real & d2
403  ) const
404  {
405  Real atr(0),rep(0),solv(0);
406  atom_pair_energy( atom1, atom2, weight, atr, rep, solv, d2 );
407  emap[st_atr()]+=atr;
408  emap[st_rep()]+=rep;
409  emap[st_sol()]+=solv;
410  }
411 
412 // virtual
413 // void
414 // atom_pair_energy_v(
415 // conformation::Atom const & atom1,
416 // conformation::Atom const & atom2,
417 // Real const weight,
418 // Real & atrE,
419 // Real & repE,
420 // Real & solE,
421 // Real & d2
422 // ) const {
423 // atom_pair_energy( atom1, atom2, weight, atrE, repE, solE, d2 );
424 // }
425 
426  inline
427  void
429  conformation::Atom const & atom1,
430  conformation::Atom const & atom2,
431  Real const weight,
432  Real &atr,
433  Real &rep,
434  Real &solv,
435  Real & d2
436  ) const;
437 
438  inline
439  Real
441  conformation::Atom const & atom1,
442  conformation::Atom const & atom2,
443  EnergyMap const & weights,
444  Vector & f1,
445  Vector & f2
446  ) const;
447 
448 
449  /// Inline Methods For Trie-vs-Trie Algorithm
450  inline
452  etrie::EtableAtom const & at1,
453  etrie::EtableAtom const & at2,
454  DistanceSquared & d2,
455  Size & /*path_dist*/
456  ) const
457  {
458  Energy atr(0.0), rep(0.0), solv(0.0);
459  atom_pair_energy( at1, at2, 1.0, atr, rep, solv, d2 );
460  return sum_energies( atr, rep, solv );
461  }
462 
463  inline
465  etrie::EtableAtom const & at1,
466  etrie::EtableAtom const & at2,
467  Size & /*path_dist*/
468  ) const
469  {
470  Energy atr(0.0), rep(0.0), solv(0.0);
471  pair_energy_H( at1, at2, 1.0, atr, rep, solv );
472  return sum_energies( atr, rep, solv );
473  }
474 
475  inline
477  etrie::EtableAtom const & at1,
478  etrie::EtableAtom const & at2,
479  Size & /*path_dist*/
480  ) const
481  {
482  Energy atr(0.0), rep(0.0), solv(0.0);
483  pair_energy_H( at1, at2, 1.0, atr, rep, solv );
484  return sum_energies( atr, rep, solv );
485  }
486 
487  inline
489  etrie::EtableAtom const & at1,
490  etrie::EtableAtom const & at2,
491  Size & /*path_dist*/
492  ) const
493  {
494  Energy atr(0.0), rep(0.0), solv(0.0);
495  pair_energy_H( at1, at2, 1.0, atr, rep, solv );
496  return sum_energies( atr, rep, solv );
497  }
498 
499  inline
500  void
502  conformation::Atom const & atom1,
503  conformation::Atom const & atom2,
504  Real const weight,
505  EnergyMap & emap
506  ) const
507  {
508  Real atr(0), rep(0), sol(0);
509  pair_energy_H( atom1, atom2, weight, atr, rep, sol );
510  emap[ st_atr() ] += atr;
511  emap[ st_rep() ] += rep;
512  emap[ st_sol() ] += sol;
513  }
514 
515  inline
516  void
518  conformation::Atom const & atom1,
519  conformation::Atom const & atom2,
520  Real const weight,
521  Real &atr,
522  Real &rep,
523  Real &solv
524  ) const;
525 
526 private:
527  bool
529  conformation::Atom const & atom1,
530  conformation::Atom const & atom2,
531  Real & d2,
532  int & disbin,
533  Real & frac
534  ) const;
535 
536 private:
537 
538  ObjexxFCL::FArray3D< Real > const & ljatr_;
539  ObjexxFCL::FArray3D< Real > const & ljrep_;
540  ObjexxFCL::FArray3D< Real > const & solv1_;
541  ObjexxFCL::FArray3D< Real > const & solv2_;
542  ObjexxFCL::FArray3D< Real > const & dljatr_;
543  ObjexxFCL::FArray3D< Real > const & dljrep_;
544  ObjexxFCL::FArray3D< Real > const & dsolv_;
545 
547 
550 
551 };
552 
553 
554 ///
555 class TableLookupEtableEnergy : public BaseEtableEnergy< TableLookupEtableEnergy > {
556 public:
559 
560 public:
563 
564 public:
565 
566  /// @brief construction with an etable
568  Etable const & etable_in,
569  methods::EnergyMethodOptions const & options
570  );
571 
572  /// @brief explicit copy constructor
574 
575  /// clone
577  clone() const;
578 
579  void
580  setup_for_scoring_(pose::Pose const& pose, scoring::ScoreFunction const&) const;
581 
582 
583  //
584  /////////////////////////////////////////////////////////////////////////////
585  // methods for ContextIndependentTwoBodyEnergies
586  /////////////////////////////////////////////////////////////////////////////
587 
588 
589  virtual
590  bool
591  defines_intrares_energy( EnergyMap const & /*weights*/ ) const;
592 
593  virtual
594  void
596  conformation::Residue const & rsd,
597  pose::Pose const & pose,
598  ScoreFunction const & sfxn,
599  EnergyMap & emap
600  ) const;
601 
602 public:
603 
604 // inline
605 // void
606 // derived_prepare_for_residue_pair(
607 // Size const res1,
608 // Size const res2,
609 // pose::Pose const &
610 // ) const;
611 //
614 
617 
618 private:
619  // bookkeeping variable -- are intra- or interresidue weights being using at the moment?
620  // don't bother to reset the BaseEtable's st_atr_, st_rep_, st_sol_ if possible.
621  //mutable bool using_interres_scoretypes_;
622 
623  virtual
624  core::Size version() const;
625 
628 
629 };
630 
631 class AnalyticEtableEnergy : public BaseEtableEnergy< AnalyticEtableEnergy > {
632 public:
635 
636 public:
639 
640 public:
641 
642  /// @brief construction with an etable
644  Etable const & etable_in,
645  methods::EnergyMethodOptions const & options
646  );
647 
648  /// @brief explicit copy constructor
650 
651  /// clone
653  clone() const;
654 
655  void
656  setup_for_scoring_(pose::Pose const& pose, scoring::ScoreFunction const&) const;
657 
658 
659  //
660  /////////////////////////////////////////////////////////////////////////////
661  // methods for ContextIndependentTwoBodyEnergies
662  /////////////////////////////////////////////////////////////////////////////
663 
664 
665  virtual
666  bool
667  defines_intrares_energy( EnergyMap const & /*weights*/ ) const;
668 
669  virtual
670  void
672  conformation::Residue const & rsd,
673  pose::Pose const & pose,
674  ScoreFunction const & sfxn,
675  EnergyMap & emap
676  ) const;
677 
678 public:
679 
680 // inline
681 // void
682 // derived_prepare_for_residue_pair(
683 // Size const res1,
684 // Size const res2,
685 // pose::Pose const &
686 // ) const;
687 
690 
693 
694 private:
695  // bookkeeping variable -- are intra- or interresidue weights being using at the moment?
696  // don't bother to reset the BaseEtable's st_atr_, st_rep_, st_sol_ if possible.
697  //mutable bool using_interres_scoretypes_;
698 
699  virtual
700  core::Size version() const;
701 
704 
705 
706 };
707 
708 
709 /*class EtableEnergyEvaluator
710 {
711 public:
712  // default ctor -- set inter-residue score types
713  EtableEnergyEvaluator( EtableEnergy const & etable_energy ) :
714  etable_energy_( etable_energy ),
715  st_atr_( fa_atr ),
716  st_rep_( fa_rep ),
717  st_sol_( fa_sol )
718  {}
719 
720  // switch to intra-res mode
721  void set_intrares() {
722  st_atr_ = fa_intra_atr;
723  st_rep_ = fa_intra_rep;
724  st_sol_ = fa_intra_sol;
725  }
726 
727 public:
728 
729  Real
730  hydrogen_interaction_cutoff2() const {
731  return etable_energy_.hydrogen_interaction_cutoff2();
732  }
733 
734  void
735  pair_energy_H(
736  Atom const & at1,
737  Atom const & at2,
738  Real const & cp_weight,
739  EnergyMap & emap
740  ) const;
741 
742  void
743  atom_pair_energy(
744  Atom const & at1,
745  Atom const & at2,
746  Real const & cp_weight,
747  EnergyMap & emap,
748  Real & dsq
749  ) const;
750 
751 
752 private:
753  EtableEnergy const & etable_energy_;
754  ScoreType st_atr_;
755  ScoreType st_rep_;
756  ScoreType st_sol_;
757 };*/
758 
759 ///////////////////////////////////////////////////////////////////////////////
760 // inline methods
761 ///////////////////////////////////////////////////////////////////////////////
762 
763 /// @brief decide between intra and interresidue score terms. Pseudo polymorphic call
764 /// from base class
765 //inline
766 //void
767 //TableLookupEtableEnergy::derived_prepare_for_residue_pair(
768 // Size const res1,
769 // Size const res2,
770 // pose::Pose const &
771 //) const {
772 //
773 // if ( res1 == res2 ) {
774 // if ( using_interres_scoretypes_ ) {
775 // //std::cout << "setting intaresidue scoretypes for residue " << res1 << std::endl;
776 // //set_scoretypes( fa_intra_atr, fa_intra_rep, fa_intra_sol );
777 // etable_evaluator()->set_scoretypes( fa_intra_atr, fa_intra_rep, fa_intra_sol );
778 // using_interres_scoretypes_ = false;
779 // }
780 // assert( etable_evaluator()->st_rep() == fa_intra_rep );
781 // } else {
782 // if ( ! using_interres_scoretypes_ ) {
783 // //std::cout << "setting interresidue scoretypes for residue pair " << res1 << " & " << res2 << std::endl;
784 // //set_scoretypes( fa_atr, fa_rep, fa_sol );
785 // etable_evaluator()->set_scoretypes( fa_atr, fa_rep, fa_sol );
786 // using_interres_scoretypes_ = true;
787 // }
788 // assert( etable_evaluator()->st_rep() == fa_rep );
789 // }
790 //
791 //}
792 
793 // TableLookupEvaluator's inline methods
794 inline
795 bool
797  conformation::Atom const & atom1,
798  conformation::Atom const & atom2,
799  Real & d2,
800  int & disbin,
801  Real & frac
802 ) const
803 {
804  d2 = atom1.xyz().distance_squared( atom2.xyz() );
805 
806  if ( ( d2 >= safe_max_dis2_ ) || ( d2 == Real(0.0) ) ) {
807  return false;
808  }
809 
810  // bin by distance:
811  Real const d2_bin = d2 * etable_bins_per_A2_;
812  disbin = static_cast< int >( d2_bin ) + 1;
813  // int const disbin2 = disbin + 1;
814  frac = d2_bin - ( disbin - 1 );
815  return true;
816  //ctsa
817  //ctsa tables have been hacked so that if disbin2 = lastbin, all values = 0.
818  //ctsa
819 }
820 
821 inline
822 void
824  conformation::Atom const & atom1,
825  conformation::Atom const & atom2,
826  Real const weight,
827  Real & atr,
828  Real & rep,
829  Real & solv,
830  Real & d2
831 ) const
832 {
833  assert( ljatr_.active() );
834  int disbin; Real frac;
835  atr = rep = solv = 0.0;
836 
837  if (interpolate_bins(atom1,atom2,d2,disbin,frac)) {
838 
839  // std::cerr << "atom_pair_energy... " << disbin << ' ' << d2 << ' ' << frac << ' ' << ljatr.size() << std::endl;
840  // l1 and l2 are FArray LINEAR INDICES for fast lookup:
841  // [ l1 ] == (disbin,attype2,attype1)
842  // [ l2 ] == (disbin2,attype2,attype1)
843 
844  int const l1 = ljatr_.index( disbin, atom1.type(), atom2.type()),
845  l2 = l1 + 1;
846 
847  Real e1 = ljatr_[ l1 ];
848  atr = weight * ( e1 + frac * ( ljatr_[ l2 ] - e1 ) );
849 
850  e1 = ljrep_[ l1 ];
851  rep = weight * ( e1 + frac * ( ljrep_[ l2 ] - e1 ) );
852 
853  e1 = solv1_[ l1 ] + solv2_[ l1 ];
854  solv = weight * ( e1 + frac * ( solv1_[ l2 ] + solv2_[l2] - e1 ) );
855  // std::cout << "solv " << solv << std::endl;
856  // std::cerr << "finished evaluating atom _pair energy " << std::endl;
857 
858  } //if within cutoff
859 
860 }
861 
862 inline
863 void
865  conformation::Atom const & atom1,
866  conformation::Atom const & atom2,
867  Real const weight,
868  Real &atr,
869  Real &rep,
870  Real &solv
871 ) const
872 {
873  assert( ljrep_.active() );
874  Real d2,frac;
875  int disbin;
876  atr = rep = solv = 0.0;
877 
878  if (interpolate_bins(atom1,atom2,d2,disbin,frac)) {
879 
880  //ctsa
881  //ctsa tables have been hacked so that if disbin2 = lastbin, all values = 0.
882  //ctsa
883 
884  // l is an FArray LINEAR INDICES for fast lookup:
885  // [ ll ] == (disbin,attype2,attype1)
886 
887  int l1 = ljrep_.index( disbin, atom1.type(), atom2.type() );
888  int l2 = l1+1;
889 
890  Real const rep_e1( ljrep_[ l1 ] );
891  rep = weight * ( rep_e1 + frac * ( ljrep_[ l2 ] - rep_e1 ) );
892 
893  Real const atr_e1 = ljatr_[ l1 ];
894  atr = weight * ( atr_e1 + frac * ( ljatr_[ l2 ] - atr_e1 ) );
895  // std::cerr << __FILE__<< ' ' << __LINE__ << std::endl;
896 
897  }
898 }
899 
900 Real
902  conformation::Atom const & atom1,
903  conformation::Atom const & atom2,
904  EnergyMap const & weights,
905  Vector & f1,
906  Vector & f2
907 ) const
908 {
909  Real d2,frac;
910  int disbin;
911 
912  if ( atom1.xyz().distance_squared( atom2.xyz() ) > safe_max_dis2_ ) return 0.;
913 
914  if ( interpolate_bins(atom1,atom2,d2,disbin,frac) ) {
915 
916 
917  f1 = atom1.xyz().cross( atom2.xyz() );
918  f2 = atom1.xyz() - atom2.xyz();
919 
920  // l1 and l2 are FArray LINEAR INDICES for fast lookup:
921  // [ l1 ] == (disbin ,attype2,attype1)
922  // [ l2 ] == (disbin+1,attype2,attype1)
923 
924  /// BEGIN DERIVATIVE INTERPOLATION
925  Real deriv = 0.0;
926 
927  int const l1 = dljatr_.index( disbin, atom1.type(), atom2.type()),
928  l2 = l1 + 1;
929 
930  Real e1 = dljatr_[ l1 ];
931  deriv = weights[ st_atr() ] * ( e1 + frac * ( dljatr_[ l2 ] - e1 ) );
932 
933  e1 = dljrep_[ l1 ];
934  deriv += weights[ st_rep() ] * ( e1 + frac * ( dljrep_[ l2 ] - e1 ) );
935 
936  e1 = dsolv_[ l1 ];
937  deriv += weights[ st_sol() ] * ( e1 + frac * ( dsolv_[ l2 ] - e1 ) );
938 
939  return deriv / std::sqrt( d2 );
940  /// END DERIVATIVE INTERPOLATION
941 
942  /// BEGIN EXACT DERIVATIVE CALCULATION
943 
944  /*Real deriv( 0.0 );
945  int const l1 = ljatr_.index( disbin, atom1.type(), atom2.type()),
946  l2 = l1 + 1;
947 
948  // d g(x) / dx with g(x) = x^2 ---> 2x; x is the distance
949  // we want to avoid the sqrt. Since at1-at2 (f2) already is the right length, consider it pre-multiplied by sqrt(d2).
950  // so what we have below is 2x / ( d2step * x ) = 2 / d2step = 2 * inv(d2step). This will be multiplied by the un-normalized f1 and f2 vectors.
951  Real dxsquared_dx_times_x2step_over_x = 2 * etable_bins_per_A2;
952 
953  Real const atr1 = ljatr_[ l1 ];
954  Real const atr2 = ljatr_[ l2 ];
955  Real const rep1 = ljrep_[ l1 ];
956  Real const rep2 = ljrep_[ l2 ];
957  Real const sol1 = solv1_[ l1 ] + solv2_[ l1 ];
958  Real const sol2 = solv1_[ l2 ] + solv2_[ l2 ];
959 
960  deriv = weights[ st_atr_ ] * ( atr2 - atr1 );
961  deriv += weights[ st_rep_ ] * ( rep2 - rep1 );
962  deriv += weights[ st_sol_ ] * ( sol2 - sol1 );
963 
964  return deriv * dxsquared_dx_times_x2step_over_x;*/
965 
966  /// TEMP
967  /*
968  std::cout << "Testing numerically: ";
969  Real f11( 0.0 );
970  Real step = 0.00001;
971  {// scope
972  Real altd = std::sqrt( d2 ) - step;
973  Real altd2 = altd*altd;
974  Real altfrac = ( altd2 * etable_bins_per_A2 - ( disbin - 1 ) );
975  int const altl1 = ljatr_.index( disbin, atom1.type(), atom2.type()),
976  altl2 = altl1 + 1;
977 
978 
979  Real e1 = ljatr_[ altl1 ];
980  f11 = weights[ st_atr_ ] * ( e1 + altfrac * ( ljatr_[ altl2 ] - e1 ) );
981 
982  e1 = ljrep_[ altl1 ];
983  f11 += weights[ st_rep_ ] * ( e1 + altfrac * ( ljrep_[ altl2 ] - e1 ) );
984 
985  e1 = solv1_[ altl1 ] + solv2_[ altl1 ];
986  f11 += weights[ st_sol_ ] * ( e1 + altfrac * ( solv1_[ altl2 ] + solv2_[altl2] - e1 ) );
987  }
988 
989  Real f22(0.0);
990  {// scope
991  Real altd = std::sqrt( d2 ) + step;
992  Real altd2 = altd*altd;
993  Real altfrac = ( altd2 * etable_bins_per_A2 - ( disbin - 1 ) );
994  int const altl1 = ljatr_.index( disbin, atom1.type(), atom2.type()),
995  altl2 = altl1 + 1;
996 
997 
998  Real e1 = ljatr_[ altl1 ];
999  f22 = weights[ st_atr_ ] * ( e1 + altfrac * ( ljatr_[ altl2 ] - e1 ) );
1000 
1001  e1 = ljrep_[ altl1 ];
1002  f22 += weights[ st_rep_ ] * ( e1 + altfrac * ( ljrep_[ altl2 ] - e1 ) );
1003 
1004  e1 = solv1_[ altl1 ] + solv2_[ altl1 ];
1005  f22 += weights[ st_sol_ ] * ( e1 + altfrac * ( solv1_[ altl2 ] + solv2_[altl2] - e1 ) );
1006  }
1007  std::cout << "Deriv discrep: " << ( f22 - f11 ) / (2 * step ) << " vs " << deriv * dxsquared_dx_times_x2step_over_x * std::sqrt( d2 ) << std::endl;
1008  */
1009 
1010  } else {
1011  return 0.0;
1012  }
1013 }
1014 
1015 
1016 /// AnalyticEtableEvaluator inline methods.
1017 
1018 void
1020  conformation::Atom const & atom1,
1021  conformation::Atom const & atom2,
1022  Real const weight,
1023  Real & atr,
1024  Real & rep,
1025  Real & solv,
1026  Real & d2
1027 ) const
1028 {
1029  atr = rep = solv = 0.0;
1030 
1031  //etable_.interpolated_analytic_etable_evaluation( atom1, atom2, atr, rep, solv, d2 );
1032  etable_.analytic_etable_evaluation( atom1, atom2, atr, rep, solv, d2 );
1033  atr *= weight;
1034  rep *= weight;
1035  solv *= weight;
1036  return;
1037 }
1038 
1039 Real
1041  conformation::Atom const & atom1,
1042  conformation::Atom const & atom2,
1043  EnergyMap const & weights,
1044  Vector & f1,
1045  Vector & f2
1046 ) const
1047 {
1048  if ( atom1.xyz().distance_squared( atom2.xyz() ) > safe_max_dis2_ ) return 0.;
1049 
1050  f1 = atom1.xyz().cross( atom2.xyz() );
1051  f2 = atom1.xyz() - atom2.xyz();
1052 
1053  Real datr, drep, dsol, invd;
1054  etable_.analytic_etable_derivatives( atom1, atom2, datr, drep, dsol, invd );
1055  return ( weights[ st_atr() ] * datr + weights[ st_rep() ] * drep + weights[ st_sol() ] * dsol ) * invd;
1056 
1057 }
1058 
1059 
1060 } // methods
1061 } // scoring
1062 } // core
1063 
1064 
1065 #endif // INCLUDED_core_scoring_EtableEnergy_HH