Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PoseMembraneRigidBodyMover.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 PoseMembraneRigidBodyMover.cc
11 /// @brief
12 /// @author Yifan Song
13 
14 
16 
17 // Rosetta Headers
18 #include <core/pose/Pose.hh>
19 // AUTO-REMOVED #include <core/pose/datacache/CacheableDataType.hh>
20 // AUTO-REMOVED #include <basic/datacache/BasicDataCache.hh>
21 
22 #include <core/types.hh>
23 
26 
27 #include <core/id/AtomID.hh>
28 #include <core/kinematics/Jump.hh>
29 
33 // AUTO-REMOVED #include <core/conformation/symmetry/util.hh>
34 
37 
38 // Utility headers
39 // AUTO-REMOVED #include <protocols/moves/PyMolMover.hh>
40 #include <basic/Tracer.hh>
41 #include <utility/vector1.hh>
42 #include <numeric/xyzVector.hh>
43 // AUTO-REMOVED #include <numeric/xyzVector.io.hh>
44 #include <numeric/xyz.functions.hh>
45 #include <numeric/random/random.hh>
46 #include <numeric/conversions.hh>
47 
48 //Auto Headers
49 //Auto using namespaces
50 namespace ObjexxFCL { namespace fmt { } } using namespace ObjexxFCL::fmt; // AUTO USING NS
51 //Auto using namespaces end
52 
53 
54 namespace protocols {
55 namespace rigid {
56 
57 using namespace core;
58 
59 static numeric::random::RandomGenerator RG(67729);
60 static basic::Tracer TR("protocols.moves.PoseMembraneRigidBodyMover");
61 
62 /// move pose into a membrane/*
63 MovePoseToMembraneCenterMover::MovePoseToMembraneCenterMover() : moves::Mover("MovePoseToMembraneCenterMover")
64 {
65 }
66 
68 {
69 
70  Vector const membrane_normal( scoring::MembraneEmbed_from_pose( pose ).normal() );
71  Vector const membrane_center( scoring::MembraneEmbed_from_pose( pose ).center() );
72 
73  Vector const current_pose_center( estimate_membrane_center(pose) );
74 
75  Real const pose_shifted_from_membrane_center( membrane_normal.dot( current_pose_center-membrane_center ) );
76  using namespace ObjexxFCL::fmt;
77  //TR << "MovePoseToMembraneCenterMover: estimate membrane center " << F(8,3,current_pose_center.x()) << F(8,3,current_pose_center.y()) << F(8,3,current_pose_center.z()) << " shifted by:" << F(8,3,pose_shifted_from_membrane_center) << std::endl;
78  if ( fabs(pose_shifted_from_membrane_center) > 20.) {
79  Vector shift_back = -pose_shifted_from_membrane_center * membrane_normal;
80 
81  WholeBodyTranslationMover whole_body_translation_mover(shift_back);
82  whole_body_translation_mover.apply(pose);
83  //TR << "MovePoseToMembraneCenterMover: shifting " << F(8,3,shift_back.x()) << F(8,3,shift_back.y()) << F(8,3,shift_back.z()) << std::endl;
84  }
85 
86  //Vector const current_pose_center2( estimate_membrane_center(pose) );
87  //Real const pose_shifted_from_membrane_center2( membrane_normal.dot( current_pose_center-membrane_center ) );
88  //TR << "MovePoseToMembraneCenterMover: after moving center " << F(8,3,current_pose_center2.x()) << F(8,3,current_pose_center2.y()) << F(8,3,current_pose_center2.z()) << " shifted by:" << F(8,3,pose_shifted_from_membrane_center2) << std::endl;
89 }
90 
91 /// use membrane topology information to estimate the membrane center of the current pose position
92 Vector
94 {
96  //Define vectors for inside and outside cap residue
97  Vector sum_membrane_anchor(0);
98  Vector center(0);
99 
100  for(Size i=1;i<=topology.tmhelix();++i)
101  {
102  //using namespace ObjexxFCL::fmt;
103  //TR << "MovePoseToMembraneCenterMover: after moving center " << I(4,i) << " " << topology.allow_tmh_scoring(i) << std::endl;
104 
105  if(!topology.allow_tmh_scoring(i)) continue;
106  Vector const & start( pose.residue( topology.span_begin(i) ).atom( 2 ).xyz());
107  Vector const & end( pose.residue( topology.span_end(i) ).atom( 2 ).xyz());
108 
109  sum_membrane_anchor+=start;
110  sum_membrane_anchor+=end;
111  }
112  center = 0.5*(sum_membrane_anchor)/(float)topology.tmh_inserted();
113 
114  // if symmetrical pose, add subunit information
115  if ( core::pose::symmetry::is_symmetric( pose ) ) {
116 
117  using namespace core::conformation::symmetry;
118  SymmetricConformation const & symm_conf (
119  dynamic_cast< SymmetricConformation const & > ( pose.conformation() ) );
120  SymmetryInfoCOP symm_info( symm_conf.Symmetry_Info() );
121 
122  for ( Size i_clone = 1; i_clone <= symm_info->num_bb_clones(); ++i_clone) {
123 
124  for(Size i=1;i<=topology.tmhelix();++i) {
125  if(!topology.allow_tmh_scoring(i)) continue;
126 
127  Vector const & start( pose.residue( symm_info->bb_clones( topology.span_begin(i) )[i_clone] ).atom( 2 ).xyz());
128  Vector const & end( pose.residue( symm_info->bb_clones( topology.span_end(i) )[i_clone] ).atom( 2 ).xyz());
129 
130  sum_membrane_anchor+=start;
131  sum_membrane_anchor+=end;
132  }
133  }
134  center = 0.5*(sum_membrane_anchor)/(float)(symm_info->num_bb_clones() + 1)/(float)topology.tmh_inserted();
135  }
136 
137  //using namespace ObjexxFCL::fmt;
138  //TR << "Yifan debug: current origin " << F(8,3,pose.conformation().atom_tree().root()->xyz().x()) << F(8,3,pose.conformation().atom_tree().root()->xyz().y()) << F(8,3,pose.conformation().atom_tree().root()->xyz().z()) << std::endl;
139  //TR << "Yifan debug: current membrane center " << F(8,3,center.x()) << F(8,3,center.y()) << F(8,3,center.z()) << std::endl;
140  //TR << "Yifan debug: current res 29 position " << F(8,3,pose.residue(29).atom("CA").xyz().x()) << F(8,3,pose.residue(29).atom("CA").xyz().y()) << F(8,3,pose.residue(29).atom("CA").xyz().z()) << std::endl;
141 
142  return center;
143 }
144 
147  return "MovePoseToMembraneCenterMover";
148 }
149 
150 /// perturb the pose along membrane normal
151 MembraneCenterPerturbationMover::MembraneCenterPerturbationMover() : moves::Mover("MembraneCenterPerturbationMover"),
152 trans_mag_(10.)
153 {
154 }
155 
157  trans_mag_ = trans_mag_in;
158 }
159 
161 {
162  Vector const membrane_normal( scoring::MembraneEmbed_from_pose( pose ).normal() );
163  Real random_translation (trans_mag_ * (2.*RG.uniform()-1.));
164  Vector const trans_vect = random_translation * membrane_normal;
165 
166  MovePoseToMembraneCenterMover move_pose_to_membrane_mover;
167  move_pose_to_membrane_mover.apply(pose);
168 
169  WholeBodyTranslationMover whole_body_translation_mover(trans_vect);
170  whole_body_translation_mover.apply(pose);
171 }
172 
174  return "MembraneCenterPerturbationMover";
175 }
176 
177 /// randomly rotate the pose along an axis on membrane plane
179 Mover("MembraneNormalPerturbationMover"),
180 rotation_mag_(15.)
181 {
182 }
183 
185  rotation_mag_ = rotation_mag_in;
186 }
187 
189 {
190  Vector const membrane_normal( scoring::MembraneEmbed_from_pose( pose ).normal() );
191  Vector const membrane_center( scoring::MembraneEmbed_from_pose( pose ).center() );
192 
193  //find a random axis through center, perpendicular to normal
194  Vector test_vec ;
195  test_vec.x() = 1.; test_vec.y() = 1.; test_vec.z() = 1.;
196  Vector x_axis (test_vec.cross(membrane_normal).normalize());
197  Vector y_axis (membrane_normal.cross(x_axis).normalize());
198 
199  Real random_angle (numeric::conversions::radians(360.) * RG.uniform());
200  Vector random_axis (cos(random_angle) * x_axis + sin(random_angle) * y_axis);
201  Real random_rotation_angle (rotation_mag_ * RG.uniform());
202 
203  MovePoseToMembraneCenterMover move_pose_to_membrane_mover;
204  move_pose_to_membrane_mover.apply(pose);
205 
206  WholeBodyRotationMover whole_body_rotation_mover(random_axis, membrane_center, random_rotation_angle);
207  whole_body_rotation_mover.apply(pose);
208 }
209 
211  return "MembraneNormalPerturbationMover";
212 }
213 
214 /// Whole Body Translation
216  trans_ = trans_in;
217 }
218 
220 {
221  using namespace ObjexxFCL::fmt;
222 
223  // MovePoseToMembraneCenterMover move_pose_to_membrane_mover;
224 
225  if ( core::pose::symmetry::is_symmetric( pose ) ) {
226  //utility::vector1 <kinematics::Jump> backup_jumps;
227  //for (Size i =1; i<= pose.num_jump(); ++i) {
228  // backup_jumps.push_back(pose.jump(i));
229  //}
230 
231  core::kinematics::Jump first_jump = pose.jump( 1 );
232 
233  //TR << "Translate: " << "Jump (before): " << first_jump << std::endl;
234  core::kinematics::Stub upstream_stub = pose.conformation().upstream_jump_stub( 1 );
235  first_jump.translation_along_axis( upstream_stub, trans_, trans_.length() );
236  //TR << "Translate: " << "Jump (after): " << first_jump << std::endl;
237  pose.set_jump( 1, first_jump );
238 
239  /*
240  id::AtomID root_id(pose.conformation().atom_tree().root()->atom_id());
241  for (core::Size iatom=1; iatom <= pose.residue(root_id.rsd()).natoms(); ++iatom) {
242  using namespace ObjexxFCL::fmt;
243  id::AtomID atom_id(iatom, root_id.rsd());
244 
245  Vector const curr_position(pose.xyz(atom_id));
246  Vector const new_position (curr_position + trans_);
247  pose.set_xyz(atom_id, new_position);
248 
249  //TR << "Yifan debug: curr_position " << I(4, iatom) << F(8,3,curr_position.x()) << F(8,3,curr_position.y()) << F(8,3,curr_position.z()) << std::endl;
250  //TR << "Yifan debug: trans_ " << I(4, iatom) << F(8,3,trans_.x()) << F(8,3,trans_.y()) << F(8,3,trans_.z()) << std::endl;
251  //TR << "Yifan debug: new_position " << I(4, iatom) << F(8,3,new_position.x()) << F(8,3,new_position.y()) << F(8,3,new_position.z()) << std::endl;
252  }
253 
254  for (Size i =1; i<= pose.num_jump(); ++i) {
255  using namespace core::conformation::symmetry;
256  SymmetricConformation const & symm_conf (
257  dynamic_cast< SymmetricConformation const & > ( pose.conformation() ) );
258  SymmetryInfoCOP symm_info( symm_conf.Symmetry_Info() );
259  if (!symm_info->jump_is_independent(i)) continue;
260 
261  pose.set_jump(i, backup_jumps[i]);
262  }
263  */
264  }
265  else {
266  //numeric::xyzMatrix< Real > const & R( numeric::xyzMatrix< Real >::identity() );
267  //pose.apply_transform_Rx_plus_v(R,trans_);
268 
269  //core::kinematics::Stub upstream_stub root_stub = pose.conformation().atom_tree().root().get_stub();
270 
271  core::kinematics::Jump first_jump = pose.jump( 1 );
272 
273  //TR << "Translate: " << "Jump (before): " << first_jump << std::endl;
274  core::kinematics::Stub upstream_stub = pose.conformation().upstream_jump_stub( 1 );
275  first_jump.translation_along_axis( upstream_stub, trans_, trans_.length() );
276  //TR << "Translate: " << "Jump (after): " << first_jump << std::endl;
277  pose.set_jump( 1, first_jump );
278 
279  }
280 
281 
282  //protocols::moves::AddPyMolObserver(pose, true); // Lets ask PyMol to store history...
283 
284  //TR << "Yifan debug: root origin " << F(8,3,pose.conformation().atom_tree().root()->xyz().x()) << F(8,3,pose.conformation().atom_tree().root()->xyz().y()) << F(8,3,pose.conformation().atom_tree().root()->xyz().z()) << std::endl;
285  //TR << "Yifan debug: new root position" << pose.conformation().atom_tree().root()->xyz() << std::endl;
286  //test_center = move_pose_to_membrane_mover.estimate_membrane_center(pose);
287  //TR << "Yifan debug: re-estimate membrane center " << F(8,3,test_center.x()) << F(8,3,test_center.y()) << F(8,3,test_center.z()) << std::endl;
288  //pose.conformation().atom_tree().root()->show(1);
289 }
290 
293  return "WholeBodyTranslationMover";
294 }
295 
296 /// Whole Body Rotation
298  Vector const & axis,
299  Vector const & center,
300  Real const & alpha /* degrees */
301 )
302  : moves::Mover()
303 {
304  axis_ = axis;
305  center_ = center;
306  alpha_ = alpha;
307 }
308 
309 /*
310 WholeBodyRotationMover::WholeBodyRotationMover( numeric::xyzMatrix< Real > const & R_in ) : Mover() {
311 rotation_m_ = R_in;
312 }
313 */
314 
315 
317 {
318  assert (! core::pose::symmetry::is_symmetric( pose ) );
319  core::kinematics::Jump first_jump = pose.jump( 1 );
320 
321  //TR << "Rotate: " << "Jump (before): " << first_jump << std::endl;
322  core::kinematics::Stub upstream_stub = pose.conformation().upstream_jump_stub( 1 );
323  first_jump.rotation_by_axis( upstream_stub, axis_, center_, alpha_ /* degrees */ );
324  //TR << "Rotate: " << "Jump (after): " << first_jump << std::endl;
325  pose.set_jump( 1, first_jump );
326 
327 
328  //Vector translation;
329  //translation.zero();
330  //pose.apply_transform_Rx_plus_v(rotation_m_, translation);
331 }
332 
335  return "WholeBodyRotationMover";
336 }
337 
338 } //ns rigid
339 } //ns protocols