Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
LayerOperations.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/flxbb/LayerOperations.cc
11 /// @brief operation defines either core, surface or periphery. It solely determines which residue to pack/design,
12 /// does not define identities.
13 /// @author Eva-Maria Strauch (evas01@uw.edu)
14 
15 
16 // Unit Headers
19 
20 // Project Headers
21 // AUTO-REMOVED #include <core/id/AtomID_Map.hh>
22 #include <core/pose/Pose.hh>
25 // AUTO-REMOVED #include <core/pack/task/PackerTask_.hh>
27 // AUTO-REMOVED #include <core/scoring/sasa.hh>
28 // AUTO-REMOVED #include <basic/options/option.hh>
29 #include <basic/Tracer.hh>
30 //#include <protocols/toolbox/LayerOperations.hh>
35 
36 // Utility Headers
37 #include <utility/string_util.hh>
38 #include <utility/tag/Tag.hh>
39 #include <utility/vector1.hh>
40 #include <string>
41 
42 using basic::T;
43 using basic::Error;
44 using basic::Warning;
45 
46 
47 #include <utility/vector0.hh>
48 #include <ObjexxFCL/format.hh>
49 #include <basic/options/keys/OptionKeys.hh>
50 
51 using namespace basic::options;
52 using namespace basic::options::OptionKeys;
53 using namespace core;
54 
55 
56 static basic::Tracer TR("protocols.toolbox.LayerOperations");
57 
58 namespace protocols {
59 namespace toolbox {
60 namespace task_operations {
61 
62 
63 /// @brief destructor
64 LayerOperations::~LayerOperations() {}
65 
66 /// @brief clone
69  return new LayerOperations( *this );
70 }
71 
72 
74 LayerOperations::create_task_operation() const
75 {
76  return new LayerOperations;
77 }
78 
79 /// @brief default constructor
80 LayerOperations::LayerOperations():
81 pick_core_( false ),
82 pick_boundary_( false ),
83 pick_surface_( false ),
84 pore_radius_( 2.0 ),
85 make_rasmol_format_file_( false )
86 {
87  initialize( 20.0, 40.0 );
88 }
89 
90 
91 /// @brief value constructor
92 LayerOperations::LayerOperations( bool const pick_core, bool const pick_boundary, bool const pick_surface ):
93 pick_core_( pick_core ),
94 pick_boundary_( pick_boundary ),
95 pick_surface_( pick_surface ),
96 pore_radius_( 2.0 ),
97 make_rasmol_format_file_( false )
98 {
99  initialize( 20.0, 40.0 );
100 }
101 
102 /// @brief value constructor
104 pick_core_( false ),
105 pick_boundary_( false ),
106 pick_surface_( false ),
107 pore_radius_( 2.0 ),
108 make_rasmol_format_file_( false )
109 {
110  initialize( 20.0, 40.0 );
111  utility::vector1< String > layers( utility::string_split( pick, '_' ) );
112  for( utility::vector1< String >::const_iterator iter = layers.begin(); iter != layers.end() ; ++iter) {
113  String layer(*iter);
114  if ( layer == "core" ) {
115  pick_core_ = true;
116  } else if ( layer == "surface" ) {
117  pick_surface_ = true;
118  } else if ( layer == "boundary" ) {
119  pick_boundary_ = true;
120  } else {
121  TR << "Error!, wrong specification of layer_mode " << layer << std::endl;
122  runtime_assert( false );
123  }
124  } // utility::vector1
125 }
126 /// @brief copy constructor
128 pick_core_( rval.pick_core_ ),
129 pick_boundary_( rval.pick_boundary_ ),
130 pick_surface_( rval.pick_surface_ ),
131 pore_radius_( rval.pore_radius_ ),
132 burial_( rval.burial_ ),
133 surface_( rval.surface_ ),
134 selected_core_residues_( rval.selected_core_residues_ ),
135 selected_boundary_residues_( rval.selected_boundary_residues_ ),
136 selected_surface_residues_( rval.selected_surface_residues_ ),
137 make_rasmol_format_file_( rval.make_rasmol_format_file_ ),
138 rsd_sasa_( rval.rsd_sasa_ ),
139 rsd_layer_( rval.rsd_layer_ )
140 {}
141 
142 /// @brief accessible surface for evaluating residues are in surface or not
143 void
145 {
146  if ( ss == "" ) {
147  surface_[ 'H' ] = r;
148  surface_[ 'L' ] = r;
149  surface_[ 'E' ] = r;
150  } else {
151  runtime_assert( ss.length() == 1 );
152  runtime_assert( ss.at( 0 ) == 'L' || ss.at( 0 ) == 'E' || ss.at( 0 ) == 'H' );
153  surface_[ ss.at( 0 ) ] = r;
154  }
155 }
156 
157 /// @brief accessible surface for evaluating residues are in core or not
158 void
160 {
161  if ( ss == "" ) {
162  burial_[ 'H' ] = r;
163  burial_[ 'L' ] = r;
164  burial_[ 'E' ] = r;
165  } else {
166  runtime_assert( ss.length() == 1 );
167  runtime_assert( ss.at( 0 ) == 'L' || ss.at( 0 ) == 'E' || ss.at( 0 ) == 'H' );
168  burial_[ ss.at( 0 ) ] = r;
169  }
170 }
171 
172 /// @brief
173 void
175 {
176  surface_.insert( std::map< char, Real >::value_type( 'H', surface ) );
177  surface_.insert( std::map< char, Real >::value_type( 'L', surface ) );
178  surface_.insert( std::map< char, Real >::value_type( 'E', surface ) );
179  burial_.insert( std::map< char, Real >::value_type( 'H', burial ) );
180  burial_.insert( std::map< char, Real >::value_type( 'L', burial ) );
181  burial_.insert( std::map< char, Real >::value_type( 'E', burial ) );
182 }
183 
184 
185 /// @brief amino acid types excluded for selection
186 //void
187 //LayerOperations::exclude_aatypes_for_selection( utility::vector1< AA > const & aas ){
188 // excluded_aatypes_for_selection_ = aas;
189 //}
190 
191 
192 /// @brief accessbile surface are of each residue
195  return rsd_sasa_[ i ];
196 }
197 
198 /// @brief return defined layer for each residue
200 LayerOperations::layer( Size const i ) const{
201  return rsd_layer_[ i ];
202 }
203 
204 /// @brief selected residues on boundary
208 }
209 
210 
211 /// @brief selected residues in core
215 }
216 
217 
218 /// @brief selected residues on surface
222 }
223 
224 
225 /// @brief return accessible surface area for each residue
227 LayerOperations::calc_rsd_sasa( Pose const & pose ) const {
228 
229  // define atom_map for main-chain and CB
231  core::pose::initialize_atomid_map( atom_map, pose, false );
232  for ( Size ir = 1; ir <= pose.total_residue(); ++ir ) {
233  for ( Size j = 1; j<=5; ++j ) {
234  core::id::AtomID atom( j, ir );
235  atom_map.set( atom, true );
236  }
237  }
238 
239  // calc sasa
242  core::scoring::calc_per_atom_sasa( pose, atom_sasa, rsd_sasa, pore_radius_, false, atom_map );
243 
244  return rsd_sasa;
245 } // calc_residue_sasa
246 
247 
248 /// @brief
251 {
252 
253  String secstruct = pose.secstruct();
254  runtime_assert( pose.total_residue() == secstruct.length() );
255 
256  // clear
257  rsd_sasa_.clear();
258  rsd_layer_.clear();
259  selected_core_residues_.clear();
262 
263  std::ofstream output;
265  output.open( "srb.ras" ,std::ios::out );
266  }
267 
268  TR << " pore_radius : " << pore_radius_ << std::endl;
269  TR << " core ( E, L, H ): " << burial_[ 'E' ] << ' ' << burial_[ 'L' ] << ' ' << burial_[ 'H' ] << std::endl;
270  TR << " surface (E, L, H ): " << surface_[ 'E' ] << ' ' << surface_[ 'L' ] << ' ' << surface_[ 'H' ] << std::endl;
271 
272  rsd_sasa_ = calc_rsd_sasa( pose );
273  rsd_layer_.resize( pose.total_residue() );
274 
275  Size start_res = 1;
276  Size end_res = pose.total_residue();
277 
278  if( chain_ > 0 ){
279  start_res = pose.conformation().chain_begin( chain_ );
280  end_res = pose.conformation().chain_end( chain_ );
281  }
282 
283  utility::vector1< Size > selected_residues;
284  for( Size iaa=start_res; iaa<= end_res ; iaa++ ) {
285 
286  char ss = secstruct.at( iaa-1 );
287  runtime_assert( ss == 'L' || ss =='E' || ss=='H' );
288  rsd_layer_[ iaa ] = "";
289 
290  if ( rsd_sasa_[ iaa ] <= burial_[ ss ] && pick_core_ ) {
291  selected_core_residues_.push_back( iaa );
292  selected_residues.push_back( iaa );
293 
295  output << "select " << iaa << std::endl;
296  output << "color blue " << std::endl;
297  }
298  rsd_layer_[ iaa ] = "core";
299 
300  } else if ( rsd_sasa_[ iaa ] >= surface_[ ss ] && pick_surface_ ) {
301  selected_surface_residues_.push_back( iaa );
302  selected_residues.push_back( iaa );
303 
305  output << "select " << iaa << std::endl;
306  output << "color red " << std::endl;
307  }
308  rsd_layer_[ iaa ] = "surface";
309 
310  } else if ( rsd_sasa_[ iaa ] < surface_[ ss ] && rsd_sasa_[ iaa ] > burial_[ ss ] && pick_boundary_ ) {
311  selected_boundary_residues_.push_back( iaa );
312  selected_residues.push_back( iaa );
313 
315  output << "select " << iaa << std::endl;
316  output << "color green " << std::endl;
317  }
318  rsd_layer_[ iaa ] = "boundary";
319  }
320  }
321 
322  return selected_residues;
323 
324 } // compute
325 
326 bool
328  bool is_part_of_this = false;
329  for( core::Size i = 1; i <= vec.size(); i++ )
330  if( i == pos ) is_part_of_this = true;
331  return is_part_of_this;
332 }
333 
334 void
336 
337  using namespace core::pack::task::operation;
338 
339  // separate bound partners if specified
341  if( (jump_ > 0) && (pose.conformation().num_chains() > 1) ) {
342  TR<<"translating along jump #"<<jump_<<std::endl;
344  translate->step_size( 1000.0 );
345  translate->apply( pose );
346  }
347 
348  // calc layers based on residue asa
349  utility::vector1< core::Size > selected_residues( compute( pose )) ;
350 
351  ///for some unfathomable reason OperateOnCertainResidues defaults to applying to all residues if none are defined, so you have to be careful here...
352  OperateOnCertainResidues oocr_repacking, oocr_prevent_repacking;
353 
354  utility::vector1 <core::Size > repacking_residues;
355  utility::vector1 <core::Size > norepack_residues;
356 
357  // since task operations are all about restricting and once a freedom has been restricted it cannot be regained. hence all negative here...
358  for (Size res = 1; res <= pose.total_residue() ; res++ ){
359  if ( !repack_rest_ ){
360  if (!is_part(selected_residues, res)) norepack_residues.push_back(res);
361  }
362  if ( design_ ){
363  if(!is_part(selected_residues, res)) repacking_residues.push_back(res);
364  }
365  }
366 
367  if( repacking_residues.size() ){
368  oocr_repacking.op( new RestrictToRepackingRLT );
369  oocr_repacking.residue_indices( repacking_residues );
370  oocr_repacking.apply( pose, task );
371  }
372  if( norepack_residues.size() ){
373  oocr_prevent_repacking.op( new PreventRepackingRLT );
374  oocr_prevent_repacking.residue_indices( norepack_residues );
375  oocr_prevent_repacking.apply( pose, task );
376  }
377 
378  // move back together
379  if( (jump_ > 0) && (pose.conformation().num_chains() > 1) ) {
380  translate->trans_axis().negate();
381  translate->apply( pose );
382  }
383 }
384 
385 
386 void
388 {
389  //use_original_ = tag->getOption< bool >( "use_original_non_designed_layer", 1 );
390 
391  String design_layers = tag->getOption< String >( "layer" );
392  utility::vector1< String > layers( utility::string_split( design_layers, '_' ) );
393 
394  design_ = tag->getOption< bool > ("design" , 1 );
395 
396  repack_rest_ = tag->getOption< bool >("repack_rest" , 1 );
397 
398  chain_ = tag->getOption< Size > ("chain", 0 );
399 
400  jump_ = tag->getOption< Size > ("jump", 0 );
401 
402  //if ( jump_ > 0 && pose.conformation().num_chains() == 1 )
403  // utility_exit_with_message("need at least two chains for jump > 0 ");
404 
405  for ( utility::vector1< String >::const_iterator iter = layers.begin(); iter != layers.end() ; ++iter) {
406  String layer(*iter);
407 
408  if ( layer == "core" ) {
409  dsgn_core = true;
410  } else if ( layer == "surface" ) {
411  dsgn_surface = true;
412  } else if ( layer == "boundary" ) {
413  dsgn_boundary = true;
414  } else {
415  TR << "Error! wrong specification of layer_mode " << layer << std::endl;
416  TR << "All layers are designed. " << std::endl;
417  dsgn_core = true;
418  dsgn_surface = true;
419  dsgn_boundary = true;
420  }
421  }
422 
423  srbl_->set_design_layer( dsgn_core, dsgn_boundary, dsgn_surface );
424 
425  if( tag->hasOption( "pore_radius" ) ) {
426  srbl_->pore_radius( tag->getOption< Real >( "pore_radius" ) );
427  }
428 
429  if( tag->hasOption( "core" ) ) {
430  srbl_->sasa_core( tag->getOption< Real >( "core" ) );
431  }
432  if( tag->hasOption( "surface" ) ) {
433  srbl_->sasa_surface( tag->getOption< Real >( "surface" ) );
434  }
435 
436  if( tag->hasOption( "core_E" ) ) {
437  srbl_->sasa_core( tag->getOption< Real >( "core_E" ), "E" );
438  }
439  if( tag->hasOption( "core_L" ) ) {
440  srbl_->sasa_core( tag->getOption< Real >( "core_L" ), "L" );
441  }
442  if( tag->hasOption( "core_H" ) ) {
443  srbl_->sasa_core( tag->getOption< Real >( "core_H" ), "H" );
444  }
445 
446  if( tag->hasOption( "surface_E" ) ) {
447  srbl_->sasa_surface( tag->getOption< Real >( "surface_E" ), "E" );
448  }
449  if( tag->hasOption( "surface_L" ) ) {
450  srbl_->sasa_surface( tag->getOption< Real >( "surface_L" ), "L" );
451  }
452  if( tag->hasOption( "surface_H" ) ) {
453  srbl_->sasa_surface( tag->getOption< Real >( "surface_H" ), "H" );
454  }
455 
456  if( tag->hasOption( "make_rasmol_script" ) ) {
457  srbl_->make_rasmol_format_file( tag->getOption< bool >( "make_rasmol_script" ) );
458  }
459 
460  //set_verbose( tag->getOption< bool >( "verbose", false ) );
461 
462 
463 }
464 
465 }
466 }
467 }