Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RollMover.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/moves/RollMover.cc
11 /// @brief RollMover methods implemented
12 /// @author
13 
14 // Unit Headers
17 // Package Headers
19 
20 // Project Headers
22 #include <core/pose/Pose.hh>
23 #include <core/id/AtomID.hh>
24 #include <numeric/xyz.functions.hh>
26 #include <boost/foreach.hpp>
27 #define foreach BOOST_FOREACH
28 // AUTO-REMOVED #include <numeric/xyz.io.hh>
29 // Random number generator
30 #include <numeric/random/random.hh>
31 // Utility Headers
32 #include <basic/Tracer.hh>
33 #include <core/types.hh>
34 
35 #include <utility/vector0.hh>
36 #include <utility/vector1.hh>
37 #include <utility/excn/Exceptions.hh>
38 #include <utility/tag/Tag.hh>
39 
40 
41 // C++ Headers
42 
43 using basic::T;
44 using basic::Error;
45 using basic::Warning;
46 static numeric::random::RandomGenerator RG(456732);
47 static basic::Tracer TR( "protocols.rigid.RollMover" );
48 
49 using namespace core;
50 
51 namespace protocols {
52 namespace rigid {
53 
54 ///@details
55 void RollMover::apply( core::pose::Pose & pose ){
56 
57  utility::vector1< utility::vector1< numeric::xyzVector< core::Real> > > coords; // some of these will change for sure
58 
59  // now we have a vector1 of vector1s with a numeric::xyzVector
60  // access will look like coords[residue][atom] to get xyz
61 
62  core::Size const nres( pose.total_residue() );
63  coords.resize( nres );
64 
65  for ( Size i=1; i<= nres; ++i ) {
66  core::conformation::Residue const & rsd( pose.residue(i) );
67  core::Size const number_atoms_this_residue( rsd.natoms() );
68  if ( number_atoms_this_residue ) {
69  coords[i].resize( number_atoms_this_residue );
70  for ( Size j=1; j <= number_atoms_this_residue; ++j ) {
71  coords[i][j] = rsd.atom( j ).xyz();
72  }
73  }
74  }
75 
76  angle_ = min_angle_ + ( max_angle_ - min_angle_ ) * RG.uniform();
77  numeric::xyzMatrix< core::Real > rotation_matrix( numeric::rotation_matrix_degrees(axis_, angle_ ) );
78  //move to origin
79  for ( core::Size i =start_res_; i <= stop_res_; ++i ) {
80  for ( core::Size j = 1; j <= coords[i].size(); ++j ) {
81 
82  // this may look strange but in a global coordinate system
83  // rotation about an axis is easily done by movement to the origin
84  // rotation and then movement back
85 
86  coords[i][j] = coords[i][j] - translate_; // translate to origin
87  coords[i][j] = rotation_matrix * coords[i][j]; // rotate atom
88  coords[i][j] = coords[i][j] + translate_; // reverse translate
89 
90  }
91  }
92 
93  // now update pose with new coordinates
94  for ( core::Size i =start_res_; i <= stop_res_; ++i ) {
95  for ( core::Size j = 1; j <= coords[i].size(); ++j ) {
96  id::AtomID id( j, i );
97  pose.set_xyz( id, coords[i][j]);
98  }
99  }
100 
101 
102 
103 }//apply
104 
105 
106 void
107 RollMover::set_min_max_angles( core::Real min_angle, core::Real max_angle ) {
108  min_angle_ = min_angle;
109  max_angle_ = max_angle;
110 }
111 
113 RollMover::get_name() const {
114  return "RollMover";
115 }
116 
117 void
118 RollMover::parse_my_tag(
119  utility::tag::TagPtr const tag,
120  moves::DataMap & /*datamap*/,
121  Filters_map const & /*filters*/,
122  moves::Movers_map const & /*movers*/,
123  Pose const & pose )
124 {
125 
126  start_res_ = ( tag->hasOption("start_res") ) ? tag->getOption<core::Size>("start_res") : 1;
127  stop_res_ = ( tag->hasOption("stop_res") ) ? tag->getOption<core::Size>("stop_res") : pose.total_residue();
128 
129  /*parse min_angle*/
130  if( tag->hasOption("min_angle") ) {
131  min_angle_ = tag->getOption<core::Real>("min_angle");
132  } else {
133  throw utility::excn::EXCN_RosettaScriptsOption("RollMover requires min_angle option");
134  }
135 
136  /*parse max_angle*/
137  if( tag->hasOption("max_angle") ) {
138  max_angle_ = tag->getOption<core::Real>("max_angle");
139  } else {
140  throw utility::excn::EXCN_RosettaScriptsOption("RollMover requires max_angle option");
141  }
142 
143  bool axis_option_parsed = false;
144  bool translate_option_parsed = false;
145 
146  if( tag->hasOption("axis") ) {
147  switch(tag->getOption<char>("axis")) {
148  case 'x':
149  axis_ = numeric::xyzVector< core::Real >( 1.0, 0.0, 0.0 );
150  break;
151  case 'y':
152  axis_ = numeric::xyzVector< core::Real >( 0.0, 1.0, 0.0 );
153  break;
154  case 'z':
155  axis_ = numeric::xyzVector< core::Real >( 0.0, 0.0, 1.0 );
156  break;
157  }
158  axis_option_parsed = true;
159  }
160 
161  foreach( utility::tag::TagPtr const child_tag, tag->getTags() ){
162  std::string name= child_tag->getName();
163 
164  if( name == "axis" ) {
165  /*parse axis x,y,z*/
167  axis_option_parsed = true;
168  } else if ( name == "translate") {
169  /*parse translate x,y,z*/
170  translate_ = protocols::rosetta_scripts::parse_xyz_vector(child_tag);
171  translate_option_parsed = true;
172  }
173 
174  }
175 
176  if ( !axis_option_parsed ) {
177  throw utility::excn::EXCN_RosettaScriptsOption("RollMover requires axis option");
178  }
179  if ( !translate_option_parsed ) {
180  //throw utility::excn::EXCN_RosettaScriptsOption("RollMover requires translate option");
181  TR << "No translation given, using the pose's center of mass" << std::endl;
182  translate_ = protocols::geometry::center_of_mass(pose, start_res_, stop_res_);
183  }
184 
185 }
186 
188 RollMoverCreator::keyname() const
189 {
190  return RollMoverCreator::mover_name();
191 }
192 
194 RollMoverCreator::mover_name()
195 {
196  return "RollMover";
197 }
198 
199 
201 RollMoverCreator::create_mover() const {
202  return new RollMover;
203 }
204 
205 ///@brief required in the context of the parser/scripting scheme
207 RollMover::fresh_instance() const
208 {
209  return new RollMover;
210 }
211 
212 ///@brief required in the context of the parser/scripting scheme
215 {
216  return new RollMover( *this );
217 }
218 
219 ///@brief
220 RollMover::RollMover(
221 ) : Mover()
222 {
223  moves::Mover::type( "RollMover" );
224 }
225 
227  core::Size start_res,
228  core::Size stop_res,
229  core::Real min_angle,
230  core::Real max_angle,
233 ):
234  Mover(),
235  start_res_(start_res),
236  stop_res_(stop_res),
237  min_angle_(min_angle),
238  max_angle_(max_angle),
239  axis_(axis),
240  translate_(translate)
241 {
242  moves::Mover::type( "RollMover" );
243 }
244 
246 
247 } //rigid
248 } //protocols
249