Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RmsdEvaluatorCreator.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/RmsdEvaluatorCreator.hh
11 /// @brief Header for RmsdEvaluatorCreator
12 /// @author Matthew O'Meara
13 
14 // Unit Headers
16 
17 // Package Headers
19 
20 // Package Headers
24 
25 #include <protocols/loops/Loop.hh>
26 #include <protocols/loops/Loops.hh>
28 
30 #include <core/pose/Pose.hh>
31 
32 // ObjexxFCL Headers
33 #include <ObjexxFCL/string.functions.hh>
34 
35 // Utility headers
36 #include <utility/pointer/ReferenceCount.hh>
37 #include <utility/vector1.hh>
38 #include <utility/string_util.hh>
39 #include <utility/file/FileName.hh>
40 
41 #include <basic/options/option.hh>
42 #include <basic/Tracer.hh>
43 
44 // due to template function
46 
47 
48 // option key includes
49 #include <basic/options/option_macros.hh>
50 #include <basic/options/keys/evaluation.OptionKeys.gen.hh>
51 #include <basic/options/keys/in.OptionKeys.gen.hh>
53 #include <utility/vector0.hh>
54 
55 
56 #ifdef WIN32
58 #endif
59 
60 
61 static basic::Tracer tr("protocols.evaluation.RmsdEvaluatorCreator");
62 
63 namespace protocols {
64 namespace simple_filters {
65 
67 
69  using namespace basic::options;
70  if ( options_registered_ ) return;
71  options_registered_ = true;
72 
73  OPT( evaluation::rmsd );
74  OPT( evaluation::gdtmm );
75  OPT( in::file::native );
76 
77 }
78 
80  using namespace core;
81  using namespace basic::options;
82  using namespace basic::options::OptionKeys;
83 
84  if ( option[ OptionKeys::evaluation::rmsd ].user() ) {
85 
86  core::pose::PoseOP native_pose = NULL;
87  if ( option[ in::file::native ].user() ) {
88  native_pose = new core::pose::Pose;
89  core::import_pose::pose_from_pdb( *native_pose, option[ in::file::native ]() );
90  }
91 
92  typedef utility::vector1< std::string > RmsdVector;
93  RmsdVector const& rmsd( option[ OptionKeys::evaluation::rmsd ]() );
94 
95  //the ultimate in RMSD technology:
96  //you can have any number of tripletts:
97  // each triplett contains the
98  // target: file or special tags: NATIVE (use in:file:native ) IRMS (use structure in Job object)
99  /// columnname: XXX creates: rms_XXX gdtmm_XXX
100  /// selection: file or special tag: FULL
101  /// modifier: EXCLUDE ( take the inverse of the selection )
102  /// INLINE r1 r2 r3 ... rm END_INLINE -- select residues r1, r2, r3, ..., rm
103  for ( RmsdVector::const_iterator it=rmsd.begin(); it!=rmsd.end(); ++it ) {
104  core::pose::PoseOP target_pose = NULL;
105  std::string fname( *it );
106  std::string column;
107  std::string selection_file;
108  bool CA( true );
109  bool invert( false );
110  bool loop_rms( false );
111  bool superimpose_for_looprms( false );
112  ++it;
113  loops::Loops core;
114  while ( it != rmsd.end() && (*it).find('=')!=std::string::npos ) {
115  Size pos( it->find('=') );
116  std::string key=it->substr(0,pos);
117  std::string value=it->substr(pos+1);
118  if ( key=="heavy" && value=="yes" ) {
119  tr.Info << "switching to full-atom RMSD " << std::endl;
120  CA=false;
121  } else if ( key == "loop") {
122  loop_rms = true;
123  } else if ( key == "superimpose") {
124  superimpose_for_looprms = (value=="yes");
125  } else if ( key == "core" ) {
126  std::ifstream is( value.c_str() );
127 
128  if (!is.good()) {
129  utility_exit_with_message( "[ERROR] Error opening RBSeg file '" + value + "'" );
130  }
133  loops::SerializedLoopList loops = reader.read_pose_numbered_loops_file(is, value, false );
134  core = loops::Loops( loops );
135  } else {
136  utility_exit_with_message( "key not recognized: "+key+" possible keys: { heavy }" );
137  }
138  tr.Info << "detected option: " << key << " : " << value << std::endl;
139  ++it;
140  }
141  if ( it != rmsd.end() ) {
142  column = *it;
143  } else {
144  utility_exit_with_message(
145  "need to specify tripletts <target> [key/value pairs] <column> <selection/FULL> with option -evaluation:rmsd last read: "+fname );
146  }
147  ++it;
148  if ( it != rmsd.end() ) {
149  selection_file = *it;
150  } else {
151  utility_exit_with_message(
152  "need to specify tripletts <target> <column> <selection/FULL> with option -evaluation:rmsd last read: "+column );
153  }
154  if ( fname == "NATIVE" ) target_pose = native_pose;
155  else if ( fname != "IRMS" ) {
156  target_pose = new pose::Pose;
157  core::import_pose::pose_from_pdb( *target_pose, fname );
158  }
159 
160  if ( selection_file == "EXCLUDE" ) {
161  invert = true;
162  ++it;
163  if ( it != rmsd.end() ) {
164  selection_file = *it; //read next tag
165  } else {
166  utility_exit_with_message(
167  "need to specify a <selection/FULL> after 'EXCLUDE' with option -evaluation:rmsd last read: "+column );
168  }
169  }
170  loops::Loops loops;
171  utility::vector1< Size> selection; //figure out selection
172  if ( selection_file == "INLINE" ) {
173  std::string next_tag( "" );
174  ++it;
175  if ( it != rmsd.end() ) {
176  next_tag = *it;
177  } else {
178  utility_exit_with_message(
179  "need to find END_INLINE after INLINE in option -evaluation:rmsd last read: "+column );
180  } //error condition
181  while( next_tag != "END_INLINE" ) {
182  selection.push_back( utility::string2int( next_tag ) );
183  ++it;
184  if ( it != rmsd.end() ) {
185  next_tag = *it;
186  } else {
187  utility_exit_with_message(
188  "need to find END_INLINE after INLINE in option -evaluation:rmsd last read: "+column );
189  } //error condition
190  }
191  } else if ( selection_file != "FULL" ) {
192  std::ifstream is( selection_file.c_str() );
193 
194  if (!is.good()) {
195  utility_exit_with_message( "[ERROR] Error opening RBSeg file '" + selection_file + "'" );
196  }
197  loops::SerializedLoopList list_of_loops;
198  if ( loop_rms ) {
200  list_of_loops = reader.read_pose_numbered_loops_file(is, selection_file, false );
201  loops = loops::Loops( list_of_loops );
202  } else {
205  list_of_loops = reader.read_pose_numbered_loops_file(is, selection_file, false );
206  loops::Loops core = loops::Loops( list_of_loops );
207  core.get_residues( selection );
208  }
209  }
210  if ( invert ) {
211  utility::vector1< Size > inverted_selection;
212  for ( Size i = 1; i<=target_pose->total_residue(); ++i) {
213  bool found( false );
214  for ( Size j = 1; j<=selection.size() && !found; ++j ) {
215  if ( selection[ j ]==i ) {
216  found = true;
217  }
218  }
219  if ( !found) inverted_selection.push_back( i );
220  }
221  selection = inverted_selection;
222  }
223  if ( selection_file != "FULL" ) {
224  if ( !loop_rms ) {
225  eval.add_evaluation( new simple_filters::SelectRmsdEvaluator( target_pose, selection, column, CA ) );
226  } else {
227  eval.add_evaluation( new simple_filters::LoopRmsdEvaluator( target_pose, loops, core, column, CA, superimpose_for_looprms ) );
228  }
229  if ( option[ OptionKeys::evaluation::gdtmm ]() ) {
230  eval.add_evaluation( new simple_filters::SelectGdtEvaluator( target_pose, selection, column) );
231  }
232  } else {
233  eval.add_evaluation( new simple_filters::SelectRmsdEvaluator( target_pose, column, CA ) );
234  if ( option[ OptionKeys::evaluation::gdtmm ]() ) {
235  eval.add_evaluation( new simple_filters::SelectGdtEvaluator( target_pose, column ) );
236  }
237  } // no selection
238  } // iterate over tripletts in option -rmsd
239  } // option -rmsd
240 
241 }
242 
244  return "RmsdEvaluatorCreator";
245 }
246 
247 } //namespace
248 } //namespace