Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SearchPattern.hh
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
11 /// @brief
12 /// @author
13 
14 
15 #ifndef INCLUDED_protocols_hotspot_hashing_SearchPattern_hh
16 #define INCLUDED_protocols_hotspot_hashing_SearchPattern_hh
17 
18 #include <boost/algorithm/string.hpp>
19 #include <boost/lexical_cast.hpp>
20 
21 #include <utility/vector1.hh>
22 #include <utility/pointer/ReferenceCount.hh>
23 #include <utility/pointer/owning_ptr.hh>
24 #include <utility/exit.hh>
25 
26 #include <numeric/xyzVector.hh>
27 #include <numeric/xyzMatrix.hh>
28 #include <numeric/xyz.functions.hh>
29 
30 #include <core/types.hh>
31 #include <core/kinematics/Stub.hh>
32 #include <core/kinematics/RT.hh>
33 
35 
36 namespace protocols {
37 namespace hotspot_hashing {
38 
41 
42 
44 {
45  public:
47  position(),
48  direction()
49  {
50  };
51 
53  position(position),
54  direction(direction)
55  {
56  };
57 
58  VectorPair(const VectorPair& src) :
59  position(src.position),
60  direction(src.direction)
61  {
62  };
63 
66 };
67 
68 inline std::ostream& operator<<(std::ostream &stream, const Vector &vector)
69 {
70  return stream << vector.x() << "," << vector.y() << "," << vector.z();
71 }
72 
73 inline std::istream &
74 operator >>( std::istream & stream, Vector & v )
75 {
76  core::Real x, y, z;
77  stream >> x;
78  stream.ignore(1, ',');
79  stream >> y;
80  stream.ignore(1, ',');
81  stream >> z;
82 
83  v.x(x);
84  v.y(y);
85  v.z(z);
86 
87  return stream;
88 }
89 
90 inline std::ostream& stub_to_points(std::ostream &stream, const core::kinematics::Stub &stub)
91 {
92  /// Generate three points that would yield this stub
93  Vector a = stub.local2global(Vector(0, 0, 0));
94  Vector b = stub.local2global(Vector(-1, 0, 0));
95  Vector c = stub.local2global(Vector(0, 1, 0));
96 
97  return stream << a << ";" << b << ";" << c;
98 }
99 
100 inline std::istream& stub_from_points( std::istream & stream, core::kinematics::Stub & stub )
101 {
102  Vector a, b, c;
103  stream >> a;
104  stream.ignore(1, ';');
105  stream >> b;
106  stream.ignore(1, ';');
107  stream >> c;
108 
109  stub.from_four_points(a, a, b, c);
110 
111  return stream;
112 }
113 
114 inline std::ostream& operator<<(std::ostream &stream, const VectorPair &pair)
115 {
116  return stream << pair.position << ";" << pair.direction;
117 }
118 
119 inline std::istream &
120 operator >>( std::istream & stream, VectorPair & pair )
121 {
122  stream >> pair.position;
123  stream.ignore(1, ';');
124  stream >> pair.direction;
125 
126  return stream;
127 }
128 
130 {
131  public:
133 };
134 
136 {
137  public:
139  target_stub(core::kinematics::default_stub)
140  {}
141 
143  target_stub(target)
144  {}
145 
147  {
149  searchpoints.push_back(target_stub);
150  return searchpoints;
151  }
152 
154 };
155 
157 {
158  public:
160  {
161  }
162 
164  {
166 
167  core::Real x = 0;
168  core::Real y = 0;
169  core::Real z = 0;
170 
171  for (x = -1; x <= 1; x += 1)
172  {
173  for (y = -1; y <= 1; y += 1)
174  {
175  for (z = -1; z <= 1; z += 1 )
176  {
177  for (core::Real angle = 0; angle < 360; angle += 180)
178  {
179  Vector translation = Vector(x, y, z);
180  Matrix rotation = numeric::z_rotation_matrix_degrees(angle);
181 
182  core::kinematics::Stub tp(rotation, translation);
183  searchpoints.push_back(tp);
184  }
185  }
186  }
187  }
188 
189  return searchpoints;
190  };
191 };
192 
194 {
195  public:
197  VectorPair lsmspec,
198  core::Real angle_sampling,
199  core::Real translocation_sampling,
200  core::Real max_radius,
201  core::Real distance_sampling,
202  core::Real max_distance) :
203  lsmspec_(lsmspec),
204  angle_sampling_(angle_sampling),
205  translocation_sampling_(translocation_sampling),
206  max_radius_(max_radius),
207  distance_sampling_(distance_sampling),
208  max_distance_(max_distance)
209  {
210 
211  }
212 
214  {
216 
217  Vector xunit = Vector(0, 0, 1);
218  Matrix normal_rotation = rotation_matrix( lsmspec_.direction.cross(xunit), angle_of(lsmspec_.direction, xunit));
219 
221  {
223  {
224  if(sqrt(x*x + y*y) <= max_radius_)
225  {
226  for (core::Real z = 0; z <= max_distance_; z += distance_sampling_)
227  {
228  for (core::Real angle = 0; angle < 360; angle += angle_sampling_)
229  {
230  Vector translation = Vector(x, y, z);
231  Matrix rotation = numeric::x_rotation_matrix_degrees(angle);
232 
233  core::kinematics::Stub tp(rotation * normal_rotation, translation + lsmspec_.position);
234  searchpoints.push_back(tp);
235  }
236  }
237  }
238  }
239  }
240 
241  return searchpoints;
242  }
243 
244  static bool parse_lsm_spec(std::string lsmstring, VectorPair & lsmspec)
245  {
246  std::vector< std::string > vectors;
247  boost::split( vectors, lsmstring, boost::is_any_of(":") );
248 
249  if(vectors.size() != 2){
250  return false;
251  }
252 
253  std::vector< std::string > position;
254  std::vector< std::string > direction;
255 
256  boost::split( position, vectors[0], boost::is_any_of(",") );
257  boost::split( direction, vectors[1], boost::is_any_of(",") );
258 
259  if(position.size() != 3 || direction.size() != 3){
260  return false;
261  }
262 
263  using boost::lexical_cast;
264 
265  lsmspec = VectorPair(
266  Vector(
267  lexical_cast<core::Real>(position[0]),
268  lexical_cast<core::Real>(position[1]),
269  lexical_cast<core::Real>(position[2])),
270  Vector(
271  lexical_cast<core::Real>(direction[0]),
272  lexical_cast<core::Real>(direction[1]),
273  lexical_cast<core::Real>(direction[2])));
274 
275  return true;
276  }
277 
278 
279  private:
286 };
287 
289 {
290  public:
294  core::Real x_min = 0,
295  core::Real x_max = 360,
296  core::Real y_min = 0,
297  core::Real y_max = 90) :
298  x_sampling(x_sampling),
299  y_sampling(y_sampling),
300  x_min(x_min),
301  x_max(x_max),
302  y_min(y_min),
303  y_max(y_max),
304  searchpoints_()
305  {
307  }
308 
315 
317  {
319 
320  for(core::Real x_sample = x_min; x_sample <= x_max; x_sample += x_sampling)
321  {
322  for(core::Real y_sample = y_min; y_sample <= y_max; y_sample += y_sampling)
323  {
324  searchpoints.push_back(
326  numeric::x_rotation_matrix_degrees(x_sample) * numeric::y_rotation_matrix_degrees(y_sample),
327  Vector(0)));
328  }
329  }
330 
331  return searchpoints;
332  }
333 
335  {
336  return searchpoints_;
337  }
338 
340 };
341 
343 {
344  // http://upload.wikimedia.org/wikipedia/commons/4/4f/3D_Spherical.svg
345  // Uses spherical coordinates as outlined in the above diagram.
346  // Altitude rotate is equiv. to theta, rotation off the polar axis.
347  // Azmiuth rotate is equiv. to phi, rotation around the polar axis.
348  // Polar rotate is rotation around the result vector from alt/azm rotation.
349 
350  public:
355  core::Real polar_min = 0,
356  core::Real polar_max = 360,
358  core::Real altitude_max = 360,
360  core::Real azmiuth_max = 360) :
361  polar_rotation_sampling(polar_rotation_sampling),
362  altitude_rotation_sampling(altitude_rotation_sampling),
363  azmiuth_rotation_sampling(azmiuth_rotation_sampling),
370  searchpoints_()
371  {
373  }
374 
384 
386  {
388 
389  for(core::Real polar_sample = polar_min; polar_sample <= polar_max; polar_sample += polar_rotation_sampling)
390  {
391  for(core::Real altitude_sample = altitude_min; altitude_sample <= altitude_max; altitude_sample += altitude_rotation_sampling)
392  {
393  for(core::Real azmiuth_sample = azmiuth_min; azmiuth_sample <= azmiuth_max; azmiuth_sample += azmiuth_rotation_sampling)
394  {
395  searchpoints.push_back(
397  numeric::x_rotation_matrix_degrees(azmiuth_sample) * numeric::y_rotation_matrix_degrees(altitude_sample) * numeric::x_rotation_matrix_degrees(polar_sample),
398  Vector(0)));
399  }
400  }
401  }
402 
403  return searchpoints;
404  }
405 
407  {
408  return searchpoints_;
409  }
410 
412 };
413 
415 {
416  public:
426  core::Real z_max) :
427  x_sampling(x_sampling),
428  y_sampling(y_sampling),
429  z_sampling(z_sampling),
430  x_min(x_min),
431  x_max(x_max),
432  y_min(y_min),
433  y_max(y_max),
434  z_min(z_min),
435  z_max(z_max),
436  searchpoints_()
437  {
439  }
440 
450 
452  {
454 
455  if(x_sampling <= 0)
456  {
457  x_sampling = x_max - x_min + 1;
458  }
459 
460  if(y_sampling <= 0)
461  {
462  y_sampling = y_max - y_min + 1;
463  }
464 
465  if(z_sampling <= 0)
466  {
467  z_sampling = z_max - z_min + 1;
468  }
469 
470  for(core::Real x_sample = x_min; x_sample <= x_max; x_sample += x_sampling)
471  {
472  for(core::Real y_sample = y_min; y_sample <= y_max; y_sample += y_sampling)
473  {
474  for(core::Real z_sample = z_min; z_sample <= z_max; z_sample += z_sampling)
475  {
476  searchpoints.push_back(
478  Matrix::identity(),
479  Vector(x_sample, y_sample, z_sample)));
480  }
481  }
482  }
483 
484  return searchpoints;
485  }
486 
488  {
489  return searchpoints_;
490  }
491 
493 };
494 
496 {
497  public:
499  SearchPatternOP source_pattern,
500  core::Size partition,
501  core::Size total_partitions) :
502  source_pattern_(source_pattern),
503  partition_(partition),
504  total_partitions_(total_partitions)
505  {
506  runtime_assert(partition < total_partitions)
507  }
508 
510  {
511  utility::vector1<core::kinematics::Stub> sourcepoints = source_pattern_->Searchpoints();
512 
514  searchpoints.reserve((sourcepoints.size() / total_partitions_) + 1);
515 
516  for (core::Size i = partition_; i < sourcepoints.size(); i += total_partitions_)
517  {
518  searchpoints.push_back(sourcepoints[i+1]);
519  }
520 
521  return searchpoints;
522  }
523 
524  private:
528 };
529 
531 {
532  public:
536  source_pattern_a(source_pattern_a),
537  source_pattern_b(source_pattern_b)
538  { }
539 
541  {
542  utility::vector1<core::kinematics::Stub> sourcepoints_a = source_pattern_a->Searchpoints();
543  utility::vector1<core::kinematics::Stub> sourcepoints_b = source_pattern_b->Searchpoints();
544 
546  searchpoints.reserve(sourcepoints_a.size() * sourcepoints_b.size());
547 
548  for (core::Size a = 1; a <= sourcepoints_a.size(); a += 1)
549  {
550  for (core::Size b = 1; b <= sourcepoints_b.size(); b += 1)
551  {
552  core::kinematics::Stub result;
553  core::kinematics::RT(core::kinematics::default_stub, sourcepoints_b[b]).make_jump(sourcepoints_a[a], result);
554  searchpoints.push_back(result);
555  }
556  }
557 
558  return searchpoints;
559  }
560 
561 
562  private:
565 
566 };
567 
569 {
570  public:
572  source_pattern_(source_pattern)
573  {}
574 
576  {
577  utility::vector1<core::kinematics::Stub> sourcepoints = source_pattern_->Searchpoints();
578 
580  searchpoints.reserve(sourcepoints.size());
581 
582  for (core::Size i = 1; i <= sourcepoints.size(); i++)
583  {
584  searchpoints.push_back( transform(sourcepoints[i]));
585  }
586 
587  return searchpoints;
588  }
589 
591 
592  private:
594 };
595 
597 {
598  public:
600  source_pattern_(source_pattern)
601  {}
602 
604  {
605  utility::vector1<core::kinematics::Stub> sourcepoints = source_pattern_->Searchpoints();
606 
608 
609  for (core::Size i = 1; i <= sourcepoints.size(); i++)
610  {
611  utility::vector1<core::kinematics::Stub> newpoints = expand(sourcepoints[i]);
612 
613  searchpoints.insert(searchpoints.end(), newpoints.begin(), newpoints.end());
614  }
615 
616  return searchpoints;
617  }
618 
620 
621  private:
623 };
624 
625 }
626 }
627 
628 #endif