Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
MMBondLengthEnergy.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/methods/MMBondLengthAnergy.cc
11 /// @brief Molecular mechanics bond length score class
12 /// @author Frank DiMaio (based on Colin Smith's MMBondAngle potential)
13 
14 // Unit headers
17 
18 // Package headers
20 // AUTO-REMOVED #include <core/scoring/methods/EnergyMethodOptions.hh>
21 
22 // Project headers
27 #include <core/pose/Pose.hh>
28 #include <basic/Tracer.hh>
29 
30 // Utility headers
31 // AUTO-REMOVED #include <utility/string_util.hh>
32 
33 // Numeric headers
34 // AUTO-REMOVED #include <numeric/xyz.functions.hh>
35 #include <numeric/deriv/distance_deriv.hh>
36 
37 // C++ headers
38 #include <iostream>
39 
40 #include <core/id/AtomID.hh>
41 #include <utility/vector1.hh>
42 
43 
44 namespace core {
45 namespace scoring {
46 namespace methods {
47 
48 
49 /// @details This must return a fresh instance of the MMBondLengthEnergy class,
50 /// never an instance already in use
53  methods::EnergyMethodOptions const & options
54 ) const {
55  return new MMBondLengthEnergy( options );
56 }
57 
60  ScoreTypes sts;
61  sts.push_back( mm_stretch );
62  return sts;
63 }
64 
65 
66 static basic::Tracer TR("core.mm.MMBondLengthEnergy");
67 
70 {}
71 
73  parent( src )
74 {}
75 
77 
78 
79 /// clone
82 {
83  return new MMBondLengthEnergy( *this );
84 }
85 
86 ///
87 void
89  pose::Pose & pose,
91  utility::vector1< bool > const & ) const
92 {
94  pose.update_actcoords();
95 }
96 
97 ///
98 void
100 {
102  pose.update_actcoords();
103 }
104 
105 ///
106 void
108 {
110  pose.update_actcoords();
111 }
112 
113 ///
114 bool
116 {
117  return true;
118 }
119 
120 void
122  conformation::Residue const & rsd1,
123  conformation::Residue const & rsd2,
124  pose::Pose const & /*pose*/,
125  ScoreFunction const & ,
126  EnergyMap & emap
127 ) const
128 {
129  // bail out if the residues aren't bonded
130  if (!rsd1.is_bonded(rsd2)) return;
131 
132  Real energy = 0;
133 
134  // get residue types
135  chemical::ResidueType const & rsd1_type = rsd1.type();
136  chemical::ResidueType const & rsd2_type = rsd2.type();
137 
138  TR(basic::t_trace) << "residue_pair_energy: processing residues "
139  << rsd1.seqpos() << "." << rsd1_type.name() << "-"
140  << rsd2.seqpos() << "." << rsd2_type.name() << std::endl;
141 
142  utility::vector1< Size > const & r1_resconn_ids( rsd1.connections_to_residue( rsd2 ) );
143 
144  for ( Size ii = 1; ii <= r1_resconn_ids.size(); ++ii ) {
145  Size const resconn_id1( r1_resconn_ids[ii] );
146  Size const resconn_id2( rsd1.residue_connection_conn_id( resconn_id1 ) );
147 
148  Size const resconn_atomno1( rsd1.residue_connection( resconn_id1 ).atomno() );
149  Size const resconn_atomno2( rsd2.residue_connection( resconn_id2 ).atomno() );
150 
151  // check for vrt
152  if ( rsd1_type.atom_type(resconn_atomno1).is_virtual() || rsd2_type.atom_type(resconn_atomno2).is_virtual() )
153  continue;
154 
155  TR(basic::t_trace) << "Found residue connection id " << resconn_id1 << "-" << resconn_id2 << ": "
156  << rsd1.atom_name( resconn_atomno1 ) << "-" << rsd2.atom_name( resconn_atomno2 ) << std::endl;
157 
158  Size const resconn_mmat1 = rsd1_type.atom( resconn_atomno1 ).mm_atom_type_index();
159  Size const resconn_mmat2 = rsd2_type.atom( resconn_atomno2 ).mm_atom_type_index();
160 
161  Real const d =
162  ( rsd1.atom( resconn_atomno1 ).xyz()-rsd2.atom( resconn_atomno2 ).xyz() ).length();
163 
164  TR(basic::t_trace)
165  << "r1 " << resconn_atomno1 << " " << rsd1.atom_name( resconn_atomno1 ) << "("
166  << rsd1_type.atom( resconn_atomno1 ).mm_name() << ") - "
167  << "r2 " << resconn_atomno2 << " " << rsd2.atom_name( resconn_atomno2 ) << "("
168  << rsd2_type.atom( resconn_atomno2 ).mm_name() << ")" << std::endl;
169 
170  energy += potential_.mm::MMBondLengthScore::score
171  ( mm::mm_bondlength_atom_pair( resconn_mmat1, resconn_mmat2 ), d );
172  }
173  emap[ mm_stretch ] += energy;
174 }
175 
176 void
178  conformation::Residue const & rsd,
179  pose::Pose const & ,
180  ScoreFunction const & ,
181  EnergyMap & emap
182 ) const {
183  Real energy = 0;
184 
185  // get residue type
186  chemical::ResidueType const & rsd_type = rsd.type();
187 
188  TR(basic::t_trace) << "MMIntrares Processing residue " << rsd.seqpos() << " " << rsd_type.name()
189  << std::endl;
190 
191  // for each bonded atom
192  for (Size atm_i=1; atm_i<=rsd_type.natoms(); ++atm_i) {
193  chemical::AtomIndices atm_nbrs = rsd_type.nbrs( atm_i );
194  for (Size j=1; j<=atm_nbrs.size(); ++j) {
195  Size atm_j = atm_nbrs[j];
196  if ( atm_i<atm_j ) { // only score each bond once -- use restype index to define ordering
197  int mmat1 = rsd_type.atom( atm_i ).mm_atom_type_index();
198  int mmat2 = rsd_type.atom( atm_j ).mm_atom_type_index();
199 
200  // check for vrt
201  if ( rsd_type.atom_type(atm_i).is_virtual() || rsd_type.atom_type(atm_j).is_virtual() )
202  continue;
203 
204  Real const d = ( rsd.atom( atm_i ).xyz()-rsd.atom( atm_j ).xyz() ).length();
205 
206  TR(basic::t_trace)
207  << "r1 " << atm_i << " " << rsd.atom_name( atm_i ) << "("
208  << rsd_type.atom( atm_i ).mm_name() << ") - "
209  << "r2 " << atm_j << " " << rsd.atom_name( atm_j ) << "("
210  << rsd_type.atom( atm_j ).mm_name() << ")" << std::endl;
211 
212  // score bond angle
213  energy += potential_.mm::MMBondLengthScore::score
214  ( mm::mm_bondlength_atom_pair( mmat1, mmat2 ), d );
215  }
216  }
217  }
218 
219  // add energy to emap
220  emap[ mm_stretch ] += energy;
221 }
222 
223 void
225  id::AtomID const & id,
226  pose::Pose const & pose,
227  kinematics::DomainMap const &,
228  ScoreFunction const &,
229  EnergyMap const & weights,
230  Vector & F1,
231  Vector & F2
232 ) const
233 {
234  //TR << "Evaluating derivatives for rsd# " << id.rsd() << " atom# " << id.atomno() << std::endl;
235 
236  Vector LF1( 0.0 );
237  Vector LF2( 0.0 );
238 
239  core::chemical::ResidueType const & rsd_type( pose.residue_type( id.rsd() ) );
240  core::conformation::Residue const & rsd( pose.residue( id.rsd() ) );
241  Size const atomno( id.atomno());
242 
243  // 1 intrares bonds
244  chemical::AtomIndices atm_nbrs = rsd_type.nbrs( atomno );
245  for (Size j=1; j<=atm_nbrs.size(); ++j) {
246  Size atm2 = atm_nbrs[j];
247 
248  int mmat1 = rsd_type.atom( atomno ).mm_atom_type_index();
249  int mmat2 = rsd_type.atom( atm2 ).mm_atom_type_index();
250 
251  // check for vrt
252  if ( rsd_type.atom_type(atomno).is_virtual() || rsd_type.atom_type(atm2).is_virtual() )
253  continue;
254 
255  Vector f1(0.0), f2(0.0);
256  Real d=0;
257  numeric::deriv::distance_f1_f2_deriv( rsd.xyz( atomno ), rsd.xyz( atm2 ), d, f1, f2 );
258 
259  Real dE_dd = weights[ mm_stretch ] * potential_.mm::MMBondLengthScore::dscore(
260  mm::mm_bondlength_atom_pair( mmat1, mmat2 ), d );
261 
262  LF1 += dE_dd * f1;
263  LF2 += dE_dd * f2;
264  }
265 
266  // 2 interres bonds
267  utility::vector1< Size > const & connections( rsd_type.residue_connections_for_atom( atomno ) );
268  for ( Size ii = 1; ii <= connections.size(); ++ii ) {
269  Size const ii_resconn = connections[ ii ];
270 
271  Size const ii_neighb = rsd.residue_connection_partner( ii_resconn );
272  Size const neighb_resconn = rsd.residue_connection_conn_id( ii_resconn );
273  conformation::Residue const & neighb_res( pose.residue( ii_neighb ));
274  chemical::ResidueType const & neighb_restype( pose.residue_type( ii_neighb ) );
275  Size const neighb_atom1 = neighb_restype.residue_connection( neighb_resconn ).atomno();
276 
277  Size const mmat1 = rsd_type.atom( atomno ).mm_atom_type_index();
278  Size const mmat2 = neighb_restype.atom( neighb_atom1 ).mm_atom_type_index();
279 
280  // check for vrt
281  if ( rsd_type.atom_type(atomno).is_virtual() || neighb_restype.atom_type(neighb_atom1).is_virtual() )
282  continue;
283 
284  Vector f1(0.0), f2(0.0);
285  Real d=0;
286  numeric::deriv::distance_f1_f2_deriv( rsd.xyz( atomno ), neighb_res.xyz( neighb_atom1 ), d, f1, f2 );
287 
288  Real dE_dd = weights[ mm_stretch ] * potential_.mm::MMBondLengthScore::dscore(
289  mm::mm_bondlength_atom_pair( mmat1, mmat2 ), d );
290 
291  LF1 += dE_dd * f1;
292  LF2 += dE_dd * f2;
293  }
294 
295  F1 += LF1;
296  F2 += LF2;
297 }
298 
299 
300 /// @brief MMBondLengthEnergy does not have an atomic interation threshold
301 Distance
303 {
304  return 0.0;
305 }
306 
307 /// @brief MMBondLengthEnergy is context independent; indicates that no context graphs are required
308 void
310 {}
311 
314 {
315  return 1; // Initial versioning
316 }
317 
318 } // namespace methods
319 } // namespace scoring
320 } // namespace core