Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SequenceRecoveryFilter.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 sw=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 /// @author Sarel Fleishman (sarelf@uw.edu)
13 #include <core/pose/Pose.hh>
14 #include <utility/tag/Tag.hh>
16 // AUTO-REMOVED #include <protocols/moves/Mover.hh>
17 // AUTO-REMOVED #include <protocols/moves/DataMap.hh>
18 #include <basic/Tracer.hh>
24 #include <basic/options/option.hh>
25 #include <basic/options/keys/in.OptionKeys.gen.hh>
30 #include <protocols/jd2/Job.hh>
32 #include <ObjexxFCL/format.hh>
33 // AUTO-REMOVED #include <core/io/pdb/pose_io.hh>
35 #include <core/pose/util.hh>
36 #include <utility/vector0.hh>
37 #include <utility/vector1.hh>
38 
39 namespace protocols {
40 namespace protein_interface_design{
41 namespace filters {
42 
43 static basic::Tracer TR( "protocols.protein_interface_design.filters.SequenceRecoveryFilter" );
44 
45 ///@brief default ctor
47  parent( "SequenceRecovery" ),
48  task_factory_( NULL ),
49  reference_pose_( NULL ),
50  rate_threshold_( 0.0 ),
51  mutation_threshold_( 100 ),
52  mutations_( 0 ),
53  verbose_( 0 )
54 {}
55 
58 {
59  return task_factory_;
60 }
61 
62 void
64 {
66 }
67 
70 {
71  return( rate_threshold_ );
72 }
73 
74 void
76 {
77  runtime_assert( rate_threshold_ >= 0 && rate_threshold_ <= 1.0 );
78  rate_threshold_ = rate;
79 }
80 
83 {
84  return reference_pose_;
85 }
86 
87 void
89 {
90  reference_pose_ = pose;
91 }
92 
93 void
95 {
96  reference_pose_ = new core::pose::Pose( pose );
97 }
98 
101 {
102  return( mutation_threshold_ );
103 }
104 
105 void
107 {
108  mutation_threshold_ = mut;
109 }
110 
111 bool
113 {
114  return( mutations_ );
115 }
116 
117 void
119 {
120  mutations_ = muts;
121 }
122 
123 bool
125 {
126  return( verbose_ );
127 }
128 
129 void
131 {
132  verbose_ = verb;
133 }
134 
135 bool
137 {
138  return( write2pdb_ );
139 }
140 
141 void
143 {
144  write2pdb_ = write;
145 }
146 
147 bool
149 {
150  if ( mutations_ ) {
151  core::Size const num_mutations( (core::Size) compute( pose, false ) );
152  TR<<"The designed pose possesses "<<num_mutations<<" compared to the reference pose. ";
153  if( num_mutations <= mutation_threshold_ ){
154  TR<<"Success."<<std::endl;
155  return true;
156  } else {
157  TR<<"Failing."<<std::endl;
158  return false;
159  }
160  } else {
161  core::Real const recovery_rate( compute( pose, false ) );
162  TR<<"Sequence recovery rate evaluates to "<<recovery_rate<<". ";
163  if( recovery_rate <= rate_threshold_ ){
164  TR<<"Failing."<<std::endl;
165  return false;
166  } else {
167  TR<<"Success."<<std::endl;
168  return true;
169  }
170  }
171 }
173  if( pmap["reference"]->size() == 1 )
174  reference_pose( *(*pmap["reference"])[0] );
175  Filter::apply( pmap );
176 }
177 
179 SequenceRecoveryFilter::compute( core::pose::Pose const & pose, bool const & write ) const{
180  runtime_assert( task_factory() );
181  runtime_assert( reference_pose() );
182  core::Size total_residue_ref;
183  core::pose::Pose asym_ref_pose;
184  //core::scoring::ScoreFunctionOP score12 = core::scoring::ScoreFunctionFactory::create_score_function("standard", "score12");
187  //(*score12)(asym_ref_pose);
188  for (core::Size i = 1; i <= asym_ref_pose.total_residue(); ++i) {
189  if (asym_ref_pose.residue_type(i).name() == "VRT") {
190  asym_ref_pose.conformation().delete_residue_slow(asym_ref_pose.total_residue());
191  }
192  }
193  total_residue_ref = asym_ref_pose.total_residue();
194  } else {
195  total_residue_ref = reference_pose()->total_residue();
196  asym_ref_pose = *reference_pose();
197  }
198  core::Size total_residue;
199  core::pose::Pose asym_pose;
200  if (core::pose::symmetry::is_symmetric( pose )) {
202  //(*score12)(asym_pose);
203  for (core::Size i = 1; i <= asym_pose.total_residue(); ++i) {
204  if (asym_pose.residue_type(i).name() == "VRT") {
205  asym_pose.conformation().delete_residue_slow(asym_pose.total_residue());
206  }
207  }
208  total_residue = asym_pose.total_residue();
209  } else {
210  total_residue = pose.total_residue();
211  asym_pose = pose;
212  }
213  if( total_residue_ref != total_residue )
214  utility_exit_with_message( "Reference pose and current pose have a different number of residues" );
215  core::pack::task::PackerTaskOP packer_task( task_factory_->create_task_and_apply_taskoperations( pose ) );
216  core::Size designable_count( 0 );
217  core::Size packable_count( 0 );
218  for( core::Size resi=1; resi<=total_residue; ++resi ) {
219  if( packer_task->being_designed( resi ) ) {
220  designable_count++;
221  }
222  if( packer_task->being_packed( resi ) ) {
223  packable_count++;
224  }
225  }
226  if( !designable_count ) {
227  TR<<"Warning: No designable residues identified in pose. Are you sure you have set the correct task operations?"<<std::endl;
228  if( !packable_count ) {
229  utility_exit_with_message("No designable or packable residues identified in pose. Are you sure you have set the correct task operations?" );
230  }
231  }
232  using namespace core::scoring;
234  rsd.calculate( asym_ref_pose, asym_pose );
235  std::map< core::Size, std::string > const res_names1( rsd.res_name1() );
236  std::map< core::Size, std::string > const res_names2( rsd.res_name2() );
237  core::Size const mutated( res_names1.size() );
238  core::Real const rate( 1.0 - (core::Real) mutated / designable_count );
239  TR<<"Your design mover mutated "<<mutated<<" positions out of "<<designable_count<<" designable positions. Sequence recovery is: "<<rate<<std::endl;
240  if ( verbose_ ) {
241  rsd.report( TR );
242  TR.flush();
243  }
244  if ( write ) {
245  write_to_pdb( res_names1, res_names2 );
246  }
247  if ( mutations_ ) {
248  return( (core::Real) mutated );
249  } else {
250  return( rate );
251  }
252 }
253 
254 /// @brief Add each mutation to the output pdb if desired
255 void
256 SequenceRecoveryFilter::write_to_pdb( std::map< core::Size, std::string > const & res_names1, std::map< core::Size, std::string > const & res_names2 ) const {
257 
259  std::string user_name = this->get_user_defined_name();
260  std::map< Size, std::string >::const_iterator it_name1 = res_names1.begin();
261  std::map< Size, std::string >::const_iterator it_name2 = res_names2.begin();
262  while( it_name1 != res_names1.end() ) {
263  std::string output_string = "SequenceRecoveryFilter " + user_name + ": " + it_name2->second + ObjexxFCL::string_of( it_name1->first ) + it_name1->second;
264  job->add_string( output_string );
265  ++it_name1; ++it_name2;
266  }
267 
268 }
269 
272 {
273  return( compute( pose, write2pdb() ) );
274 }
275 
276 void
277 SequenceRecoveryFilter::report( std::ostream & out, core::pose::Pose const & pose ) const
278 {
279  out<<"SequenceRecoveryFilter returns "<<compute( pose, false )<<std::endl;
280 }
281 
282 void
287  core::pose::Pose const & pose )
288 {
289  TR << "SequenceRecoveryFilter"<<std::endl;
291  rate_threshold( tag->getOption< core::Real >( "rate_threshold", 0.0 ) );
292  mutation_threshold( tag->getOption< core::Size >( "mutation_threshold", 100 ) );
293  mutations( tag->getOption< bool >( "report_mutations", 0 ) );
294  verbose( tag->getOption< bool >( "verbose", 0 ) );
295  write2pdb( tag->getOption< bool >( "write2pdb", 0 ) );
296 
297  using namespace basic::options;
298  using namespace basic::options::OptionKeys;
299 
300  if( option[ in::file::native ].user() ){
301  std::string const reference_pdb = option[ in::file::native ]();
302  core::pose::PoseOP temp_pose( new core::pose::Pose );
303  core::import_pose::pose_from_pdb( *temp_pose, reference_pdb );
304  reference_pose( temp_pose );
305  TR<<"Using native pdb "<<reference_pdb<<" as reference.";
306  }
307  else{
308  TR<<"Using starting pdb as reference. You could use -in::file::native to specify a different pdb for reference";
309  reference_pose( pose );
310  }
311  TR<<std::endl;
312 }
313 
314 void SequenceRecoveryFilter::parse_def( utility::lua::LuaObject const & def,
315  utility::lua::LuaObject const & ,
316  utility::lua::LuaObject const & tasks ) {
317  TR << "SequenceRecoveryFilter"<<std::endl;
318  task_factory( protocols::elscripts::parse_taskdef( def["tasks"], tasks ));
319  rate_threshold( def["rate_threshold"] ? def["rate_threshold"].to<core::Real>() : 0.0 );
320  mutation_threshold( def["mutation_threshold"] ? def["mutation_threshold"].to<core::Size>() : 100 );
321  mutations( def["report_mutations"] ? def["report_mutations"].to<bool>() : false );
322  verbose( def["verbose"] ? def["verbose"].to<bool>() : false );
323  write2pdb( def["write2pdb"] ? def["write2pdb"].to<bool>() : false );
324 
325  using namespace basic::options;
326  using namespace basic::options::OptionKeys;
327 
328  if( option[ in::file::native ].user() ){
329  std::string const reference_pdb = option[ in::file::native ]();
330  core::pose::PoseOP temp_pose( new core::pose::Pose );
331  core::import_pose::pose_from_pdb( *temp_pose, reference_pdb );
332  reference_pose( temp_pose );
333  TR<<"Using native pdb "<<reference_pdb<<" as reference.";
334  }
335  TR<<std::endl;
336 }
339  return new SequenceRecoveryFilter();
340 }
341 
343 
344 
347  return new SequenceRecoveryFilter( *this );
348 }
349 
352 
354 SequenceRecoveryFilterCreator::keyname() const { return "SequenceRecovery"; }
355 
356 
357 } // filters
358 } // protein_interface_design
359 } // protocols