Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RigidBodyMotionMover.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 protocols/rigid/RigidBodyMotionMover.cc
11 /// @author Christopher Miles (cmiles@uw.edu)
12 
13 // Unit header
15 
16 // C/C++ headers
17 #include <cmath>
18 #include <iostream>
19 #include <string>
20 
21 // Utility headers
22 #include <basic/Tracer.hh>
23 #include <basic/options/option.hh>
24 #include <basic/options/keys/OptionKeys.hh>
25 #include <basic/options/keys/rigid.OptionKeys.gen.hh>
26 #include <numeric/random/random.hh>
27 #include <numeric/xyzVector.hh>
28 // AUTO-REMOVED #include <numeric/xyzVector.io.hh>
29 
30 // Project headers
31 #include <core/id/NamedAtomID.hh>
33 #include <core/kinematics/Jump.hh>
34 #include <core/pose/Pose.hh>
35 #include <protocols/loops/Loop.hh>
36 #include <protocols/loops/Loops.hh>
37 
38 // Package headers
39 #include <protocols/moves/Mover.hh>
40 
41 //Auto Headers
42 #include <utility/vector1.hh>
43 #ifdef WIN32
44  #define _USE_MATH_DEFINES
45  #include <math.h>
46 #endif
47 
48 
49 namespace protocols {
50 namespace rigid {
51 
52 static basic::Tracer TR("protocols.moves.RigidBodyMotionMover");
53 
55  double radians = std::acos(a.dot(b) / (a.length() * b.length()));
56  return radians * 180 / M_PI;
57 }
58 
60  using namespace basic::options;
61  using namespace basic::options::OptionKeys;
62 
63  // update chunks
64  set_fold_tree(tree);
65 
66  // retrieve defaults from options system
67  set_magnitude_rotation(option[OptionKeys::rigid::rotation]());
68  set_magnitude_translation(option[OptionKeys::rigid::translation]());
69  set_chainbreak_bias(option[OptionKeys::rigid::chainbreak_bias]());
70 }
71 
74  using numeric::xyzVector;
75  using std::endl;
76 
77  if (chunks_.size() < 2) {
78  TR << "No sensible action possible-- num_chunks=" << chunks_.size() << endl;
79  return;
80  } else if(fold_tree() != pose.fold_tree()) {
81  TR << "Mismatching fold trees" << endl;
82  TR << "Input: " << fold_tree() << endl;
83  TR << "Apply: " << pose.fold_tree() << endl;
84  return;
85  }
86 
87  unsigned i = numeric::random::random_range(1, chunks_.size());
88  Jump jump = pose.jump(i);
89 
90  // rotation
91  jump.set_rb_delta(Jump::ROT_X, 1, numeric::random::gaussian() * magnitude_rotation());
92  jump.set_rb_delta(Jump::ROT_Y, 1, numeric::random::gaussian() * magnitude_rotation());
93  jump.set_rb_delta(Jump::ROT_Z, 1, numeric::random::gaussian() * magnitude_rotation());
94 
95  // translation
96  xyzVector<double> bias;
97  compute_bias(i, pose, &bias);
98 
99  double tx = numeric::random::gaussian() * magnitude_translation() + bias.x();
100  double ty = numeric::random::gaussian() * magnitude_translation() + bias.y();
101  double tz = numeric::random::gaussian() * magnitude_translation() + bias.z();
102 
103  jump.set_rb_delta(Jump::TRANS_X, 1, tx);
104  jump.set_rb_delta(Jump::TRANS_Y, 1, ty);
105  jump.set_rb_delta(Jump::TRANS_Z, 1, tz);
106 
107  // update the jump
108  jump.fold_in_rb_deltas();
109  pose.set_jump(i, jump);
110 }
111 
113  using core::id::NamedAtomID;
114  using numeric::xyzVector;
116  assert(bias);
117 
118  bool has_prev = i > 1;
119  bool has_next = i < chunks_.size();
120 
121  const Loop& chunk = chunks_[i];
122 
123  if (has_prev && has_next) {
124  const Loop& prev = chunks_[i - 1];
125  const Loop& next = chunks_[i + 1];
126 
127  xyzVector<double> a = pose.xyz(NamedAtomID("CA", chunk.start())) - pose.xyz(NamedAtomID("CA", prev.stop()));
128  xyzVector<double> b = pose.xyz(NamedAtomID("CA", chunk.stop())) - pose.xyz(NamedAtomID("CA", next.start()));
129 
130  // If the absolute value of the angle between vectors is too great,
131  // we're better served biasing translation toward one of the endpoints
132  double degrees = std::abs(angle_between(a, b));
133  if (degrees < 90) {
134  *bias = (a + b) / 2.0;
135  } else {
136  *bias = (numeric::random::uniform() < 0.9) ? a : b;
137  }
138  } else if (has_prev) {
139  const Loop& prev = chunks_[i - 1];
140  *bias = pose.xyz(NamedAtomID("CA", chunk.start())) - pose.xyz(NamedAtomID("CA", prev.stop()));
141  } else if (has_next) {
142  const Loop& next = chunks_[i + 1];
143  *bias = pose.xyz(NamedAtomID("CA", chunk.stop())) - pose.xyz(NamedAtomID("CA", next.start()));
144  }
145 
146  // Normalize the vector and scale by the chainbreak bias term
147  bias->normalize();
148  *bias *= chainbreak_bias();
149 }
150 
152  chunks_.clear();
153 
154  unsigned start = 1;
155  for (int i = 1; i <= tree_.num_cutpoint(); ++i) {
156  unsigned stop = tree_.cutpoint(i);
158  start = stop + 1;
159  }
160 
162 }
163 
165  return mag_rot_;
166 }
167 
169  return mag_trans_;
170 }
171 
173  return cb_bias_;
174 }
175 
177  return tree_;
178 }
179 
181  assert(mag_rot >= 0);
182  mag_rot_ = mag_rot;
183 }
184 
186  assert(mag_trans >= 0);
187  mag_trans_ = mag_trans;
188 }
189 
191  assert(cb_bias >= 0);
192  assert(cb_bias <= 1);
193  cb_bias_ = cb_bias;
194 }
195 
197  assert(tree.check_fold_tree());
198  tree_ = tree;
199  update_chunks();
200 }
201 
203  return "RigidBodyMotionMover";
204 }
205 
206 } // namespace rigid
207 } // namespace protocols