Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
MinimizationGraph.cc
Go to the documentation of this file.
1 // -*- mode:c++;tab-width:2;indent-tabs-mode:t;show-trailing-whitespace:t;rm-trailing-spaces:t -*-
2 // vi: set ts=2 noet:
3 //
4 // (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/MinimizationGraph.cc
11 /// @brief Minimization graph class implementation
12 /// @author Andrew Leaver-Fay (leaverfa@email.unc.edu)
13 
14 // Unit Headers
16 
17 // Package Headers
18 // AUTO-REMOVED #include <core/scoring/DerivVectorPair.hh>
22 
23 // Numeric headers
24 // AUTO-REMOVED #include <numeric/xyzVector.hh>
25 
26 // Boost Headers
28 
29 // C++ headers
30 #include <iostream>
31 
32 #include <utility/vector1.hh>
33 #include <boost/pool/pool.hpp>
34 
35 
36 namespace core {
37 namespace scoring {
38 
39 using namespace graph;
40 
41 ///////// Minimization Node Class /////////////
42 
44  parent( owner, index )
45 {}
46 
48 
49 
51 {
52  std::cout << "MinimizationNode::print() deferring to parent::print()" << std::endl;
53  parent::print();
54 }
55 
56 /// @brief copy mmember data from source node
57 ///
58 /// invoked by copy ctor and operator= methods from Graph base class
59 void MinimizationNode::copy_from( parent const * source )
60 {
61  //MinimizationNode const * mn_source = utility::down_cast< MinimizationNode const * > ( source );
62  MinimizationNode const & mn_source = static_cast< MinimizationNode const & > ( * source );
63 
64  res_min_data_ = mn_source.res_min_data_; // deep copy
65 
80  weight_ = mn_source.weight_;
81 
82 }
83 
85 {
86  return sizeof ( MinimizationNode );
87 }
88 
90 {
91  Size tot = 0;
92  tot += parent::count_dynamic_memory(); //recurse to parent
93  /// add in the cost of storing the minimization data here
94  return tot;
95 }
96 
97 bool MinimizationNode::add_onebody_enmeth( OneBodyEnergyCOP enmeth, Residue const & rsd, Pose const & pose, int domain_map_color )
98 {
99  onebody_enmeths_.push_back( enmeth );
100  return classify_onebody_enmeth( enmeth, rsd, pose, domain_map_color );
101 }
102 
103 /// @details Note that the minimization graph is used both to evaluate the scores for
104 /// both the "modern" EnergyMethods and the "old" energy methods (those which still
105 /// define eval_atom_derivative instead of the pairwise-decomposable derivative
106 /// evaluation methods) so when these older energy methods are added to the minimization
107 /// graph, they should not simply be rejected.
109  TwoBodyEnergyCOP enmeth,
110  Residue const & rsd,
111  Pose const & pose,
112  EnergyMap const & weights,
113  int domain_map_color
114 )
115 {
116  //if ( enmeth->minimize_in_whole_structure_context( pose ) ) return false;
117 
118  twobody_enmeths_.push_back( enmeth );
119  return classify_twobody_enmeth( enmeth, rsd, pose, weights, domain_map_color );
120 }
121 
122 void
124  Residue const & rsd,
125  pose::Pose const & pose,
126  ScoreFunction const & sfxn,
127  kinematics::MinimizerMapBase const & min_map
128 )
129 {
131  iter_end = active_1benmeths_end(); iter != iter_end; ++iter ) {
132  (*iter)->setup_for_minimizing_for_residue( rsd, pose, sfxn, min_map, res_min_data_ );
133  }
134  for ( TwoBodyEnergiesIterator iter = twobody_enmeths_.begin(),
135  iter_end = twobody_enmeths_.end(); iter != iter_end; ++iter ) {
136  (*iter)->setup_for_minimizing_for_residue( rsd, pose, sfxn, min_map, res_min_data_ );
137  }
138 }
139 
141  Residue const & rsd,
142  pose::Pose const & pose,
143  ScoreFunction const & sfxn
144 )
145 {
146  /// 1a 1body energy methods
148  iter_end = sfs_req_1benmeths_end(); iter != iter_end; ++iter ) {
149  (*iter)->setup_for_scoring_for_residue( rsd, pose, sfxn, res_min_data_ );
150  }
151  /// 1b 2body intraresidue contributions
153  iter_end = sfs_req_2benmeths_end(); iter != iter_end; ++iter ) {
154  (*iter)->setup_for_scoring_for_residue( rsd, pose, sfxn, res_min_data_ );
155  }
156 }
157 
159  Residue const & rsd,
160  pose::Pose const & pose,
161  ScoreFunction const & sfxn
162 )
163 {
164  /// 1a 1body energy methods
166  iter_end = sfd_req_1benmeths_end(); iter != iter_end; ++iter ) {
167  (*iter)->setup_for_derivatives_for_residue( rsd, pose, sfxn, res_min_data_ );
168  }
169  /// 1b 2body intraresidue contributions
171  iter_end = sfd_req_2benmeths_end(); iter != iter_end; ++iter ) {
172  (*iter)->setup_for_derivatives_for_residue( rsd, pose, sfxn, res_min_data_ );
173  }
174 }
175 
177  Residue const & rsd,
178  pose::Pose const & pose,
179  EnergyMap const & weights,
180  int domain_map_color
181 )
182 {
183  active_1benmeths_.clear();
184  active_1benmeths_std_.clear();
185  active_1benmeths_ext_.clear();
186  dof_deriv_1benmeths_.clear();
187  sfs_req_1benmeths_.clear();
188  sfd_req_1benmeths_.clear();
189 
193  dof_deriv_2benmeths_.clear();
194  sfs_req_2benmeths_.clear();
195  sfd_req_2benmeths_.clear();
196 
197  for ( OneBodyEnergiesIterator iter = onebody_enmeths_.begin(),
198  iter_end = onebody_enmeths_.end(); iter != iter_end; ++iter ) {
199  classify_onebody_enmeth( *iter, rsd, pose, domain_map_color );
200  }
201  for ( TwoBodyEnergiesIterator iter = twobody_enmeths_.begin(),
202  iter_end = twobody_enmeths_.end(); iter != iter_end; ++iter ) {
203  classify_twobody_enmeth( *iter, rsd, pose, weights, domain_map_color );
204  }
205 }
206 
208 void MinimizationNode::add_active_1benmeth_ext( OneBodyEnergyCOP enmeth ) { active_1benmeths_.push_back( enmeth ); active_1benmeths_ext_.push_back( enmeth ); }
212 
218 
219 bool
220 MinimizationNode::classify_onebody_enmeth( OneBodyEnergyCOP enmeth, Residue const & rsd, Pose const & pose, int domain_map_color )
221 {
222  if ( domain_map_color == 0 ) {
223  if ( enmeth->defines_score_for_residue( rsd )) {
224  if ( enmeth->use_extended_residue_energy_interface() ) {
225  add_active_1benmeth_ext( enmeth );
226  } else {
227  add_active_1benmeth_std( enmeth );
228  }
229  if ( enmeth->defines_dof_derivatives( pose ) ) {
230  add_dof_deriv_1benmeth( enmeth );
231  }
232  if ( enmeth->requires_a_setup_for_scoring_for_residue_opportunity( pose ) ) {
233  add_sfs_1benmeth( enmeth );
234  }
235  if ( enmeth->requires_a_setup_for_derivatives_for_residue_opportunity( pose ) ) {
236  add_sfd_1benmeth( enmeth );
237  }
238  return true;
239  } else {
240  return false;
241  }
242  } else {
243  return false; // need to think about this
244  }
245 }
246 
248  TwoBodyEnergyCOP enmeth,
249  Residue const & rsd,
250  Pose const & pose,
251  EnergyMap const & weights,
252  int domain_map_color
253 )
254 {
255  bool added( false );
256  if (enmeth->requires_a_setup_for_scoring_for_residue_opportunity( pose )) {
257  /// should we let energy methods setup for scoring for a residue even if they
258  /// don't define an intrares energy for that residue? Yes. These
259  add_sfs_2benmeth( enmeth );
260  }
261  if (enmeth->requires_a_setup_for_derivatives_for_residue_opportunity( pose )) {
262  /// should we let energy methods setup for scoring for a residue even if they
263  /// don't define an intrares energy for that residue? Yes. These
264  add_sfd_2benmeth( enmeth );
265  }
266 
267  /// Domain map check only prevents intra-residue sfxn/deriv evaluations; but not
268  /// SFS or SFD registration.
269  if ( domain_map_color == 0 ) {
270  if ( enmeth->defines_intrares_energy( weights ) && enmeth->defines_intrares_energy_for_residue( rsd )) {
271  if ( enmeth->use_extended_intrares_energy_interface() ) {
272  add_active_2benmeth_ext( enmeth );
273  } else {
274  add_active_2benmeth_std( enmeth );
275  }
276  added = true;
277  } else {
278  added = false;
279  }
280  if ( enmeth->defines_intrares_dof_derivatives( pose ) ) {
281  add_dof_deriv_2benmeth( enmeth );
282  }
283  }
284  return added;
285 }
286 
287 
290  return active_1benmeths_.begin();
291 }
292 
295  return active_1benmeths_.end();
296 }
297 
300  return active_1benmeths_std_.begin();
301 }
302 
305  return active_1benmeths_std_.end();
306 }
307 
310  return active_1benmeths_ext_.begin();
311 }
312 
315  return active_1benmeths_ext_.end();
316 }
317 
320  return dof_deriv_1benmeths_.begin();
321 }
322 
325  return dof_deriv_1benmeths_.end();
326 }
327 
330  return sfs_req_1benmeths_.begin();
331 }
332 
335  return sfs_req_1benmeths_.end();
336 }
337 
338 
339 
342  return sfd_req_1benmeths_.begin();
343 }
344 
347  return sfd_req_1benmeths_.end();
348 }
349 
350 
353  return active_intrares2benmeths_.begin();
354 }
355 
358  return active_intrares2benmeths_.end();
359 }
360 
363  return active_intrares2benmeths_std_.begin();
364 }
365 
368  return active_intrares2benmeths_std_.end();
369 }
370 
371 
374  return active_intrares2benmeths_ext_.begin();
375 }
376 
379  return active_intrares2benmeths_ext_.end();
380 }
381 
384  return dof_deriv_2benmeths_.begin();
385 }
386 
389  return dof_deriv_2benmeths_.end();
390 }
391 
394  return sfs_req_2benmeths_.begin();
395 }
396 
399  return sfs_req_2benmeths_.end();
400 }
401 
404  return sfd_req_2benmeths_.begin();
405 }
406 
409  return sfd_req_2benmeths_.end();
410 }
411 
412 ///////// Minimization Edge Class /////////////
413 
414 /// @brief Minimization edge ctor
416  MinimizationGraph * owner,
417  Size n1,
418  Size n2
419 ) :
420  parent( owner, n1, n2 ),
421  weight_( 1.0 )
422 {}
423 
425  MinimizationGraph * owner,
426  MinimizationEdge const & example_edge
427 )
428 :
429  parent( owner, example_edge.get_first_node_ind(), example_edge.get_second_node_ind() ),
430  weight_( 1.0 )
431 {
432  copy_from( & example_edge );
433 }
434 
435 /// @brief virtual dstor; The MinimizationEdge must free the array pool element it
436 /// holds before it disappears.
438 {
439 }
440 
441 /// @brief copies data from MinimizationEdge const * source;
442 ///
443 /// called from the copy ctor and operator= methods defined in the Graph base class
444 void MinimizationEdge::copy_from( parent const * source )
445 {
446  //MinimizationEdge const * ee = static_cast< MinimizationEdge const * > ( source );
447  // down_cast is *supposed* to assert the dynamic cast in debug builds; doesn't work for some reason
448  MinimizationEdge const & minedge = static_cast< MinimizationEdge const & > ( * source );
449 
457  weight_ = minedge.weight_;
458 }
459 
460 
461 /// @brief virtual call to determine the static size of an Edge object
462 /// dynamic memory use is counted through the recursive count_dynamic_memory()
463 /// calling path
465 {
466  return sizeof ( MinimizationEdge );
467 }
468 
469 /// @brief virtual call to determine the amount of dynamic memory allocated by
470 /// an edge; this function must recurse to the parent class to determine how
471 /// much memory the parent class is responsible for. Do not account for
472 /// the size of the ArrayPool array here; instead, that is accounted for in
473 /// the MinimizationGraph::count_dynamic_memory method.
475 {
476  Size tot = 0;
477  tot += parent::count_dynamic_memory(); //recurse to parent
478  /// add in cost of storing the residue-pair minimization data here
479  return tot;
480 }
481 
483  TwoBodyEnergyCOP enmeth,
484  Residue const & rsd1,
485  Residue const & rsd2,
486  pose::Pose const & pose,
487  bool res_moving_wrt_eachother
488 )
489 {
490  twobody_enmeths_.push_back( enmeth );
491  return classify_twobody_enmeth( enmeth, rsd1, rsd2, pose, res_moving_wrt_eachother );
492 
493 }
494 
496  Residue const & rsd1,
497  Residue const & rsd2,
498  pose::Pose const & pose,
499  ScoreFunction const & sfxn,
500  kinematics::MinimizerMapBase const & min_map
501 )
502 {
503  for ( TwoBodyEnergiesIterator iter = active_2benmeths_.begin(),
504  iter_end = active_2benmeths_.end(); iter != iter_end; ++iter ) {
505  (*iter)->setup_for_minimizing_for_residue_pair(
506  rsd1, rsd2, pose, sfxn, min_map,
507  get_minimization_node( 0 )->res_min_data(),
508  get_minimization_node( 1 )->res_min_data(),
510  }
511 }
512 
514  Residue const & rsd1,
515  Residue const & rsd2,
516  Pose const & pose,
517  ScoreFunction const & sfxn
518 )
519 {
521  iter_end = sfs_req_2benmeths_end(); iter != iter_end; ++iter ) {
522  (*iter)->setup_for_scoring_for_residue_pair(
523  rsd1, rsd2,
524  get_minimization_node( 0 )->res_min_data(),
525  get_minimization_node( 1 )->res_min_data(),
526  pose, sfxn, res_pair_min_data_ );
527  }
528 }
529 
531  Residue const & rsd1,
532  Residue const & rsd2,
533  Pose const & pose,
534  ScoreFunction const & sfxn
535 )
536 {
538  iter_end = sfd_req_2benmeths_end(); iter != iter_end; ++iter ) {
539  (*iter)->setup_for_derivatives_for_residue_pair(
540  rsd1, rsd2,
541  get_minimization_node( 0 )->res_min_data(),
542  get_minimization_node( 1 )->res_min_data(),
543  pose, sfxn, res_pair_min_data_ );
544  }
545 
546 }
547 
549  Residue const & rsd1,
550  Residue const & rsd2,
551  Pose const & pose,
552  bool res_moving_wrt_eachother
553 )
554 {
555  active_2benmeths_.clear();
556  active_2benmeths_std_.clear();
557  active_2benmeths_ext_.clear();
558  sfs_req_2benmeths_.clear();
559  sfd_req_2benmeths_.clear();
560 
561  for ( TwoBodyEnergiesIterator iter = twobody_enmeths_.begin(),
562  iter_end = twobody_enmeths_.end(); iter != iter_end; ++iter ) {
563  classify_twobody_enmeth( *iter, rsd1, rsd2, pose, res_moving_wrt_eachother );
564  }
565 }
566 
567 void MinimizationEdge::add_active_enmeth_std( TwoBodyEnergyCOP enmeth ) { active_2benmeths_.push_back( enmeth ); active_2benmeths_std_.push_back( enmeth );}
568 void MinimizationEdge::add_active_enmeth_ext( TwoBodyEnergyCOP enmeth ) { active_2benmeths_.push_back( enmeth ); active_2benmeths_ext_.push_back( enmeth ); }
571 
573  TwoBodyEnergyCOP enmeth,
574  Residue const & rsd1,
575  Residue const & rsd2,
576  pose::Pose const & pose,
577  bool res_moving_wrt_eachother
578 )
579 {
580  ///if ( enmeth->minimize_in_whole_structure_context( pose ) ) return false; !NO! Go ahead and include them for scoring.
581  if ( ! enmeth->defines_score_for_residue_pair( rsd1, rsd2, res_moving_wrt_eachother ) ) return false;
582 
583  if ( enmeth->use_extended_residue_pair_energy_interface() ) {
584  add_active_enmeth_ext( enmeth );
585  } else {
586  add_active_enmeth_std( enmeth );
587  }
588 
589  if ( enmeth->requires_a_setup_for_scoring_for_residue_pair_opportunity( pose ) ) {
590  add_sfs_enmeth( enmeth );
591  }
592  if ( enmeth->requires_a_setup_for_derivatives_for_residue_pair_opportunity( pose ) ) {
593  add_sfd_enmeth( enmeth );
594  }
595  return true;
596 }
597 
598 
601  return active_2benmeths_.begin();
602 }
603 
606  return active_2benmeths_.end();
607 }
608 
611  return active_2benmeths_std_.begin();
612 }
613 
616  return active_2benmeths_std_.end();
617 }
618 
619 
622  return active_2benmeths_ext_.begin();
623 }
624 
627  return active_2benmeths_ext_.end();
628 }
629 
632  return sfs_req_2benmeths_.begin();
633 }
634 
637  return sfs_req_2benmeths_.end();
638 }
639 
642  return sfd_req_2benmeths_.begin();
643 }
644 
647  return sfd_req_2benmeths_.end();
648 }
649 
650 ///////// Minimization Graph Class /////////////
651 
653 {
654  Edge * edge( find_edge( n1, n2 ) );
655  if ( edge ) {
656  return static_cast< MinimizationEdge * > ( edge );
657  //return utility::down_cast< MinimizationEdge * > ( edge );
658  } else {
659  return 0;
660  }
661 }
662 
664 {
665  Edge const * edge( find_edge( n1, n2 ) );
666  if ( edge ) {
667  return static_cast< MinimizationEdge const * > ( edge );
668  //return utility::down_cast< MinimizationEdge const * > ( edge );
669  } else {
670  return 0;
671  }
672 }
673 
674 
676 :
677  parent(),
678  minimization_edge_pool_( new boost::unordered_object_pool< MinimizationEdge > ( 256 ) )
679 {}
680 
681 /// @details This does not call the base class parent( Size ) constructor since
682 /// that produces calls to the polymorphic function create_new_node() and polymorphism
683 /// does not work during constructor intialization.
685 :
686  parent(),
687  minimization_edge_pool_( new boost::unordered_object_pool< MinimizationEdge > ( 256 ) )
688 {
689  set_num_nodes( num_nodes );
690 }
691 
692 /// @details Notice that this does not call the parent( src ) copy constructor.
693 /// This is because the copy constructor relies on polymorphic functions which
694 /// are unavailable during the Graph constructor. Instead, this function waits
695 /// until parent construction is complete, and relies on the assigmnent operator.
697 :
698  parent( ),
699  minimization_edge_pool_( new boost::unordered_object_pool< MinimizationEdge > ( 256 ) )
700 {
701  parent::operator = ( src );
702 }
703 
707 }
708 
709 
710 /// @brief assignment operator -- performs a deep copy
711 MinimizationGraph const &
713 {
714  parent::operator = ( rhs );
715  return *this;
716 }
717 
719 {
720  assert( dynamic_cast< MinimizationEdge* > (edge) );
721  minimization_edge_pool_->destroy( static_cast< MinimizationEdge* > (edge) );
722 }
723 
725 {
726  return sizeof ( MinimizationGraph );
727 }
728 
730 {
731  Size tot(0);
732  tot += parent::count_dynamic_memory(); //recurse to parent
733  return tot;
734 }
735 
737 {
738  whole_pose_context_enmeths_.push_back( enmeth );
739 }
740 
743 {
744  return whole_pose_context_enmeths_.begin();
745 }
746 
749 {
750  return whole_pose_context_enmeths_.end();
751 }
752 
755 
756 
757 /// @brief Factory method for node creation
758 Node*
760 {
761  return new MinimizationNode( this, index );
762 }
763 
764 /// @brief Factory method for edge creation
765 Edge*
767 {
768  return minimization_edge_pool_->construct( this, index1, index2 );
769 }
770 
771 /// @brief Factory copy-constructor method for edge creation
772 Edge*
774 {
775  return minimization_edge_pool_->construct(
776  this,
777  static_cast< MinimizationEdge const & > (*example_edge)
778  );
779 }
780 
781 
782 ///// NON MEMBER FUNCTIONS////
783 
784 /*void
785 reinitialize_minedge_for_respair(
786  MinimizationEdge & min_edge,
787  conformation::Residue const & rsd1,
788  conformation::Residue const & rsd2,
789  ResSingleMinimizationData const & res1_ressingle_min_data,
790  ResSingleMinimizationData const & res2_ressingle_min_data,
791  pose::Pose & pose,
792  ScoreFunction const & sfxn,
793  kinematics::MinimizerMapBase const & minmap
794 )
795 {
796 
797  //assert( rsd1.seqpos() < rsd2.seqpos() );
798  for ( MinimizationEdge::TwoBodyEnergiesIterator
799  iter = min_edge.active_2benmeths_begin(),
800  iter_end = min_edge.active_2benmeths_end();
801  iter != iter_end; ++iter ) {
802 
803  (*iter)->setup_for_minimizing_for_residue_pair(
804  rsd1, rsd2, pose, sfxn, minmap,
805  res1_ressingle_min_data,
806  res2_ressingle_min_data,
807  min_edge.res_pair_min_data() );
808 
809  }
810 
811 
812 }*/
813 
814 
815 /*void
816 setup_for_scoring_for_minnode(
817  MinimizationNode & min_node,
818  conformation::Residue const & rsd,
819  pose::Pose const & pose
820 )
821 {
822  /// 1a 1body energy methods
823  for ( MinimizationNode::OneBodyEnergiesIterator
824  iter = min_node.sfd_req_1benmeths_begin(),
825  iter_end = min_node.sfd_req_1benmeths_end(); iter != iter_end; ++iter ) {
826  (*iter)->setup_for_scoring_for_residue( rsd, pose, min_node.res_min_data() );
827  }
828  /// 1b 2body intraresidue contributions
829  for ( MinimizationNode::TwoBodyEnergiesIterator
830  iter = min_node.sfd_req_2benmeths_begin(),
831  iter_end = min_node.sfd_req_2benmeths_end(); iter != iter_end; ++iter ) {
832  (*iter)->setup_for_scoring_for_residue( rsd, pose, min_node.res_min_data() );
833  }
834 
835 }*/
836 
837 /*void
838 setup_for_scoring_for_minedge(
839  MinimizationEdge & min_edge,
840  conformation::Residue const & rsd1,
841  conformation::Residue const & rsd2,
842  pose::Pose const & pose,
843  ResSingleMinimizationData const & res1_ressingle_min_data,
844  ResSingleMinimizationData const & res2_ressingle_min_data
845 )
846 {
847  //assert( rsd1.seqpos() < rsd2.seqpos() );
848  for ( MinimizationEdge::TwoBodyEnergiesIterator
849  iter = min_edge.sfd_req_2benmeths_begin(),
850  iter_end = min_edge.sfd_req_2benmeths_end();
851  iter != iter_end; ++iter ) {
852  (*iter)->setup_for_scoring_for_residue_pair(
853  rsd1, rsd2, res1_ressingle_min_data, res2_ressingle_min_data, pose, min_edge.res_pair_min_data() );
854  }
855 
856 }*/
857 
858 /*void
859 setup_for_derivatives_for_minnode(
860  MinimizationNode & min_node,
861  conformation::Residue const & rsd,
862  pose::Pose const & pose
863 )
864 {
865  ResSingleMinimizationData & ressingle_min_data( min_node.res_min_data() );
866 
867  /// 1a 1body energy methods
868  for ( MinimizationNode::OneBodyEnergiesIterator
869  iter = min_node.sfd_req_1benmeths_begin(),
870  iter_end = min_node.sfd_req_1benmeths_end(); iter != iter_end; ++iter ) {
871  (*iter)->setup_for_derivatives_for_residue( rsd, pose, ressingle_min_data );
872  }
873  /// 1b 2body intraresidue contributions
874  for ( MinimizationNode::TwoBodyEnergiesIterator
875  iter = min_node.sfd_req_2benmeths_begin(),
876  iter_end = min_node.sfd_req_2benmeths_end(); iter != iter_end; ++iter ) {
877  (*iter)->setup_for_derivatives_for_residue( rsd, pose, ressingle_min_data );
878  }
879 
880 }*/
881 
882 /*void
883 setup_for_derivatives_for_minedge(
884  MinimizationEdge & min_edge,
885  conformation::Residue const & rsd1,
886  conformation::Residue const & rsd2,
887  pose::Pose const & pose,
888  ResSingleMinimizationData const & res1_min_data,
889  ResSingleMinimizationData const & res2_min_data
890 )
891 {
892  //assert( rsd1.seqpos() < rsd2.seqpos() );
893  for ( MinimizationEdge::TwoBodyEnergiesIterator
894  iter = min_edge.sfd_req_2benmeths_begin(),
895  iter_end = min_edge.sfd_req_2benmeths_end();
896  iter != iter_end; ++iter ) {
897  (*iter)->setup_for_derivatives_for_residue_pair(
898  rsd1, rsd2, res1_min_data, res2_min_data, pose, min_edge.res_pair_min_data() );
899  }
900 
901 }*/
902 
903 void
905  MinimizationNode const & min_node,
906  conformation::Residue const & rsd,
907  pose::Pose const & pose,
908  EnergyMap const & res_weights,
910 )
911 {
913  iter = min_node.active_1benmeths_begin(),
914  iter_end = min_node.active_1benmeths_end(); iter != iter_end; ++iter ) {
915  (*iter)->eval_residue_derivatives(
916  rsd, min_node.res_min_data(), pose, res_weights, atom_derivs );
917  }
918  /// 1b 2body intraresidue contributions
920  iter = min_node.active_intrares2benmeths_begin(),
921  iter_end = min_node.active_intrares2benmeths_end(); iter != iter_end; ++iter ) {
922  (*iter)->eval_intrares_derivatives(
923  rsd, min_node.res_min_data(), pose, res_weights, atom_derivs );
924  }
925 
926 }
927 
928 /*void
929 eval_atom_derivative_for_minnode(
930  MinimizationNode const & min_node,
931  Size atom_index,
932  conformation::Residue const & rsd,
933  pose::Pose const & pose,
934  kinematics::DomainMap const & domain_map,
935  ScoreFunction const & sfxn,
936  EnergyMap const & res_weights,
937  Vector & F1, // accumulated into
938  Vector & F2 // accumulated into
939 )
940 {
941  utility_exit_with_message( "Deprecated" );
942 
943  /// 1. eval 1 body derivatives
944  /// 1a 1body energy methods
945  for ( MinimizationNode::OneBodyEnergiesIterator
946  iter = min_node.active_1benmeths_begin(),
947  iter_end = min_node.active_1benmeths_end(); iter != iter_end; ++iter ) {
948  (*iter)->eval_atom_derivative_for_residue(
949  atom_index, rsd, min_node.res_min_data(), pose, domain_map, sfxn, res_weights, F1, F2 );
950  }
951  /// 1b 2body intraresidue contributions
952  for ( MinimizationNode::TwoBodyEnergiesIterator
953  iter = min_node.active_intrares2benmeths_begin(),
954  iter_end = min_node.active_intrares2benmeths_end(); iter != iter_end; ++iter ) {
955  (*iter)->eval_intrares_atom_derivative(
956  atom_index, rsd, min_node.res_min_data(), pose, domain_map, sfxn, res_weights, F1, F2 );
957  }
958 
959 }*/
960 
961 void
963  MinimizationNode const & min_node,
964  conformation::Residue const & rsd,
965  pose::Pose const & pose,
966  ScoreFunction const & sfxn,
967  EnergyMap & emap // accumulated into
968 )
969 {
971  iter = min_node.active_1benmeths_std_begin(),
972  iter_end = min_node.active_1benmeths_std_end();
973  iter != iter_end; ++iter ) {
974  (*iter)->residue_energy( rsd, pose, emap );
975  }
977  iter = min_node.active_1benmeths_ext_begin(),
978  iter_end = min_node.active_1benmeths_ext_end();
979  iter != iter_end; ++iter ) {
980  (*iter)->residue_energy_ext( rsd, min_node.res_min_data(), pose, emap );
981  }
982  /// 1b 2body intraresidue contributions
984  iter = min_node.active_intrares2benmeths_std_begin(),
985  iter_end = min_node.active_intrares2benmeths_std_end();
986  iter != iter_end; ++iter ) {
987  (*iter)->eval_intrares_energy( rsd, pose, sfxn, emap );
988  }
990  iter = min_node.active_intrares2benmeths_ext_begin(),
991  iter_end = min_node.active_intrares2benmeths_ext_end();
992  iter != iter_end; ++iter ) {
993  (*iter)->eval_intrares_energy_ext( rsd, min_node.res_min_data(), pose, sfxn, emap );
994  }
995 
996 }
997 
998 void
1000  MinimizationEdge const & min_edge,
1001  conformation::Residue const & res1,
1002  conformation::Residue const & res2,
1003  ResSingleMinimizationData const & res1_min_data,
1004  ResSingleMinimizationData const & res2_min_data,
1005  pose::Pose const & pose,
1006  EnergyMap const & respair_weights,
1007  utility::vector1< DerivVectorPair > & r1atom_derivs,
1008  utility::vector1< DerivVectorPair > & r2atom_derivs
1009 )
1010 {
1012  iter = min_edge.active_2benmeths_begin(),
1013  iter_end = min_edge.active_2benmeths_end();
1014  iter != iter_end; ++iter ) {
1015  (*iter)->eval_residue_pair_derivatives(
1016  res1, res2, res1_min_data, res2_min_data, min_edge.res_pair_min_data(),
1017  pose, respair_weights, r1atom_derivs, r2atom_derivs );
1018  }
1019 }
1020 
1021 /*void
1022 eval_atom_deriv_for_minedge(
1023  MinimizationEdge const & min_edge,
1024  Size atom_index,
1025  conformation::Residue const & res1,
1026  conformation::Residue const & res2,
1027  ResSingleMinimizationData const & res1_min_data,
1028  ResSingleMinimizationData const & res2_min_data,
1029  pose::Pose const & pose,
1030  kinematics::DomainMap const & domain_map,
1031  ScoreFunction const & sfxn,
1032  EnergyMap const & respair_weights,
1033  Vector & F1, // accumulated into
1034  Vector & F2 // accumulated into
1035 )
1036 {
1037  utility_exit_with_message( "Deprecated" );
1038  /// iterate across the two-body energies for this edge
1039  for ( MinimizationEdge::TwoBodyEnergiesIterator
1040  iter = min_edge.active_2benmeths_begin(),
1041  iter_end = min_edge.active_2benmeths_end();
1042  iter != iter_end; ++iter ) {
1043  (*iter)->eval_atom_derivative_for_residue_pair(
1044  atom_index, res1, res2,
1045  res1_min_data, res2_min_data, min_edge.res_pair_min_data(),
1046  pose, domain_map, sfxn, respair_weights, F1, F2 );
1047  }
1048 }
1049 */
1050 
1051 void
1053  MinimizationEdge const & min_edge,
1054  conformation::Residue const & res1,
1055  conformation::Residue const & res2,
1056  pose::Pose const & pose,
1057  ScoreFunction const & sfxn,
1058  EnergyMap & emap
1059 )
1060 {
1062  iter = min_edge.active_2benmeths_std_begin(),
1063  iter_end = min_edge.active_2benmeths_std_end();
1064  iter != iter_end; ++iter ) {
1065  (*iter)->residue_pair_energy(
1066  res1, res2, pose, sfxn, emap );
1067  }
1069  iter = min_edge.active_2benmeths_ext_begin(),
1070  iter_end = min_edge.active_2benmeths_ext_end();
1071  iter != iter_end; ++iter ) {
1072  (*iter)->residue_pair_energy_ext(
1073  res1, res2, min_edge.res_pair_min_data(), pose, sfxn, emap );
1074  }
1075 }
1076 
1077 Real
1079  MinimizationNode const & min_node,
1080  conformation::Residue const & rsd,
1081  pose::Pose const & pose,
1082  id::DOF_ID const & dof_id,
1083  id::TorsionID const & torsion_id,
1084  ScoreFunction const & sfxn,
1085  EnergyMap const & weights
1086 )
1087 {
1088  Real deriv( 0 );
1089  /// 1. eval 1 body derivatives
1090  /// 1a 1body energy methods
1092  iter = min_node.dof_deriv_1benmeths_begin(),
1093  iter_end = min_node.dof_deriv_1benmeths_end(); iter != iter_end; ++iter ) {
1094  deriv += (*iter)->eval_residue_dof_derivative(
1095  rsd, min_node.res_min_data(), dof_id, torsion_id, pose, sfxn, weights );
1096  }
1097 
1099  iter = min_node.dof_deriv_2benmeths_begin(),
1100  iter_end = min_node.dof_deriv_2benmeths_end(); iter != iter_end; ++iter ) {
1101  deriv += (*iter)->eval_intraresidue_dof_derivative(
1102  rsd, min_node.res_min_data(), dof_id, torsion_id, pose, sfxn, weights );
1103  }
1104  return deriv;
1105 }
1106 
1107 
1108 /*void
1109 eval_weighted_atom_derivative_for_minnode(
1110  MinimizationNode const & min_node,
1111  Size atom_index,
1112  conformation::Residue const & rsd,
1113  pose::Pose const & pose,
1114  kinematics::DomainMap const & domain_map,
1115  ScoreFunction const & sfxn,
1116  EnergyMap const & res_weights,
1117  Vector & F1, // accumulated into
1118  Vector & F2 // accumulated into
1119 )
1120 {
1121  utility_exit_with_message( "DEPRECATED" );
1122 
1123  Vector f1(0.0), f2(0.0);
1124  /// 1. eval 1 body derivatives
1125  /// 1a 1body energy methods
1126  for ( MinimizationNode::OneBodyEnergiesIterator
1127  iter = min_node.active_1benmeths_begin(),
1128  iter_end = min_node.active_1benmeths_end(); iter != iter_end; ++iter ) {
1129  (*iter)->eval_atom_derivative_for_residue(
1130  atom_index, rsd, min_node.res_min_data(), pose, domain_map, sfxn, res_weights, f1, f2 );
1131  }
1132  /// 1b 2body intraresidue contributions
1133  for ( MinimizationNode::TwoBodyEnergiesIterator
1134  iter = min_node.active_intrares2benmeths_begin(),
1135  iter_end = min_node.active_intrares2benmeths_end(); iter != iter_end; ++iter ) {
1136  (*iter)->eval_intrares_atom_derivative(
1137  atom_index, rsd, min_node.res_min_data(), pose, domain_map, sfxn, res_weights, f1, f2 );
1138  }
1139  F1 += min_node.weight() * f1;
1140  F2 += min_node.weight() * f2;
1141 }*/
1142 
1143 void
1145  MinimizationNode const & min_node,
1146  conformation::Residue const & rsd,
1147  pose::Pose const & pose,
1148  ScoreFunction const & sfxn,
1149  EnergyMap & emap, // accumulated into
1150  EnergyMap & scratch_emap
1151 )
1152 {
1154  iter = min_node.active_1benmeths_std_begin(),
1155  iter_end = min_node.active_1benmeths_std_end();
1156  iter != iter_end; ++iter ) {
1157  (*iter)->residue_energy( rsd, pose, scratch_emap );
1158  emap.accumulate( scratch_emap, (*iter)->score_types(), min_node.weight() );
1159  scratch_emap.zero( (*iter)->score_types() );
1160  }
1162  iter = min_node.active_1benmeths_ext_begin(),
1163  iter_end = min_node.active_1benmeths_ext_end();
1164  iter != iter_end; ++iter ) {
1165  (*iter)->residue_energy_ext( rsd, min_node.res_min_data(), pose, scratch_emap );
1166  emap.accumulate( scratch_emap, (*iter)->score_types(), min_node.weight() );
1167  scratch_emap.zero( (*iter)->score_types() );
1168  }
1169  /// 1b 2body intraresidue contributions
1171  iter = min_node.active_intrares2benmeths_std_begin(),
1172  iter_end = min_node.active_intrares2benmeths_std_end();
1173  iter != iter_end; ++iter ) {
1174  (*iter)->eval_intrares_energy( rsd, pose, sfxn, scratch_emap );
1175  emap.accumulate( scratch_emap, (*iter)->score_types(), min_node.weight() );
1176  scratch_emap.zero( (*iter)->score_types() );
1177  }
1179  iter = min_node.active_intrares2benmeths_ext_begin(),
1180  iter_end = min_node.active_intrares2benmeths_ext_end();
1181  iter != iter_end; ++iter ) {
1182  (*iter)->eval_intrares_energy_ext( rsd, min_node.res_min_data(), pose, sfxn, scratch_emap );
1183  emap.accumulate( scratch_emap, (*iter)->score_types(), min_node.weight() );
1184  scratch_emap.zero( (*iter)->score_types() );
1185  }
1186 
1187 }
1188 
1189 /// @details evaluates the atom derivative for this edge, and applies the
1190 /// edge weight into the f1 and f2 vectors before accumulating into the F1 and F2
1191 /// vectors
1192 /*void
1193 eval_weighted_atom_deriv_for_minedge(
1194  MinimizationEdge const & min_edge,
1195  Size atom_index,
1196  conformation::Residue const & res1,
1197  conformation::Residue const & res2,
1198  ResSingleMinimizationData const & res1_min_data,
1199  ResSingleMinimizationData const & res2_min_data,
1200  pose::Pose const & pose,
1201  kinematics::DomainMap const & domain_map,
1202  ScoreFunction const & sfxn,
1203  EnergyMap const & respair_weights,
1204  Vector & F1, // accumulated into
1205  Vector & F2 // accumulated into
1206 )
1207 {
1208  utility_exit_with_message( "DEPRECATED" );
1209  /// iterate across the two-body energies for this edge
1210  Vector f1( 0.0 ), f2( 0.0 );
1211  for ( MinimizationEdge::TwoBodyEnergiesIterator
1212  iter = min_edge.active_2benmeths_begin(),
1213  iter_end = min_edge.active_2benmeths_end();
1214  iter != iter_end; ++iter ) {
1215  (*iter)->eval_atom_derivative_for_residue_pair(
1216  atom_index, res1, res2,
1217  res1_min_data, res2_min_data, min_edge.res_pair_min_data(),
1218  pose, domain_map, sfxn, respair_weights, f1, f2 );
1219  }
1220  F1 += min_edge.weight() * f1;
1221  F2 += min_edge.weight() * f2;
1222 }*/
1223 
1224 void
1226  MinimizationEdge const & min_edge,
1227  conformation::Residue const & res1,
1228  conformation::Residue const & res2,
1229  pose::Pose const & pose,
1230  ScoreFunction const & sfxn,
1231  EnergyMap & emap,
1232  EnergyMap & scratch_emap // should be zeros coming in, left zeroed at the end;
1233 )
1234 {
1236  iter = min_edge.active_2benmeths_std_begin(),
1237  iter_end = min_edge.active_2benmeths_std_end();
1238  iter != iter_end; ++iter ) {
1239  (*iter)->residue_pair_energy(
1240  res1, res2, pose, sfxn, scratch_emap );
1241  emap.accumulate( scratch_emap, (*iter)->score_types(), min_edge.weight() );
1242  scratch_emap.zero( (*iter)->score_types() );
1243  }
1245  iter = min_edge.active_2benmeths_ext_begin(),
1246  iter_end = min_edge.active_2benmeths_ext_end();
1247  iter != iter_end; ++iter ) {
1248  (*iter)->residue_pair_energy_ext(
1249  res1, res2, min_edge.res_pair_min_data(), pose, sfxn, scratch_emap );
1250  emap.accumulate( scratch_emap, (*iter)->score_types(), min_edge.weight() );
1251  scratch_emap.zero( (*iter)->score_types() );
1252  }
1253 }
1254 
1255 Real
1257  MinimizationNode const & min_node,
1258  conformation::Residue const & rsd,
1259  pose::Pose const & pose,
1260  id::DOF_ID const & dof_id,
1261  id::TorsionID const & torsion_id,
1262  ScoreFunction const & sfxn,
1263  EnergyMap const & weights
1264 )
1265 {
1266  Real deriv( 0 );
1267  /// 1. eval 1 body derivatives
1268  /// 1a 1body energy methods
1270  iter = min_node.dof_deriv_1benmeths_begin(),
1271  iter_end = min_node.dof_deriv_1benmeths_end(); iter != iter_end; ++iter ) {
1272  deriv += (*iter)->eval_residue_dof_derivative(
1273  rsd, min_node.res_min_data(), dof_id, torsion_id, pose, sfxn, weights );
1274  }
1275 
1277  iter = min_node.dof_deriv_2benmeths_begin(),
1278  iter_end = min_node.dof_deriv_2benmeths_end(); iter != iter_end; ++iter ) {
1279  deriv += (*iter)->eval_intraresidue_dof_derivative(
1280  rsd, min_node.res_min_data(), dof_id, torsion_id, pose, sfxn, weights );
1281  }
1282  return deriv * min_node.weight();
1283 }
1284 
1285 
1286 } //namespace scoring
1287 } //namespace core