Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RestrictToAlignedSegments.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/toolbox/task_operations/RestrictToAlignedSegmentsOperation.cc
11 /// @brief
12 /// @author Sarelf Fleishman sarelf@uw.edu
13 
14 // Unit Headers
18 #include <core/pose/selection.hh>
20 #include <core/pose/Pose.hh>
24 // Project Headers
25 #include <core/pose/Pose.hh>
26 
27 // AUTO-REMOVED #include <core/pack/task/PackerTask.hh>
28 // AUTO-REMOVED #include <core/pack/task/operation/TaskOperations.hh>
29 
30 // Utility Headers
31 #include <core/types.hh>
32 #include <basic/Tracer.hh>
33 #include <utility/exit.hh>
34 #include <utility/vector1.hh>
35 #include <utility/tag/Tag.hh>
38 
39 #include <boost/foreach.hpp>
40 #define foreach BOOST_FOREACH
41 
42 // C++ Headers
43 #include <set>
44 
45 #include <utility/vector0.hh>
46 
47 
48 using basic::Error;
49 using basic::Warning;
50 static basic::Tracer TR( "protocols.toolbox.TaskOperations.RestrictToAlignedSegmentsOperation" );
51 
52 namespace protocols {
53 namespace toolbox {
54 namespace task_operations {
55 
56 using namespace core::pack::task::operation;
57 using namespace std;
58 
60 {
61  source_pose_.clear();
62  start_res_.clear();
63  stop_res_.clear();
64  chain_ = 1;
65  repack_shell_ = 6.0;
66 }
67 
69 
72 {
74 }
75 
77 {
78  return new RestrictToAlignedSegmentsOperation( *this );
79 }
80 
81 void
83 {
84  using namespace protocols::rosetta_scripts;
85 
86  std::set< core::Size > designable;
87  designable.clear();
88  for( core::Size count = 1; count <= source_pose_.size(); ++count ){
89  core::Size const nearest_to_from = find_nearest_res( pose, *source_pose_[ count ], start_res_[ count ], chain() );
90  core::Size const nearest_to_to = find_nearest_res( pose, *source_pose_[ count ], std::min( stop_res_[ count ], source_pose_[ count ]->total_residue() ), chain() );
91 
92  TR<<"Finding nearest residue to residue pair "<<start_res_[ count ]<<','<<stop_res_[ count ]<<" in source pose"<<std::endl;
93  if( nearest_to_from == 0 || nearest_to_to == 0 ){
94  TR<<"nearest_to_from: "<<nearest_to_from<<" nearest_to_to: "<<nearest_to_to<<". Failing"<<std::endl;
95  continue;
96  }
97  for( core::Size position = nearest_to_from; position <= nearest_to_to; ++position )
98  designable.insert( position );
99  }
100 /// in the following we use dao to compute the residues that surround the aligned region. We then go over these residues to make sure they're within the target chain
102  dao->design_shell( 0.1 );
103  dao->repack_shell( repack_shell() );
104  foreach( core::Size const d, designable ){
105  dao->include_residue( d );
106  }
108  dao_tf->push_back( dao );
109 
110  utility::vector1< core::Size > const surrounding_shell( protocols::rosetta_scripts::residue_packer_states( pose, dao_tf, false/*designable*/, true/*packable*/ ) );
111  utility::vector1< core::Size > const designed_residues( protocols::rosetta_scripts::residue_packer_states( pose, dao_tf, true/*designable*/, false/*packable*/ ) );
112 
113  utility::vector1< core::Size > repackable, immutable;
114  repackable.clear(); immutable.clear();
115  for( core::Size i = pose.conformation().chain_begin( chain() ); i<=pose.conformation().chain_end( chain() ); ++i ){
116  if( std::find( designed_residues.begin(), designed_residues.end(), i ) != designed_residues.end() ) // don't change designed residues
117  continue;
118  if( std::find( surrounding_shell.begin(), surrounding_shell.end(), i ) == surrounding_shell.end() )
119  immutable.push_back( i );
120  else
121  repackable.push_back( i );
122  }
123 ///for some unfathomable reason OperateOnCertainResidues defaults to applying to all residues if none are defined, so you have to be careful here...
124  OperateOnCertainResidues oocr_repackable, oocr_immutable;
125  oocr_immutable.op( new PreventRepackingRLT );
126  oocr_repackable.op( new RestrictToRepackingRLT );
127  if( repackable.size() ){
128  oocr_repackable.residue_indices( repackable );
129  oocr_repackable.apply( pose, task );
130  TR<<"allowing repacking in: ";
131  foreach( core::Size const r, repackable )
132  TR<<r<<' ';
133  TR<<std::endl;
134  }
135  if( immutable.size() ){
136  oocr_immutable.residue_indices( immutable );
137  oocr_immutable.apply( pose, task );
138  TR<<"no repack in: ";
139  foreach( core::Size const i, immutable )
140  TR<<i<<' ';
141  TR<<std::endl;
142  }
143 }
144 
145 void
147 {
148  using namespace protocols::rosetta_scripts;
149  utility::vector1< std::string > pdb_names, start_res, stop_res;
150  pdb_names.clear(); start_res.clear(); stop_res.clear();
151  if( tag->hasOption( "source_pdb" ) )
152  pdb_names.push_back( tag->getOption< std::string >( "source_pdb" ) );
153  if( tag->hasOption( "start_res" ) )
154  start_res.push_back( tag->getOption< std::string >( "start_res" ) );
155  if( tag->hasOption( "stop_res" ) )
156  stop_res.push_back( tag->getOption< std::string >( "stop_res" ) );
157 
158  chain( tag->getOption< core::Size >( "chain", 1 ) );
159  if( tag->hasOption( "source_pdb" ) || tag->hasOption( "start_res" ) || tag->hasOption( "stop_res" ) ){
160  runtime_assert( tag->hasOption( "source_pdb" ) && tag->hasOption( "start_res" ) && tag->hasOption( "stop_res" ) );
161  }
162 
163  utility::vector0< TagPtr > const btags( tag->getTags() );
164  foreach( TagPtr const btag, btags ){
165  pdb_names.push_back( btag->getOption< std::string >( "source_pdb" ) );
166  start_res.push_back( btag->getOption< std::string >( "start_res" ) );
167  stop_res.push_back( btag->getOption< std::string >( "stop_res" ) );
168  }
169 
170  for( core::Size i = 1; i <= pdb_names.size(); ++i ){
171  if( i == 1 || pdb_names[ i ] != pdb_names[ i - 1 ]){ // scrimp on reading from disk
172  source_pose_.push_back( new core::pose::Pose );
173  core::import_pose::pose_from_pdb( *source_pose_[ i ], pdb_names[ i ] );
174  }
175  else
176  source_pose_.push_back( source_pose_[ i - 1 ] );
177  core::Size const parsed_start( core::pose::parse_resnum( start_res[ i ], *source_pose_[ i ] ) );
178  core::Size const parsed_stop ( core::pose::parse_resnum( stop_res[ i ], *source_pose_[ i ] ) );
179  start_res_.push_back( parsed_start );
180  stop_res_. push_back( parsed_stop );
181  }
182  repack_shell( tag->getOption< core::Real >( "repack_shell", 6.0 ));
183 }
184 } //namespace protocols
185 } //namespace toolbox
186 } //namespace task_operations