Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CartesianMultifunc.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/optimization/CartesianMultifunc.hh
11 /// @brief
12 /// @author Frank DiMaio
13 
14 /// Unit headers
16 
17 /// Package headers
21 
22 /// Project headers
23 #include <basic/prof.hh>
24 // AUTO-REMOVED #include <core/conformation/Residue.hh>
25 #include <core/pose/Pose.hh>
27 
28 // AUTO-REMOVED #include <core/scoring/ResidueNeighborList.hh>
30 // AUTO-REMOVED #include <core/scoring/etable/EtableEnergy.hh>
32 // AUTO-REMOVED #include <core/scoring/MinimizationGraph.hh>
36 #include <core/scoring/Energies.hh>
37 
38 /// Utility headers
39 #include <utility/string_util.hh>
40 
41 #include <utility/vector1.hh>
42 
43 
44 namespace core {
45 namespace optimization {
46 
47 Real
49  PROF_START( basic::FUNC );
51  Real const score( score_function_( pose_ ) );
52  PROF_STOP( basic::FUNC );
53  return score;
54 }
55 
56 void
57 CartesianMultifunc::dfunc( Multivec const & vars, Multivec & dE_dvars ) const
58 {
59  PROF_START( basic::DFUNC );
60  // in cartesian_minimize.cc
61  cartesian_dfunc( pose_, min_map_, score_function_, vars, dE_dvars );
62  // optional derivative checking
63  if ( deriv_check_ ) {
65  }
66  PROF_STOP( basic::DFUNC );
67 }
68 
70 {
71  deriv_check_result_ = deriv_check_result;
72 }
73 
75  return pose_;
76 }
77 
78 /// @details Useful debugging code that can be re-enabled by changing the boolean
79 /// variables at the top of this function.
80 void
81 CartesianMultifunc::dump( Multivec const & vars, Multivec const & vars2 ) const {
82  bool debug_inaccurateG = false; // disables everything below
83  bool check_score_components = true;
84  bool check_score_components_verbose = false;
85  bool check_rama = false;
86  bool check_hbonds = true;
87  //bool check_nblist = true;
88 
89  if ( ! debug_inaccurateG ) return;
90 
91  static int count_dumped( 0 );
92  static bool after( true ); // dump two poses, a before and an after. Note, dumping poses as pdbs is often useless.
93 
94  if ( after ) { ++count_dumped; after = false; }
95  else { after = true; }
96 
97  pose::Pose pose1( pose_ );
98  pose::Pose pose2( pose_ );
99  min_map_.copy_dofs_to_pose( pose1, vars );
100  min_map_.copy_dofs_to_pose( pose2, vars2 );
101 
103  Real score_vars( score_function_( pose_ ) );
104 
105  min_map_.copy_dofs_to_pose( pose_, vars2 );
106  Real score_vars2( score_function_( pose_ ) );
107 
108  Real alt_score_vars = score_function_( pose1 );
109  pose1.dump_pdb( "Cartesian_multifunc_error_pose_before" + utility::to_string( count_dumped ) + ".pdb" );
110 
111  Real alt_score_vars2 = score_function_( pose2 );
112  pose2.dump_pdb( "Cartesian_multifunc_error_pose_after" + utility::to_string( count_dumped ) + ".pdb" );
113 
114  std::cerr << "starting pose energies: " << score_vars << " vs " << alt_score_vars << std::endl;
115  pose1.energies().total_energies().show_weighted( std::cerr, score_function_.weights() );
116  std::cerr << std::endl;
117  std::cerr << "moved pose energies: " << score_vars2 << " vs " << alt_score_vars2 << std::endl;
118  pose2.energies().total_energies().show_weighted( std::cerr, score_function_.weights() );
119  std::cerr << std::endl;
120  using namespace scoring;
121 
122  if ( check_score_components ) {
123  // slow! Iterate through all the components and check their derivatives one by one.
124  const_cast< bool & > (deriv_check_) = true;
125  if ( check_score_components_verbose ) {
126  const_cast< bool & > (deriv_check_verbose_) = true;
127  }
128  Multivec dvars( vars );
129  scoring::EnergyMap orig_weights( score_function_.weights() );
130  for ( Size ii = 1; ii <= scoring::n_score_types; ++ii ) {
131  using namespace scoring;
132 
133  if ( score_function_.weights()[ (ScoreType ) ii ] == 0.0 ) continue;
134 
135  for ( Size jj = 1; jj <= scoring::n_score_types; ++jj ) {
136  if ( jj == ii ) {
137  const_cast< scoring::ScoreFunction & > (score_function_).set_weight( (scoring::ScoreType) jj, orig_weights[ (scoring::ScoreType) jj ]);
138  } else if ( score_function_.weights()[ (scoring::ScoreType ) jj ] != 0.0 ) {
139  const_cast< scoring::ScoreFunction & > (score_function_).set_weight( (scoring::ScoreType) jj, 1e-9 );
140  }
141  }
142  std::cout << "Checking score type: " << scoring::ScoreType( ii ) << std::endl;
143  dfunc( vars, dvars ); // invokes numeric derivative checker.
144  }
145  for ( Size ii = 1; ii <= scoring::n_score_types; ++ii ) {
146  if ( orig_weights[ scoring::ScoreType( ii ) ] != 0 ) {
147  const_cast< scoring::ScoreFunction & > (score_function_).set_weight( (scoring::ScoreType)ii, orig_weights[ (scoring::ScoreType) ii ]);
148  }
149  }
150  const_cast< bool & > (deriv_check_) = false;
151  const_cast< bool & > (deriv_check_verbose_) = false;
152  }
153 
154  if ( check_rama ) {
155  // useful if rama seems to be the culprit. This is the only piece of code
156  // that invokes eval_rama_score_all, so that function may be hacked to provide
157  // clearer debugging output.
159  }
160 
161  if ( check_hbonds ) {
162  scoring::hbonds::HBondSet hbond_set;
163  fill_hbond_set( pose1, true, hbond_set );
164 
165  for ( Size ii = 1; ii <= hbond_set.nhbonds(); ++ii ) {
166  scoring::hbonds::HBond const & iihbond = hbond_set.hbond( ii );
167  std::cerr << "Hbond " << ii <<
168  " d: " << iihbond.don_res() << " " << iihbond.don_hatm() <<
169  " a: " << iihbond.acc_res() << " " << iihbond.acc_atm() <<
170  " e: " << iihbond.energy() << " " << iihbond.weight() <<
171  " good? " << hbond_set.allow_hbond( iihbond ) << std::endl;
172  }
173  }
174 }
175 
177  pose::Pose & pose_in,
178  CartesianMinimizerMap & min_map_in,
179  scoring::ScoreFunction const & scorefxn_in,
180  bool const deriv_check_in,
181  bool const deriv_check_verbose_in
182 ) :
183  pose_( pose_in ),
184  min_map_( min_map_in ),
185  score_function_( scorefxn_in ),
186  deriv_check_( deriv_check_in ),
187  deriv_check_verbose_( deriv_check_verbose_in ),
189 {}
190 
192 
193 CartesianMinimizerMap const &
195  return min_map_;
196 }
197 
199  return score_function_;
200 }
201 
202 } // namespace optimization
203 } // namespace core
204