Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
DdgFilter.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/simple_filters/DdgFilter.cc
11 /// @brief
12 /// @author Sarel Fleishman (sarelf@u.washington.edu), Jacob Corn (jecorn@u.washington.edu)
13 
16 
21 #include <basic/Tracer.hh>
26 #include <core/pose/Pose.hh>
27 #include <core/pose/PDBInfo.hh>
28 #include <core/pose/util.hh>
31 #include <core/scoring/Energies.hh>
34 #include <utility/tag/Tag.hh>
35 #include <utility/string_util.hh>
36 #include <ObjexxFCL/FArray1D.hh>
37 #include <utility/excn/Exceptions.hh>
38 #include <ObjexxFCL/format.hh>
39 
40 namespace protocols {
41 namespace simple_filters {
42 
43 static basic::Tracer TR( "protocols.simple_filters.DdgFilter" );
44 
46 
49 
51 DdgFilterCreator::keyname() const { return "Ddg"; }
52 
53 
55  filters::Filter( "Ddg" ),
56  ddg_threshold_( -15.0 ),
57  scorefxn_( NULL ),
58  rb_jump_( 1 ),
59  use_custom_task_(false),
60  repack_bound_(true),
61  relax_bound_(false),
62  repeats_( 1 ),
63  symmetry_(false),
64  repack_( true ),
65  relax_mover_( NULL ),
66  pb_enabled_(false),
67  translate_by_(DEFAULT_TRANSLATION_DISTANCE)
68 {
69  scorename_ = "ddg";
70 }
71 
72 
73 DdgFilter::DdgFilter( core::Real const ddg_threshold,
75  core::Size const rb_jump/*=1*/,
76  core::Size const repeats/*=1*/,
77  bool const symmetry /*=false*/ ) :
78  Filter("Ddg" ),
79  ddg_threshold_(ddg_threshold),
80  scorefxn_(scorefxn->clone()),
81  rb_jump_(rb_jump),
82  use_custom_task_( false ),
83  repack_bound_( true ),
84  relax_bound_( false ),
85  repeats_(repeats),
86  symmetry_(symmetry),
87  repack_( true ),
88  relax_mover_( NULL ),
89  pb_enabled_(false),
90  translate_by_(DEFAULT_TRANSLATION_DISTANCE)
91 {
92  // Determine if this PB enabled.
93  if( scorefxn_->get_weight(core::scoring::PB_elec) != 0.) {
94  // Set this to PB enabled
95  pb_enabled_ = true;
96  TR << "PB enabled" << std::endl;
97  }
98  else{
99  pb_enabled_ = false;
100  }
101 }
102 
104 
106  return new DdgFilter( *this );
107 }
109  return new DdgFilter();
110 }
111 
112 void
113 DdgFilter::repack( bool const repack )
114 {
115  repack_ = repack;
116 }
117 
118 bool
120 {
121  return repack_;
122 }
123 
124 void
126  moves::DataMap & data,
127  filters::Filters_map const & ,
128  moves::Movers_map const & movers,
129  core::pose::Pose const & )
130 {
131  using namespace core::scoring;
132 
133  std::string const scorefxn_name( tag->getOption<std::string>( "scorefxn", "score12" ) );
134  scorefxn_ = new ScoreFunction( *(data.get< ScoreFunction * >( "scorefxns", scorefxn_name )) );
135  ddg_threshold_ = tag->getOption<core::Real>( "threshold", -15 );
136  rb_jump_ = tag->getOption< core::Size >( "jump", 1 );
137  repeats( tag->getOption< core::Size >( "repeats", 1 ) );
138  repack( tag->getOption< bool >( "repack", 1 ) );
139  symmetry_ = tag->getOption<bool>( "symmetry", 0 );
140  use_custom_task( tag->hasOption("task_operations") );
142  repack_bound( tag->getOption<bool>( "repack_bound", 1 ) );
143  relax_bound( tag->getOption<bool>( "relax_bound", 0 ) );
144  translate_by_ = tag->getOption<int>( "translate_by", DEFAULT_TRANSLATION_DISTANCE );
145 
146  if( tag->hasOption( "relax_mover" ) )
147  relax_mover( protocols::rosetta_scripts::parse_mover( tag->getOption< std::string >( "relax_mover" ), movers ) );
148 
149  if(tag->hasOption("chain_num"))
150  {
151  chain_ids_ = utility::string_split(tag->getOption<std::string>("chain_num"),',',core::Size());
152  }
153 
154  if( repeats() > 1 && !repack() )
155  throw utility::excn::EXCN_RosettaScriptsOption( "ERROR: it doesn't make sense to have repeats if repack is false, since the values converge very well." );
156 
157  if ( symmetry_ )
158  TR<<"ddg filter with threshold "<< ddg_threshold_<<" repeats="<<repeats()<<" and scorefxn "<<scorefxn_name<<" with symmetry " <<std::endl;
159  else
160  TR<<"ddg filter with threshold "<< ddg_threshold_<<" repeats="<<repeats()<<" and scorefxn "<<scorefxn_name<<" over jump "<<rb_jump_<<" and repack "<<repack()<<std::endl;
161 
162  // Determine if this PB enabled.
163  if( scorefxn_->get_weight(core::scoring::PB_elec) != 0.) {
164  // Set this to PB enabled
165  pb_enabled_ = true;
166  TR << "PB enabled. Translation distance = " << translate_by_ << " A" << std::endl;
168  TR.Warning << "Translation distance may be too large for PB-enabled scoring. Consider 100 (default) if you run out of memory: " << translate_by_ << std::endl;
169  TR.Warning.flush();
170  }
171  }
172  else{
173  pb_enabled_ = false;
174  }
175  TR.flush();
176 }
177 
178 void DdgFilter::parse_def( utility::lua::LuaObject const & def,
179  utility::lua::LuaObject const & score_fxns,
180  utility::lua::LuaObject const & /*tasks*/ ) {
181  using namespace core::scoring;
182  if( def["scorename"] )
183  scorename_ = def["scorename"].to<std::string>();
184  if( def["scorefxn"] ) {
185  scorefxn_ = protocols::elscripts::parse_scoredef( def["scorefxn"], score_fxns );
186  } else {
187  scorefxn_ = score_fxns["score12"].to<ScoreFunctionSP>()->clone();
188  }
189  ddg_threshold_ = def["threshold"] ? def["threshold"].to<core::Real>() : -15;
190  rb_jump_ = def["jump"] ? def["jump"].to<core::Size>() : 1;
191  repeats( def["repeats"] ? def["repeats"].to<core::Size>() : 1 );
192  repack( def["repack"] ? def["repack"].to<bool>() : true );
193  symmetry_ = def["symmetry"] ? def["symmetry"].to<bool>() : false;
194  repack_bound_ = def["repack_bound"] ? def["repack_bound"].to<bool>() : true;
195  relax_bound_ = def["relax_bound"] ? def["relax_bound"].to<bool>() : false;
196  translate_by_ = def["translate_by"] ? def["translate_by"].to<int>() : DEFAULT_TRANSLATION_DISTANCE;
197  // ignoring relax_mover option
198  if( def["chain_num"] ) {
199  chain_ids_.clear();
200  for (utility::lua::LuaIterator i=def["chain_num"].begin(), end; i != end; ++i) {
201  chain_ids_.push_back( (*i).to<core::Size>() );
202  }
203  }
204 
205  if( repeats() > 1 && !repack() )
206  utility_exit_with_message( "ERROR: it doesn't make sense to have repeats if repack is false, since the values converge very well." );
207 
208  if ( symmetry_ )
209  TR<<"ddg filter with threshold "<< ddg_threshold_<<" repeats="<<repeats()<<" with symmetry " <<std::endl;
210  else
211  TR<<"ddg filter with threshold "<< ddg_threshold_<<" repeats="<<repeats()<<" over jump "<<rb_jump_<<" and repack "<<repack()<<std::endl;
212 }
213 
214 bool
215 DdgFilter::apply( core::pose::Pose const & pose ) const
216 {
217  core::Real const pose_ddg( compute( pose ) );
218  TR<<"ddg is "<<pose_ddg<<" ";
219  if( pose_ddg <= ddg_threshold_ ) {
220  TR<<"passing"<<std::endl;
221  return true;
222  }
223  TR<<"failing"<<std::endl;
224  TR.flush();
225  return false;
226 }
227 
228 void
229 DdgFilter::report( std::ostream & out, core::pose::Pose const & pose ) const {
230  core::Real const pose_ddg( compute( pose ) );
231  out<<"ddg "<<pose_ddg<<'\n';
232 }
233 
235 DdgFilter::report_sm( core::pose::Pose const & pose ) const {
236  core::Real const pose_ddg( compute( pose ) );
237  return( pose_ddg );
238 }
239 
242 {
243  return( repeats_ );
244 }
245 
246 void
248 {
249  repeats_ = repeats;
250 }
251 
253 DdgFilter::compute( core::pose::Pose const & pose_in ) const {
254  core::pose::Pose pose(pose_in);
255  if( repack() ){
257  if ( use_custom_task() ) {
259  ddg.task_factory( task_factory() );
260  }
261  if ( repack_bound() ) {
262  ddg.repack_bound( repack_bound() );
263  }
264  if ( relax_bound() ) {
265  ddg.relax_bound( relax_bound() );
266  }
267  ddg.relax_mover( relax_mover() );
268  core::Real average( 0.0 );
269  for( core::Size i = 1; i<=repeats_; ++i ){
270  ddg.calculate( pose );
271  average += ddg.sum_ddG();
272  ddg.report_ddG( TR );
273  }
274  return average / (core::Real)repeats_;
275  } else {
276  if( repeats() > 1 && !repack() )
277  utility_exit_with_message( "ERROR: it doesn't make sense to have repeats if repack is false, since the values converge very well." );
278  using namespace protocols::moves;
279 
280  simple_filters::ScoreTypeFilter const stf( scorefxn_, core::scoring::total_score, 10000/*threshold*/ );
281  core::pose::Pose split_pose( pose );
282  if(chain_ids_.size() > 0)
283  {
284  //We want to translate each chain the same direction, though it doesnt matter much which one
285  core::Vector translation_axis(1,0,0);
286  for(utility::vector1<core::Size>::const_iterator chain_it = chain_ids_.begin(); chain_it != chain_ids_.end();++chain_it)
287  {
288  core::Size current_chain_id = *chain_it;
289  core::Size current_jump_id = core::pose::get_jump_id_from_chain_id(current_chain_id,split_pose);
290  rigid::RigidBodyTransMoverOP translate( new rigid::RigidBodyTransMover( split_pose, current_jump_id) );
291  translate->step_size( translate_by_ );
292  translate->trans_axis(translation_axis);
293  translate->apply( split_pose );
294  }
295  }else
296  {
298  translate->step_size( translate_by_ );
299  translate->apply( split_pose );
300  }
301 
302  core::Real const bound_energy( stf.compute( pose ));
303  core::Real const unbound_energy( stf.compute( split_pose ));
304  core::Real const dG( bound_energy - unbound_energy );
305  return( dG );
306  }
307 }
308 
309 void
311  relax_mover_ = m;
312 }
313 
316 
317 
318 }
319 }