Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FragData.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 // :noTabs=false:tabSize=4:indentSize=4:
4 //
5 // (c) Copyright Rosetta Commons Member Institutions.
6 // (c) This file is part of the Rosetta software suite and is made available under license.
7 // (c) The Rosetta software is developed by the contributing members of the Rosetta Commons.
8 // (c) For more information, see http://www.rosettacommons.org. Questions about this can be
9 // (c) addressed to University of Washington UW TechTransfer, email: license@u.washington.edu.
10 
11 /// @file core/fragments/FragData.cc
12 /// @brief a collection classes of the FragData and SingleResidueFragData class hirachy
13 /// @author Oliver Lange (olange@u.washington.edu)
14 /// @date Wed Oct 20 12:08:31 2007
15 ///
16 
17 // Unit Headers
19 
20 // Package Headers
21 #include <core/fragment/Frame.hh>
22 
23 // Project Headers
24 #include <core/pose/Pose.hh>
28 // ObjexxFCL Headers
29 #include <ObjexxFCL/format.hh>
30 
31 // Utility headers
32 #include <utility/vector1.fwd.hh>
33 
34 #include <utility/vector1.hh>
35 
36 
37 
38 namespace core {
39 namespace fragment {
40 
41 using namespace kinematics;
42 
43 
44 //helper function
45 void
47  std::string sequence,
48  chemical::ResidueTypeSet residue_set,
49  pose::Pose& pose
50 ) {
51  using namespace chemical;
52  // clear all of the old data in the pose
53  pose.clear();
54 
55  // setup the pose by appending the appropriate residues residues
56  for ( Size seqpos = 1; seqpos <= sequence.length(); ++seqpos ) {
57  char aa = sequence[seqpos-1]; // string indexing is zero-based!
58  AA my_aa = aa_from_oneletter_code( aa );
59  ResidueTypeCOPs const & rsd_type_list( residue_set.aa_map( my_aa ) );
60  Size best_index = 1;
61  ResidueType const & rsd_type( *(rsd_type_list[ best_index ]) );
63  } // for seqpos
64  // pose.conformation().insert_chain_ending( pose.total_residue() - 1 ); probably not necessary
65 } // make_pose_match_sequence_
66 
67 FragData::FragData( SingleResidueFragDataOP SRFD, Size n) : valid_( false ), score_( 0.0 ) {
68  for ( Size i = 1; i<=n; i++ ) {
69  data_.push_back( SRFD->clone() );
70  }
71 }
72 
73 
75  FragDataOP fd = new FragData( size() );
76  for ( Size pos = 1; pos<=size(); pos++ ) {
77  fd->data_[pos] = data_[pos]->clone();
78  };
79  return fd;
80 }
81 
82 Size FragData::apply( MoveMap const& mm, pose::Pose& pose, Size start, Size end ) const {
83  if ( !is_valid() ) return 0;
84  Size pos = start;
85  Size ct( 0 );
86  for ( SRFD_List::const_iterator it= data_.begin(), eit=data_.end(); it!=eit; ++it, ++pos ) {
87  //success = success && data_[ pos-start+1 ]->apply( pose, pos );
88  if ( pos > end ) break;
89  if ( pos > pose.total_residue() ) break;
90  if ( !(*it)->is_applicable( mm, pos ) ) continue; //don't apply for this residue
91  if ( !(*it)->apply( mm, pose, pos ) ) continue; //don't apply for this residue
92  ct++;
93  }
94  return ct;
95 }
96 
98  Size pos = start;
99  Size ct ( 0 );
100  if ( !is_valid() ) return 0;
101  for ( SRFD_List::const_iterator it= data_.begin(), eit=data_.end(); it!=eit; ++it, ++pos ) {
102  if ( pos > end ) break;
103  if ( !(*it)->apply( pose, pos ) ) continue;
104  ++ct;
105  }
106  return ct;
107 }
108 
109 Size FragData::apply( MoveMap const& mm, pose::Pose& pose, Frame const& frame ) const {
110  runtime_assert( size() == frame.length() );
111  if ( !is_valid() ) return 0;
112  if ( frame.is_continuous() ) {
113  return apply( mm, pose, frame.start(), frame.end() );
114  }
115  Size ct ( 0 );
116  Size ipos( 1 );
117  for ( SRFD_List::const_iterator it= data_.begin(), eit=data_.end(); it!=eit; ++it, ++ipos ) {
118  if ( frame.seqpos( ipos ) > pose.total_residue() ) continue;
119  if ( !(*it)->is_applicable( mm, ipos, frame ) ) continue;
120  if ( !(*it)->apply( mm, pose, ipos, frame ) ) continue;
121  ++ct;
122  }
123  return ct;
124 }
125 
126 Size FragData::apply( pose::Pose& pose, Frame const& frame ) const {
127  runtime_assert( size() == frame.length() );
128  if ( !is_valid() ) return 0;
129  Size ipos( 1 );
130  Size ct ( 0 );
131  for ( SRFD_List::const_iterator it= data_.begin(), eit=data_.end(); it!=eit; ++it, ++ipos ) {
132  if ( frame.seqpos( ipos ) > pose.total_residue() ) continue;
133  if ( !(*it)->apply( pose, ipos, frame ) ) continue;
134  ++ct;
135  }
136  return ct;
137 }
138 
139 Size FragData::apply_ss( MoveMap const& mm, std::string& ss, Frame const& frame ) const {
140  Size ipos ( 1 );
141  Size ct( 0 );
142  if ( !is_valid() ) return 0;
143  for ( SRFD_List::const_iterator it= data_.begin(), eit=data_.end(); it!=eit; ++it, ++ipos ) {
144  if ( !(*it)->is_applicable( mm, ipos, frame ) ) continue;
145  if ( !(*it)->apply_ss( ss, ipos, frame ) ) continue;
146  ++ct;
147  }
148  return ct;
149 }
150 
151 
153  Size insert_size( 0 );
154  // if ( !is_valid() ) return 0; //this might be necessary to have!!!
155  for (Size pos=start; pos<=end; pos++ ) {
156  if ( !data_[ pos-start+1 ]->is_applicable( mm, pos ) ) continue;
157  ++insert_size;
158  }
159  return insert_size;
160 }
161 
162 Size FragData::is_applicable( kinematics::MoveMap const& mm, Frame const& frame ) const {
163  runtime_assert( size() == frame.length() );
164  // if ( !is_valid() ) return 0;
165  if ( frame.is_continuous() ) {
166  return is_applicable( mm, frame.start(), frame.end() );
167  }
168  Size insert_size( 0 );
169  for (Size j=1; j<=size(); j++ ) {
170  if ( !data_[ j ]->is_applicable( mm, j, frame ) ) continue;
171  ++insert_size;
172  }
173  return insert_size;
174 }
175 
176 bool FragData::steal( pose::Pose const& pose, Size start, Size end ) {
177  bool success( true );
178  for (Size pos=start; pos<=end; pos++) {
179  runtime_assert( start > 0 );
180  if ( pos > pose.total_residue() ) return false;
181  success = success && data_[ pos-start+1 ]->steal( pose, pos );
182  }
183  if ( success ) set_valid();
184  return success;
185 }
186 
187 
188 bool FragData::steal( pose::Pose const& pose, Frame const& frame ) {
189  runtime_assert( size() == frame.length() );
190  if ( frame.is_continuous() ) {
191  return steal( pose, frame.start(), frame.end() );
192  }
193  bool success( true );
194  for (Size j=1; j<=size(); j++ ) {
195  runtime_assert( frame.seqpos( j ) > 0 );
196  if ( frame.seqpos( j ) > pose.total_residue() ) return false;
197  success = success && data_[ j ]->steal( pose, j, frame );
198  }
199  if ( success ) set_valid();
200  return success;
201 }
202 
204  runtime_assert( stop >= start );
205  runtime_assert( stop <= size() );
206  FragDataOP new_frag = new FragData;
207  for ( Size pos = start; pos<=stop; pos++ ) {
208  new_frag->add_residue( data_[ pos ] ); //reuse of data
209  }
210  new_frag->set_valid();
211  return new_frag;
212 }
213 
214 bool FragData::is_compatible( FragData const& frag_data ) const {
215  if ( frag_data.size() != size() ) return false;
216  for ( SRFD_List::const_iterator it1= data_.begin(), it2=frag_data.data_.begin(), eit1=data_.end(); it1!=eit1; ++it1,++it2 ) {
217  // if ( typeid( *it1 ) != typeid( *it2 ) ) return false;
218  if ( ! (*it1)->is_compatible( **it2 ) ) return false;
219  }
220  return true;
221 }
222 
223 void FragData::show( std::ostream &os, Frame const& frame ) const {
224  Size i = 1;
225  if ( is_valid() ) {
226  for ( SRFD_List::const_iterator it= data_.begin(), eit=data_.end(); it!=eit; ++it ) {
227  os << ObjexxFCL::fmt::RJ( 10, frame.seqpos( i++ ) ) << " " << ObjexxFCL::fmt::RJ( 5, pdbpos() ) << " " << pdbid() <<" ";
228  // std::cerr << "FragData::show " << i-1 << std::endl;
229  (*it)->show( os );
230  os << std::endl;
231  // std::cerr << "FragData:show -- done" << std::endl;
232  }
233  } else {
234  os << "EMPTY TEMPLATE" << std::endl;
235  }
236 }
237 
238 void FragData::show( std::ostream &os ) const {
239  Size i = 1;
240  if ( is_valid() ) {
241  for ( SRFD_List::const_iterator it= data_.begin(), eit=data_.end(); it!=eit; ++it ) {
242  os << ObjexxFCL::fmt::RJ( 10, i++ ) << " " << ObjexxFCL::fmt::RJ( 5, pdbpos() ) << " " << pdbid() << " " ;
243  (*it)->show( os );
244  os << std::endl;
245  }
246  } else {
247  os << "EMPTY_TEMPLATE" << std::endl;
248  }
249 }
250 
251 void FragData::show_classic( std::ostream &os ) const {
252  for ( SRFD_List::const_iterator it= data_.begin(), eit=data_.end(); it!=eit; ++it ) {
253  os << " 1xxx X 111 ";
254  (*it)->show( os );
255  os << std::endl;
256  }
257 }
258 
260  return new AnnotatedFragData( pdbid_, startpos_, *Parent::clone() );
261 }
262 
263 
264 } // fragment
265 } // core