Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
DunbrackEnergy.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/dunbrack/DunbrackEnergy.cc
11 /// @brief Dunbrack energy method implementation
12 /// @author Andrew Leaver-Fay (aleaverfay@gmail.com)
13 
14 // Unit headers
17 
18 // Package Headers
22 
24 
25 // Project headers
28 #include <core/pose/Pose.hh>
29 
30 #include <core/id/TorsionID.hh>
31 
32 // Utility headers
33 #include <numeric/conversions.hh>
34 
35 #include <utility/vector1.hh>
36 
37 
38 
39 namespace core {
40 namespace pack {
41 namespace dunbrack {
42 
43 using namespace scoring;
44 using namespace scoring::methods;
45 
46 /// @details This must return a fresh instance of the DunbrackEnergy class,
47 /// never an instance already in use
51 ) const {
52  return new DunbrackEnergy;
53 }
54 
57  ScoreTypes sts;
58  sts.push_back( fa_dun );
59  sts.push_back( fa_dun_dev );
60  sts.push_back( fa_dun_rot );
61  sts.push_back( fa_dun_semi );
62  return sts;
63 }
64 
65 
66 
67 /// ctor
70 {}
71 
73 
74 /// clone
77 {
78  return new DunbrackEnergy;
79 }
80 
81 /////////////////////////////////////////////////////////////////////////////
82 // methods for ContextIndependentOneBodyEnergies
83 /////////////////////////////////////////////////////////////////////////////
84 
85 /// @details Allocate the scratch space object on the stack to
86 /// alieviate thread-safety concerns. Scratch does not use new.
87 void
89  conformation::Residue const & rsd,
90  pose::Pose const &,
91  scoring::EnergyMap & emap
92 ) const
93 {
94  // ignore scoring residues which have been marked as "REPLONLY" residues (only the repulsive energy will be calculated)
96  return;
97  }
98 
99  //
100  //static boost::detail::atomic_count count_present( 0 );
101  //++count_present;
102  //std::cout << "D" << count_present << std::flush;
103 
104  if ( rsd.is_virtual_residue() ) return;
105 
106  /* old emap[ fa_dun ] = rot_lib_.rotamer_energy( rsd ); */
108  if ( rotlib ) {
110  emap[ fa_dun ] += rotlib->rotamer_energy( rsd, scratch );
111  emap[ fa_dun_rot ] += scratch.fa_dun_rot();
112  emap[ fa_dun_semi ] += scratch.fa_dun_semi();
113  emap[ fa_dun_dev ] += scratch.fa_dun_dev();
114  }
115  //--count_present;
116  //std::cout << "D" << count_present << std::flush;
117 
118 }
119 
120 bool DunbrackEnergy::defines_dof_derivatives( pose::Pose const & ) const { return true; }
121 
122 Real
124  conformation::Residue const & rsd,
125  ResSingleMinimizationData const & ,//min_data,
126  id::DOF_ID const & ,// dof_id,
127  id::TorsionID const & tor_id,
128  pose::Pose const & ,//pose,
129  scoring::ScoreFunction const & ,//sfxn,
130  scoring::EnergyMap const & weights
131 ) const
132 {
133  // ignore scoring residues which have been marked as "REPLONLY" residues (only the repulsive energy will be calculated)
135  return 0.0;
136  }
137 
138  Real deriv(0.0);
139  Real deriv_dev(0.0);
140  Real deriv_rot(0.0);
141  Real deriv_semi(0.0);
142  if ( tor_id.valid() ) {
143  assert( rsd.seqpos() == tor_id.rsd() );
144  //utility::vector1< Real > dE_dbb, dE_dchi;
145  // std::cerr << __FILE__<< ' ' << __LINE__ << ' ' << tor_id.rsd() << std::endl;
148  if ( rsd.is_protein() && rotlib ) {
150  rotlib->rotamer_energy_deriv( rsd, scratch );
151  if ( tor_id.type() == id::BB && tor_id.torsion() <= dunbrack::DUNBRACK_MAX_BBTOR ) {
152  deriv = scratch.dE_dbb()[ tor_id.torsion() ];
153  deriv_dev = scratch.dE_dbb_dev()[ tor_id.torsion() ];
154  deriv_rot = scratch.dE_dbb_rot()[ tor_id.torsion() ];
155  deriv_semi = scratch.dE_dbb_semi()[ tor_id.torsion() ];
156  } else if ( tor_id.type() == id::CHI && tor_id.torsion() <= dunbrack::DUNBRACK_MAX_SCTOR ) {
157  deriv = scratch.dE_dchi()[ tor_id.torsion() ];
158  deriv_dev = scratch.dE_dchi_dev()[ tor_id.torsion() ];
159  deriv_semi = scratch.dE_dchi_semi()[ tor_id.torsion() ];
160  }
161  }
162  }
163  return numeric::conversions::degrees( weights[ fa_dun ] * deriv + weights[ fa_dun_dev ] * deriv_dev + weights[ fa_dun_rot ] * deriv_rot + weights[ fa_dun_semi ] * deriv_semi);
164 }
165 
166 
167 ///
168 Real
170  id::DOF_ID const &,// dof_id,
171  id::TorsionID const & tor_id,
172  pose::Pose const & pose,
173  scoring::ScoreFunction const &,
174  scoring::EnergyMap const & weights
175 ) const
176 {
177  // ignore scoring residues which have been marked as "REPLONLY" residues (only the repulsive energy will be calculated)
178  if ( pose.residue( tor_id.rsd() ).has_variant_type( core::chemical::REPLONLY )){
179  return 0.0;
180  }
181 
182  //
183  //static boost::detail::atomic_count count_present( 0 );
184  //++count_present;
185  //std::cout << "dD" << count_present << std::flush;
186 
187  Real deriv(0.0);
188  Real deriv_dev(0.0);
189  Real deriv_rot(0.0);
190  Real deriv_semi(0.0);
191  if ( tor_id.valid() ) {
192  //utility::vector1< Real > dE_dbb, dE_dchi;
193  // std::cerr << __FILE__<< ' ' << __LINE__ << ' ' << tor_id.rsd() << std::endl;
195  RotamerLibrary::get_instance().get_rsd_library( pose.residue( tor_id.rsd() ).type() );
196 
197  if ( pose.residue( tor_id.rsd() ).is_virtual_residue() ) return 0.0;
198 
199  if ( rotlib ) {
201  rotlib->rotamer_energy_deriv
202  ( pose.residue( tor_id.rsd() ), scratch );
203 
204  /// ASSUMPTION: Derivatives for amino acids only!
205  if ( pose.residue_type( tor_id.rsd() ).is_protein() ) {
206  if ( tor_id.type() == id::BB && tor_id.torsion() <= dunbrack::DUNBRACK_MAX_BBTOR ) {
207  deriv = scratch.dE_dbb()[ tor_id.torsion() ];
208  deriv_dev = scratch.dE_dbb_dev()[ tor_id.torsion() ];
209  deriv_rot = scratch.dE_dbb_rot()[ tor_id.torsion() ];
210  deriv_semi = scratch.dE_dbb_semi()[ tor_id.torsion() ];
211  } else if ( tor_id.type() == id::CHI && tor_id.torsion() <= dunbrack::DUNBRACK_MAX_SCTOR ) {
212  deriv = scratch.dE_dchi()[ tor_id.torsion() ];
213  deriv_dev = scratch.dE_dchi_dev()[ tor_id.torsion() ];
214  deriv_semi = scratch.dE_dchi_semi()[ tor_id.torsion() ];
215  }
216  }
217  }
218  }
219  //--count_present;
220  //std::cout << "dD" << count_present << std::flush;
221  return numeric::conversions::degrees( weights[ fa_dun ] * deriv + weights[ fa_dun_dev ] * deriv_dev + weights[ fa_dun_rot ] * deriv_rot + weights[ fa_dun_semi ] * deriv_semi );
222 }
223 
224 /// @brief DunbrackEnergy is context independent; indicates that no context graphs are required
225 void
227  utility::vector1< bool > & /*context_graphs_required*/
228 ) const
229 {}
232 {
233  return 1; // Initial versioning
234 }
235 
236 
237 
238 } // dunbrack
239 } // pack
240 } // core
241