Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
MatchResidues.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 protocolsoped 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/fldsgn/MatchResidues.cc
11 /// @brief
12 /// @author Javier Castellanos ( javiercv@uw.edu )
13 
14 // Unit Headers
16 
17 // Project Headers
18 #include <core/types.hh>
19 #include <core/pose/Pose.hh>
21 #include <core/pose/util.hh>
23 #include <core/scoring/rms_util.hh>
24 #include <core/id/AtomID_Map.hh>
25 
26 // Utility headers
27 #include <utility/vector1.hh>
28 #include <basic/Tracer.hh>
29 #include <ObjexxFCL/format.hh>
31 #include <protocols/moves/Mover.hh>
33 #include <utility/exit.hh>
34 
35 // Parser headers
37 #include <protocols/moves/Mover.hh>
38 #include <utility/tag/Tag.hh>
39 #include <utility/string_util.hh>
40 
41 
42 // Boost Headers
43 #include <boost/tuple/tuple.hpp>
44 #include <boost/tuple/tuple_comparison.hpp>
45 #include <boost/lexical_cast.hpp>
46 #include <boost/foreach.hpp>
47 #include "boost/assign.hpp"
48 
49 #define foreach BOOST_FOREACH
50 
51 static basic::Tracer TR("protocols.fldsgn.MatchResidues");
52 
53 namespace protocols {
54 namespace fldsgn {
55 
58 
59 
60 // @brief default constructor
62 {}
63 
64 
65 // @brief destructor
67 
68 
69 
71 MatchResidues::compute_comb( core::pose::Pose const & pose, VecSize const & comb ) const
72 {
73  std::map< core::id::AtomID, core::id::AtomID > atom_id_map;
74  for(Size i = 1; i < comb.size(); i++) {
75  const core::id::AtomID mod_id(pose.residue_type( comb[i] ).atom_index( "CA" ), comb[i] );
77  atom_id_map.insert( std::make_pair< core::id::AtomID, core::id::AtomID >(mod_id, ref_id) );
78  }
80 }
81 
84 {
87  for ( Size i = 1; i < comb.size(); ++i ) {
88  const core::id::AtomID mod_id(pose.residue_type( comb[i] ).atom_index( "CA" ), comb[i] );
90  atom_map.set( mod_id, ref_id);
91 
92  }
93  return core::scoring::superimpose_pose(pose, reference_pose_, atom_map);
94 }
95 
97 MatchResidues::compute( core::pose::Pose const & pose, VecSize & best_fit ) const
98 {
99  Real smallest_rms = 99999;
100  foreach(VecSize const & comb, mod_segment_prod_){
101  Real rms = compute_comb(pose, comb);
102  if( rms < smallest_rms ) {
103  smallest_rms = rms;
104  best_fit = comb;
105  }
106  }
107  TR << "best fit:" <<std::endl;
108  TR <<"ref_pos\tmod_pos" << std::endl;
109  for(Size i = 1; i <= best_fit.size(); i++)// {
110  TR << "\t" << reference_residues_indexes_[i] << "\t" << best_fit[i] << std::endl;
111  TR << std::endl << "rmsd matched positions " << smallest_rms << std::endl;
112 
113  return smallest_rms;
114 }
115 
116 
117 void
119  VecVecSize& rvvi, // final result
120  VecSize& rvi, // current result
121  VecVecSize::const_iterator me, // current input
122  VecVecSize::const_iterator end) const // final input
123 {
124  if(me == end) {
125  // terminal condition of the recursion. We no longer have
126  // any input vectors to manipulate.
127  rvvi.push_back(rvi);
128  return;
129  }
130 
131  const VecSize& mevi = *me;
132  for(VecSize::const_iterator it = mevi.begin();
133  it != mevi.end();
134  it++) {
135  rvi.push_back(*it);
136  cart_product(rvvi, rvi, me+1, end);
137  rvi.pop_back();
138  }
139 }
140 
141 VecVecSize
143  VecVecSize tmp;
144  VecVecSize output;
145  VecSize outputTemp;
146  cart_product(tmp, outputTemp, input.begin(), input.end());
147  //remove duplicates in combination
148  foreach(VecSize const & vec, tmp) {
149  std::set<Size> comb(vec.begin(), vec.end());
150  if(comb.size() == vec.size())
151  output.push_back(vec);
152  }
153  return output;
154 }
155 
156 
157 /// @brief parse xml
158 void
160  utility::tag::TagPtr const tag,
161  protocols::moves::DataMap & /*data*/,
164  core::pose::Pose const & )
165 {
166  const std::string reference = tag->getOption< std::string >("reference");
168 
169  VecVecSize mod_match_segments;
170 
171  threshold_ = tag->getOption< core::Real >("threshold", 3.0);
172  const std::string blueprint = tag->getOption< std::string >("blueprint", "");
173  std::map< std::string, boost::tuple< core::Size, core::Size> > ss_seg;
174  if(blueprint != "") {
175  // get the segment start and end points from the blueprint
177  blue.read_blueprint( blueprint );
178  const std::string ss = blue.secstruct();
179  ss_seg = map_ss_segments( ss );
180  }
181 
182  foreach( utility::tag::TagPtr pairs_tag, tag->getTags() ) {
183  if( pairs_tag->getName() == "match" ) {
184  const Size ref_pos = pairs_tag->getOption< Size >("ref_pos");
185  Size mod_pos_start= 0;
186  Size mod_pos_end = 0;
187  if( pairs_tag->hasOption("segment") ) {
188  assert( blueprint != "");
189  boost::tuple< Size, Size> range = ss_seg[ pairs_tag->getOption< std::string >("segment") ];
190  mod_pos_start = boost::get<0>(range);
191  mod_pos_end = boost::get<1>(range);
192 
193  } else if( pairs_tag->hasOption("mod_pos_start") || pairs_tag->hasOption("mod_pos_end") ) {
194  mod_pos_start = pairs_tag->getOption< Size >("mod_pos_start");
195  mod_pos_end = pairs_tag->getOption< Size >("mod_pos_end");
196 
197  } else if( pairs_tag->hasOption("mod_pos") ) {
198  mod_pos_start = mod_pos_end = pairs_tag->getOption< Size >("mod_pos");
199 
200  } else {
201  utility_exit_with_message("need to specify a segment to be matched in the modified structure");
202  }
203  VecSize vrange;
204  for(Size n = mod_pos_start; n <= mod_pos_end; n++)
205  vrange.push_back(n);
206 
207  TR << "Residue " << ref_pos << " from the reference structure matches against segment [" << mod_pos_start << "," << mod_pos_end <<"]" << std::endl;
208  reference_residues_indexes_.push_back( ref_pos );
209  mod_match_segments.push_back( vrange );
210 
211  } else {
212  utility_exit_with_message("wrong tag \"" + pairs_tag->getName() + "\" used in MatchResidues.");
213  }
214  }
215  mod_segment_prod_ = cart_product( mod_match_segments );
216 }
217 
218 
219 std::map< std::string, boost::tuple< core::Size, core::Size> >
221 {
222  std::map< std::string, boost::tuple<Size, Size> > ss_map;
223  std::map< char, Size > ss_seg_count = boost::assign::map_list_of ( 'L', 0 ) ( 'H', 0 ) ( 'E', 0 );
224  char last = ss[0];
225  ss_seg_count[ last ] += 1;
226  Size start = 1;
227  Size end = 1;
228 
229  for(Size i = 1; i < ss.size(); i++) {
230  if( ss[i] == last ) {
231  // push if last element
232  if(i + 1 == ss.size())
233  ss_map.insert( std::make_pair< std::string, boost::tuple<Size, Size> >( last + boost::lexical_cast< std::string >( ss_seg_count[ss[i - 1] ] ), boost::make_tuple(start, i) ) );
234  continue;
235  } else {
236  end = i ;
237  ss_map.insert( std::make_pair< std::string, boost::tuple<Size, Size> >( last + boost::lexical_cast< std::string >( ss_seg_count[ss[i - 1] ] ), boost::make_tuple(start, end) ) );
238  ss_seg_count[ ss[i] ] += 1;
239  start = end + 1;
240  last = ss[i + 1];
241  }
242  }
243  return ss_map;
244 }
245 
246 
247 } // fldsgn
248 } // protocols