Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SubToFullInfo.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/swa/SubToFullInfo.cc
11 /// @brief Mapping from a working pose into a bigger pose, for swa monte carlo stuff.
12 /// @author Rhiju Das
13 
14 // Unit headers
17 
18 // Package headers
19 
20 // Project headers
21 #include <core/pose/Pose.hh>
23 #include <basic/datacache/BasicDataCache.hh>
24 
25 // Utility headers
26 #include <utility/vector1.hh>
27 
28 // C++
29 #include <string>
30 #include <map>
31 
32 ///////////////////////////////////////////////////////
33 // Keep track of some base geometry that is
34 // useful for RNA scoring.
35 ///////////////////////////////////////////////////////
36 
37 using namespace core;
38 using namespace core::pose::datacache;
39 using namespace basic::datacache;
40 
41 namespace protocols {
42 namespace swa {
43 namespace monte_carlo {
44 
45 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
46 SubToFullInfo::SubToFullInfo() {} // blank. Should not be used?
47 
48 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
49 SubToFullInfo::SubToFullInfo( std::map< Size, Size > sub_to_full,
50  utility::vector1< Size > moving_res_list,
51  std::string full_sequence,
52  utility::vector1< Size > cutpoints_in_full_pose) : //proper constructor
53  CacheableData(),
54  sub_to_full_( sub_to_full ),
55  moving_res_list_( moving_res_list ),
56  full_sequence_( full_sequence ),
57  cutpoints_in_full_pose_( cutpoints_in_full_pose )
58 {
59 }
60 
61 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
62 /// @details Copy constructors must copy all data, not just some...
64  CacheableData(),
65  sub_to_full_( src.sub_to_full_ ),
66  moving_res_list_( src.moving_res_list_ ),
67  full_sequence_( src.full_sequence_ ),
68  cutpoints_in_full_pose_( src.cutpoints_in_full_pose_ )
69 {
70 }
71 
72 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
73 void
75  moving_res_list_ = setting;
76 }
77 
78 
79 /// @details Pose must already contain a sub_to_full_info object or this method will fail.
80 SubToFullInfo const &
82 {
84  return *( static_cast< SubToFullInfo const * >( pose.data().get_const_ptr( core::pose::datacache::CacheableDataType::SUB_TO_FULL_INFO)() ) );
85 }
86 
87 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
88 /// @details Either returns a non-const reference to the rna_scoring object already stored
89 /// in the pose, or creates a new rna scoring info object, places it in the pose, and returns
90 /// a non-const reference to it.
91 SubToFullInfo &
93 {
95  return *( static_cast< SubToFullInfo * >( pose.data().get_ptr( core::pose::datacache::CacheableDataType::SUB_TO_FULL_INFO )() ));
96  }
97 
98  SubToFullInfoOP sub_to_full_info = new SubToFullInfo();
100  return *sub_to_full_info;
101 }
102 
103 
104 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
107  Size const & res_to_delete ){
108 
109  utility::vector1< Size > moving_res_list_new;
110 
111  for (Size i = 1; i <= moving_res_list.size(); i++ ){
112  Size const n = moving_res_list[ i ];
113  if ( n < res_to_delete ) moving_res_list_new.push_back( n );
114  else if (n > res_to_delete ) moving_res_list_new.push_back( n-1 );
115  }
116 
117  return moving_res_list_new;
118 
119 }
120 
121 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
122 std::map<Size,Size>
123 reorder_after_delete( std::map<Size,Size> sub_to_full,
124  Size const & res_to_delete ){
125 
126  std::map< Size, Size > sub_to_full_new;
127 
128  for ( std::map< Size, Size >::const_iterator it = sub_to_full.begin(); it != sub_to_full.end(); ++it ) {
129  Size const n = it->first;
130  Size const m = it->second;
131  if ( n < res_to_delete ) sub_to_full_new[ n ] = m;
132  else if ( n > res_to_delete ) sub_to_full_new[ n-1 ] = m;
133  }
134 
135  return sub_to_full_new;
136 
137 }
138 
139 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
142  Size const & res_to_add ){
143 
144  utility::vector1< Size > moving_res_list_new;
145 
146  for (Size i = 1; i <= moving_res_list.size(); i++ ){
147  Size const n = moving_res_list[ i ];
148  if ( n < res_to_add ) moving_res_list_new.push_back( n );
149  }
150  moving_res_list_new.push_back( res_to_add );
151  for (Size i = 1; i <= moving_res_list.size(); i++ ){
152  Size const n = moving_res_list[ i ];
153  if ( n >= res_to_add ) moving_res_list_new.push_back( n+1 );
154  }
155 
156  return moving_res_list_new;
157 
158 }
159 
160 
161 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
162 std::map<Size,Size>
163 reorder_after_prepend( std::map<Size,Size> sub_to_full,
164  Size const & res_to_add ){
165 
166  std::map< Size, Size > sub_to_full_new;
167 
168  for ( std::map< Size, Size >::const_iterator it = sub_to_full.begin(); it != sub_to_full.end(); ++it ) {
169  Size const n = it->first;
170  Size const m = it->second;
171  if ( n < res_to_add ) sub_to_full_new[ n ] = m;
172  if ( n >= res_to_add ) sub_to_full_new[ n+1 ] = m;
173  }
174  sub_to_full_new[ res_to_add ] = sub_to_full[ res_to_add ]-1;
175 
176  return sub_to_full_new;
177 }
178 
179 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
180 std::map<Size,Size>
181 reorder_after_append( std::map<Size,Size> sub_to_full,
182  Size const & res_to_add ){
183 
184  std::map< Size, Size > sub_to_full_new;
185 
186  for ( std::map< Size, Size >::const_iterator it = sub_to_full.begin(); it != sub_to_full.end(); ++it ) {
187  Size const n = it->first;
188  Size const m = it->second;
189  if ( n < res_to_add ) sub_to_full_new[ n ] = m;
190  if ( n >= res_to_add ) sub_to_full_new[ n+1 ] = m;
191  }
192  sub_to_full_new[ res_to_add ] = sub_to_full[ res_to_add-1 ]+1;
193 
194  return sub_to_full_new;
195 }
196 
197 
198 
199 
200 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
201 void
203  using namespace protocols::swa::monte_carlo;
204  SubToFullInfo & sub_to_full_info = nonconst_sub_to_full_info_from_pose( pose );
205 
206  std::map< Size, Size > sub_to_full_new = reorder_after_delete( sub_to_full_info.sub_to_full(), res_to_delete );
207  utility::vector1< Size > moving_res_list_new = reorder_after_delete( sub_to_full_info.moving_res_list(), res_to_delete );
208 
209  sub_to_full_info.set_sub_to_full( sub_to_full_new );
210  sub_to_full_info.set_moving_res_list( moving_res_list_new );
211 
212 }
213 
214 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
215 void
217  using namespace protocols::swa::monte_carlo;
218  SubToFullInfo & sub_to_full_info = nonconst_sub_to_full_info_from_pose( pose );
219 
220  std::map< Size, Size > sub_to_full_new = reorder_after_append( sub_to_full_info.sub_to_full(), res_to_add );
221  utility::vector1< Size > moving_res_list_new = reorder_after_insert( sub_to_full_info.moving_res_list(), res_to_add );
222 
223  sub_to_full_info.set_sub_to_full( sub_to_full_new );
224  sub_to_full_info.set_moving_res_list( moving_res_list_new );
225 
226 }
227 
228 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
229 void
231  using namespace protocols::swa::monte_carlo;
232  SubToFullInfo & sub_to_full_info = nonconst_sub_to_full_info_from_pose( pose );
233 
234  std::map< Size, Size > sub_to_full_new = reorder_after_prepend( sub_to_full_info.sub_to_full(), res_to_add );
235  utility::vector1< Size > moving_res_list_new = reorder_after_insert( sub_to_full_info.moving_res_list(), res_to_add );
236 
237  sub_to_full_info.set_sub_to_full( sub_to_full_new );
238  sub_to_full_info.set_moving_res_list( moving_res_list_new );
239 
240 }
241 
242 
243 
244 
245 
246 }
247 }
248 }