Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
BaseEtableEnergy.tmpl.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/etable/EtableEnergy.cc
11 /// @brief Atom pair energy functions
12 /// @author Stuart G. Mentzer (Stuart_Mentzer@objexx.com)
13 /// @author Kevin P. Hinshaw (KevinHinshaw@gmail.com)
14 /// @author Andrew Leaver-Fay
15 
16 #ifndef INCLUDED_core_scoring_etable_BaseEtableEnergy_tmpl_hh
17 #define INCLUDED_core_scoring_etable_BaseEtableEnergy_tmpl_hh
18 
19 /// #define APL_TEMP_DEBUG
20 
21 
22 // Unit headers
23 // AUTO-REMOVED #include <core/scoring/etable/EtableEnergy.hh>
24 
25 // Package headers
34 // AUTO-REMOVED #include <core/scoring/methods/EnergyMethodCreator.hh>
35 
38 
39 //#include <core/scoring/etable/count_pair/CountPair1BC3.hh> // remove this
40 //#include <core/scoring/etable/count_pair/CountPair1BC4.hh> // remove this
41 //#include <core/scoring/etable/count_pair/CountPairIntraResC3.hh>
42 //#include <core/scoring/etable/count_pair/CountPairIntraResC4.hh>
45 
52 
53 // AUTO-REMOVED
55 // AUTO-REMOVED
57 // AUTO-REMOVED
66 
67 // Project headers
68 #include <core/pose/Pose.hh>
69 #include <core/scoring/Energies.hh>
72 
73 // AUTO-REMOVED #include <core/chemical/VariantType.hh>
75 #include <basic/options/option.hh>
76 
77 // option key includes
78 
79 #include <basic/options/keys/score.OptionKeys.gen.hh>
80 #include <basic/options/keys/run.OptionKeys.gen.hh>
81 
82 //Auto Headers
83 #include <platform/types.hh>
84 #include <core/types.hh>
85 #include <core/chemical/AA.hh>
87 #include <core/chemical/Adduct.hh>
106 #include <core/chemical/types.hh>
115 #include <core/conformation/Atom.hh>
139 #include <core/graph/ArrayPool.hh>
140 #include <core/graph/Graph.fwd.hh>
141 #include <core/graph/Graph.hh>
145 #include <core/id/AtomID.fwd.hh>
146 #include <core/id/AtomID.hh>
147 #include <core/id/AtomID_Map.fwd.hh>
148 #include <core/id/AtomID_Map.hh>
150 #include <core/id/DOF_ID.fwd.hh>
151 #include <core/id/DOF_ID.hh>
152 #include <core/id/DOF_ID_Map.fwd.hh>
153 #include <core/id/DOF_ID_Map.hh>
156 #include <core/id/NamedAtomID.hh>
159 #include <core/id/TorsionID.fwd.hh>
160 #include <core/id/TorsionID.hh>
161 #include <core/id/types.hh>
168 #include <core/kinematics/Edge.hh>
172 #include <core/kinematics/Jump.hh>
175 #include <core/kinematics/RT.fwd.hh>
176 #include <core/kinematics/RT.hh>
179 #include <core/kinematics/Stub.hh>
182 #include <core/pose/MiniPose.fwd.hh>
183 #include <core/pose/PDBInfo.fwd.hh>
184 #include <core/pose/Pose.fwd.hh>
185 #include <core/pose/util.hh>
199 #include <core/scoring/EnergyMap.hh>
207 #include <core/scoring/ScoreType.hh>
269 #include <utility/Bound.fwd.hh>
270 #include <utility/Bound.hh>
271 #include <utility/PyAssert.hh>
272 #include <utility/assert.hh>
273 #include <utility/down_cast.hh>
274 #include <utility/exit.hh>
275 #include <utility/in_place_list.fwd.hh>
276 #include <utility/in_place_list.hh>
277 #include <utility/stream_util.hh>
278 #include <utility/string_util.hh>
279 #include <utility/vector0_bool.hh>
280 #include <utility/vector1.fwd.hh>
281 #include <utility/vector1.hh>
282 #include <utility/vector1_bool.hh>
283 #include <utility/vectorL.fwd.hh>
284 #include <utility/vectorL.hh>
285 #include <utility/vectorL_Selector.hh>
286 #include <utility/vectorL_bool.hh>
287 #include <utility/file/FileName.fwd.hh>
288 #include <utility/file/FileName.hh>
289 #include <utility/file/PathName.fwd.hh>
290 #include <utility/file/PathName.hh>
291 #include <utility/keys/AutoKey.fwd.hh>
292 #include <utility/keys/AutoKey.hh>
293 #include <utility/keys/Key.fwd.hh>
294 #include <utility/keys/Key.hh>
295 #include <utility/keys/Key2Tuple.fwd.hh>
296 #include <utility/keys/Key2Tuple.hh>
297 #include <utility/keys/Key3Tuple.fwd.hh>
298 #include <utility/keys/Key3Tuple.hh>
299 #include <utility/keys/Key4Tuple.fwd.hh>
300 #include <utility/keys/Key4Tuple.hh>
301 #include <utility/keys/KeyLess.fwd.hh>
302 #include <utility/keys/KeyLookup.fwd.hh>
303 #include <utility/keys/KeyLookup.hh>
304 #include <utility/keys/NoClient.fwd.hh>
305 #include <utility/keys/NoClient.hh>
306 #include <utility/keys/SmallKeyVector.fwd.hh>
307 #include <utility/keys/SmallKeyVector.hh>
308 #include <utility/keys/UserKey.fwd.hh>
309 #include <utility/keys/VariantKey.fwd.hh>
310 #include <utility/keys/VariantKey.hh>
311 #include <utility/options/AnyOption.fwd.hh>
312 #include <utility/options/AnyOption.hh>
313 #include <utility/options/AnyVectorOption.fwd.hh>
314 #include <utility/options/AnyVectorOption.hh>
315 #include <utility/options/BooleanOption.fwd.hh>
316 #include <utility/options/BooleanOption.hh>
317 #include <utility/options/BooleanVectorOption.fwd.hh>
318 #include <utility/options/BooleanVectorOption.hh>
319 #include <utility/options/FileOption.fwd.hh>
320 #include <utility/options/FileOption.hh>
321 #include <utility/options/FileVectorOption.fwd.hh>
322 #include <utility/options/FileVectorOption.hh>
323 #include <utility/options/IntegerOption.fwd.hh>
324 #include <utility/options/IntegerOption.hh>
325 #include <utility/options/IntegerVectorOption.fwd.hh>
326 #include <utility/options/IntegerVectorOption.hh>
327 #include <utility/options/Option.fwd.hh>
328 #include <utility/options/Option.hh>
329 #include <utility/options/OptionCollection.fwd.hh>
330 #include <utility/options/OptionCollection.hh>
331 #include <utility/options/PathOption.fwd.hh>
332 #include <utility/options/PathOption.hh>
333 #include <utility/options/PathVectorOption.fwd.hh>
334 #include <utility/options/PathVectorOption.hh>
335 #include <utility/options/RealOption.fwd.hh>
336 #include <utility/options/RealOption.hh>
337 #include <utility/options/RealVectorOption.fwd.hh>
338 #include <utility/options/RealVectorOption.hh>
339 #include <utility/options/ScalarOption.fwd.hh>
340 #include <utility/options/ScalarOption.hh>
341 #include <utility/options/ScalarOption_T_.fwd.hh>
342 #include <utility/options/ScalarOption_T_.hh>
343 #include <utility/options/StringOption.fwd.hh>
344 #include <utility/options/StringOption.hh>
345 #include <utility/options/StringVectorOption.fwd.hh>
346 #include <utility/options/StringVectorOption.hh>
347 #include <utility/options/VariantOption.fwd.hh>
348 #include <utility/options/VariantOption.hh>
349 #include <utility/options/VectorOption.fwd.hh>
350 #include <utility/options/VectorOption.hh>
351 #include <utility/options/VectorOption_T_.fwd.hh>
352 #include <utility/options/VectorOption_T_.hh>
353 #include <utility/options/mpi_stderr.hh>
354 #include <utility/options/keys/AnyOptionKey.fwd.hh>
355 #include <utility/options/keys/AnyOptionKey.hh>
356 #include <utility/options/keys/AnyVectorOptionKey.fwd.hh>
357 #include <utility/options/keys/AnyVectorOptionKey.hh>
358 #include <utility/options/keys/BooleanOptionKey.fwd.hh>
359 #include <utility/options/keys/BooleanOptionKey.hh>
360 #include <utility/options/keys/BooleanVectorOptionKey.fwd.hh>
361 #include <utility/options/keys/BooleanVectorOptionKey.hh>
362 #include <utility/options/keys/FileOptionKey.fwd.hh>
363 #include <utility/options/keys/FileOptionKey.hh>
364 #include <utility/options/keys/FileVectorOptionKey.fwd.hh>
365 #include <utility/options/keys/FileVectorOptionKey.hh>
366 #include <utility/options/keys/IntegerOptionKey.fwd.hh>
367 #include <utility/options/keys/IntegerOptionKey.hh>
368 #include <utility/options/keys/IntegerVectorOptionKey.fwd.hh>
369 #include <utility/options/keys/IntegerVectorOptionKey.hh>
370 #include <utility/options/keys/OptionKey.fwd.hh>
371 #include <utility/options/keys/OptionKey.hh>
372 #include <utility/options/keys/OptionKeys.hh>
373 #include <utility/options/keys/PathOptionKey.fwd.hh>
374 #include <utility/options/keys/PathOptionKey.hh>
375 #include <utility/options/keys/PathVectorOptionKey.fwd.hh>
376 #include <utility/options/keys/PathVectorOptionKey.hh>
377 #include <utility/options/keys/RealOptionKey.fwd.hh>
378 #include <utility/options/keys/RealOptionKey.hh>
379 #include <utility/options/keys/RealVectorOptionKey.fwd.hh>
380 #include <utility/options/keys/RealVectorOptionKey.hh>
381 #include <utility/options/keys/ScalarOptionKey.fwd.hh>
382 #include <utility/options/keys/ScalarOptionKey.hh>
383 #include <utility/options/keys/StringOptionKey.fwd.hh>
384 #include <utility/options/keys/StringOptionKey.hh>
385 #include <utility/options/keys/StringVectorOptionKey.fwd.hh>
386 #include <utility/options/keys/StringVectorOptionKey.hh>
387 #include <utility/options/keys/VectorOptionKey.fwd.hh>
388 #include <utility/options/keys/VectorOptionKey.hh>
389 #include <utility/options/keys/all.hh>
390 #include <utility/pointer/ReferenceCount.fwd.hh>
391 #include <utility/pointer/ReferenceCount.hh>
392 #include <utility/pointer/access_ptr.fwd.hh>
393 #include <utility/pointer/access_ptr.hh>
394 #include <utility/pointer/owning_ptr.functions.hh>
395 #include <utility/pointer/owning_ptr.fwd.hh>
396 #include <utility/pointer/owning_ptr.hh>
397 #include <utility/signals/BufferedSignalHub.fwd.hh>
398 #include <utility/signals/BufferedSignalHub.hh>
399 #include <utility/signals/Link.fwd.hh>
400 #include <utility/signals/Link.hh>
401 #include <utility/signals/LinkUnit.fwd.hh>
402 #include <utility/signals/LinkUnit.hh>
403 #include <utility/signals/PausableSignalHub.fwd.hh>
404 #include <utility/signals/PausableSignalHub.hh>
405 #include <utility/signals/SignalHub.fwd.hh>
406 #include <utility/signals/SignalHub.hh>
407 #include <numeric/NumericTraits.hh>
408 #include <numeric/constants.hh>
409 #include <numeric/conversions.hh>
410 #include <numeric/numeric.functions.hh>
411 #include <numeric/sphericalVector.fwd.hh>
412 #include <numeric/sphericalVector.hh>
413 #include <numeric/trig.functions.hh>
414 #include <numeric/types.hh>
415 #include <numeric/xyz.functions.fwd.hh>
416 #include <numeric/xyz.functions.hh>
417 #include <numeric/xyzMatrix.fwd.hh>
418 #include <numeric/xyzMatrix.hh>
419 #include <numeric/xyzTriple.fwd.hh>
420 #include <numeric/xyzTriple.hh>
421 #include <numeric/xyzVector.fwd.hh>
422 #include <numeric/xyzVector.hh>
423 #include <numeric/internal/ColPointers.hh>
424 #include <numeric/internal/ColVectors.hh>
425 #include <numeric/internal/ColsPointer.hh>
426 #include <numeric/internal/RowPointers.hh>
427 #include <numeric/internal/RowVectors.hh>
428 #include <numeric/internal/RowsPointer.hh>
429 #include <ObjexxFCL/Dimension.fwd.hh>
430 #include <ObjexxFCL/Dimension.hh>
431 #include <ObjexxFCL/DimensionExpression.hh>
432 #include <ObjexxFCL/DynamicIndexRange.fwd.hh>
433 #include <ObjexxFCL/DynamicIndexRange.hh>
434 #include <ObjexxFCL/FArray.all.fwd.hh>
435 #include <ObjexxFCL/FArray.fwd.hh>
436 #include <ObjexxFCL/FArray.hh>
437 #include <ObjexxFCL/FArray1.all.fwd.hh>
438 #include <ObjexxFCL/FArray1.fwd.hh>
439 #include <ObjexxFCL/FArray1.hh>
440 #include <ObjexxFCL/FArray1A.fwd.hh>
441 #include <ObjexxFCL/FArray1D.fwd.hh>
442 #include <ObjexxFCL/FArray1D.hh>
443 #include <ObjexxFCL/FArray1P.fwd.hh>
444 #include <ObjexxFCL/FArray2.all.fwd.hh>
445 #include <ObjexxFCL/FArray2.fwd.hh>
446 #include <ObjexxFCL/FArray2.hh>
447 #include <ObjexxFCL/FArray2A.fwd.hh>
448 #include <ObjexxFCL/FArray2D.fwd.hh>
449 #include <ObjexxFCL/FArray2D.hh>
450 #include <ObjexxFCL/FArray2P.fwd.hh>
451 #include <ObjexxFCL/FArray3.all.fwd.hh>
452 #include <ObjexxFCL/FArray3.fwd.hh>
453 #include <ObjexxFCL/FArray3.hh>
454 #include <ObjexxFCL/FArray3A.fwd.hh>
455 #include <ObjexxFCL/FArray3D.fwd.hh>
456 #include <ObjexxFCL/FArray3D.hh>
457 #include <ObjexxFCL/FArray3P.fwd.hh>
458 #include <ObjexxFCL/FArray4.all.fwd.hh>
459 #include <ObjexxFCL/FArray4.fwd.hh>
460 #include <ObjexxFCL/FArray4A.fwd.hh>
461 #include <ObjexxFCL/FArray4D.fwd.hh>
462 #include <ObjexxFCL/FArray4P.fwd.hh>
463 #include <ObjexxFCL/FArray5.all.fwd.hh>
464 #include <ObjexxFCL/FArray5.fwd.hh>
465 #include <ObjexxFCL/FArray5A.fwd.hh>
466 #include <ObjexxFCL/FArray5D.fwd.hh>
467 #include <ObjexxFCL/FArray5P.fwd.hh>
468 #include <ObjexxFCL/FArray6.all.fwd.hh>
469 #include <ObjexxFCL/FArray6.fwd.hh>
470 #include <ObjexxFCL/FArray6A.fwd.hh>
471 #include <ObjexxFCL/FArray6D.fwd.hh>
472 #include <ObjexxFCL/FArray6P.fwd.hh>
473 #include <ObjexxFCL/FArrayInitializer.fwd.hh>
474 #include <ObjexxFCL/FArrayInitializer.hh>
475 #include <ObjexxFCL/FArraySection.fwd.hh>
476 #include <ObjexxFCL/FArraySection.hh>
477 #include <ObjexxFCL/FArrayTraits.fwd.hh>
478 #include <ObjexxFCL/FArrayTraits.hh>
479 #include <ObjexxFCL/IndexRange.fwd.hh>
480 #include <ObjexxFCL/IndexRange.hh>
481 #include <ObjexxFCL/InitializerSentinel.hh>
482 #include <ObjexxFCL/KeyFArray1D.fwd.hh>
483 #include <ObjexxFCL/KeyFArray2D.fwd.hh>
484 #include <ObjexxFCL/KeyFArray3D.fwd.hh>
485 #include <ObjexxFCL/KeyFArray4D.fwd.hh>
486 #include <ObjexxFCL/KeyFArray5D.fwd.hh>
487 #include <ObjexxFCL/KeyFArray6D.fwd.hh>
488 #include <ObjexxFCL/Observer.fwd.hh>
489 #include <ObjexxFCL/Observer.hh>
490 #include <ObjexxFCL/ObserverMulti.hh>
491 #include <ObjexxFCL/ObserverSingle.hh>
492 #include <ObjexxFCL/ProxySentinel.hh>
493 #include <ObjexxFCL/SetWrapper.fwd.hh>
494 #include <ObjexxFCL/Star.fwd.hh>
495 #include <ObjexxFCL/Star.hh>
496 #include <ObjexxFCL/TypeTraits.hh>
497 #include <ObjexxFCL/char.functions.hh>
498 #include <ObjexxFCL/proxy_const_assert.hh>
499 #include <ObjexxFCL/string.functions.hh>
500 #include <algorithm>
501 #include <cassert>
502 #include <cmath>
503 #include <cstddef>
504 #include <cstdio>
505 #include <cstdlib>
506 #include <iomanip>
507 #include <iosfwd>
508 #include <iostream>
509 #include <limits>
510 #include <list>
511 #include <map>
512 #include <ostream>
513 #include <set>
514 #include <sstream>
515 #include <string>
516 #include <time.h>
517 #include <typeinfo>
518 #include <utility>
519 #include <vector>
520 #include <basic/MetricValue.fwd.hh>
521 #include <basic/datacache/BasicDataCache.fwd.hh>
522 #include <basic/datacache/BasicDataCache.hh>
523 #include <basic/datacache/CacheableData.fwd.hh>
524 #include <basic/datacache/CacheableData.hh>
525 #include <basic/datacache/DataCache.fwd.hh>
526 #include <basic/datacache/DataCache.hh>
527 #include <basic/options/keys/OptionKeys.hh>
528 #include <basic/prof.hh>
529 #include <boost/algorithm/string/erase.hpp>
530 #include <boost/bind.hpp>
531 #include <boost/config.hpp>
532 #include <boost/function.hpp>
533 #include <boost/functional/hash.hpp>
534 #include <boost/pool/detail/mutex.hpp>
535 #include <boost/pool/poolfwd.hpp>
536 #include <boost/unordered_map.hpp>
537 #include <core/pose/util.tmpl.hh>
538 
539 namespace core {
540 namespace scoring {
541 namespace etable {
542 
543 #ifdef APL_TEMP_DEBUG
544 inline
545 Size & mingraph_n_atpairE_evals()
546 {
547  static Size mingraph_n_atpairE_evals_;
548  return mingraph_n_atpairE_evals_;
549 }
550 #endif
551 
552 template< class Evaluator >
554 {
555 public:
557  conformation::Residue const & rsd1,
558  conformation::Residue const & rsd2,
559  Evaluator const & evaluator,
560  EnergyMap & emap
561  ) :
562  rsd1_( rsd1 ),
563  rsd2_( rsd2 ),
564  evaluator_( evaluator ),
565  emap_( emap )
566  {}
567 
568  virtual ~ResResEnergyInvoker() {}
569 
570 protected:
571 
572  conformation::Residue const & rsd1() { return rsd1_; }
573  conformation::Residue const & rsd2() { return rsd2_; }
574  Evaluator const & evaluator() { return evaluator_; }
575  EnergyMap & emap() { return emap_; }
576 
577 private:
580  Evaluator const & evaluator_;
582 };
583 
584 template< class Evaluator >
585 class WholeWholeEnergyInvoker : public ResResEnergyInvoker< Evaluator >
586 {
587 public:
589 public:
591  conformation::Residue const & rsd1,
592  conformation::Residue const & rsd2,
593  Evaluator const & evaluator,
594  EnergyMap & emap
595  )
596  : parent( rsd1, rsd2, evaluator, emap )
597  {}
598 
600 
601  virtual void invoke( count_pair::CountPairFunction const & cp )
602  {
603  parent::evaluator().residue_atom_pair_energy( parent::rsd1(), parent::rsd2(), cp, parent::emap() );
604  }
605 
606 };
607 
608 template< class Evaluator >
609 class SC_BB_EnergyInvoker : public ResResEnergyInvoker< Evaluator >
610 {
611 public:
613 public:
615  conformation::Residue const & rsd1,
616  conformation::Residue const & rsd2,
617  Evaluator const & evaluator,
618  EnergyMap & emap
619  )
620  : parent( rsd1, rsd2, evaluator, emap )
621  {}
622 
623  virtual ~SC_BB_EnergyInvoker() {}
624 
625  virtual void invoke( count_pair::CountPairFunction const & cp )
626  {
627  parent::evaluator().residue_atom_pair_energy_sidechain_backbone( parent::rsd1(), parent::rsd2(), cp, parent::emap() );
628  }
629 
630 };
631 
632 template< class Evaluator >
633 class SC_Whole_EnergyInvoker : public ResResEnergyInvoker< Evaluator >
634 {
635 public:
637 public:
639  conformation::Residue const & rsd1,
640  conformation::Residue const & rsd2,
641  Evaluator const & evaluator,
642  EnergyMap & emap
643  )
644  : parent( rsd1, rsd2, evaluator, emap )
645  {}
646 
648 
649  virtual void invoke( count_pair::CountPairFunction const & cp )
650  {
651  parent::evaluator().residue_atom_pair_energy_sidechain_whole( parent::rsd1(), parent::rsd2(), cp, parent::emap() );
652  }
653 
654 };
655 
656 template< class Evaluator >
657 class BB_BB_EnergyInvoker : public ResResEnergyInvoker< Evaluator >
658 {
659 public:
661 public:
663  conformation::Residue const & rsd1,
664  conformation::Residue const & rsd2,
665  Evaluator const & evaluator,
666  EnergyMap & emap
667  )
668  : parent( rsd1, rsd2, evaluator, emap )
669  {}
670 
671  virtual ~BB_BB_EnergyInvoker() {}
672 
673  virtual void invoke( count_pair::CountPairFunction const & cp )
674  {
675  parent::evaluator().residue_atom_pair_energy_backbone_backbone( parent::rsd1(), parent::rsd2(), cp, parent::emap() );
676  }
677 
678 };
679 
680 template< class Evaluator >
681 class SC_SC_EnergyInvoker : public ResResEnergyInvoker< Evaluator >
682 {
683 public:
685 public:
687  conformation::Residue const & rsd1,
688  conformation::Residue const & rsd2,
689  Evaluator const & evaluator,
690  EnergyMap & emap
691  )
692  : parent( rsd1, rsd2, evaluator, emap )
693  {}
694 
695  virtual ~SC_SC_EnergyInvoker() {}
696 
697  virtual void invoke( count_pair::CountPairFunction const & cp )
698  {
699  parent::evaluator().residue_atom_pair_energy_sidechain_sidechain( parent::rsd1(), parent::rsd2(), cp, parent::emap() );
700  }
701 
702 };
703 
704 
705 using namespace etrie;
706 using namespace trie;
707 using namespace basic::options;
708 
709  /// construction with an etable
710 template < class Derived >
713  Etable const & etable_in,
714  methods::EnergyMethodOptions const & options
715 ):
716  parent( creator ),
717  etable_( etable_in ),
718  safe_max_dis2( etable_in.get_safe_max_dis2() ),
719  hydrogen_interaction_cutoff2_( option[ OptionKeys::score::fa_Hatr ] ?
720  std::pow( std::sqrt( etable_in.hydrogen_interaction_cutoff2()) + std::sqrt( safe_max_dis2 ), 2)
721  : etable_in.hydrogen_interaction_cutoff2() ),
722  exclude_DNA_DNA( options.exclude_DNA_DNA() )
723 {}
724 
725 /// @details an explicit copy constructor is required so that the etable_evaluator_ instance,
726 /// which is held in an owning pointer, is not shared between multiple instances of this (or rather
727 /// the derived) class.
728 template < class Derived >
730  parent( src ),
731  etable_( src.etable_ ),
732  safe_max_dis2( src.safe_max_dis2 ),
733  hydrogen_interaction_cutoff2_( src.hydrogen_interaction_cutoff2_ ),
734  exclude_DNA_DNA( src.exclude_DNA_DNA )
735 {
736 }
737 
738 
739 ///////////////////////////////////////////////////////////////////////////////
740 template < class Derived >
741 void
743  pose::Pose & pose,
744  ScoreFunction const &,
745  EnergyMap & totals
746 ) const
747 {
748 #ifdef APL_TEMP_DEBUG
749  if ( mingraph_n_atpairE_evals() != 0 ) {
750  std::cout << "mingraph_n_atpairE_evals: " << mingraph_n_atpairE_evals() << std::endl;
751  }
752  mingraph_n_atpairE_evals() = 0;
753 #endif
754 
755  /// Only use this finalize_total_energies routine if we're using the long-distance minimization
756  /// auto-update trick
757  if ( pose.energies().use_nblist() && pose.energies().use_nblist_auto_update() ) {
758 #ifdef APL_TEMP_DEBUG
759  Size n_d2( 0 );
760 #endif
761 
762  EnergyMap tbenergy_map;
763  // add in contributions from the nblist atom-pairs
764  NeighborList const & nblist
766 
767  nblist.check_domain_map( pose.energies().domain_map() );
768 
769  /// Trick to avoid calls to Conformation::residue()
771  resvect.reserve( pose.total_residue() );
772  for ( Size ii = 1; ii <= pose.total_residue(); ++ii ) {
773  resvect.push_back( & pose.residue( ii ) );
774  }
775  Real dsq(0.0);
776  for ( Size i=1, i_end = pose.total_residue(); i<= i_end; ++i ) {
777  conformation::Residue const & ires( *resvect[i] );
778  for ( Size ii=1, ii_end=ires.natoms(); ii<= ii_end; ++ii ) {
779  /// 1. Iterate across intra-residue atom neighbors if there are any;
780  /// 2. Iterate across inter-residue atom neighbors.
781  //prepare_for_residue_pair( 1,1, pose ); // set intra-res
782  AtomNeighbors const & intranbrs( nblist.intrares_upper_atom_neighbors(i,ii) );
783  conformation::Atom const & iatom( ires.atom(ii) );
784  for ( AtomNeighbors::const_iterator nbr=intranbrs.begin(),
785  nbr_end=intranbrs.end(); nbr!= nbr_end; ++nbr ) {
786  Size const jj( nbr->atomno() );
787  Real const cp_weight( nbr->weight_func() * nbr->weight() ); //fpd
788 
789  conformation::Atom const & jatom( ires.atom(jj) );
790  static_cast< Derived const & > (*this).intrares_evaluator().atom_pair_energy( iatom, jatom, cp_weight, tbenergy_map, dsq );
791  }
792 
793  ///prepare_for_residue_pair( 1,2, pose ); // set inter-res
794  AtomNeighbors const & nbrs( nblist.upper_atom_neighbors(i,ii) );
795  for ( AtomNeighbors::const_iterator nbr=nbrs.begin(),
796  nbr_end=nbrs.end(); nbr!= nbr_end; ++nbr ) {
797 #ifdef APL_TEMP_DEBUG
798  ++n_d2;
799 #endif
800  Size const j( nbr->rsd() );
801  Size const jj( nbr->atomno() );
802 
803  Real const cp_weight( nbr->weight_func()*nbr->weight() );
804  conformation::Atom const & jatom( resvect[j]->atom(jj) );
805  static_cast< Derived const & > (*this).interres_evaluator().atom_pair_energy( iatom, jatom, cp_weight, tbenergy_map, dsq );
806  }
807  }
808 
809  }
810 #ifdef APL_TEMP_DEBUG
811  std::cout << "n_at_pairE_evals: " << n_d2 << std::endl;
812 #endif
813  //std::cout << "totals[ fa_atr ] : " << totals[ fa_atr ] << std::endl;
814  //std::cout << "totals[ fa_rep ] : " << totals[ fa_rep ] << std::endl;
815  //std::cout << "totals[ fa_sol ] : " << totals[ fa_sol ] << std::endl;
816  //std::cout << "totals[ fa_intra_atr ] : " << totals[ fa_intra_atr ] << std::endl;
817  //std::cout << "totals[ fa_intra_rep ] : " << totals[ fa_intra_rep ] << std::endl;
818  //std::cout << "totals[ fa_intra_sol ] : " << totals[ fa_intra_sol ] << std::endl;
819  totals += tbenergy_map;
820  }
821 }
822 
823 template < class Derived >
824 bool
826 {
827  return pose.energies().use_nblist_auto_update();
828 }
829 
830 ///////////////////////////////////////////////////////////////////////////////
831 template < class Derived >
832 void
834  pose::Pose & pose,
835  ScoreFunction const & sfxn,
836  kinematics::MinimizerMapBase const & min_map
837 ) const
838 {
839  using namespace basic::options;
840  using namespace basic::options::OptionKeys;
841 
842  if ( pose.energies().use_nblist() && pose.energies().use_nblist_auto_update() ) {
843  // stash our nblist inside the pose's energies object
844  Energies & energies( pose.energies() );
845 
846  // setup the atom-atom nblist
847  NeighborListOP nblist;
848 
849  if ( pose.energies().use_nblist_auto_update() ) {
850  Real const tolerated_narrow_nblist_motion = option[ run::nblist_autoupdate_narrow ];
851  Real const XX = etable_.max_dis() + 2 * tolerated_narrow_nblist_motion;
852  Real const XH = etable_.max_non_hydrogen_lj_radius() + etable_.max_hydrogen_lj_radius()
853  + 2 * tolerated_narrow_nblist_motion;
854  Real const HH = etable_.max_hydrogen_lj_radius() + etable_.max_hydrogen_lj_radius()
855  + 2 * tolerated_narrow_nblist_motion;
856 
857  nblist = new NeighborList(
858  min_map.domain_map(),
859  XX*XX,
860  XH*XH,
861  HH*HH);
862  nblist->set_auto_update( tolerated_narrow_nblist_motion );
863  } else {
864 
865  /// Use the default parameters
866  nblist = new NeighborList(
867  min_map.domain_map(),
868  etable_.nblist_dis2_cutoff_XX(),
869  etable_.nblist_dis2_cutoff_XH(),
870  etable_.nblist_dis2_cutoff_HH());
871  }
872  // this partially becomes the EtableEnergy classes's responsibility
873  nblist->setup( pose, sfxn, static_cast<Derived const&> (*this));
874 
875  energies.set_nblist( EnergiesCacheableDataType::ETABLE_NBLIST, nblist );
876  }
877 }
878 
879 // check compatibility with atomtypeset
880 template < class Derived >
881 void
883  pose::Pose &pose,
884  ScoreFunction const &scfxn
885 ) const
886 {
887  assert( dynamic_cast< Derived const* > (this) );
888  Derived const * ptr = static_cast< Derived const * > (this);
889  ptr->setup_for_scoring_(pose,scfxn);
890  if ( pose.energies().use_nblist() ) {
892  //std::cout << "nblist autoupdate" << std::endl;
893  nblist.prepare_for_scoring( pose, scfxn, *ptr );
894  }
895 }
896 
897 ///@details Make sure that the neighborlist is up-to-date bfore evaluating derivatives
898 template < class Derived >
899 void
901  pose::Pose &pose,
902  ScoreFunction const &scfxn
903 ) const
904 {
905  //std::cout << "BaseEtable Setup for derivatives" << std::endl;
906  assert( dynamic_cast< Derived const* > (this) );
907  Derived const * ptr = static_cast< Derived const* > (this);
908  ptr->setup_for_scoring_(pose,scfxn);
909  if ( pose.energies().use_nblist() ) {
911  //std::cout << "nblist autoupdate2" << std::endl;
912  nblist.prepare_for_scoring( pose, scfxn, *ptr );
913  }
914 }
915 
916 
917 
918 // The EtableEnergy method stores a vector of rotamer trie objects in the Energies
919 // object for use in rapid rotamer/background energy calculations. Overrides default
920 // do-nothing behavior.
921 template < class Derived >
922 void
924  pose::Pose & pose,
925  utility::vector1< bool > const &,
927 ) const
928 {
929 
930  TrieCollectionOP tries = new TrieCollection;
931  tries->total_residue( pose.total_residue() );
932  for ( Size ii = 1; ii <= pose.total_residue(); ++ii ) {
933  // Do not compute energy for virtual residues.
934  if (pose.residue(ii).aa() == core::chemical::aa_vrt) continue;
935  //iwd Temporary hack: also skip ligand residues
936  //if ( !pose.residue(ii).is_polymer() )
937  // continue;
938 
939  EtableRotamerTrieOP one_rotamer_trie = create_rotamer_trie( pose.residue(ii), pose );
940  tries->trie( ii, one_rotamer_trie );
941  }
943 
944 }
945 
946 // @brief Creates a rotamer trie for the input set of rotamers and stores the trie
947 // in the rotamer set.
948 template < class Derived >
949 void
951  pose::Pose const & pose,
953 ) const
954 {
955 
956  EtableRotamerTrieOP rottrie = create_rotamer_trie( set, pose );
957  set.store_trie( methods::etable_method, rottrie );
958 }
959 
960 
961 // @brief Updates the cached rotamer trie for a residue if it has changed during the course of
962 // a repacking
963 template < class Derived >
964 void
966  pose::Pose & pose,
967  Size resid
968 ) const
969 {
970 
971  EtableRotamerTrieOP one_rotamer_trie = create_rotamer_trie( pose.residue( resid ), pose );
972 
973  // grab non-const & of the cached tries and replace resid's trie with a new one.
974  TrieCollection & trie_collection
975  ( static_cast< TrieCollection & > (pose.energies().data().get( EnergiesCacheableDataType::ETABLE_TRIE_COLLECTION )));
976  trie_collection.trie( resid, one_rotamer_trie );
977 
978 }
979 
980 
981 // @brief convenience function
982 template < class Derived >
985  Size res1,
986  Size res2,
987  pose::Pose const & pose,
988  ScoreFunction const & sfxn
989 ) const
990 {
991  return get_count_pair_function( pose.residue( res1 ), pose.residue( res2 ), pose, sfxn );
992 }
993 
994 // @brief all of the residue level count pair logic goes here
995 /// and gets duplicated in a handful of other places within this class... this NEEDS to be reworked.
996 template < class Derived >
999  conformation::Residue const & res1,
1000  conformation::Residue const & res2,
1001  pose::Pose const & pose, // does the pose hold the connectivity information or do the residues?
1002  ScoreFunction const & sfxn
1003 ) const
1004 {
1005  using namespace count_pair;
1006 
1007  if ( exclude_DNA_DNA && res1.is_DNA() && res2.is_DNA() ) {
1008  return new CountPairNone;
1009  }
1010 
1011  count_pair::CPCrossoverBehavior crossover = determine_crossover_behavior( res1, res2, pose, sfxn );
1012  return CountPairFactory::create_count_pair_function( res1, res2, crossover );
1013 }
1014 
1015 // @brief get a count pair object for intraresidue pair energies
1016 template < class Derived >
1019  conformation::Residue const & res,
1020  pose::Pose const & pose,
1021  ScoreFunction const & sfxn
1022 ) const
1023 {
1024  using namespace count_pair;
1025 
1026  if ( exclude_DNA_DNA && res.is_DNA() ) {
1027  return new CountPairNone;
1028  }
1029 
1030  CPCrossoverBehavior crossover = determine_crossover_behavior( res, res, pose, sfxn );
1031  return CountPairFactory::create_intrares_count_pair_function( res, crossover );
1032 }
1033 
1034 
1035 /// @brief figure out the trie count pair function to use
1036 /// Need to refactor this so that the decision "what kind of count pair behavior should I use" can be decoupled
1037 /// from class instantiation, and therefore shared between the creation of the trie count pair classes and the regular
1038 /// count pair classes
1039 template < class Derived >
1042  conformation::RotamerSetBase const & set1,
1043  conformation::RotamerSetBase const & set2,
1044  pose::Pose const & pose,
1045  ScoreFunction const & sfxn
1046 ) const
1047 {
1048  using namespace methods;
1049  conformation::Residue const & res1( pose.residue( set1.resid() ) );
1050  conformation::Residue const & res2( pose.residue( set2.resid() ) );
1051  trie::RotamerTrieBaseCOP trie1( static_cast< trie::RotamerTrieBase const * > ( set1.get_trie( etable_method )() ));
1052  trie::RotamerTrieBaseCOP trie2( static_cast< trie::RotamerTrieBase const * > ( set2.get_trie( etable_method )() ));
1053 
1054  return get_count_pair_function_trie( res1, res2, trie1, trie2, pose, sfxn );
1055 }
1056 
1057 template < class Derived >
1060  conformation::Residue const & res1,
1061  conformation::Residue const & res2,
1064  pose::Pose const & pose,
1065  ScoreFunction const & sfxn
1066 ) const
1067 {
1068  using namespace count_pair;
1069 
1070  TrieCountPairBaseOP tcpfxn;
1071  if ( exclude_DNA_DNA && res1.is_DNA() && res2.is_DNA() ) {
1072  tcpfxn = new TrieCountPairNone();
1073  return tcpfxn;
1074  }
1075 
1077  Size conn1 = trie1->get_count_pair_data_for_residue( res2.seqpos() );
1078  Size conn2 = trie2->get_count_pair_data_for_residue( res1.seqpos() );
1079 
1080  if ( connection == CP_ONE_BOND ) {
1081  CPCrossoverBehavior crossover = determine_crossover_behavior( res1, res2, pose, sfxn );
1082  switch ( crossover ) {
1083  case CP_CROSSOVER_3 :
1084  tcpfxn = new TrieCountPair1BC3( conn1, conn2 );
1085  break;
1086  case CP_CROSSOVER_4 :
1087  tcpfxn = new TrieCountPair1BC4( conn1, conn2 );
1088  break;
1089  default:
1090  utility_exit();
1091  break;
1092  }
1093  } else if ( connection == CP_MULTIPLE_BONDS_OR_PSEUDOBONDS ) {
1094  CPCrossoverBehavior crossover = determine_crossover_behavior( res1, res2, pose, sfxn );
1095 
1096  TrieCountPairGenericOP cpgen = new TrieCountPairGeneric( res1, res2, conn1, conn2 );
1097  if ( crossover == CP_CROSSOVER_3 ) {
1098  cpgen->crossover( 3 );
1099  } else if ( crossover == CP_CROSSOVER_4 ) {
1100  cpgen->crossover( 4 );
1101  } else {
1102  utility_exit();
1103  }
1104  cpgen->hard_crossover( false );
1105  tcpfxn = cpgen;
1106  } else {
1107  tcpfxn = new TrieCountPairAll;
1108  }
1109  return tcpfxn;
1110 
1111 }
1112 
1113 
1114 /*
1115 template < class Derived >
1116 count_pair::CPResidueConnectionType
1117 BaseEtableEnergy< Derived >::determine_residue_connection(
1118  conformation::Residue const & res1,
1119  conformation::Residue const & res2,
1120  pose::Pose const &
1121 ) const
1122 {
1123  using namespace count_pair;
1124  /// this code is incompatible with designing both disulfides and non-disulfies
1125  /// at the same residue...
1126  if ( res1.is_pseudobonded( res2.seqpos ) {
1127  return CP_MULTIPLE_BONDS_OR_PSEUDOBONDS;
1128  } else if ( res1.is_bonded(res2) ) {
1129  if ( res1.connections_to_residue( res2 ).size() == 1 ) {
1130  return CP_ONE_BOND;
1131  } else {
1132  return CP_MULTIPLE_BONDS_OR_PSEUDOBONDS;
1133  }
1134  } else {
1135  return CP_NO_BONDS;
1136  }
1137 }
1138 */
1139 
1140 template < class Derived >
1143  conformation::Residue const & res1,
1144  conformation::Residue const & res2,
1145  pose::Pose const &,
1146  ScoreFunction const & sfxn
1147 ) const
1148 {
1149  using namespace count_pair;
1150  // maybe should ask "are these two residues polymers and do they share a polymeric bond"
1151  if ( res1.polymeric_sequence_distance(res2) == 1 ) {
1152  if ( ( !sfxn.has_zero_weight( mm_twist ) && sfxn.has_zero_weight( rama )) ||
1153  ( ( !res1.is_protein() || !res2.is_protein()) &&
1154  ( !res1.is_RNA() || !res2.is_RNA())
1155  ) ) {
1156  return CP_CROSSOVER_3;
1157  } else {
1158  return CP_CROSSOVER_4; // peptide bond w/ or w/o rama, but definately w/o mm_twist
1159  }
1160  } else if ( res1.seqpos() == res2.seqpos() ) {
1161  // logic for controlling intra-residue count pair behavior goes here; for now, default to crossover 3
1162  return CP_CROSSOVER_3;
1163  }else {
1164  return CP_CROSSOVER_3; // e.g. disulfides where seqsep != 1
1165  }
1166 }
1167 
1168 ///
1169 template < class Derived >
1170 void
1172  conformation::Residue const & rsd1,
1173  conformation::Residue const & rsd2,
1174  pose::Pose const & pose,
1175  ScoreFunction const & sfxn,
1176  EnergyMap & emap
1177 ) const
1178 {
1179  assert( rsd1.seqpos() != rsd2.seqpos() );
1180  //std::cerr << __FILE__<< ' ' << __LINE__ << std::endl;
1181 
1182  if ( ! pose.energies().use_nblist() ) {
1183  prepare_for_residue_pair(rsd1.seqpos(),rsd2.seqpos(),pose);
1184  //count_pair::CountPairFunctionCOP cpfxn = get_count_pair_function( rsd1, rsd2, pose, sfxn );
1185  //cpfxn->residue_atom_pair_energy( rsd1, rsd2, static_cast<Derived const&> (*this), emap );
1186  if ( exclude_DNA_DNA && rsd1.is_DNA() && rsd2.is_DNA() ) {
1187  return;
1188  }
1189  count_pair::CPCrossoverBehavior crossover = determine_crossover_behavior( rsd1, rsd2, pose, sfxn );
1190  WholeWholeEnergyInvoker< typename Derived::Evaluator > invoker( rsd1, rsd2, static_cast< Derived const & > (*this).interres_evaluator(), emap );
1192  }
1193 }
1194 
1195 template < class Derived >
1196 bool
1198 {
1199  return true;
1200 }
1201 
1202 template < class Derived >
1203 void
1205  conformation::Residue const & rsd1,
1206  conformation::Residue const & rsd2,
1207  ResPairMinimizationData const & min_data,
1208  pose::Pose const & pose,
1209  ScoreFunction const &,
1210  EnergyMap & emap
1211 ) const
1212 {
1213 
1214  if ( pose.energies().use_nblist_auto_update() ) return;
1215 
1216 /* prepare_for_residue_pair( 1,2, pose ); // set inter-res
1217  assert( dynamic_cast< ResiduePairNeighborList const * > (min_data.get_data( etab_pair_nblist )() ));
1218  ResiduePairNeighborList const & nblist( static_cast< ResiduePairNeighborList const & > ( min_data.get_data_ref( etab_pair_nblist ) ) );
1219  Real dsq;
1220  utility::vector1< utility::vector1< AtomNeighbor > > const & neighbs( nblist.r1_at_neighbors() );
1221  //for ( Size ii = nblist.r1_nonempty().head(), iiend = 0; ii != iiend; ii = nblist.r1_nonempty()[ ii ].next() ) {
1222  for ( Size ii = 1, iiend = neighbs.size(); ii <= iiend; ++ii ) {
1223  conformation::Atom const & iiatom( rsd1.atom( ii ) );
1224  utility::vector1< AtomNeighbor > const & iinbs( neighbs[ ii ] );
1225  //ResiduePairNeighborList::AtomNeighbors const & iinbrs( nblist.r1_narrow_neighbors( ii ) );
1226  //for ( Size jj = iinbrs.head(), jjend = 0; jj != jjend; jj = iinbrs[ jj ].next() ) {
1227  //for ( Size jj = 1, jjend = neighbs[ii].size(); jj <= jjend; ++jj ) {
1228  for ( scoring::AtomNeighbors::const_iterator it2=iinbs.begin(),
1229  it2e=iinbs.end(); it2 != it2e; ++it2 ) {
1230  scoring::AtomNeighbor const & nbr( *it2 );
1231 
1232  //std::cout << " rpe_ext: " << rsd1.seqpos() << " " << rsd2.seqpos() << " " << ii << " " << jj << std::endl;
1233  //Real const cp_weight( iinbrs[ jj ].data().weight_func() * iinbrs[ jj ].data().weight() ); //fpd
1234  //atom_pair_energy( rsd1.atom( ii ), rsd2.atom( iinbrs[ jj ].data().atomno() ), cp_weight, emap, dsq );
1235  atom_pair_energy( iiatom, rsd2.atom( nbr.atomno() ), nbr.weight() , emap, dsq );
1236 #ifdef APL_TEMP_DEBUG
1237  ++mingraph_n_atpairE_evals();
1238 #endif
1239  }
1240  }*/
1241  ///prepare_for_residue_pair( 1,2, pose ); // set inter-res
1242  assert( dynamic_cast< ResiduePairNeighborList const * > (min_data.get_data( etab_pair_nblist )() ));
1243  ResiduePairNeighborList const & nblist( static_cast< ResiduePairNeighborList const & > ( min_data.get_data_ref( etab_pair_nblist ) ) );
1244  Real dsq;
1245  utility::vector1< SmallAtNb > const & neighbs( nblist.atom_neighbors() );
1246  for ( Size ii = 1, iiend = neighbs.size(); ii <= iiend; ++ii ) {
1247  conformation::Atom const & atom1( rsd1.atom( neighbs[ ii ].atomno1() ) );
1248  conformation::Atom const & atom2( rsd2.atom( neighbs[ ii ].atomno2() ) );
1249  static_cast< Derived const & > (*this).interres_evaluator().atom_pair_energy( atom1, atom2, neighbs[ ii ].weight(), emap, dsq );
1250 #ifdef APL_TEMP_DEBUG
1251  ++mingraph_n_atpairE_evals();
1252 #endif
1253  }
1254 }
1255 
1256 template < class Derived >
1257 void
1259  conformation::Residue const & rsd1,
1260  conformation::Residue const & rsd2,
1261  pose::Pose const & pose,
1262  ScoreFunction const & sfxn,
1263  kinematics::MinimizerMapBase const &, // is this necessary?
1264  ResSingleMinimizationData const &,//, r1_min_dat,
1265  ResSingleMinimizationData const &,// r2_min_dat,
1266  ResPairMinimizationData & pair_data
1267 ) const
1268 {
1269 
1270  if ( pose.energies().use_nblist_auto_update() ) return;
1271 
1272 /* count_pair::CountPairFunctionCOP count_pair = get_count_pair_function( rsd1, rsd2, pose, sfxn );
1273 
1274  // update the existing nblist if it's already present in the min_data object
1275  ResiduePairNeighborListOP nblist( static_cast< ResiduePairNeighborList * > (pair_data.get_data( etab_pair_nblist )() ));
1276  if ( ! nblist ) nblist = new ResiduePairNeighborList;
1277 
1278  ResidueNblistData const & r1nbdat( static_cast< ResidueNblistData const & > ( r1_min_dat.get_data_ref( etab_single_nblist ) ) );
1279  ResidueNblistData const & r2nbdat( static_cast< ResidueNblistData const & > ( r2_min_dat.get_data_ref( etab_single_nblist ) ) );
1280 
1281  nblist->initialize_from_residues(
1282  etable_.max_heavy_heavy_cutoff(),
1283  etable_.max_heavy_hydrogen_cutoff(),
1284  etable_.max_hydrogen_hydrogen_cutoff(),
1285  rsd1, rsd2, r1nbdat, r2nbdat, count_pair );
1286 
1287  pair_data.set_data( etab_pair_nblist, nblist );*/
1288 
1289 
1290  using namespace basic::options;
1291  using namespace basic::options::OptionKeys;
1292  count_pair::CountPairFunctionCOP count_pair = get_count_pair_function( rsd1, rsd2, pose, sfxn );
1293 
1294  // update the existing nblist if it's already present in the min_data object
1295  ResiduePairNeighborListOP nblist( static_cast< ResiduePairNeighborList * > (pair_data.get_data( etab_pair_nblist )() ));
1296  if ( ! nblist ) nblist = new ResiduePairNeighborList;
1297 
1298  /// STOLEN CODE!
1299  Real const tolerated_narrow_nblist_motion = 0.75; //option[ run::nblist_autoupdate_narrow ];
1300  Real const XX = etable_.max_dis() + 2 * tolerated_narrow_nblist_motion;
1301  Real const XH = etable_.max_non_hydrogen_lj_radius() + etable_.max_hydrogen_lj_radius()
1302  + 2 * tolerated_narrow_nblist_motion;
1303  Real const HH = etable_.max_hydrogen_lj_radius() + etable_.max_hydrogen_lj_radius()
1304  + 2 * tolerated_narrow_nblist_motion;
1305 
1306  nblist->initialize_from_residues(
1307  XX*XX, XH*XH, HH*HH,
1308  rsd1, rsd2, count_pair );
1309 
1310  pair_data.set_data( etab_pair_nblist, nblist );
1311 
1312 }
1313 
1314 template < class Derived >
1315 bool
1317 {
1318  // if ( pose.energies().use_nblist_auto_update() ) return false;
1319 
1320  //return true;
1321  return false; // TEMP -- disable autoupdate
1322 }
1323 
1324 
1325 template < class Derived >
1326 void
1328  conformation::Residue const &,// rsd,
1329  pose::Pose const &,
1330  ScoreFunction const &,
1331  ResSingleMinimizationData & // min_data
1332 ) const
1333 {}
1334 /* assert( dynamic_cast< ResidueNblistData * > (min_data.get_data( etab_single_nblist )() ));
1335  ResidueNblistData & nbdata( static_cast< ResidueNblistData & > ( min_data.get_data_ref( etab_single_nblist ) ));
1336  nbdata.update( rsd );
1337 }*/
1338 
1339 
1340 template < class Derived >
1341 bool
1343 {
1344  ///if ( pose.energies().use_nblist_auto_update() ) return false;
1345 
1346  //return true;
1347  return false; // disable autoupdate (TEMP!)
1348 }
1349 
1350 
1351 template < class Derived >
1352 void
1354  conformation::Residue const & rsd,
1355  pose::Pose const & pose,
1356  ScoreFunction const & sfxn,
1357  ResSingleMinimizationData & min_data
1358 ) const
1359 {
1360  setup_for_scoring_for_residue( rsd, pose, sfxn, min_data );
1361 }
1362 
1363 
1364 template < class Derived >
1365 bool
1367 {
1368  //return true;
1369  return false; /// TEMP -- disable autoupdate
1370 }
1371 
1372 
1373 template < class Derived >
1374 void
1376  conformation::Residue const &,// rsd1,
1377  conformation::Residue const &,// rsd2,
1378  ResSingleMinimizationData const &,// minsingle_data1,
1379  ResSingleMinimizationData const &,// minsingle_data2,
1380  pose::Pose const &,
1381  ScoreFunction const &,
1382  ResPairMinimizationData &// data_cache
1383 ) const
1384 {
1385 /* assert( dynamic_cast< ResidueNblistData const * > (minsingle_data1.get_data( etab_single_nblist )() ));
1386  assert( dynamic_cast< ResidueNblistData const * > (minsingle_data2.get_data( etab_single_nblist )() ));
1387  assert( dynamic_cast< ResiduePairNeighborList * > (data_cache.get_data( etab_pair_nblist )() ));
1388 
1389  ResidueNblistData const & r1nbdat( static_cast< ResidueNblistData const & > ( minsingle_data1.get_data_ref( etab_single_nblist ) ));
1390  ResidueNblistData const & r2nbdat( static_cast< ResidueNblistData const & > ( minsingle_data2.get_data_ref( etab_single_nblist ) ));
1391  ResiduePairNeighborList & nblist( static_cast< ResiduePairNeighborList & > ( data_cache.get_data_ref( etab_pair_nblist ) ) );
1392 
1393  nblist.update(
1394  etable_.max_heavy_heavy_cutoff(),
1395  etable_.max_heavy_hydrogen_cutoff(),
1396  etable_.max_hydrogen_hydrogen_cutoff(),
1397  rsd1, rsd2, r1nbdat, r2nbdat );*/
1398 
1399 }
1400 
1401 
1402 template < class Derived >
1403 bool
1405 {
1406  return false;
1407 }
1408 
1409 
1410 template < class Derived >
1411 void
1413  conformation::Residue const & rsd1,
1414  conformation::Residue const & rsd2,
1415  ResSingleMinimizationData const & minsingle_data1,
1416  ResSingleMinimizationData const & minsingle_data2,
1417  pose::Pose const & pose,
1418  ScoreFunction const & sfxn,
1419  ResPairMinimizationData & data_cache
1420 ) const
1421 {
1422  setup_for_scoring_for_residue_pair( rsd1, rsd2, minsingle_data1, minsingle_data2, pose, sfxn, data_cache );
1423 }
1424 
1425 /*
1426 template < class Derived >
1427 void
1428 BaseEtableEnergy< Derived >::eval_atom_derivative_for_residue_pair(
1429  Size const atom_index,
1430  conformation::Residue const & rsd1,
1431  conformation::Residue const & rsd2,
1432  ResSingleMinimizationData const &,
1433  ResSingleMinimizationData const &,
1434  ResPairMinimizationData const & min_data,
1435  pose::Pose const & pose, // provides context
1436  kinematics::DomainMap const &,
1437  ScoreFunction const &,
1438  EnergyMap const & weights,
1439  Vector & F1,
1440  Vector & F2
1441 ) const
1442 {
1443  assert( dynamic_cast< ResiduePairNeighborList const * > (min_data.get_data( etab_pair_nblist )() ));
1444  ResiduePairNeighborList const & nblist( static_cast< ResiduePairNeighborList const & > (min_data.get_data_ref( etab_pair_nblist )) );
1445  utility::vector1< AtomNeighbor > const & atneighbs( rsd1.seqpos() < rsd2.seqpos() ?
1446  nblist.r1_at_neighbors()[ atom_index ] :
1447  nblist.r2_at_neighbors()[ atom_index ] );
1448  if ( atneighbs.empty() ) return; // early exit
1449 
1450  conformation::Atom const & atom1( rsd1.atom( atom_index ));
1451  prepare_for_residue_pair( 1, 2, pose ); // set inter-res
1452  Vector f1,f2;
1453  //ResiduePairNeighborList::AtomNeighbors const & atneighbs( rsd1.seqpos() < rsd2.seqpos() ?
1454  // nblist.r1_narrow_neighbors( atom_index ) :
1455  // nblist.r2_narrow_neighbors( atom_index ) );
1456  //for ( Size ii = atneighbs.head(), iiend = atneighbs.end(); ii != iiend; ii = atneighbs[ ii ].next() ) {
1457  for ( Size ii = 1, iiend = atneighbs.size(); ii <= iiend; ++ii ) {
1458  //Real const cp_weight( atneighbs[ ii ].data().weight() ); // do not use nbr->weight_func() here
1459  Real const cp_weight( atneighbs[ ii ].weight() ); // do not use nbr->weight_func() here
1460  conformation::Atom const & atom2( rsd2.atom( atneighbs[ ii ].atomno() ) );
1461  Real const dE_dR_over_r( eval_dE_dR_over_r( atom1, atom2, weights, f1, f2 ) );
1462  //std::cout << " atom deriv: " << rsd1.seqpos() << " " << atom_index << " with " << rsd2.seqpos() << " " << nbr->atomno() << ". w= " << nbr->weight() << " dE_dR_over_r: " << dE_dR_over_r << std::endl;
1463  if ( dE_dR_over_r != 0.0 ) {
1464  F1 += dE_dR_over_r * cp_weight * f1;
1465  F2 += dE_dR_over_r * cp_weight * f2;
1466  }
1467  }
1468 }*/
1469 
1470 template < class Derived >
1471 void
1473  conformation::Residue const & rsd1,
1474  conformation::Residue const & rsd2,
1475  ResSingleMinimizationData const &,
1476  ResSingleMinimizationData const &,
1477  ResPairMinimizationData const & min_data,
1478  pose::Pose const & pose, // provides context
1479  EnergyMap const & weights,
1480  utility::vector1< DerivVectorPair > & r1_at_derivs,
1482 ) const
1483 {
1484 
1485  if ( pose.energies().use_nblist_auto_update() ) return;
1486 
1487 /* assert( r1_at_derivs.size() >= rsd1.natoms() );
1488  assert( r2_at_derivs.size() >= rsd2.natoms() );
1489 
1490  assert( dynamic_cast< ResiduePairNeighborList const * > (min_data.get_data( etab_pair_nblist )() ));
1491  ResiduePairNeighborList const & nblist( static_cast< ResiduePairNeighborList const & > (min_data.get_data_ref( etab_pair_nblist )) );
1492 
1493  prepare_for_residue_pair( 1, 2, pose ); // set inter-res
1494  Vector f1,f2;
1495  utility::vector1< utility::vector1< AtomNeighbor > > const & r1_nbs = nblist.r1_at_neighbors();
1496  for ( Size ii = nblist.r1_nonempty().head(), iiend = 0; ii != iiend; ii = nblist.r1_nonempty()[ ii ].next() ) {
1497  utility::vector1< AtomNeighbor > const & ii_nbs( r1_nbs[ ii ] );
1498  conformation::Atom const & iiatom( rsd1.atom( ii ) );
1499  for ( Size jj = 1, jj_end = ii_nbs.size(); jj <= jj_end; ++jj ) {
1500  conformation::Atom const & jjatom( rsd2.atom( ii_nbs[ jj ].atomno() ) );
1501  Real const dE_dR_over_r( eval_dE_dR_over_r( iiatom, jjatom, weights, f1, f2 ) );
1502  //std::cout << " atom deriv: " << rsd1.seqpos() << " " << atom_index << " with " << rsd2.seqpos() << " " << nbr->atomno() << ". w= " << nbr->weight() << " dE_dR_over_r: " << dE_dR_over_r << std::endl;
1503  if ( dE_dR_over_r != 0.0 ) {
1504  f1 *= dE_dR_over_r * ii_nbs[ jj ].weight();
1505  f2 *= dE_dR_over_r * ii_nbs[ jj ].weight();
1506  r1_at_derivs[ ii ].f1() += f1;
1507  r1_at_derivs[ ii ].f2() += f2;
1508  r2_at_derivs[ ii_nbs[ jj ].atomno() ].f1() += -1*f1;
1509  r2_at_derivs[ ii_nbs[ jj ].atomno() ].f2() += -1*f2;
1510  }
1511  }
1512  }*/
1513 
1514  assert( r1_at_derivs.size() >= rsd1.natoms() );
1515  assert( r2_at_derivs.size() >= rsd2.natoms() );
1516 
1517  assert( dynamic_cast< ResiduePairNeighborList const * > (min_data.get_data( etab_pair_nblist )() ));
1518  ResiduePairNeighborList const & nblist( static_cast< ResiduePairNeighborList const & > (min_data.get_data_ref( etab_pair_nblist )) );
1519 
1520  //prepare_for_residue_pair( 1, 2, pose ); // set inter-res
1521  typename Derived::Evaluator evaluator( static_cast< Derived const & > (*this).interres_evaluator() );
1522  evaluator.set_weights( weights );
1523 
1524  Vector f1,f2;
1525  utility::vector1< SmallAtNb > const & neighbs( nblist.atom_neighbors() );
1526  for ( Size ii = 1, iiend = neighbs.size(); ii <= iiend; ++ii ) {
1527  conformation::Atom const & atom1( rsd1.atom( neighbs[ ii ].atomno1() ) );
1528  conformation::Atom const & atom2( rsd2.atom( neighbs[ ii ].atomno2() ) );
1529  Real const dE_dR_over_r( evaluator.eval_dE_dR_over_r( atom1, atom2, weights, f1, f2 ) );
1530  //std::cout << " atom deriv: " << rsd1.seqpos() << " " << atom_index << " with " << rsd2.seqpos() << " " << nbr->atomno() << ". w= " << nbr->weight() << " dE_dR_over_r: " << dE_dR_over_r << std::endl;
1531  if ( dE_dR_over_r != 0.0 ) {
1532  f1 *= dE_dR_over_r * neighbs[ ii ].weight();
1533  f2 *= dE_dR_over_r * neighbs[ ii ].weight();
1534  r1_at_derivs[ neighbs[ ii ].atomno1() ].f1() += f1;
1535  r1_at_derivs[ neighbs[ ii ].atomno1() ].f2() += f2;
1536  r2_at_derivs[ neighbs[ ii ].atomno2() ].f1() += -1*f1;
1537  r2_at_derivs[ neighbs[ ii ].atomno2() ].f2() += -1*f2;
1538  }
1539  }
1540 }
1541 
1542 
1543 /// @details do not use this during minimization
1544 template < class Derived >
1545 void
1547  conformation::Residue const & rsd1,
1548  conformation::Residue const & rsd2,
1549  pose::Pose const & pose,
1550  ScoreFunction const & sfxn,
1551  EnergyMap & emap
1552 ) const
1553 {
1554  assert( ! pose.energies().use_nblist() );
1555  //prepare_for_residue_pair(rsd1.seqpos(),rsd2.seqpos(),pose);
1556  //count_pair::CountPairFunctionCOP cpfxn = get_count_pair_function( rsd1, rsd2, pose, sfxn );
1557  //cpfxn->residue_atom_pair_energy_backbone_backbone( rsd1, rsd2, static_cast< Derived const&> (*this), emap );
1558  if ( exclude_DNA_DNA && rsd1.is_DNA() && rsd2.is_DNA() ) {
1559  return;
1560  }
1561  count_pair::CPCrossoverBehavior crossover = determine_crossover_behavior( rsd1, rsd2, pose, sfxn );
1562  BB_BB_EnergyInvoker< typename Derived::Evaluator > invoker( rsd1, rsd2, static_cast< Derived const & > (*this).interres_evaluator(), emap );
1564 }
1565 
1566 
1567 /// @details do not use this during minimization
1568 template < class Derived >
1569 void
1571  conformation::Residue const & rsd1,
1572  conformation::Residue const & rsd2,
1573  pose::Pose const & pose,
1574  ScoreFunction const & sfxn,
1575  EnergyMap & emap
1576 ) const
1577 {
1578  assert( ! pose.energies().use_nblist() );
1579  //prepare_for_residue_pair(rsd2.seqpos(),rsd1.seqpos(),pose);
1580  //count_pair::CountPairFunctionCOP cpfxn = get_count_pair_function( rsd2, rsd1, pose, sfxn );
1581  //cpfxn->residue_atom_pair_energy_sidechain_backbone( rsd2, rsd1, static_cast<Derived const&> (*this), emap );
1582  if ( exclude_DNA_DNA && rsd1.is_DNA() && rsd2.is_DNA() ) {
1583  return;
1584  }
1585  count_pair::CPCrossoverBehavior crossover = determine_crossover_behavior( rsd2, rsd1, pose, sfxn );
1586  SC_BB_EnergyInvoker< typename Derived::Evaluator > invoker( rsd2, rsd1, static_cast< Derived const & > (*this).interres_evaluator(), emap );
1588 }
1589 
1590 //@details do not use this during minimization
1591 template < class Derived >
1592 void
1594  conformation::Residue const & rsd1,
1595  conformation::Residue const & rsd2,
1596  pose::Pose const & pose,
1597  ScoreFunction const & sfxn,
1598  EnergyMap & emap
1599 ) const
1600 {
1601  assert( ! pose.energies().use_nblist() );
1602  //prepare_for_residue_pair(rsd1.seqpos(),rsd2.seqpos(),pose);
1603  //count_pair::CountPairFunctionCOP cpfxn = get_count_pair_function( rsd1, rsd2, pose, sfxn );
1604  //cpfxn->residue_atom_pair_energy_sidechain_sidechain( rsd1, rsd2, static_cast<Derived const&> (*this), emap );
1605  if ( exclude_DNA_DNA && rsd1.is_DNA() && rsd2.is_DNA() ) {
1606  return;
1607  }
1608  count_pair::CPCrossoverBehavior crossover = determine_crossover_behavior( rsd1, rsd2, pose, sfxn );
1609  SC_SC_EnergyInvoker< typename Derived::Evaluator > invoker( rsd1, rsd2, static_cast< Derived const & > (*this).interres_evaluator(), emap );
1611 }
1612 
1613 
1614 
1615 template < class Derived >
1616 void
1618  conformation::RotamerSetBase const & set1,
1619  conformation::RotamerSetBase const & set2,
1620  pose::Pose const & pose,
1621  ScoreFunction const & sfxn,
1622  EnergyMap const & weights,
1623  ObjexxFCL::FArray2D< core::PackerEnergy > & energy_table
1624 ) const
1625 {
1626  assert( set1.resid() != set2.resid() );
1627 
1628  using namespace methods;
1629  ObjexxFCL::FArray2D< core::PackerEnergy > temp_table1( energy_table );
1630  ObjexxFCL::FArray2D< core::PackerEnergy > temp_table2( energy_table );
1631 
1632  temp_table1 = 0; temp_table2 = 0;
1633 
1634  // save weight information so that its available during tvt execution
1635  //weights_ = weights; <--- getting rid of this non-bitwise-const data.
1636  typename Derived::Evaluator evaluator( static_cast< Derived const & > (*this).interres_evaluator() );
1637  evaluator.set_weights( weights );
1638 
1639  EtableRotamerTrieCOP trie1( static_cast< trie::RotamerTrieBase const * > ( set1.get_trie( etable_method )() ));
1640  EtableRotamerTrieCOP trie2( static_cast< trie::RotamerTrieBase const * > ( set2.get_trie( etable_method )() ));
1641 
1642  //prepare_for_residue_pair( set1.resid(), set2.resid(), pose );
1643 
1644 
1645  // figure out which trie countPairFunction needs to be used for this set
1646  TrieCountPairBaseOP cp = get_count_pair_function_trie( set1, set2, pose, sfxn );
1647 
1648  /// now execute the trie vs trie algorithm.
1649  /// this steps through three rounds of type resolution before finally arriving at the
1650  /// actual trie_vs_trie method. The type resolution calls allow the trie-vs-trie algorithm
1651  /// to be templated with full type knowledge (and therefore be optimized by the compiler for
1652  /// each variation on the count pair data used and the count pair funtions invoked.
1653  evaluator.trie_vs_trie( *trie1, *trie2, *cp, temp_table1, temp_table2 );
1654  //trie1->trie_vs_trie( *trie2, *cp, static_cast<Derived const&>(*this), temp_table1, temp_table2 );
1655 
1656  /// add in the energies calculated by the tvt alg.
1657  energy_table += temp_table1;
1658  //std::cout << "FINISHED evaluate_rotamer_pair_energies" << std::endl;
1659 
1660  /* // There should be a way to turn this on without recompiling...
1661  // debug
1662  ObjexxFCL::FArray2D< core::PackerEnergy > temp_table3( energy_table );
1663  temp_table3 = 0;
1664  EnergyMap emap;
1665  for ( Size ii = 1, ii_end = set1.num_rotamers(); ii <= ii_end; ++ii ) {
1666  for ( Size jj = 1, jj_end = set2.num_rotamers(); jj <= jj_end; ++jj ) {
1667  emap.zero();
1668  residue_pair_energy( *set1.rotamer( ii ), *set2.rotamer( jj ), pose, sfxn, emap );
1669  temp_table3( jj, ii ) += weights.dot( emap );
1670  if ( std::abs( temp_table1( jj, ii ) - temp_table3( jj, ii )) > 0.001 ) {
1671  std::cout << "Residues " << set1.resid() << " & " << set2.resid() << " rotamers: " << ii << " & " << jj;
1672  std::cout << " tvt/reg discrepancy: tvt= " << temp_table1( jj, ii ) << " reg= " << temp_table3( jj, ii );
1673  std::cout << " delta: " << temp_table1( jj, ii ) - temp_table3( jj, ii ) << std::endl;
1674  }
1675  }
1676  }
1677  //std::cout << "Finished RPE calcs for residues " << set1.resid() << " & " << set2.resid() << std::endl;
1678  */
1679 }
1680 
1681 template < class Derived >
1682 void
1684  conformation::RotamerSetBase const & set,
1685  conformation::Residue const & residue,
1686  pose::Pose const & pose,
1687  ScoreFunction const & sfxn,
1688  EnergyMap const & weights,
1690 ) const
1691 {
1692 
1693  using namespace methods;
1694  // allocate space for the trie-vs-trie algorithm
1695  utility::vector1< core::PackerEnergy > temp_vector1( set.num_rotamers(), 0.0 );
1696  utility::vector1< core::PackerEnergy > temp_vector2( set.num_rotamers(), 0.0 );
1697 
1698  // save weight information so that its available during tvt execution
1699  typename Derived::Evaluator evaluator( static_cast< Derived const & > (*this).interres_evaluator() );
1700  evaluator.set_weights( weights );
1701 
1702  EtableRotamerTrieCOP trie1( static_cast< trie::RotamerTrieBase const * > ( set.get_trie( etable_method )() ));
1703  EtableRotamerTrieCOP trie2 = ( static_cast< TrieCollection const & >
1704  ( pose.energies().data().get( EnergiesCacheableDataType::ETABLE_TRIE_COLLECTION )) ).trie( residue.seqpos() );
1705 
1706  //prepare_for_residue_pair( set.resid(), residue.seqpos(), pose );
1707 
1708  // figure out which trie countPairFunction needs to be used for this set
1709  TrieCountPairBaseOP cp = get_count_pair_function_trie( pose.residue( set.resid() ), residue, trie1, trie2, pose, sfxn );
1710 
1711  /// now execute the trie vs path algorithm.
1712  /// this steps through three rounds of type resolution before finally arriving at the
1713  /// actual trie_vs_path method. The type resolution calls allow the trie-vs-trie algorithm
1714  /// to be templated with full type knowledge (and therefore be optimized by the compiler for
1715  /// each variation on the count pair data used and the count pair funtions invoked.
1716  /// old! trie1->trie_vs_path( *trie2, *cp, static_cast<Derived const&> (*this), temp_vector1, temp_vector2 );
1717  evaluator.trie_vs_path( *trie1, *trie2, *cp, temp_vector1, temp_vector2 );
1718 
1719  /// add in the energies calculated by the tvt alg.
1720  for ( Size ii = 1; ii <= set.num_rotamers(); ++ii ) {
1721  energy_vector[ ii ] += temp_vector1[ ii ];
1722  }
1723  //std::cout << "FINISHED evaluate_rotamer_background_energies" << std::endl;
1724 
1725  /*
1726  //debug
1727  utility::vector1< Energy > temp_vector3( energy_vector.size(), 0.0f );
1728  EnergyMap emap;
1729  for ( Size ii = 1, ii_end = set.num_rotamers(); ii <= ii_end; ++ii ) {
1730  emap.zero();
1731  residue_pair_energy( *set.rotamer( ii ), residue, pose, sfxn, emap );
1732  temp_vector3[ ii ] += weights.dot( emap );
1733  if ( std::abs( temp_vector1[ ii ] - temp_vector3[ ii ]) > 0.001 ) {
1734  std::cout << "Residues " << set.resid() << " & " << residue.seqpos() << " rotamers: " << ii << " & bg";
1735  std::cout << " tvt/reg discrepancy: tvt= " << temp_vector1[ ii ] << " reg= " << temp_vector3[ ii ];
1736  std::cout << " delta: " << temp_vector1[ ii ] - temp_vector3[ ii ] << std::endl;
1737  }
1738  }
1739  std::cout << "Finished Rotamer BG calcs for residues " << set.resid() << " & " << residue.seqpos() << std::endl;
1740  */
1741 }
1742 
1743 
1744 template < class Derived >
1745 bool
1747 {
1748  return true;
1749 }
1750 
1751 template < class Derived >
1752 void
1754  conformation::Residue const & rsd,
1755  ResSingleMinimizationData const & min_data,
1756  pose::Pose const & pose,
1757  ScoreFunction const &,
1758  EnergyMap & emap
1759 ) const
1760 {
1761  if ( pose.energies().use_nblist_auto_update() ) return;
1762 
1763  assert( dynamic_cast< ResidueNblistData const * > (min_data.get_data( etab_single_nblist )() ));
1764  ResidueNblistData const & nblist( static_cast< ResidueNblistData const & > ( min_data.get_data_ref( etab_single_nblist ) ) );
1765 
1766  //prepare_for_residue_pair( 1,1, pose ); // set intra-res
1767  utility::vector1< SmallAtNb > const & neighbs( nblist.atom_neighbors() );
1768 
1769  Real dsq;
1770  for ( Size ii = 1, iiend = neighbs.size(); ii <= iiend; ++ii ) {
1771  conformation::Atom const & atom1( rsd.atom( neighbs[ ii ].atomno1() ) );
1772  conformation::Atom const & atom2( rsd.atom( neighbs[ ii ].atomno2() ) );
1773  static_cast< Derived const & > (*this).intrares_evaluator().atom_pair_energy( atom1, atom2, neighbs[ ii ].weight(), emap, dsq );
1774  //std::cout << "evaluated " << neighbs[ ii ].atomno1() << " " << neighbs[ ii ].atomno2() << " " <<
1775  // emap[ fa_atr ] << " " << emap[ fa_rep ] << " " << emap[ fa_sol ] << " " <<
1776  // emap[ fa_intra_atr ] << " " << emap[ fa_intra_rep ] << " " << emap[ fa_intra_sol ] << std::endl;
1777  }
1778 }
1779 
1780 template < class Derived >
1781 void
1783  conformation::Residue const & rsd,
1784  pose::Pose const & pose,
1785  ScoreFunction const & sfxn,
1787  ResSingleMinimizationData & min_data
1788 ) const
1789 {
1790  if ( pose.energies().use_nblist_auto_update() ) return;
1791 
1792  if ( (static_cast< Derived const & > (*this)).defines_intrares_energy( sfxn.weights() ) ) {
1793  using namespace basic::options;
1794  using namespace basic::options::OptionKeys;
1795 
1796  // update the existing nblist if it's already present in the min_data object
1797  ResidueNblistDataOP nbdata( static_cast< ResidueNblistData * > (min_data.get_data( etab_single_nblist )() ));
1798  if ( ! nbdata ) nbdata = new ResidueNblistData;
1799 
1800  /// STOLEN CODE!
1801  Real const tolerated_narrow_nblist_motion = option[ run::nblist_autoupdate_narrow ];
1802  Real const XX = etable_.max_dis() + 2 * tolerated_narrow_nblist_motion;
1803  Real const XH = etable_.max_non_hydrogen_lj_radius() + etable_.max_hydrogen_lj_radius()
1804  + 2 * tolerated_narrow_nblist_motion;
1805  Real const HH = etable_.max_hydrogen_lj_radius() + etable_.max_hydrogen_lj_radius()
1806  + 2 * tolerated_narrow_nblist_motion;
1807 
1808  count_pair::CountPairFunctionCOP count_pair = get_intrares_countpair( rsd, pose, sfxn );
1809  nbdata->initialize(
1810  rsd, count_pair, XX*XX, XH*XH, HH*HH );
1811  min_data.set_data( etab_single_nblist, nbdata );
1812 
1813  }
1814 }
1815 
1816 
1817 template < class Derived >
1818 void
1820  conformation::Residue const & rsd,
1821  ResSingleMinimizationData const & min_data,
1822  pose::Pose const & pose,
1823  EnergyMap const & weights,
1825 ) const
1826 {
1827  if ( pose.energies().use_nblist_auto_update() ) return;
1828 
1829  assert( dynamic_cast< ResidueNblistData const * > (min_data.get_data( etab_single_nblist )() ));
1830  ResidueNblistData const & nblist( static_cast< ResidueNblistData const & > ( min_data.get_data_ref( etab_single_nblist )) );
1831 
1832  utility::vector1< SmallAtNb > const & neighbs( nblist.atom_neighbors() );
1833 
1834  //prepare_for_residue_pair( 1, 1, pose ); // set intra-res
1835  typename Derived::Evaluator evaluator( static_cast< Derived const & > (*this).intrares_evaluator() );
1836  evaluator.set_weights( weights );
1837  Vector f1(0.0),f2(0.0);
1838  for ( Size ii = 1, iiend = neighbs.size(); ii <= iiend; ++ii ) {
1839  conformation::Atom const & atom1( rsd.atom( neighbs[ ii ].atomno1() ) );
1840  conformation::Atom const & atom2( rsd.atom( neighbs[ ii ].atomno2() ) );
1841  Real const dE_dR_over_r( evaluator.eval_dE_dR_over_r( atom1, atom2, weights, f1, f2 ) );
1842  if ( dE_dR_over_r != 0.0 ) {
1843  f1 *= dE_dR_over_r * neighbs[ ii ].weight();
1844  f2 *= dE_dR_over_r * neighbs[ ii ].weight();
1845  atom_derivs[ neighbs[ ii ].atomno1() ].f1() += f1;
1846  atom_derivs[ neighbs[ ii ].atomno1() ].f2() += f2;
1847  atom_derivs[ neighbs[ ii ].atomno2() ].f1() += -1 * f1;
1848  atom_derivs[ neighbs[ ii ].atomno2() ].f2() += -1 * f2;
1849  }
1850  }
1851 }
1852 
1853 /// @brief create a rotamer trie for a particular set, deciding upon the kind of count pair data that
1854 /// needs to be contained by the trie.
1855 ///
1856 template < class Derived >
1859  conformation::RotamerSetBase const & rotset,
1860  pose::Pose const & // will be need to create tries for disulfides
1861 ) const
1862 {
1863  using namespace etrie;
1864  using namespace trie;
1865 
1867  if ( cpdata_map.has_pseudobonds() ||
1868  cpdata_map.max_connpoints_for_residue() > 1 ||
1869  cpdata_map.n_entries() > 3 ) {
1871  return create_trie( rotset, at, cpdat, cpdata_map, atomic_interaction_cutoff() );
1872  } else if ( cpdata_map.n_entries() == 1 || cpdata_map.n_entries() == 0 /* HACK! */ ) {
1874  return create_trie( rotset, at, cpdat, cpdata_map, atomic_interaction_cutoff() );
1875  } else if ( cpdata_map.n_entries() == 2 ) {
1877  return create_trie( rotset, at, cpdat, cpdata_map, atomic_interaction_cutoff() );
1878  } else if ( cpdata_map.n_entries() == 3 ) {
1880  return create_trie( rotset, at, cpdat, cpdata_map, atomic_interaction_cutoff() );
1881  } else {
1882  /// As of 10/21, all count pair data combinations should be covered. This code should not execute.
1883  std::cerr << "Unsupported number of residue connections in trie construction." << std::endl;
1884  utility_exit();
1885  return 0;
1886  }
1887 }
1888 
1889 /// @details Create a one-residue trie.
1890 template < class Derived >
1893  conformation::Residue const & residue,
1894  pose::Pose const & // will be need to create tries for disulfides
1895 ) const
1896 {
1897  using namespace etrie;
1898  using namespace trie;
1899 
1901  if ( cpdata_map.has_pseudobonds() ||
1902  cpdata_map.max_connpoints_for_residue() > 1 ||
1903  cpdata_map.n_entries() > 3 ) {
1905  return create_trie( residue, at, cpdat, cpdata_map, atomic_interaction_cutoff() );
1906  } else if ( cpdata_map.n_entries() == 1 || cpdata_map.n_entries() == 0 /* HACK! */ ) {
1908  return create_trie( residue, at, cpdat, cpdata_map, atomic_interaction_cutoff() );
1909  } else if ( cpdata_map.n_entries() == 2 ) {
1911  return create_trie( residue, at, cpdat, cpdata_map, atomic_interaction_cutoff() );
1912  } else if ( cpdata_map.n_entries() == 3 ) {
1914  return create_trie( residue, at, cpdat, cpdata_map, atomic_interaction_cutoff() );
1915  } else {
1916  /// As of 10/21, all count pair data combinations should be covered. This code should not execute.
1917  std::cerr << "Unsupported number of residue connections in trie construction." << std::endl;
1918  utility_exit();
1919  return 0;
1920  }
1921 }
1922 
1923 template < class Derived >
1924 void
1926 {
1927  //context_graphs_required[ ten_A_neighbor_graph ] = true; // when did this get here?
1928 }
1929 
1930 template < class Derived >
1931 void
1933  conformation::Residue const & rsd1,
1934  conformation::Residue const & rsd2,
1935  pose::Pose const & pose,
1936  ScoreFunction const & sfxn,
1937  EnergyMap & emap
1938 ) const
1939 {
1940  EnergyMap tbemap;
1941  //prepare_for_residue_pair(rsd1.seqpos(),rsd2.seqpos(),pose);
1942 // count_pair::CountPairFunctionCOP cpfxn = get_count_pair_function( rsd1, rsd2, pose, sfxn );
1943 // cpfxn->residue_atom_pair_energy_sidechain_whole( rsd1, rsd2, static_cast<Derived const&> (*this), tbemap );
1944  if ( exclude_DNA_DNA && rsd1.is_DNA() && rsd2.is_DNA() ) {
1945  return;
1946  }
1947  count_pair::CPCrossoverBehavior crossover = determine_crossover_behavior( rsd1, rsd2, pose, sfxn );
1948  typename Derived::Evaluator const & evaluator( static_cast< Derived const & > (*this).interres_evaluator() );
1949  SC_Whole_EnergyInvoker< typename Derived::Evaluator > invoker( rsd1, rsd2, evaluator, tbemap );
1951 
1952  emap[ evaluator.st_atr() ] += tbemap[ evaluator.st_atr() ]; // consider moving this into the derived class
1953  emap[ evaluator.st_rep() ] += tbemap[ evaluator.st_rep() ];
1954 
1955 }
1956 
1957 template < class Derived >
1958 void
1960  conformation::Residue const & rsd1,
1961  conformation::Residue const & rsd2,
1962  pose::Pose const & pose,
1963  ScoreFunction const & sfxn,
1964  EnergyMap & emap
1965 ) const
1966 {
1967  EnergyMap tbemap;
1968  //prepare_for_residue_pair(rsd1.seqpos(),rsd2.seqpos(),pose);
1969  //count_pair::CountPairFunctionCOP cpfxn = get_count_pair_function( rsd1, rsd2, pose, sfxn );
1970  //cpfxn->residue_atom_pair_energy_sidechain_backbone( rsd1, rsd2, static_cast<Derived const&> (*this), tbemap );
1971  if ( exclude_DNA_DNA && rsd1.is_DNA() && rsd2.is_DNA() ) {
1972  return;
1973  }
1974  count_pair::CPCrossoverBehavior crossover = determine_crossover_behavior( rsd1, rsd2, pose, sfxn );
1975  typename Derived::Evaluator const & evaluator( static_cast< Derived const & > (*this).interres_evaluator() );
1976  SC_BB_EnergyInvoker< typename Derived::Evaluator > invoker( rsd1, rsd2, evaluator, tbemap );
1978 
1979  emap[ evaluator.st_atr() ] += tbemap[ evaluator.st_atr() ]; // consider moving this into the derived class
1980  emap[ evaluator.st_rep() ] += tbemap[ evaluator.st_rep() ];
1981 
1982 }
1983 
1984 
1985 ///////////////////////////////////////////////////////////////////////////////
1986 
1987 template < class Derived >
1988 void
1990  id::AtomID const & id,
1991  pose::Pose const & pose,
1992  kinematics::DomainMap const &, // domain_map,
1993  ScoreFunction const & /*sfxn*/, // needed for non-nblist minimization
1994  EnergyMap const & weights,
1995  Vector & F1,
1996  Vector & F2
1997 ) const
1998 {
1999  Size const idresid = id.rsd();
2000  conformation::Atom const & atom1( pose.residue( idresid ).atom( id.atomno() ) );
2001 
2002  if ( pose.energies().use_nblist() ) {
2003  scoring::AtomNeighbors const & nbrs
2005 
2006  typename Derived::Evaluator intrares_evaluator( static_cast< Derived const & > (*this).intrares_evaluator() );
2007  typename Derived::Evaluator interres_evaluator( static_cast< Derived const & > (*this).interres_evaluator() );
2008  intrares_evaluator.set_weights( weights );
2009  interres_evaluator.set_weights( weights );
2010  Vector f1(0.0),f2(0.0);
2011  for ( scoring::AtomNeighbors::const_iterator it2=nbrs.begin(),
2012  it2e=nbrs.end(); it2 != it2e; ++it2 ) {
2013  scoring::AtomNeighbor const & nbr( *it2 );
2014 
2015  // Intra residue weights separate from interresidue weights; set which weights to use before scoring.
2016  // Compairison between idresid and nb.rsd performed by EtableEnergy but not by
2017  // CoarseEtableEnergy -> both are passed as arguments
2018  // static_cast<Derived const&> (*this).decide_scoretypes( idresid, nbr.rsd() );
2019  //prepare_for_residue_pair( idresid, nbr.rsd(), pose );
2020  if ( idresid == (Size) nbr.rsd() ) {
2021  Real const cp_weight( nbr.weight() ); // do not use nbr->weight_func() here
2022  conformation::Atom const & atom2( pose.residue( nbr.rsd() ).atom( nbr.atomno() ) );
2023  Real const dE_dR_over_r( intrares_evaluator.eval_dE_dR_over_r( atom1, atom2, weights, f1, f2 ) );
2024  //std::cout << " gold atom deriv: " << idresid << " " << id.atomno() << " with " << nbr.rsd() << " " << nbr.atomno() << ". w= " << nbr.weight() << " dE_dR_over_r: " << dE_dR_over_r << std::endl ;
2025  if ( dE_dR_over_r != 0.0 ) {
2026  F1 += dE_dR_over_r * cp_weight * f1;
2027  F2 += dE_dR_over_r * cp_weight * f2;
2028  }
2029  } else {
2030  Real const cp_weight( nbr.weight() ); // do not use nbr->weight_func() here
2031  conformation::Atom const & atom2( pose.residue( nbr.rsd() ).atom( nbr.atomno() ) );
2032  Real const dE_dR_over_r( interres_evaluator.eval_dE_dR_over_r( atom1, atom2, weights, f1, f2 ) );
2033  //std::cout << " gold atom deriv: " << idresid << " " << id.atomno() << " with " << nbr.rsd() << " " << nbr.atomno() << ". w= " << nbr.weight() << " dE_dR_over_r: " << dE_dR_over_r << std::endl ;
2034  if ( dE_dR_over_r != 0.0 ) {
2035  F1 += dE_dR_over_r * cp_weight * f1;
2036  F2 += dE_dR_over_r * cp_weight * f2;
2037  }
2038  }
2039  }
2040  } else {
2041  utility_exit_with_message("non-nblist minimize!");
2042  }
2043 }
2044 
2045 
2046 /// @brief return the Etables atomic distance cutoff
2047 template < class Derived >
2048 Distance
2050 {
2051  using namespace basic::options;
2052  using namespace basic::options::OptionKeys;
2053  return etable_.max_dis() +
2054  ( option[ score::fa_Hatr ] ? chemical::MAX_CHEMICAL_BOND_TO_HYDROGEN_LENGTH * 2 : 0.0 ); /// HACK -- add in hydrogen/heavy max dist * 2
2055 }
2056 
2057 
2058 
2059 } // namespace etable
2060 } // namespace scoring
2061 } // namespace core
2062 
2063 
2064 #endif