Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FragInsertAndAlignMover.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
11 /// @brief
12 /// @author Frank DiMaio
14 
15 // Package headers
16 #include <protocols/moves/Mover.hh>
17 // AUTO-REMOVED #include <protocols/rigid/RB_geometry.hh>
18 
19 #include <core/types.hh>
20 #include <core/pose/Pose.fwd.hh>
22 // AUTO-REMOVED #include <core/chemical/ResidueTypeSet.hh>
23 // AUTO-REMOVED #include <core/scoring/ScoreFunction.hh>
25 #include <basic/Tracer.hh>
26 
27 #include <basic/options/option.hh>
28 // AUTO-REMOVED #include <basic/options/after_opts.hh>
29 #include <basic/options/keys/loops.OptionKeys.gen.hh>
30 
31 //
33 
34 // C++ Headers
35 #include <map>
36 
37 // Utility Headers
38 // AUTO-REMOVED #include <numeric/xyzVector.io.hh>
39 #include <numeric/xyzVector.hh>
40 #include <numeric/xyz.functions.hh>
41 #include <numeric/random/random.hh>
42 
43 #include <utility/pointer/ReferenceCount.hh>
44 
45 //
46 #include <string>
47 
49 #include <core/id/AtomID.hh>
50 #include <core/pose/Pose.hh>
52 #include <utility/vector1.hh>
53 
54 
55 namespace protocols {
56 namespace rbsegment_relax {
57 
58 using namespace core;
59 
60 static numeric::random::RandomGenerator rbseg_RG(18633);
61 static basic::Tracer TR("FragInsertAndAlignMover");
62 
63 
66 
67 
69  utility::vector1< RBSegment > const &rbsegs,
70  core::pose::Pose const &ref_pose,
71  core::Real randomness/*=0.0*/ ) {
72  initialize_rb_fragments(rbsegs,ref_pose,randomness );
73 }
74 
75 
76 ///
77 ///@brief Initialize fragment library
78 ///@brief Loads RMS vall data, sets up frame set
80  utility::vector1< RBSegment > const &rbsegs,
81  core::pose::Pose const &ref_pose,
82  core::Real randomness/*=0.0*/ )
83 {
84  using namespace basic::options;
85 
86  if ( !option[ OptionKeys::loops::vall_file ].user() ) {
87  TR.Error << "FragInsertAndAlignMover::initialize_rb_fragments() with no vall! Specify location with -loops::vall" << std::endl;
88  return;
89  }
90 
91  if ( rbsegs.size() == 0 ) {
92  TR.Error << "FragInsertAndAlignMover::initialize_rb_fragments() called with empty RBSeglist! continuing ..." << std::endl;
93  return;
94  }
95 
96  // declare as static so we only load once
97  static protocols::frags::RMSVallData rms_vall( option[ OptionKeys::loops::vall_file ] );
98 
99  std::string input_seq = ref_pose.sequence();
100  //core::Size res_ctr = 1;
101 
102  frames_.clear();
103 
104  // TO DO: COMPOUND SEGMENT SUPPORT(??)
105  for (int i = 1; i <= (int)rbsegs.size(); ++i) {
106  if (rbsegs[i].isCompound()) {
107  TR.Warning << "[ WARNING ] FragInsertAndAlignMover::initialize_rb_fragments() undefined for compound segments! continuing..." << std::endl;
108  continue;
109  }
110 
111  int frag_start = rbsegs[i][1].start();
112  int frag_size = rbsegs[i][1].end() - frag_start + 1;
113 
114  // add a new frame
115  frames_.push_back( new core::fragment::Frame( frag_start, frag_size ) );
116 
118  for (int k=0; k<frag_size; ++k)
119  cas[k+1] = ref_pose.residue(frag_start+k).atom("CA").xyz();
120 
121  std::string frag_seq = input_seq.substr( rbsegs[i][1].start()-1, frag_size );
122  rms_vall.get_frags(
123  200, cas, frag_seq, rbsegs[i][1].char_type(), frames_[frames_.size()], randomness
124  );
125  }
126  TR.Debug << "Read " << frames_.size() << " frames" << std::endl;
127 }
128 
129 
131  if (frames_.size() == 0) {
132  TR.Warning << "[ WARNING ] FragInsertAndAlignMover::apply()called with no frames defined! continuing..." << std::endl;
133  return;
134  }
135 
136  // pick a random rbseg
137  int idx = numeric::random::random_range( 1, frames_.size() );
138  apply( pose,idx );
139 }
140 
143  return "FragInsertAndAlignMover";
144 }
145 
146 
147 void FragInsertAndAlignMover::apply( core::pose::Pose & pose, int idx, bool idealize ) {
148  core::Size start = frames_[idx]->start(),len = frames_[idx]->length();
149 
150  TR.Debug << "FragInsertAndAlignMover::apply() called [" << start << " , " << start+len-1 << "]" << std::endl;
151 
152  // grab coords
153  ObjexxFCL::FArray2D< core::Real > init_coords( 3, len );
155  for (int i=0; i<(int)len; ++i) {
156  numeric::xyzVector< core::Real > x_i = pose.residue(start+i).atom("CA").xyz(); // CA
157  com1 += x_i;
158  for (int j=0; j<3; ++j)
159  init_coords(j+1,i+1) = x_i[j];
160  }
161  com1 /= len;
162  for (int i=0; i<(int)len; ++i)
163  for ( int j=0; j<3; ++j )
164  init_coords(j+1,i+1) -= com1[j];
165 
166 //core::pose::Pose pose_copy = pose;
167 
168  if (idealize) {
169  for (int i=0; i<(int)len; ++i) {
171  }
172  }
173 
174  // insert frag
175  core::Size toget = numeric::random::random_range( 1, frames_[idx]->nr_frags() );
176  frames_[idx]->apply( toget, pose );
177 
178  // grab new coords
179  ObjexxFCL::FArray2D< core::Real > final_coords( 3, len );
181  for (int i=0; i<(int)len; ++i) {
182  numeric::xyzVector< core::Real > x_i = pose.residue(start+i).atom(" CA ").xyz(); // CA
183  com2 += x_i;
184  for (int j=0; j<3; ++j)
185  final_coords(j+1,i+1) = x_i[j];
186  }
187  com2 /= len;
188  for (int i=0; i<(int)len; ++i)
189  for ( int j=0; j<3; ++j )
190  final_coords(j+1,i+1) -= com2[j];
191 
192  // get optimal superposition
193  // rotate >final< to >init<
194  ObjexxFCL::FArray1D< numeric::Real > ww( len, 1.0 );
195  ObjexxFCL::FArray2D< numeric::Real > uu( 3, 3, 0.0 );
196  numeric::Real ctx;
197 
198  numeric::model_quality::findUU( final_coords, init_coords, ww, len, uu, ctx );
200  R.xx( uu(1,1) ); R.xy( uu(2,1) ); R.xz( uu(3,1) );
201  R.yx( uu(1,2) ); R.yy( uu(2,2) ); R.yz( uu(3,2) );
202  R.zx( uu(1,3) ); R.zy( uu(2,3) ); R.zz( uu(3,3) );
203 
204  // apply rotation to ALL atoms
205  // x_i' <- = R*x_i + com1;
206 
207 
208  for ( Size i = 0; i < len; ++i ) {
209 //std::cout << i << " " << j << " " << pose.xyz(id) << " " << R * ( pose.xyz(id) - com2) + com1
210  for ( Size j = 1; j <= pose.residue_type(start+i).natoms(); ++j ) {
211  id::AtomID id( j, start+i );
212  pose.set_xyz( id, R * ( pose.xyz(id) - com2) + com1 );
213  }
214  }
215 }
216 
217 /// @brief take a CA-only pose and insert idealized fragments close to the trace
219  for (int i=1; i<=(int)frames_.size(); ++i) {
220  apply( start_pose , i , true);
221  }
222 }
223 
224 
225 }
226 }