Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GridSearchIterator.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  //////////////////////////////////////////////
11  /// @begin
12  ///
13  /// @file GridSearchIterator.cc
14  ///
15  /// @brief
16  ///
17  /// @detailed
18  ///
19  /// @param
20  ///
21  /// @return
22  ///
23  /// @remarks
24  ///
25  /// @references
26  ///
27  /// @authorsv Christophe Schmitz
28  ///
29  /// @last_modified June 2009
30  ////////////////////////////////////////////////
31 
32 
33 // Unit headers
35 
36 // Package headers
37 
38 // Project headers
39 
40 // Utility headers
41 #include <utility/exit.hh>
42 
43 // Numeric headers
44 #include <numeric/constants.hh>
45 #include <numeric/xyzVector.hh>
46 
47 // Objexx headers
48 
49 // C++ headers
50 #include <iostream>
51 
52 //#include <limits>
53 
54 namespace protocols{
55 namespace scoring{
56 namespace methods{
57 namespace pcs{
58 
59 
61  x_center_(0),
62  y_center_(0),
63  z_center_(0),
64  step_(0),
65  edge_(0),
66  delta_(0),
67  small_cutoff_square_(0),
68  large_cutoff_square_(0),
69  x_vector_(0),
70  y_vector_(0),
71  z_vector_(0),
72  norme_vector_(0),
73  cone_angle_cos_(0)
74 {
75  utility_exit_with_message( "You shouldn't call the empty constructor for GridSearchIterator class" );
76 }
77 
79 }
80 
82  ReferenceCount(),
83  x_center_(other.x_center_),
84  y_center_(other.y_center_),
85  z_center_(other.z_center_),
86  step_(other.step_),
87  edge_(other.edge_),
88  delta_(other.delta_),
89  small_cutoff_square_(other.small_cutoff_square_),
90  large_cutoff_square_(other.large_cutoff_square_),
91  x_vector_(other.x_vector_),
92  y_vector_(other.y_vector_),
93  z_vector_(other.z_vector_),
94  norme_vector_(other.norme_vector_),
95  cone_angle_cos_(other.cone_angle_cos_)
96 {
97  x_current_ = other.x_current_;
98  y_current_ = other.y_current_;
99  z_current_ = other.z_current_;
100  step_x_ = other.step_x_;
101  step_y_ = other.step_y_;
102  step_z_ = other.step_z_;
104 }
105 
108  if ( this != &other ) {
109  if((x_center_ != other.x_center_)||
110  (y_center_ != other.y_center_)||
111  (z_center_ != other.z_center_)||
112  (step_ != other.step_)||
113  (edge_ != other.edge_)||
114  (delta_ != other.delta_)){
115  utility_exit_with_message( "You can't call the = operator on GridSearchIterator object of different size" );
116  }
117  x_current_ = other.x_current_;
118  y_current_ = other.y_current_;
119  z_current_ = other.z_current_;
120  step_x_ = other.step_x_;
121  step_y_ = other.step_y_;
122  step_z_ = other.step_z_;
124  }
125  return *this;
126 }
127 
128 
131  core::Real const k,
132  core::Real const edge_size,
133  core::Real const step_size,
134  core::Real const small_cutoff,
135  core::Real const large_cutoff,
136  core::Real const cone_angle
137 ):
138  x_center_(coo2.x() + k*( coo2.x() - coo1.x() )),
139  y_center_(coo2.y() + k*( coo2.y() - coo1.y() )),
140  z_center_(coo2.z() + k*( coo2.z() - coo1.z() )),
141  step_(step_size),
142  edge_(edge_size),
143  delta_(step_/2.0),
144  small_cutoff_square_(small_cutoff * small_cutoff),
145  large_cutoff_square_(large_cutoff * large_cutoff),
146  x_vector_(coo1.x() - coo2.x()),
147  y_vector_(coo1.y() - coo2.y()),
148  z_vector_(coo1.z() - coo2.z()),
149  norme_vector_(sqrt( (coo2.x()-coo1.x())*(coo2.x()-coo1.x()) + (coo2.y()-coo1.y())*(coo2.y()-coo1.y()) + (coo2.z()-coo1.z())*(coo2.z()-coo1.z()) )),
150  cone_angle_cos_(cos(cone_angle/180.0*core::Real( numeric::constants::d::pi )))
151 {
152  if( edge_size < 0){
153  utility_exit_with_message("Edge size of the cube search is negative and has to be positive");
154  }
155  if( step_size <= 0){
156  utility_exit_with_message("step_size of the cube search has to be strictly positive");
157  }
158 
159  reset();
160 }
161 
162 
163 bool
165  core::Real &y,
166  core::Real &z){
167 
168  double r2;
169  while(next(x, y, z) == true){
170  r2 = (x-x_center_)*(x-x_center_) + (y-y_center_)* (y-y_center_) + (z-z_center_)*(z-z_center_);
171  if((r2 <= large_cutoff_square_) && (r2 >= small_cutoff_square_ )){ //we test small and large cutoff
172  core::Real cos_angle = ((x-x_center_)*x_vector_ + (y-y_center_)*y_vector_ + (z-z_center_)*z_vector_ );
173  if((r2 == 0 ) || (norme_vector_ == 0)){
174  return true;
175  }
176  cos_angle = cos_angle / sqrt(r2) / norme_vector_;
177  //std::cout << "comparing " << cos_angle << "with ref" << cone_angle_cos_ << std::endl;
178  //std::cout << x_vector_ << y_vector_ << z_vector_ << std::endl;
179  if(cos_angle >= cone_angle_cos_){ //we test cone angle
180  return true;
181  }
182  }
183  }
184  return false;
185 }
186 
187 // This iterator sample a cube in 3D space.
188 // The following code looks strange and could be written in an easier way.
189 // However, it is strange because the iterator ensure that
190 // the points are visited in a specific order in such a way
191 // that the next point visited is a direct neighboor of the previous one
192 // It will be important if I decide to work on unassigned PCS Data.
193 bool
195  core::Real &y,
196  core::Real &z){
197  x = x_current_;
198  y = y_current_;
199  z = z_current_;
200 
201  if(!next_to_return_){
202  reset();
203  return(false);
204  }
205 
206  if( z_current_ - z_center_ > edge_/2.0){
207  next_to_return_ = false;
208  return(true);
209  }
210 
211  x_current_ += step_x_;
212 
213  if( x_current_ - x_center_> edge_/2.0 + delta_){
214  step_x_ = -step_;
215  x_current_ += step_x_;
216  y_current_ += step_y_;
217  }
218 
219  if( x_current_ - x_center_ < -edge_/2.0 - delta_){
220  step_x_ = step_;
221  x_current_ += step_x_;
222  y_current_ += step_y_;
223  }
224 
225  if( y_current_ - y_center_> edge_/2.0 + delta_){
226  step_y_ = -step_;
227  y_current_ += step_y_;
228  z_current_ += step_z_;
229  }
230 
231  if( y_current_ - y_center_ < -edge_/2.0 - delta_){
232  step_y_ = step_;
233  y_current_ += step_y_;
234  z_current_ += step_z_;
235  }
236 
237  if( z_current_ - z_center_ > edge_/2.0 + delta_){
238  next_to_return_ = false;
239  return(true);
240  }
241 
242  return(true);
243 }
244 
245 void
247  x_current_ = -edge_/2.0 + x_center_;
248  y_current_ = -edge_/2.0 + y_center_;
249  z_current_ = -edge_/2.0 + z_center_;
250  step_x_ = step_;
251  step_y_ = step_;
252  step_z_ = step_;
253  next_to_return_ = true;
254 }
255 
256 } //namespace pcs
257 } //namespace methods
258 } //namespace scoring
259 } //namespace methods