Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RestrictToNeighborhoodOperation.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/RestrictToNeighborhoodOperation.cc
11 /// @brief TaskOperation class that finds a neighborhood and leaves it mobile in the PackerTask
12 /// @author Steven Lewis smlewi@gmail.com
13 
14 // Unit Headers
17 
18 // Project Headers
19 #include <core/pose/Pose.hh>
20 
22 
24 
26 
27 // Utility Headers
28 #include <core/types.hh>
29 #include <utility/vector1_bool.hh>
30 #include <basic/Tracer.hh>
31 #include <utility/string_util.hh>
32 #include <utility/excn/Exceptions.hh>
33 
34 // C++ Headers
35 #include <set>
36 
37 using basic::Error;
38 using basic::Warning;
39 static basic::Tracer TR( "protocols.toolbox.TaskOperations.RestrictToNeighborhoodOperation" );
40 
41 namespace protocols {
42 namespace toolbox {
43 namespace task_operations {
44 
46 
47 ///@details this ctor assumes a pregenerated Neighborhood and Neighbors calculators - if you want a particular non-default cutoff distance, assemble those calculators separately then pass them to this operation.
49  : parent(), calculator_name_(calculator)
50 {
51  //I suppose you could reasonably create this object BEFORE the calculator was generated/registered
52 // if( !core::pose::metrics::CalculatorFactory::Instance().check_calculator_exists( calculator_name_ ) ){
53 // utility_exit_with_message("In RestrictToNeighborhoodOperation, calculator " + calculator + " does not exist.");
54 // }
55 }
56 
57 ///@details this ctor generates calculators (easier to use but will rely on defaults, including default distance cutoff)
58 RestrictToNeighborhoodOperation::RestrictToNeighborhoodOperation( std::set< core::Size > const & central_residues )
59  : parent(), calculator_name_("")
60 {
61  make_calculator( central_residues );
62 }
63 
64 RestrictToNeighborhoodOperation::RestrictToNeighborhoodOperation( std::set< core::Size > const & central_residues, core::Real const dist_cutoff )
65  : parent(), calculator_name_("")
66 {
67  make_calculator( central_residues, dist_cutoff );
68 }
69 
71 
72 ///@details be warned if you use clone that you'll not get a new interface calculator
74 {
75  return new RestrictToNeighborhoodOperation( *this );
76 }
77 
79  parent(rhs)
80 {
81  *this = rhs;
82 }
83 
84 ///@brief assignment operator
86  RestrictToNeighborhoodOperation const & rhs ){
87 
88  //abort self-assignment
89  if (this == &rhs) return *this;
90 
92 
93  return *this;
94 }
95 
96 ///@details private helper function to make calculator - runs in the ctor
98  std::set< core::Size > const & central_residues,
99  core::Real dist_cutoff
100 ) {
101  make_name( central_residues );
102 
103  using namespace core::pose::metrics;
104  if( CalculatorFactory::Instance().check_calculator_exists( calculator_name_ ) ){
105  Warning() << "In RestrictToNeighborhoodOperation, calculator " << calculator_name_
106  << " already exists, this is hopefully correct for your purposes" << std::endl;
107  } else {
109  CalculatorFactory::Instance().register_calculator( calculator_name_, new NeighborhoodByDistanceCalculator( central_residues, dist_cutoff ) );
110  }
111 }
112 
113 ///@details private helper function to make calculator - runs in the ctor
114 void RestrictToNeighborhoodOperation::make_calculator( std::set< core::Size > const & central_residues ) {
115  make_name( central_residues );
116 
117  using namespace core::pose::metrics;
118  if( CalculatorFactory::Instance().check_calculator_exists( calculator_name_ ) ){
119  Warning() << "In RestrictToNeighborhoodOperation, calculator " << calculator_name_
120  << " already exists, this is hopefully correct for your purposes" << std::endl;
121  } else {
123  CalculatorFactory::Instance().register_calculator( calculator_name_, new NeighborhoodByDistanceCalculator( central_residues ) );
124  }
125 }
126 
127 ///@details private helper function to name calculator- runs in the ctor
128 void RestrictToNeighborhoodOperation::make_name( std::set< core::Size > const & central_residues ) {
129  calculator_name_ = "RTNhO_calculator";
130 
131  for(SizeSet::const_iterator it(central_residues.begin()), end(central_residues.end()) ; it != end; ++it){
132  calculator_name_ += '_' + utility::to_string( *it );
133  }
134 
135 }
136 
137 void
139 {
140 
141  //vector for filling packertask
142  utility::vector1_bool repack(pose.total_residue(), false);
143 
144  //this is in the parent class, RestrictOperationsBase
145  run_calculator(pose, calculator_name_, "neighbors", repack);
146 
147  task.restrict_to_residues(repack);
148 
149  return;
150 }
151 
152 //utility function for get_central_residues and get_distance_cutoff
155  using namespace core::pose::metrics;
156  if( !CalculatorFactory::Instance().check_calculator_exists( calculator_name_ ) ){
157  throw utility::excn::EXCN_Msg_Exception("In RestrictToNeighborhoodOperation get_calculator, calculator " + calculator_name_ + " does not exist");
158  }
159 
162 
163  assert( dynamic_cast< NeighborhoodByDistanceCalculator const * > (CalculatorFactory::Instance().retrieve_calculator(calculator_name_).get()));
164 
166  static_cast< NeighborhoodByDistanceCalculator const * >
167  (CalculatorFactory::Instance().retrieve_calculator(calculator_name_).get()));
168 
169  return calculator;
170 }
171 
172 std::set< core::Size > const & RestrictToNeighborhoodOperation::get_central_residues() const {
173  return get_calculator()->central_residues();
174 }
175 
177  return get_calculator()->dist_cutoff();
178 }
179 
180 ///@brief reskin of normal make_calculator
182  SizeSet const & central_residues,
183  core::Real dist_cutoff )
184 {
185  make_calculator(central_residues, dist_cutoff);
186 }
187 
188 ///@brief reskin of normal make_calculator
190 {
191  make_calculator(central_residues);
192 }
193 
196 {
198 }
199 
200 } //namespace protocols
201 } //namespace toolbox
202 } //namespace task_operations