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 protocols/scoring/methods/pcs2/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 February 2010
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 namespace protocols{
53 namespace scoring{
54 namespace methods{
55 namespace pcs2{
56 
57 
59  x_center_(0),
60  y_center_(0),
61  z_center_(0),
62  step_(0),
63  edge_(0),
64  delta_(0),
65  small_cutoff_square_(0),
66  large_cutoff_square_(0),
67  x_vector_(0),
68  y_vector_(0),
69  z_vector_(0),
70  norme_vector_(0),
71  cone_angle_cos_(0)
72 {
73  utility_exit_with_message( "You shouldn't call the empty constructor for GridSearchIterator class" );
74 }
75 
77 }
78 
80  ReferenceCount(),
81  x_center_(other.x_center_),
82  y_center_(other.y_center_),
83  z_center_(other.z_center_),
84  step_(other.step_),
85  edge_(other.edge_),
86  delta_(other.delta_),
87  small_cutoff_square_(other.small_cutoff_square_),
88  large_cutoff_square_(other.large_cutoff_square_),
89  x_vector_(other.x_vector_),
90  y_vector_(other.y_vector_),
91  z_vector_(other.z_vector_),
92  norme_vector_(other.norme_vector_),
93  cone_angle_cos_(other.cone_angle_cos_)
94 {
95  x_current_ = other.x_current_;
96  y_current_ = other.y_current_;
97  z_current_ = other.z_current_;
98  step_x_ = other.step_x_;
99  step_y_ = other.step_y_;
100  step_z_ = other.step_z_;
102 }
103 
106  if ( this != &other ) {
107  if((x_center_ != other.x_center_)||
108  (y_center_ != other.y_center_)||
109  (z_center_ != other.z_center_)||
110  (step_ != other.step_)||
111  (edge_ != other.edge_)||
112  (delta_ != other.delta_)){
113  utility_exit_with_message( "You can't call the = operator on GridSearchIterator object of different size" );
114  }
115  x_current_ = other.x_current_;
116  y_current_ = other.y_current_;
117  z_current_ = other.z_current_;
118  step_x_ = other.step_x_;
119  step_y_ = other.step_y_;
120  step_z_ = other.step_z_;
122  }
123  return *this;
124 }
125 
126 
129  core::Real const k,
130  core::Real const edge_size,
131  core::Real const step_size,
132  core::Real const small_cutoff,
133  core::Real const large_cutoff,
134  core::Real const cone_angle
135 ):
136  x_center_(coo2.x() + k*( coo2.x() - coo1.x() )),
137  y_center_(coo2.y() + k*( coo2.y() - coo1.y() )),
138  z_center_(coo2.z() + k*( coo2.z() - coo1.z() )),
139  step_(step_size),
140  edge_(edge_size),
141  delta_(step_/2.0),
142  small_cutoff_square_(small_cutoff * small_cutoff),
143  large_cutoff_square_(large_cutoff * large_cutoff),
144  x_vector_(coo1.x() - coo2.x()),
145  y_vector_(coo1.y() - coo2.y()),
146  z_vector_(coo1.z() - coo2.z()),
147  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()) )),
148  cone_angle_cos_(cos(cone_angle/180.0*core::Real( numeric::constants::d::pi )))
149 {
150  if( edge_size < 0){
151  utility_exit_with_message("Edge size of the cube search is negative and has to be positive");
152  }
153  if( step_size <= 0){
154  utility_exit_with_message("step_size of the cube search has to be strictly positive");
155  }
156 
157  reset();
158 }
159 
160 
161 bool
163  core::Real &y,
164  core::Real &z){
165 
166  double r2;
167  while(next(x, y, z) == true){
168  r2 = (x-x_center_)*(x-x_center_) + (y-y_center_)* (y-y_center_) + (z-z_center_)*(z-z_center_);
169  if((r2 <= large_cutoff_square_) && (r2 >= small_cutoff_square_ )){ //we test small and large cutoff
170  core::Real cos_angle = ((x-x_center_)*x_vector_ + (y-y_center_)*y_vector_ + (z-z_center_)*z_vector_ );
171  if((r2 == 0 ) || (norme_vector_ == 0)){
172  return true;
173  }
174  cos_angle = cos_angle / sqrt(r2) / norme_vector_;
175  //std::cout << "comparing " << cos_angle << "with ref" << cone_angle_cos_ << std::endl;
176  //std::cout << x_vector_ << y_vector_ << z_vector_ << std::endl;
177  if(cos_angle >= cone_angle_cos_){ //we test cone angle
178  return true;
179  }
180  }
181  }
182  return false;
183 }
184 
185 // This iterator sample a cube in 3D space.
186 // The following code looks strange and could be written in an easier way.
187 // However, it is strange because the iterator ensure that
188 // the points are visited in a specific order in such a way
189 // that the next point visited is a direct neighboor of the previous one
190 // It will be important if I decide to work on unassigned PCS Data.
191 bool
193  core::Real &y,
194  core::Real &z){
195  x = x_current_;
196  y = y_current_;
197  z = z_current_;
198 
199  if(!next_to_return_){
200  reset();
201  return(false);
202  }
203 
204  if( z_current_ - z_center_ > edge_/2.0){
205  next_to_return_ = false;
206  return(true);
207  }
208 
209  x_current_ += step_x_;
210 
211  if( x_current_ - x_center_> edge_/2.0 + delta_){
212  step_x_ = -step_;
213  x_current_ += step_x_;
214  y_current_ += step_y_;
215  }
216 
217  if( x_current_ - x_center_ < -edge_/2.0 - delta_){
218  step_x_ = step_;
219  x_current_ += step_x_;
220  y_current_ += step_y_;
221  }
222 
223  if( y_current_ - y_center_> edge_/2.0 + delta_){
224  step_y_ = -step_;
225  y_current_ += step_y_;
226  z_current_ += step_z_;
227  }
228 
229  if( y_current_ - y_center_ < -edge_/2.0 - delta_){
230  step_y_ = step_;
231  y_current_ += step_y_;
232  z_current_ += step_z_;
233  }
234 
235  if( z_current_ - z_center_ > edge_/2.0 + delta_){
236  next_to_return_ = false;
237  return(true);
238  }
239 
240  return(true);
241 }
242 
243 void
245  x_current_ = -edge_/2.0 + x_center_;
246  y_current_ = -edge_/2.0 + y_center_;
247  z_current_ = -edge_/2.0 + z_center_;
248  step_x_ = step_;
249  step_y_ = step_;
250  step_z_ = step_;
251  next_to_return_ = true;
252 }
253 
254 } //namespace pcs2
255 } //namespace methods
256 } //namespace scoring
257 } //namespace methods