Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
WaterAdductHBondPotential.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/WaterAdductHBondPotential.cc
11 /// @brief
12 /// @author Jim Havranek
13 
14 // Project headers
18 // AUTO-REMOVED #include <core/scoring/hbonds/hbonds.hh>
24 #include <core/scoring/Energies.hh>
25 // AUTO-REMOVED #include <core/scoring/etable/count_pair/CountPairFunction.hh>
26 // AUTO-REMOVED #include <core/scoring/etable/count_pair/CountPairFactory.hh>
27 // AUTO-REMOVED #include <core/scoring/etable/count_pair/types.hh>
28 
29 // AUTO-REMOVED #include <core/kinematics/DomainMap.hh>
30 
31 // // Project headers
33 #include <core/graph/Graph.hh>
34 #include <core/pose/Pose.hh>
36 // AUTO-REMOVED #include <core/scoring/ScoreFunction.hh>
40 
41 // Numeric
42 #include <numeric/conversions.hh>
43 
44 // Utility headers
45 #include <utility/exit.hh>
46 
48 #include <utility/vector1.hh>
49 
50 
51 
52 //////////////////////////////////////////////////////////////////////////////////
53 //////////////////////////////////////////////////////////////////////////////////
54 //////////////////////////////////////////////////////////////////////////////////
55 
56 
57 namespace core {
58 namespace scoring {
59 
61  hbondoptions_( new hbonds::HBondOptions ),
62  hb_database_( scoring::hbonds::HBondDatabase::get_database())
63 {
64  hbondoptions_->use_sp2_chi_penalty( false ); // do not use the chi penalty -- override command line
65 }
66 
68 
69 Real
71  conformation::Residue const & rsd1,
72  conformation::Residue const & rsd2
73 ) const
74 {
75  // Take turns assuming the waters are on either residue
76  return h2o_hbond_score_1way( rsd1, rsd2 ) + h2o_hbond_score_1way( rsd2, rsd1 );
77 }
78 
79 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
80 // A rough translation based on Phil's implementation in rosetta++
81 
82 Real
84  conformation::Residue const & h2o_rsd,
85  conformation::Residue const & other_rsd
86 ) const
87 {
88 
89 
90  Real h2o_hbond_score( 0.0 );
91  hbonds::HBondDerivs deriv;
92 
93  static Real const HO_dist( 0.96 );
94  static Real const theta( numeric::conversions::radians( 107.0 ) );
95  static Real const HO_x_dist( HO_dist * std::cos( theta ) );
96  static Real const HO_y_dist( HO_dist * std::sin( theta ) );
97 
98  // Loop over waters
99  for( Size i = 1, ei = h2o_rsd.natoms() ; i <= ei ; ++i ) {
100  if( !h2o_rsd.atom_type(i).is_h2o() ) continue;
101 
102  Size const h2o_index( i );
103 
104  Vector const h2o_coord( h2o_rsd.xyz( i ) );
105  Vector const h2o_base_coord( h2o_rsd.xyz( h2o_rsd.atom_base(i) ) );
106  Vector const h2o_base2_coord( h2o_rsd.xyz( h2o_rsd.abase2(i) ) );
107  Vector const normal_from_base( Vector( h2o_coord - h2o_base_coord ).normalized() );
108 
109  // First check for interactions with donors
110  for( Size j = 1, ej = other_rsd.Hpos_polar().size() ; j <= ej ; ++j ) {
111  Size const hyd_index( other_rsd.Hpos_polar()[j] );
112  Size const donor_index( other_rsd.atom_base( hyd_index ) );
113  Vector const hyd_coord( other_rsd.xyz( hyd_index ) );
114  Vector const donor_coord( other_rsd.xyz( donor_index ) );
115 
116  // std::cout << "other rsd type " << other_rsd.type().name() << " hyd name " << other_rsd.atom_name( hyd_index ) << " donor name " << other_rsd.atom_name( donor_index ) << std::endl;
117 
118  Vector const separation( hyd_coord - h2o_coord );
119  if( separation.length_squared() > scoring::hbonds::MAX_R2 ) continue;
120 
121  scoring::hbonds::HBEvalTuple const hbe_type( donor_index, other_rsd, h2o_index, h2o_rsd );
122 
123  Real h2o_hbond_energy( 0.0 );
124  bool const eval_deriv( false );
126  hbe_type, donor_coord, hyd_coord, h2o_coord, h2o_base_coord, h2o_base2_coord,
127  h2o_hbond_energy, eval_deriv, deriv );
128 
129  if( h2o_hbond_energy < 0.0 ) {
130  h2o_hbond_score += h2o_hbond_energy;
131  }
132 
133  }
134 
135  // Second check for interactions with acceptors
136  for( Size j = 1, ej = other_rsd.accpt_pos().size() ; j <= ej ; ++j ) {
137  Size accpt_index( other_rsd.accpt_pos()[j] );
138  Vector accpt_coord( other_rsd.xyz( accpt_index ) );
139 
140  Vector const separation( accpt_coord - h2o_coord );
141  if( separation.length_squared() > scoring::hbonds::MAX_R2 ) continue;
142 
143  Size accpt_base_index( other_rsd.atom_base( accpt_index ) );
144  Vector accpt_base_coord( other_rsd.xyz( accpt_base_index ) );
145  Size accpt_base2_index( other_rsd.abase2( accpt_index ) );
146  Vector accpt_base2_coord( other_rsd.xyz( accpt_base2_index ) );
147  scoring::hbonds::HBEvalTuple const hbe_type( h2o_index, h2o_rsd, accpt_index, other_rsd );
148 
149  // build a fictitious hydrogen for the water
150  Vector const z( cross( normal_from_base, separation ).normalized() );
151  Vector const y( cross( z, normal_from_base ) );
152  Vector const faux_hyd_coord( h2o_coord + HO_x_dist * normal_from_base + HO_y_dist * y );
153 
154  Real h2o_hbond_energy( 0.0 );
155  bool const eval_deriv( false );
158  hbe_type, h2o_coord, faux_hyd_coord, accpt_coord, accpt_base_coord, accpt_base2_coord,
159  h2o_hbond_energy, eval_deriv, deriv );
160 
161  if( h2o_hbond_energy < 0.0 ) {
162  h2o_hbond_score += h2o_hbond_energy;
163  }
164  }
165  }
166 
167  return h2o_hbond_score;
168 }
169 
170 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
171 
172 /**
173  This routine fills an hbond-set with hbonds. All hbonds are included,
174  even ones which might be excluded later based on the backbone-hbond
175  exclusion.
176 **/
177 
178 void
180  pose::Pose const & pose,
181  hbonds::HBondSet & hbond_set
182 ) const
183 {
184  // clear old data
185  hbond_set.clear();
186  hbond_set.set_hbond_options( *hbondoptions_ );
187 
188  // need to know which residues are neighbors
189  // and what the neighbor-numbers are for each residue since some of the
190  // weights are environment-dependent.
191  EnergyGraph const & energy_graph( pose.energies().energy_graph() );
192  TenANeighborGraph const & tenA_neighbor_graph( pose.energies().tenA_neighbor_graph() );
193 
194  // loop over all nbr-pairs
195  for ( Size res1 = 1; res1 <= pose.total_residue(); ++res1 ) {
196  int const nb1 = tenA_neighbor_graph.get_node( res1 )->num_neighbors_counting_self();
197  conformation::Residue const & rsd1( pose.residue( res1 ) );
198 
200  iru = energy_graph.get_node(res1)->const_upper_edge_list_begin(),
201  irue = energy_graph.get_node(res1)->const_upper_edge_list_end();
202  iru != irue; ++iru ) {
203 
204  int const res2( (*iru)->get_second_node_ind() );
205 
206  conformation::Residue const & rsd2( pose.residue( res2 ) );
207 
208  int const nb2 = tenA_neighbor_graph.get_node( res2 )->num_neighbors_counting_self();
209 
210  // rsd1 as water, rsd2 as other
211  get_residue_residue_h2o_hbonds_1way( rsd1, rsd2, nb1, nb2, hbond_set );
212 
213  // rsd2 as water, rsd1 as other
214  get_residue_residue_h2o_hbonds_1way( rsd2, rsd1, nb2, nb1, hbond_set );
215 
216  } // nbrs of res1
217  } // res1
218 }
219 
220 
221 /**
222  compiles list of hbonds
223  and evaluates the derivative
224 **/
225 
226 
227 void
229  // input
230  conformation::Residue const & h2o_rsd,
231  conformation::Residue const & other_rsd,
232  int const & /*h2o_nb*/,
233  int const & /*other_nb*/,
234  // output
235  hbonds::HBondSet & hbond_set
236 ) const
237 {
238  assert( h2o_rsd.seqpos() != other_rsd.seqpos() ); // otherwise include in allow
239 
240  // <f1,f2> -- derivative vectors
241  hbonds::HBondDerivs deriv;
242 
243  static Real const HO_dist( 0.96 );
244  static Real const theta( numeric::conversions::radians( 107.0 ) );
245  static Real const HO_x_dist( HO_dist * std::cos( theta ) );
246  static Real const HO_y_dist( HO_dist * std::sin( theta ) );
247 
248  // Loop over waters
249  for( Size i = 1, ei = h2o_rsd.natoms() ; i <= ei ; ++i ) {
250  if( !h2o_rsd.atom_type(i).is_h2o() ) continue;
251 
252  Size const h2o_index( i );
253 
254  Vector const h2o_coord( h2o_rsd.xyz( i ) );
255  Vector const h2o_base_coord( h2o_rsd.xyz( h2o_rsd.atom_base(i) ) );
256  Vector const h2o_base2_coord( h2o_rsd.xyz( h2o_rsd.abase2(i) ) );
257  Vector const normal_from_base( Vector( h2o_coord - h2o_base_coord ).normalized() );
258 
259  // First check for interactions with donors
260  for( Size j = 1, ej = other_rsd.Hpos_polar().size() ; j <= ej ; ++j ) {
261  Size const hyd_index( other_rsd.Hpos_polar()[j] );
262  Size const donor_index( other_rsd.atom_base( hyd_index ) );
263  Vector const hyd_coord( other_rsd.xyz( hyd_index ) );
264  Vector const donor_coord( other_rsd.xyz( donor_index ) );
265 
266  // std::cout << "other rsd type " << other_rsd.type().name() << " hyd name " << other_rsd.atom_name( hyd_index ) << " donor name " << other_rsd.atom_name( donor_index ) << std::endl;
267 
268  Vector const separation( hyd_coord - h2o_coord );
269  if( separation.length_squared() > scoring::hbonds::MAX_R2 ) continue;
270 
271  scoring::hbonds::HBEvalTuple const hbe_type( donor_index, other_rsd, h2o_index, h2o_rsd );
272 
273  Real h2o_hbond_energy( 0.0 );
274  bool const eval_deriv( true );
276  hbe_type, donor_coord, hyd_coord, h2o_coord, h2o_base_coord, h2o_base2_coord,
277  h2o_hbond_energy, eval_deriv, deriv );
278 
279  if( h2o_hbond_energy < 0.0 ) {
280 // Real const weight ( get_environment_dependent_weight( hbe_type, h2o_nb, other_nb, *hbond_set.options() ) );
281  Real const weight ( 1.0 );
282  hbond_set.append_hbond(
283  hyd_index, other_rsd, h2o_index, h2o_rsd, hbe_type,
284  h2o_hbond_energy, weight, deriv );
285 // std::cout << "Stashing h2o hbond, water is acceptor " << std::endl;
286 // std::cout << "Energy is " << h2o_hbond_energy << std::endl;
287 // std::cout << "F1 is " <<
288 // deriv.first[0] << " " <<
289 // deriv.first[1] << " " <<
290 // deriv.first[2] << " " <<
291 // std::endl;
292 // std::cout << "F2 is " <<
293 // deriv.second[0] << " " <<
294 // deriv.second[1] << " " <<
295 // deriv.second[2] << " " <<
296 // std::endl;
297  }
298  }
299 
300  // Second check for interactions with acceptors
301  for( Size j = 1, ej = other_rsd.accpt_pos().size() ; j <= ej ; ++j ) {
302  Size accpt_index( other_rsd.accpt_pos()[j] );
303  Vector accpt_coord( other_rsd.xyz( accpt_index ) );
304 
305  Vector const separation( accpt_coord - h2o_coord );
306  if( separation.length_squared() > scoring::hbonds::MAX_R2 ) continue;
307 
308  Size accpt_base_index( other_rsd.atom_base( accpt_index ) );
309  Vector accpt_base_coord( other_rsd.xyz( accpt_base_index ) );
310  Size accpt_base2_index( other_rsd.abase2( accpt_index ) );
311  Vector accpt_base2_coord( other_rsd.xyz( accpt_base2_index ) );
312  scoring::hbonds::HBEvalTuple const hbe_type( h2o_index, h2o_rsd, accpt_index, other_rsd );
313 
314  // build a fictitious hydrogen for the water
315  Vector const z( cross( normal_from_base, separation ).normalized() );
316  Vector const y( cross( z, normal_from_base ) );
317  Vector const faux_hyd_coord( h2o_coord + HO_x_dist * normal_from_base + HO_y_dist * y );
318 
319  Real h2o_hbond_energy( 0.0 );
320  bool const eval_deriv( true );
322  hbe_type, h2o_coord, faux_hyd_coord,
323  accpt_coord, accpt_base_coord, accpt_base2_coord,
324  h2o_hbond_energy, eval_deriv, deriv );
325 
326  if( h2o_hbond_energy < 0.0 ) {
327 // Real const weight ( get_environment_dependent_weight( hbe_type, h2o_nb, other_nb, *hbond_set.options() ) );
328  Real const weight ( 1.0 );
329  hbond_set.append_hbond( h2o_index, h2o_rsd, accpt_index, other_rsd, hbe_type,
330  h2o_hbond_energy, weight, deriv );
331 // std::cout << "Stashing h2o hbond, water is donor " << std::endl;
332 // std::cout << "Energy is " << h2o_hbond_energy << std::endl;
333 // std::cout << "F1 is " <<
334 // deriv.first[0] << " " <<
335 // deriv.first[1] << " " <<
336 // deriv.first[2] << " " <<
337 // std::endl;
338 // std::cout << "F2 is " <<
339 // deriv.second[0] << " " <<
340 // deriv.second[1] << " " <<
341 // deriv.second[2] << " " <<
342 // std::endl;
343  }
344  }
345  }
346 }
347 
348 
349 
350 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
351 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
352 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
353 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
354 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
355 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
356 
357 } // namespace scoring
358 } // namespace core