Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RandomMutation.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/protein_interface_design/movers/RandomMutation.cc
11 /// @brief
12 /// @author Sarel Fleishman (sarelf@u.washington.edu), Jacob Corn (jecorn@u.washington.edu)
13 
14 // Unit headers
21 // Package headers
22 #include <core/pose/Pose.hh>
23 // AUTO-REMOVED #include <core/conformation/Conformation.hh>
26 #include <basic/Tracer.hh>
28 // AUTO-REMOVED #include <core/pack/task/operation/TaskOperations.hh>
29 #include <utility/tag/Tag.hh>
30 #include <numeric/random/random.hh>
32 #include <utility/vector1.hh>
34 #include <protocols/moves/Mover.hh>
36 #include <boost/foreach.hpp>
37 
38 #include <utility/vector0.hh>
39 
40 //Auto Headers
42 #include <core/kinematics/Jump.hh>
43 
44 
45 #define foreach BOOST_FOREACH
46 
47 namespace protocols {
48 namespace protein_interface_design {
49 namespace movers {
50 
51 using namespace std;
52 using namespace core::scoring;
53 
54 static basic::Tracer TR( "protocols.protein_interface_design.movers.RandomMutation" );
55 static numeric::random::RandomGenerator RG( 2111918 );
56 
59 {
61 }
62 
65  return new RandomMutation;
66 }
67 
70 {
71  return "RandomMutation";
72 }
73 
75  Mover( RandomMutationCreator::mover_name() ),
76  task_factory_( NULL ),
77  scorefxn_( NULL )
78 {
79 }
80 
81 
83 
84 void
86 {
87  using namespace core::pack::task;
88  using namespace core::pack::task::operation;
89  using namespace core::chemical;
90 
91  PackerTaskCOP task;
92  if ( cache_task_ && task_ ) {
93  if( pose.total_residue() == task_->total_residue() ) {
94  task = task_;
95  } else {
96  task_ = 0; // Invalidate cached task.
97  }
98  }
99  if ( ! task ) {
100  task = task_factory()->create_task_and_apply_taskoperations( pose );
101  }
102  if ( cache_task_ && !task_ ) {
103  task_ = task;
104  }
105 
106  utility::vector1< core::Size > being_designed;
107  being_designed.clear();
108 
109  for( core::Size resi = 1; resi <= pose.total_residue(); ++resi ){
110  if( task->residue_task( resi ).being_designed() && pose.residue(resi).is_protein() )
111  being_designed.push_back( resi );
112  }
113  if( being_designed.empty() ) {
114  TR.Warning << "WARNING: No residues are listed as designable." << std::endl;
115  return;
116  }
117  core::Size const random_entry = being_designed[ (core::Size) floor( RG.uniform() * being_designed.size() )+1 ];
118  typedef list< ResidueTypeCOP > ResidueTypeCOPList;
119  ResidueTypeCOPList const & allowed( task->residue_task( random_entry ).allowed_residue_types() );
120  utility::vector1< AA > allow_temp;
121  allow_temp.clear();
122  foreach( ResidueTypeCOP const t, allowed ){
123  if( t->aa() != pose.residue( random_entry ).aa() )
124  allow_temp.push_back( t->aa() );
125  }
126 
127  AA const target_aa( allow_temp[ (core::Size) floor( RG.uniform() * allow_temp.size() ) + 1 ] );
128  utility::vector1< bool > allowed_aas;
129  allowed_aas.clear();
130  allowed_aas.assign( num_canonical_aas, false );
131  allowed_aas[ target_aa ] = true;
132  //PackerTaskOP mutate_residue = task_factory()->create_task_and_apply_taskoperations( pose );
133  PackerTaskOP mutate_residue( task->clone() );
134  mutate_residue->initialize_from_command_line().or_include_current( true );
135  for( core::Size resi = 1; resi <= pose.total_residue(); ++resi ){
136  if( resi != random_entry )
137  mutate_residue->nonconst_residue_task( resi ).restrict_to_repacking();
138  else
139  mutate_residue->nonconst_residue_task( resi ).restrict_absent_canonical_aas( allowed_aas );
140  }
141  TR<<"Mutating residue "<<pose.residue( random_entry ).name3()<<random_entry<<" to ";
145  else
146  pack = new protocols::simple_moves::PackRotamersMover( scorefxn(), mutate_residue );
147  pack->apply( pose );
148  TR<<pose.residue( random_entry ).name3()<<std::endl;
149  (*scorefxn())(pose);
150 }
151 
155 }
156 
157 void
159 {
161  std::string const scorefxn = tag->getOption< std::string >( "scorefxn", "score12" );
162  scorefxn_ = new core::scoring::ScoreFunction( *data.get< ScoreFunction * >( "scorefxns", scorefxn ) );
163  cache_task_ = tag->getOption< bool >( "cache_task", false );
164 }
165 
168  return( protocols::moves::MoverOP( new RandomMutation( *this ) ));
169 }
170 
173  return scorefxn_;
174 }
175 
176 void
178 {
180 }
181 
184  return( task_factory_ );
185 }
186 
187 void
190 }
191 
193  return( cache_task_ );
194 }
195 
196 void RandomMutation::cache_task( bool cache ) {
197  cache_task_ = cache;
198 }
199 
200 } //movers
201 } //protein_interface_design
202 } //protocols