Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RmsdFilter.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/filters/RmsdFilter.cc
11 /// @brief rmsd filtering
12 /// @author Jacob Corn (jecorn@u.washington.edu)
16 
17 // Project Headers
18 #include <core/types.hh>
19 #include <core/pose/Pose.hh>
22 #include <utility/tag/Tag.hh>
23 // AUTO-REMOVED #include <protocols/moves/DataMap.hh>
24 #include <protocols/moves/Mover.fwd.hh> //Movers_map
25 #include <core/pose/PDBInfo.hh>
26 
27 #include <core/scoring/rms_util.hh>
30 #include <core/pose/selection.hh>
31 #include <basic/options/option.hh>
32 #include <basic/options/keys/in.OptionKeys.gen.hh>
33 // AUTO-REMOVED #include <core/io/pdb/pose_io.hh>
35 
36 #include <core/id/AtomID.hh>
37 #include <core/id/AtomID_Map.hh>
38 #include <ObjexxFCL/FArray1D.hh>
39 
40 #include <algorithm>
41 #include <list>
42 
43 #include <utility/vector0.hh>
44 #include <utility/vector1.hh>
45 #include <basic/Tracer.hh>
46 
47 namespace protocols {
48 namespace protein_interface_design {
49 namespace filters {
50 
52  protocols::filters::Filter( "Rmsd" ),
53  superimpose_( true ),
54  symmetry_( false ),
55  threshold_( 5.0 ),
56  reference_pose_( NULL ),
57  selection_from_segment_cache_(false),
58  superimpose_on_all_( false )
59 {
60  selection_.clear();
61 }
62 
64  std::list<core::Size> const selection,
65  bool const superimpose,
66  core::Real const threshold,
67  core::pose::PoseOP reference_pose
68 ) : protocols::filters::Filter( "Rmsd" ),
69  selection_(selection),
70  superimpose_(superimpose),
71  threshold_(threshold),
72  reference_pose_(reference_pose),
73  selection_from_segment_cache_(false)
74 {}
75 
76 
78 
81  return new RmsdFilter( *this );
82 }
83 
84 static basic::Tracer TR( "protocols.protein_interface_design.filters.RmsdFilter" );
87 {
88  using namespace core;
89  using namespace core::scoring;
90  core::pose::Pose copy_pose = pose;
92  core::Real rmsd( 0.0 );
93 
94  if ( !symmetry_ )
95  runtime_assert_msg( copy_pose.total_residue() == native.total_residue(), "the reference pose must be the same size as the working pose" );
96 
97  // generate temporary FArray
98  FArray1D_bool selection_array( pose.total_residue(), false ); // on which residues to check rmsd
99  FArray1D_bool superimpose_array( pose.total_residue(), false ); // which residues to superimpose
100 
103  else {
104  if( selection_.size() && superimpose_on_all() ){
106  }
107  for( std::list<core::Size>::const_iterator it = selection_.begin(); it!=selection_.end(); ++it ) {
108  selection_array[*it-1] = true; // FArray1D is 0 indexed
109  superimpose_array[*it-1] = true;
110  }
111  }
112 
113  if( superimpose_ && !superimpose_on_all() ) {
114  if ( symmetry_ ) // SJF I haven't changed symmetry selection_array b/c I don't know which tests to use
115  rmsd = sym_rmsd_with_super_subset( copy_pose, native, selection_array, core::scoring::is_protein_CA );
116  else
117  rmsd = rmsd_with_super_subset( copy_pose, native, superimpose_array, core::scoring::is_protein_CA );
118  }else if( superimpose_ && superimpose_on_all() ){
119  calpha_superimpose_pose( copy_pose, native );
120  rmsd = core::scoring::rmsd_no_super_subset( copy_pose, native, selection_array, core::scoring::is_protein_CA );
121  } else {
122  rmsd = core::scoring::rmsd_no_super_subset( copy_pose, native, selection_array, core::scoring::is_protein_CA );
123  }
124  return rmsd;
125 }
126 
127 bool
128 RmsdFilter::apply( core::pose::Pose const & pose ) const {
129 
130  core::Real const rmsd( compute( pose ));
131  TR << "RMSD over selected residues: " << rmsd ;
132  if( rmsd <= threshold_ )
133  {
134  TR<<" passing."<<std::endl;
135  return( true );
136  }
137  else TR<<" failing." << std::endl;
138  return( false );
139 }
140 
141 void
142 RmsdFilter::report( std::ostream & out, core::pose::Pose const & pose ) const {
143  core::Real const rmsd( compute( pose ));
144  out<<"RMSD: " << rmsd<<'\n';
145 }
146 
149  core::Real const rmsd( compute( pose ));
150  return( (core::Real) rmsd );
151 }
152 
153 void
155 {
156  /// @details
157  ///if the save pose mover has been instantiated, this filter can calculate the rms
158  ///against the ref pose
159  if( tag->hasOption("reference_name") ){
161  }
162  else{
163  reference_pose_ = new core::pose::Pose( reference_pose );
164  if ( basic::options::option[ basic::options::OptionKeys::in::file::native ].user() )
165  core::import_pose::pose_from_pdb( *reference_pose_, basic::options::option[ basic::options::OptionKeys::in::file::native ] );
166  }
167 
168  symmetry_ = tag->getOption<bool>( "symmetry", 0 );
169  std::string chains = tag->getOption<std::string>( "chains", "" );
170  superimpose_on_all( tag->getOption< bool >( "superimpose_on_all", false ) );
171  if( chains != "" ) {
172  core::Size chain_start( 0 );
173  core::Size chain_end( 0 );
174 
175  utility::vector1<core::Size> chain_ends = reference_pose_->conformation().chain_endings();
176  chain_ends.push_back( reference_pose_->total_residue() ); // chain_endings() doesn't count last residue as a chain ending (sigh)
177  for( std::string::const_iterator chain_it = chains.begin(); chain_it != chains.end(); ++chain_it ) { // for each chain letter
178  char const chain = *chain_it;
179  TR.Debug << "Chain " << chain << " selected" << std::endl;
180  for( utility::vector1<core::Size>::const_iterator it = chain_ends.begin(); it != chain_ends.end(); ++it ) {
181  chain_end = *it;
182  core::Size const chainid = reference_pose.residue( chain_end ).chain();
183  if( reference_pose_->pdb_info()->chain( chain_end ) == chain ) { // if chain letter of chain_end == chain specified
184  if( chain_end == reference_pose_->total_residue() ) { // all of this because the last residue doesn't count as a chain ending. why, god, why!?
185  //core::Size const chainid = reference_pose_.residue( chain_end ).chain();
186  for( core::Size i = 1; i <= reference_pose_->total_residue(); ++i ) {
187  if( (core::Size)reference_pose_->residue(i).chain() == chainid ) { // first time we hit this, we're at the start of the chain in question
188  chain_start = i;
189  break;
190  }
191  }
192  }
193  else chain_start = reference_pose_->conformation().chain_begin( chainid );
194  for( core::Size i = chain_start; i <= chain_end; ++i ) { // populate selection_ list
195  selection_.push_back( i );
196  }
197  }
198  }
199  }
200  }
201 
202  utility::vector0< utility::tag::TagPtr > const rmsd_tags( tag->getTags() );
203  for( utility::vector0< utility::tag::TagPtr >::const_iterator it=rmsd_tags.begin(); it!=rmsd_tags.end(); ++it ) {
204  utility::tag::TagPtr const rmsd_tag = *it;
205  if( rmsd_tag->getName() == "residue" ) {
206  core::Size const resnum( core::pose::get_resnum( rmsd_tag, *reference_pose_ ) );
207  selection_.push_back( resnum );
208  }
209  if( rmsd_tag->getName() == "span" ) {
210  core::Size const begin( core::pose::get_resnum( rmsd_tag, *reference_pose_, "begin_" ) );
211  core::Size const end( core::pose::get_resnum( rmsd_tag, *reference_pose_, "end_" ) );
212  runtime_assert( end > begin );
213  runtime_assert( begin>=1);
214  runtime_assert( end<=reference_pose_->total_residue() );
215  for( core::Size i=begin; i<=end; ++i ) selection_.push_back( i );
216  }
217  }
218 
219  if( selection_.size() > 0 ) selection_.unique(); // make sure our selection list doesn't have redudancies
220  TR.Debug << "RMSD selected residues: ";
221  if( selection_.size() == 0 ) TR.Debug << "ALL" << std::endl;
222  else {
223  for( std::list<core::Size>::const_iterator it = selection_.begin(); it != selection_.end(); ++it ) {
224  TR.Debug << *it << " ";
225  }
226  }
227  TR.Debug << std::endl;
228 
229  superimpose_ = tag->getOption<bool>( "superimpose", 1 );
230  threshold_ = tag->getOption<core::Real>( "threshold", 5 );
231  if( tag->hasOption("rms_residues_from_pose_cache") ){
232  selection_from_segment_cache_ = tag->getOption<bool>( "rms_residues_from_pose_cache", 1 );
233  if( selection_.size() != 0 ) std::cerr << "Warning: in rmsd filter tag, both a span selection and the instruction to set the residues from the pose cache is given. Incompatible, defined span will be ignored." << std::endl;
234  }
235 
236  TR<<"RMSD filter with superimpose=" << superimpose_ << " and threshold="<< threshold_ << " over residues ";
237  if( superimpose_on_all() )
238  TR<<" superimpose_on_all set to true. Any spans defined will be used only to measure RMSd but the pose will be supreimposed on the reference pose through all residues ";
239  if( selection_from_segment_cache_ ) TR << " that are in pose segment observer cache at apply time." << std::endl;
240  else if( selection_.size() == 0 ) {
241  TR << "ALL" << std::endl;
242  for( core::Size i=1; i<=reference_pose.total_residue(); ++i ) selection_.push_back( i );
243  }
244  else {
245  for( std::list<core::Size>::const_iterator it=selection_.begin(); it != selection_.end(); ++it ) TR << *it << " ";
246  TR << std::endl;
247  }
248 }
249 
252 
254 RmsdFilterCreator::keyname() const { return "Rmsd"; }
255 
256 
257 } // filters
258 } // protein_interface_design
259 } // devel
260 
261