Rosetta
 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 #include <core/pose/Pose.hh>
22 
23 // ObjexxFCL Headers
24 
25 // C++ Headers
26 
27 //Utility Headers
28 #include <numeric/conversions.hh>
29 #include <numeric/random/random.hh>
30 #include <numeric/trig.functions.hh>
31 #include <numeric/xyz.functions.hh>
32 #include <numeric/xyzMatrix.hh>
33 //#include <numeric/xyzVector.io.hh>
34 #include <basic/Tracer.hh>
35 
36 #include <utility/vector1.hh>
37 
38 
39 using basic::T;
40 using basic::Error;
41 using basic::Warning;
42 
43 static THREAD_LOCAL basic::Tracer TR( "protocols.geometry.RB_geometry" );
44 
45 using namespace ObjexxFCL;
46 
47 // RB_geometry.cc: some supporting functions for rigid body moves
48 
49 //------------------------------------------------------------------------------
50 
51 
52 namespace protocols {
53 namespace geometry {
54 
55 using namespace core;
56 
57 //////////////////////////////////////////////////////////////////////////
58 // these functions should probably be moves somewhere else
59 // copied from rosetta++ jumping_util.cc
60 numeric::xyzMatrix_double
61 random_reorientation_matrix(const double phi_range, const double psi_range)
62 {
63  // a genuine rotation matrix which will randomly reorient the coord sys.
64  // from Euler theorem
65  const double phi( phi_range * numeric::random::rg().uniform() ); // degrees
66  const double psi( psi_range * numeric::random::rg().uniform() ); // degrees
67  const double theta(
68  numeric::conversions::degrees( std::acos(numeric::sin_cos_range( 1.0 - 2.0 * numeric::random::rg().uniform() ) ) )
69  ); // degrees
70 
71  TR << "random_reorientation_matrix phi: " << phi << " psi: " << psi << " theta: " << theta << std::endl;
72  return
73  numeric::z_rotation_matrix_degrees( psi ) *
74  numeric::y_rotation_matrix_degrees( theta ) *
75  numeric::z_rotation_matrix_degrees( phi );
76 }
77 
78 
79 /// @brief Unweighted centroids of all atoms upstream of the jump
80 /// vs. all atoms downstream of the jump.
81 /// @details Deliberately includes H -- is this OK?
82 void
84  core::pose::Pose const & pose,
85  core::Size const jump_id,
86  core::Vector & upstream_ctrd, //< output
87  core::Vector & downstream_ctrd //< output
88 )
89 {
90  utility::vector1< bool > ok_for_centroid_calculation; //empty is fine.
91  centroids_by_jump( pose, jump_id, upstream_ctrd, downstream_ctrd, ok_for_centroid_calculation );
92 }
93 
94 /// @brief Unweighted centroids of all atoms upstream of the jump
95 /// vs. all atoms downstream of the jump.
96 /// @details Deliberately includes H -- is this OK?
97 void
99  core::pose::Pose const & pose,
100  core::Size const jump_id,
101  core::Vector & upstream_ctrd, //< output
102  core::Vector & downstream_ctrd, //< output
103  utility::vector1< bool > ok_for_centroid_calculation
104 )
105 {
106  FArray1D_bool is_upstream ( pose.total_residue(), false );
107  pose.fold_tree().partition_by_jump( jump_id, is_upstream );
108 
109  upstream_ctrd = 0;
110  downstream_ctrd = 0;
111  int upstream_atoms = 0, downstream_atoms = 0;
112 
113  for ( int ii = 1, ii_end = pose.total_residue(); ii <= ii_end; ++ii ) {
114  // Use a reference so we have to evaluate is_upstream only once per residue
115  // but still increment the correct variable.
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  // AMW cppcheck: this is falsely found as a division by zero. The above code redirects the int reference
133  // natoms to add to either upstream or downstream atoms depending on the residue's location
134  // This is definitely opaque and I will add a comment indicating such
135  // AMW: oh, I see: what if there are zero atoms in all? Take an empty pose (somehow) or a pose with two zero-atom residues (somehow) or...
136  // so I will make a clear modification
137  if ( upstream_atoms > 0 ) upstream_ctrd /= upstream_atoms;
138  else TR << "critical error: upstream_atoms was zero; could not divide!" << std::endl;
139  //TR << "upstream_ctrd: " << upstream_ctrd.x() << " " << upstream_ctrd.y() << " " << upstream_ctrd.z() << std::endl;
140  //TR << "upstream_ctrd: " << upstream_ctrd.x() << " " << upstream_ctrd.y() << " " << upstream_ctrd.z() << std::endl;
141  if ( downstream_atoms > 0 ) downstream_ctrd /= downstream_atoms;
142  else TR << "critical error: downstream_atoms was zero; could not divide!" << std::endl;
143  //TR << "Upstream: " << upstream_atoms << " atoms, " << upstream_ctrd << std::endl;
144  //TR << "Downstream: " << downstream_atoms << " atoms, " << downstream_ctrd << std::endl;
145 }
146 
147 std::pair< core::Vector, core::Vector > centroid_pair_by_jump(
148  core::pose::Pose const & pose,
149  core::Size jump_id
150 ){
151  std::pair<core::Vector, core::Vector > centroids;
152  centroids_by_jump(pose, jump_id, centroids.first, centroids.second);
153  return centroids;
154 }
155 
157  core::pose::Pose const & pose,
158  core::Size jump_id
159 ){
160  return (centroid_pair_by_jump(pose, jump_id)).second;
161 }
162 
164  core::pose::Pose const & pose,
165  core::Size jump_id
166 ){
167  return centroid_pair_by_jump(pose, jump_id).second;
168 }
169 
170 /// @brief Unweighted centroids of all atoms upstream of the jump
171 /// vs. all atoms downstream of the jump for interface residues only.
172 /// needed to calculate rb_centers for fullatom docking - Sid C.
173 /// @details Deliberately includes H -- is this OK?
174 void
176  core::pose::Pose const & pose,
177  core::Size jump_id,
178  core::Vector & upstream_ctrd, //< output
179  core::Vector & downstream_ctrd //< output
180 )
181 {
182  FArray1D_bool is_upstream ( pose.total_residue(), false );
183  TR.Debug << "fold-tree: " << pose.fold_tree() << std::endl;
184  TR.Debug << "partition by jump " << jump_id << std::endl;
185  pose.fold_tree().partition_by_jump( jump_id, is_upstream );
186 
187  upstream_ctrd = 0;
188  downstream_ctrd = 0;
189  core::Size upstream_atoms = 0, downstream_atoms = 0;
190 
191  protocols::scoring::Interface interface( jump_id );
192  //interface.calculate( pose );
193 
194  Size int_res_num = 0;
195  Real int_distance = 8.0;
196 
197  //increments the interface distance until an interface is found, starting from 8A
198  for ( Size ll = 1; ll <= 5; ll++ ) {
199  if ( int_res_num == 0 ) {
200  interface.distance( int_distance );
201  interface.calculate( pose );
202 
203  //count interface residues
204  for ( Size kk = 1; kk <= pose.total_residue(); kk++ ) {
205  if ( interface.is_interface( kk ) ) int_res_num++;
206  }
207 
208  //increment interface distance by 2A
209  int_distance = int_distance+2;
210  }
211  }
212 
213  for ( Size ii = 1, ii_end = pose.total_residue(); ii <= ii_end; ++ii ) {
214  Size & natoms = ( is_upstream(ii) ? upstream_atoms : downstream_atoms );
215  core::Vector & ctrd = ( is_upstream(ii) ? upstream_ctrd : downstream_ctrd );
216  core::conformation::Residue const & rsd = pose.residue(ii);
217  for ( Size jj = 1, jj_end = rsd.natoms(); jj <= jj_end; ++jj ) {
218  if ( interface.is_interface(rsd) ) {
219  ctrd += rsd.xyz(jj);
220  natoms += 1;
221  }
222  }
223  }
224 
225  if ( upstream_atoms == 0 || downstream_atoms == 0 ) {
226  TR.Warning << "centroids_by_jump_int called but no interface detected!!" << std::endl;
227  TR.Warning << "calling centroids_by_jump..." << std::endl;
228  centroids_by_jump( pose, jump_id, upstream_ctrd, downstream_ctrd);
229  } else {
230  upstream_ctrd /= upstream_atoms;
231  downstream_ctrd /= downstream_atoms;
232  }
233 
234  //TR << "Upstream: " << upstream_atoms << " atoms, " << upstream_ctrd << std::endl;
235  //TR << "Downstream: " << downstream_atoms << " atoms, " << downstream_ctrd << std::endl;
236 }
237 ////////////////////////////////////////////////////////////////////////////////////
238 /// @begin center_of_mass
239 ///
240 /// @brief calculates the center of mass of a pose
241 /// @detailed
242 /// the start and stop positions (or residues) within the pose are used to
243 /// find the starting and finishing locations
244 ///
245 /// @authors Monica Berrondo June 14 2007
246 ///
247 /// @last_modified Javier Castellanos June 4 2012
248 /////////////////////////////////////////////////////////////////////////////////
249 numeric::xyzVector< core::Real>
251  core::pose::Pose const & pose,
252  int const start,
253  int const stop
254 )
255 {
256  Vector center( 0.0 );
257  for ( int i=start; i<=stop; ++i ) {
258  if ( !pose.residue( i ).is_protein() ) {
259  Vector ca_pos( pose.residue( i ).nbr_atom_xyz() );
260  center += ca_pos;
261  } else {
262  Vector ca_pos( pose.residue( i ).atom( "CA" ).xyz() );
263  center += ca_pos;
264  }
265  }
266  center /= (stop-start+1);
267 
268  return center;
269 }
270 
271 
272 } // namespace geometry
273 } // namespace core
Fold tree class.
kinematics::FoldTree const & fold_tree() const
Returns the pose FoldTree.
Definition: Pose.cc:303
void centroids_by_jump_int(core::pose::Pose const &pose, core::Size jump_id, core::Vector &upstream_ctrd, core::Vector &downstream_ctrd)
Unweighted centroids of all atoms upstream of the jump vs. all atoms downstream of the jump for inter...
Definition: RB_geometry.cc:175
void calculate(core::pose::Pose const &pose)
base for calculating the interface
Definition: Interface.cc:98
A molecular system including residues, kinematics, and energies.
Definition: Pose.hh:151
void centroids_by_jump(core::pose::Pose const &pose, core::Size const jump_id, core::Vector &upstream_ctrd, core::Vector &downstream_ctrd, utility::vector1< bool > ok_for_centroid_calculation)
Unweighted centroids of all atoms upstream of the jump vs. all atoms downstream of the jump...
Definition: RB_geometry.cc:98
numeric::xyzVector< core::Real > center_of_mass(core::pose::Pose const &pose, int const start, int const stop)
calculates the center of mass of a pose
Definition: RB_geometry.cc:250
Vector const & nbr_atom_xyz() const
Definition: Residue.hh:963
void partition_by_jump(int const jump_number, FoldTree &f1, FoldTree &f2) const
partition into two foldtrees by cutting at jump= jump_number
Definition: FoldTree.cc:1780
core::Vector downstream_centroid_by_jump(core::pose::Pose const &pose, core::Size jump_id)
Definition: RB_geometry.cc:163
platform::Size Size
Definition: types.hh:30
Instance Residue class, used for placed residues and rotamers.
Definition: Residue.hh:90
Size total_residue() const
Returns the number of residues in the pose conformation.
Definition: Pose.cc:732
Vector const & xyz() const
Returns the atom coordinates as an xyzVector.
Definition: Atom.hh:101
Vector const & xyz(Size const atm_index) const
Returns the position of this residue's atom with index number
Definition: Residue.cc:325
Size natoms() const
Returns the number of atoms in this residue.
Definition: Residue.hh:237
core::Vector upstream_centroid_by_jump(core::pose::Pose const &pose, core::Size jump_id)
Definition: RB_geometry.cc:156
numeric::xyzMatrix_double random_reorientation_matrix(const double phi_range, const double psi_range)
Definition: RB_geometry.cc:61
Atom const & atom(Size const atm_index) const
Returns this residue's Atom with index number (const)
Definition: Residue.hh:497
numeric::xyzVector< Length > Vector
Definition: types.hh:65
platform::Real Real
Definition: types.hh:35
bool is_interface(core::conformation::Residue const &rsd) const
Definition: Interface.cc:435
Method declarations and simple accessor definitions for the Residue class.
Residue const & residue(Size const seqpos) const
Returns the Residue at position (read access) Note: this method will trigger a refold if eit...
Definition: Pose.cc:866
void distance(Real const distance_in)
Definition: Interface.cc:438
bool is_protein() const
Returns true if this residue is an amino acid.
Definition: Residue.hh:1673
static THREAD_LOCAL basic::Tracer TR("protocols.geometry.RB_geometry")
Pose class.
std::pair< core::Vector, core::Vector > centroid_pair_by_jump(core::pose::Pose const &pose, core::Size jump_id)
Definition: RB_geometry.cc:147