Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RB_geometry.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 RB_geometry - rigid body geometry
11 /// @brief functions that are needed to do geometric functions for rigid body moves
12 /// @author Monica Berrondo
13 
14 
16 
17 // Rosetta Headers
18 // AUTO-REMOVED #include <basic/basic.hh>
19 #include <core/pose/Pose.hh>
23 
24 // ObjexxFCL Headers
25 
26 // C++ Headers
27 
28 //Utility Headers
29 #include <numeric/conversions.hh>
30 #include <numeric/random/random.hh>
31 #include <numeric/trig.functions.hh>
32 #include <numeric/xyz.functions.hh>
33 #include <numeric/xyzMatrix.hh>
34 //#include <numeric/xyzVector.io.hh>
35 #include <basic/Tracer.hh>
36 
37 #include <utility/vector1.hh>
38 
39 
40 using basic::T;
41 using basic::Error;
42 using basic::Warning;
43 
44 static basic::Tracer TR("protocols.geometry.RB_geometry");
45 static numeric::random::RandomGenerator RG(62451); // <- Magic number, do not change it!!!
46 
47 using namespace ObjexxFCL;
48 
49 // RB_geometry.cc: some supporting functions for rigid body moves
50 
51 //------------------------------------------------------------------------------
52 //
53 
54 namespace protocols {
55 namespace geometry {
56 
57 using namespace core;
58 
59 //////////////////////////////////////////////////////////////////////////
60 // these functions should probably be moves somewhere else
61 // copied from rosetta++ jumping_util.cc
62 numeric::xyzMatrix_double
63 random_reorientation_matrix(const double phi_range, const double psi_range)
64 {
65  // a genuine rotation matrix which will randomly reorient the coord sys.
66  // from Euler theorem
67  const double phi( phi_range * RG.uniform() ); // degrees
68  const double psi( psi_range * RG.uniform() ); // degrees
69  const double theta(
70  numeric::conversions::degrees( std::acos(numeric::sin_cos_range( 1.0 - 2.0 *RG.uniform() ) ) )
71  ); // degrees
72 
73  TR << "random_reorientation_matrix phi: " << phi << " psi: " << psi << " theta: " << theta << std::endl;
74  return
75  numeric::z_rotation_matrix_degrees( psi ) *
76  numeric::y_rotation_matrix_degrees( theta ) *
77  numeric::z_rotation_matrix_degrees( phi );
78 }
79 
80 
81 /// @brief Unweighted centroids of all atoms upstream of the jump
82 /// vs. all atoms downstream of the jump.
83 /// @details Deliberately includes H -- is this OK?
84 void
86  core::pose::Pose const & pose,
87  core::Size const jump_id,
88  core::Vector & upstream_ctrd, //< output
89  core::Vector & downstream_ctrd //< output
90 )
91 {
92  utility::vector1< bool > ok_for_centroid_calculation; //empty is fine.
93  centroids_by_jump( pose, jump_id, upstream_ctrd, downstream_ctrd, ok_for_centroid_calculation );
94 }
95 
96 /// @brief Unweighted centroids of all atoms upstream of the jump
97 /// vs. all atoms downstream of the jump.
98 /// @details Deliberately includes H -- is this OK?
99 void
101  core::pose::Pose const & pose,
102  core::Size const jump_id,
103  core::Vector & upstream_ctrd, //< output
104  core::Vector & downstream_ctrd, //< output
105  utility::vector1< bool > ok_for_centroid_calculation
106 )
107 {
108  FArray1D_bool is_upstream ( pose.total_residue(), false );
109  pose.fold_tree().partition_by_jump( jump_id, is_upstream );
110 
111  upstream_ctrd = 0;
112  downstream_ctrd = 0;
113  int upstream_atoms = 0, downstream_atoms = 0;
114 
115  for(int ii = 1, ii_end = pose.total_residue(); ii <= ii_end; ++ii) {
116  int & natoms = ( is_upstream(ii) ? upstream_atoms : downstream_atoms );
117  core::Vector & ctrd = ( is_upstream(ii) ? upstream_ctrd : downstream_ctrd );
118  core::conformation::Residue const & rsd = pose.residue(ii);
119 
120  if ( ok_for_centroid_calculation.size() > 0 && !ok_for_centroid_calculation[ ii ] ) {
121  // std::cout << "skipping res "<< ii << std::endl;
122  continue;
123  }
124 
125  for(int jj = 1, jj_end = rsd.natoms(); jj <= jj_end; ++jj) {
126  //if ( rsd.is_virtual( jj ) ) continue;
127  ctrd += rsd.xyz(jj);
128  natoms += 1;
129  }
130  }
131 
132  upstream_ctrd /= upstream_atoms;
133  downstream_ctrd /= downstream_atoms;
134  //TR << "Upstream: " << upstream_atoms << " atoms, " << upstream_ctrd << std::endl;
135  //TR << "Downstream: " << downstream_atoms << " atoms, " << downstream_ctrd << std::endl;
136 }
137 
138 std::pair< core::Vector, core::Vector > centroid_pair_by_jump(
139  core::pose::Pose const & pose,
140  core::Size jump_id
141 ){
142  std::pair<core::Vector, core::Vector > centroids;
143  centroids_by_jump(pose, jump_id, centroids.first, centroids.second);
144  return centroids;
145 }
146 
148  core::pose::Pose const & pose,
149  core::Size jump_id
150 ){
151  return (centroid_pair_by_jump(pose, jump_id)).second;
152 }
153 
155  core::pose::Pose const & pose,
156  core::Size jump_id
157 ){
158  return centroid_pair_by_jump(pose, jump_id).second;
159 }
160 
161 /// @brief Unweighted centroids of all atoms upstream of the jump
162 /// vs. all atoms downstream of the jump for interface residues only.
163 /// needed to calculate rb_centers for fullatom docking - Sid C.
164 /// @details Deliberately includes H -- is this OK?
165 void
167  core::pose::Pose const & pose,
168  core::Size jump_id,
169  core::Vector & upstream_ctrd, //< output
170  core::Vector & downstream_ctrd //< output
171 )
172 {
173  FArray1D_bool is_upstream ( pose.total_residue(), false );
174  TR.Debug << "fold-tree: " << pose.fold_tree() << std::endl;
175  TR.Debug << "partition by jump " << jump_id << std::endl;
176  pose.fold_tree().partition_by_jump( jump_id, is_upstream );
177 
178  upstream_ctrd = 0;
179  downstream_ctrd = 0;
180  core::Size upstream_atoms = 0, downstream_atoms = 0;
181 
182  protocols::scoring::Interface interface( jump_id );
183  //interface.calculate( pose );
184 
185  Size int_res_num = 0;
186  Real int_distance = 8.0;
187 
188  //increments the interface distance until an interface is found, starting from 8A
189  for( Size ll = 1; ll <= 5; ll++){
190  if (int_res_num == 0){
191  interface.distance( int_distance );
192  interface.calculate( pose );
193 
194  //count interface residues
195  for(Size kk = 1; kk <= pose.total_residue(); kk++){
196  if (interface.is_interface( kk )) int_res_num++;
197  }
198 
199  //increment interface distance by 2A
200  int_distance = int_distance+2;
201  }
202  }
203 
204  for ( Size ii = 1, ii_end = pose.total_residue(); ii <= ii_end; ++ii ) {
205  Size & natoms = ( is_upstream(ii) ? upstream_atoms : downstream_atoms );
206  core::Vector & ctrd = ( is_upstream(ii) ? upstream_ctrd : downstream_ctrd );
207  core::conformation::Residue const & rsd = pose.residue(ii);
208  for ( Size jj = 1, jj_end = rsd.natoms(); jj <= jj_end; ++jj ) {
209  if ( interface.is_interface(rsd) ) {
210  ctrd += rsd.xyz(jj);
211  natoms += 1;
212  }
213  }
214  }
215 
216  if ( upstream_atoms == 0 || downstream_atoms == 0 ){
217  TR.Warning << "centroids_by_jump_int called but no interface detected!!" << std::endl;
218  TR.Warning << "calling centroids_by_jump..." << std::endl;
219  centroids_by_jump( pose, jump_id, upstream_ctrd, downstream_ctrd);
220  } else {
221  upstream_ctrd /= upstream_atoms;
222  downstream_ctrd /= downstream_atoms;
223  }
224 
225  //TR << "Upstream: " << upstream_atoms << " atoms, " << upstream_ctrd << std::endl;
226  //TR << "Downstream: " << downstream_atoms << " atoms, " << downstream_ctrd << std::endl;
227 }
228 ////////////////////////////////////////////////////////////////////////////////////
229 /// @begin center_of_mass
230 ///
231 /// @brief calculates the center of mass of a pose
232 /// @detailed
233 /// the start and stop positions (or residues) within the pose are used to
234 /// find the starting and finishing locations
235 ///
236 /// @authors Monica Berrondo June 14 2007
237 ///
238 /// @last_modified Javier Castellanos June 4 2012
239 /////////////////////////////////////////////////////////////////////////////////
242  pose::Pose const & pose,
243  int const start,
244  int const stop
245 )
246 {
247  Vector center( 0.0 );
248  for ( int i=start; i<=stop; ++i ) {
249  if( !pose.residue( i ).is_protein()) {
250  Vector ca_pos( pose.residue( i ).nbr_atom_xyz() );
251  center += ca_pos;
252  } else {
253  Vector ca_pos( pose.residue( i ).atom( "CA" ).xyz() );
254  center += ca_pos;
255  }
256  }
257  center /= (stop-start+1);
258 
259  return center;
260 }
261 
262 ////////////////////////////////////////////////////////////////////////////////////
263 /// @begin residue_center_of_mass
264 ///
265 /// @brief calculates the center of mass of a pose
266 /// @detailed
267 /// the start and stop positions (or residues) within the pose are used to
268 /// find the starting and finishing locations
269 ///
270 /// @authors Monica Berrondo June 14 2007
271 ///
272 /// @last_modified Javier Castellanos June 4 2012
273 /////////////////////////////////////////////////////////////////////////////////
274 int
276  pose::Pose const & pose,
277  int const start,
278  int const stop
279 )
280 {
281  Vector center = center_of_mass(pose, start, stop );
282  return return_nearest_residue( pose, start, stop, center );
283 }
284 
285 ////////////////////////////////////////////////////////////////////////////////////
286 /// @begin return_nearest_residue
287 ///
288 /// @brief finds the residue nearest some position passed in (normally a
289 /// center of mass)
290 /// @detailed
291 /// the start and stop positions (or residues) within the pose are used to
292 /// find the starting and finishing locations
293 ///
294 /// @authors Monica Berrondo June 14 2007
295 ///
296 /// @last_modified June 29 2007
297 /////////////////////////////////////////////////////////////////////////////////
298 int
300  pose::Pose const & pose,
301  int const begin,
302  int const end,
303  Vector center
304 )
305 {
306  Real min_dist = 9999.9;
307  int res = 0;
308  for ( int i=begin; i<=end; ++i )
309  {
310  Vector ca_pos;
311  if( !pose.residue( i ).is_protein() ){
312  ca_pos = pose.residue( i ).nbr_atom_xyz();
313  } else {
314  //Vector ca_pos( pose.residue( i ).atom( "CA" ).xyz() );
315  ca_pos = pose.residue( i ).atom( "CA" ).xyz() ;
316  }
317 
318  ca_pos -= center;
319  Real tmp_dist( ca_pos.length_squared() );
320  if ( tmp_dist < min_dist ) {
321  res = i;
322  min_dist = tmp_dist;
323  }
324  }
325  return res;
326 }
327 
328 } // namespace geometry
329 } // namespace core