Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SCMinMultifunc.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/pack/scmin/SCMinMultifunc.cc
11 /// @brief Class for interfacing with the minimizer during sidechain minimization.
12 /// @author Andrew Leaver-Fay (aleaverfay@gmail.com)
13 
14 // Unit headers
16 
17 // Package Headers
18 // AUTO-REMOVED #include <core/pack/scmin/AtomTreeCollection.hh>
20 
21 // Project Headers
22 #include <core/types.hh>
24 // AUTO-REMOVED #include <core/kinematics/AtomTree.hh>
25 // AUTO-REMOVED #include <core/pose/Pose.hh>
29 
30 // Utility headers
31 #include <utility/vector1.hh>
32 #include <utility/pointer/ReferenceCount.hh>
33 
34 // Numeric headers
35 #include <numeric/constants.hh>
36 
37 #include <core/kinematics/Jump.hh>
40 
41 
42 namespace core {
43 namespace pack {
44 namespace scmin {
45 
46 
48  pose::Pose & p,
50  scoring::ScoreFunction const & sfxn,
51  scoring::MinimizationGraph & mingraph,
52  SCMinMinimizerMap & scminmap
53 ) :
54  pose_( p ),
55  bg_residues_( bg_residues ),
56  sfxn_( sfxn ),
57  g_( mingraph ),
58  scminmap_( scminmap ),
59  scoretypes_( sfxn_.get_nonzero_weighted_scoretypes() )
60 {}
61 
63 
64 Real
66 {
67  using namespace scoring;
68 
70 
71  /// 1. setup for scoring -- nodes first
72  for ( Size ii = 1, iiend = scminmap_.nactive_residues(); ii <= iiend; ++ii ) {
73  Size const iiresid = scminmap_.active_residue( ii );
75  }
76  /// edges second.
77  for ( Size ii = 1, iiend = scminmap_.nactive_residues(); ii <= iiend; ++ii ) {
78  Size const iiresid = scminmap_.active_residue( ii );
79  conformation::Residue const & iires( scminmap_.residue( iiresid ) );
81  edgeit = g_.get_node( iiresid )->edge_list_begin(),
82  edgeit_end = g_.get_node( iiresid )->edge_list_end();
83  edgeit != edgeit_end; ++edgeit ) {
84  Size const jjresid = (*edgeit)->get_other_ind( iiresid );
85  bool const jjmoving = scminmap_.dm()( jjresid ) == 0;
86  if ( jjmoving && iiresid > jjresid ) continue;
87  conformation::Residue const & jjres( jjmoving ? scminmap_.residue( jjresid ) : *bg_residues_[ jjresid ] );
88 
89  MinimizationEdge & minedge = static_cast< MinimizationEdge & > ( (**edgeit) );
90  if ( iiresid < jjresid ) {
91  minedge.setup_for_scoring( iires, jjres, pose_, sfxn_ );
92  } else {
93  minedge.setup_for_scoring( jjres, iires, pose_, sfxn_ );
94  }
95 
96  }
97  }
98 
99  //emap.zero( scoretypes_ );
100  EnergyMap emap;
101  /// 2. score function evaluation -- 1body & 2body energies only
102  for ( Size ii = 1, iiend = scminmap_.nactive_residues(); ii <= iiend; ++ii ) {
103  Size const iiresid = scminmap_.active_residue( ii );
105  }
106  for ( Size ii = 1, iiend = scminmap_.nactive_residues(); ii <= iiend; ++ii ) {
107  Size const iiresid = scminmap_.active_residue( ii );
108  conformation::Residue const & iires( scminmap_.residue( iiresid ) );
110  edgeit = g_.get_node( iiresid )->const_edge_list_begin(),
111  edgeit_end = g_.get_node( iiresid )->const_edge_list_end();
112  edgeit != edgeit_end; ++edgeit ) {
113  Size const jjresid = (*edgeit)->get_other_ind( iiresid );
114  bool const jjmoving = scminmap_.dm()( jjresid ) == 0;
115  if ( jjmoving && iiresid > jjresid ) continue;
116  conformation::Residue const & jjres( jjmoving ? scminmap_.residue( jjresid ) : *bg_residues_[ jjresid ] );
117  MinimizationEdge const & minedge = static_cast< MinimizationEdge const & > ( (**edgeit) );
118 
119  if ( iiresid < jjresid ) {
120  eval_res_pair_energy_for_minedge( minedge, iires, jjres, pose_, sfxn_, emap );
121  } else {
122  eval_res_pair_energy_for_minedge( minedge, jjres, iires, pose_, sfxn_, emap );
123  }
124  }
125  }
126  return sfxn_.weights().dot( emap, scoretypes_ );
127 }
128 
129 
130 void
131 SCMinMultifunc::dfunc( Multivec const & chi, Multivec & dE_dchi ) const
132 {
133  using namespace scoring;
136 
137  /// 1. setup for derivatives -- nodes first
138  for ( Size ii = 1, iiend = scminmap_.nactive_residues(); ii <= iiend; ++ii ) {
139  Size const iiresid = scminmap_.active_residue( ii );
141  }
142  /// edges second.
143  for ( Size ii = 1, iiend = scminmap_.nactive_residues(); ii <= iiend; ++ii ) {
144  Size const iiresid = scminmap_.active_residue( ii );
145  conformation::Residue const & iires( scminmap_.residue( iiresid ) );
147  edgeit = g_.get_node( iiresid )->edge_list_begin(),
148  edgeit_end = g_.get_node( iiresid )->edge_list_end();
149  edgeit != edgeit_end; ++edgeit ) {
150  Size const jjresid = (*edgeit)->get_other_ind( iiresid );
151  bool const jjmoving = scminmap_.dm()( jjresid ) == 0;
152  if ( jjmoving && iiresid > jjresid ) continue;
153  conformation::Residue const & jjres( jjmoving ? scminmap_.residue( jjresid ) : *bg_residues_[ jjresid ] );
154  MinimizationEdge & minedge = static_cast< MinimizationEdge & > ( (**edgeit) );
155  if ( iiresid < jjresid ) {
156  minedge.setup_for_derivatives( iires, jjres, pose_, sfxn_ );
157  } else {
158  minedge.setup_for_derivatives( jjres, iires, pose_, sfxn_ );
159  }
160  }
161  }
162 
163  /// 2a. Evaluate 1body atom derivatives for the active nodes
164  for ( Size ii = 1, iiend = scminmap_.nactive_residues(); ii <= iiend; ++ii ) {
165  Size const iiresid = scminmap_.active_residue( ii );
166  conformation::Residue const & iirsd = scminmap_.residue( iiresid );
167  MinimizationNode const & minnode( * g_.get_minimization_node( iiresid ) );
168  eval_atom_derivatives_for_minnode( minnode, iirsd, pose_,
169  sfxn_.weights(), scminmap_.atom_derivatives( iiresid ) );
170  }
171  /// 2b. Evaluate 2body atom derivatives for the active nodes
172  for ( Size ii = 1, iiend = scminmap_.nactive_residues(); ii <= iiend; ++ii ) {
173  Size const iiresid = scminmap_.active_residue( ii );
174  MinimizationNode const & iiminnode( * g_.get_minimization_node( iiresid ) );
175  conformation::Residue const & iires( scminmap_.residue( iiresid ) );
177  edgeit = g_.get_node( iiresid )->edge_list_begin(),
178  edgeit_end = g_.get_node( iiresid )->edge_list_end();
179  edgeit != edgeit_end; ++edgeit ) {
180  Size const jjresid = (*edgeit)->get_other_ind( iiresid );
181  bool const jjmoving = scminmap_.dm()( jjresid ) == 0;
182  if ( jjmoving && iiresid > jjresid ) continue;
183 
184  conformation::Residue const & jjres( jjmoving ? scminmap_.residue( jjresid ) : *bg_residues_[ jjresid ] );
185  MinimizationNode const & jjminnode( * g_.get_minimization_node( jjresid ) );
186  MinimizationEdge const & minedge = static_cast< MinimizationEdge const & > ( (**edgeit) );
187  if ( iiresid < jjresid ) {
188  eval_atom_derivatives_for_minedge( minedge, iires, jjres,
189  iiminnode.res_min_data(), jjminnode.res_min_data(), pose_, sfxn_.weights(),
190  scminmap_.atom_derivatives( iiresid ), scminmap_.atom_derivatives( jjresid ));
191  } else {
192  eval_atom_derivatives_for_minedge( minedge, jjres, iires,
193  jjminnode.res_min_data(), iiminnode.res_min_data(), pose_, sfxn_.weights(),
194  scminmap_.atom_derivatives( jjresid ), scminmap_.atom_derivatives( iiresid ));
195  }
196  }
197  }
198 
199 
200  /// 3. Accumulate the atom derivatives into the DOF_Node f1/f2s
201  for ( Size ii = 1, iiend = scminmap_.n_dof_nodes(); ii <= iiend; ++ii ) {
202  optimization::DOF_Node & iidofnode( scminmap_.dof_node( ii ) );
203  iidofnode.F1() = 0; iidofnode.F2() = 0;
204  optimization::DOF_Node::AtomIDs iiatoms( iidofnode.atoms() );
205  for ( Size jj = 1, jjend = iiatoms.size(); jj <= jjend; ++jj ) {
206  iidofnode.F1() += scminmap_.atom_derivatives( iiatoms[ jj ].rsd() )[ iiatoms[ jj ].atomno() ].f1();
207  iidofnode.F2() += scminmap_.atom_derivatives( iiatoms[ jj ].rsd() )[ iiatoms[ jj ].atomno() ].f2();
208  }
209  }
210 
211  /// 3. Link torsion vectors
213 
214  id::DOF_ID junk;
215  for ( Size ii = 1, iiend = scminmap_.n_dof_nodes(); ii <= iiend; ++ii ) {
216  optimization::DOF_Node & iidofnode( scminmap_.dof_node( ii ) );
217  //fpd we assume that torsion-defined funcs have no derivatives w.r.t. d or theta DOFs
218  if (iidofnode.type() == core::id::PHI) {
219  id::TorsionID torid = scminmap_.tor_for_dof( iidofnode.dof_id() );
220  /// 4. Evaluate chi-dof derivatives
221  Real dofderiv = eval_dof_deriv_for_minnode( * g_.get_minimization_node( iidofnode.rsd() ),
222  scminmap_.residue( iidofnode.rsd() ), pose_, junk, torid, sfxn_, sfxn_.weights() );
223 
225  scminmap_.atom( iidofnode.atom_id() ), iidofnode,
226  dofderiv, numeric::constants::d::rad2deg );
227  }
228  }
229 }
230 
231 bool
233  return false;
234 }
235 
236 
237 void
238 SCMinMultifunc::dump( Multivec const & /*vars*/, Multivec const & /*vars2*/ ) const
239 {}
240 
241 
242 /*void
243 SCMinMultifunc::eval_atom_deriv(
244  id::AtomID const & atom,
245  Vector & F1,
246  Vector & F2
247 ) const
248 {
249  using namespace scoring;
250 
251  Size const rsdno = atom.rsd();
252  Size const atomno = atom.atomno();
253 
254  conformation::Residue const & rsd = scminmap_.residue( rsdno );
255 
256  MinimizationNode const & minnode = * g_.get_minimization_node( rsdno );
257  /// 1. eval intra-residue derivatives
258  eval_atom_derivative_for_minnode( minnode, atomno, rsd, pose_, scminmap_.dm(), sfxn_, sfxn_.weights(), F1, F2 );
259 
260  ResSingleMinimizationData const & ressingle_min_data( minnode.res_min_data() );
261  /// 2. eval inter-residue derivatives
262  for ( graph::Node::EdgeListConstIter
263  edgeit = minnode.const_edge_list_begin(), edgeit_end = minnode.const_edge_list_end();
264  edgeit != edgeit_end; ++edgeit ) {
265  MinimizationEdge const & minedge = static_cast< MinimizationEdge const & > ( (**edgeit) );
266  Size const other_rsdno = minedge.get_other_ind( rsdno );
267  conformation::Residue const & other_rsd( scminmap_.dm()( other_rsdno ) == 0 ? scminmap_.residue( other_rsdno ) : *bg_residues_[ other_rsdno ]);
268  ResSingleMinimizationData const & other_ressingle_min_data( g_.get_minimization_node( other_rsdno )->res_min_data() );
269 
270  eval_atom_deriv_for_minedge( minedge, atomno, rsd, other_rsd,
271  ressingle_min_data, other_ressingle_min_data,
272  pose_, scminmap_.dm(), sfxn_, sfxn_.weights(), F1, F2 );
273  }
274 }*/
275 
276 
277 } // namespace scmin
278 } // namespace pack
279 } // namespace core