Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FragQualCalculator.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/toolbox/PoseMetricCalculators/FragQualCalculator.cc
11 /// @brief calculate rmsd fragment quality given a pose
12 /// Roughly, fragment quality is number of fragments which are close to a pose in rmsd
13 /// @detailed
14 /// @author Nobuyasu Koga ( nobuyasu@uw.edu )
15 
16 // Unit Headers
18 
19 // Project Headers
20 // AUTO-REMOVED #include <core/chemical/ChemicalManager.hh>
21 
22 #include <basic/MetricValue.hh>
23 #include <core/pose/Pose.hh>
24 #include <basic/Tracer.hh>
25 #include <core/scoring/rms_util.hh>
26 #include <core/fragment/FragSet.hh>
29 #include <core/fragment/Frame.hh>
31 
32 // Utility headers
33 #include <utility/vector1.hh>
34 #include <utility/string_util.hh>
35 #include <utility/tag/Tag.hh>
36 #include <utility/exit.hh>
37 
38 //// C++ headers
39 #include <cmath>
40 #include <ObjexxFCL/format.hh>
41 
42 // AUTO-REMOVED #include <core/chemical/AtomType.hh>
44 #include <core/id/types.hh>
45 #include <core/kinematics/Jump.hh>
47 #include <utility/vector0.hh>
48 
49 //Auto Headers
50 #include <utility/excn/Exceptions.hh>
52 
53 
54 static basic::Tracer TR("protocols.toolbox.PoseMetricCalculators.FragQualCalculator");
55 
56 namespace protocols {
57 namespace toolbox {
58 namespace pose_metric_calculators {
59 
60 
61 /// @brief default constructor
63  rmsd_cutoff_goodfrag_( 1.0 ),
64  ratio_cutoff_goodfrag_( 0.3 ),
65  total_goodfrags_( 0 ),
66  coverage_( 0 ),
67  frag_( NULL ),
68  begin_( 0 ),
69  end_( 0 ),
70  verbose_( false )
71 {
72  goodfrags_.clear();
73 }
74 
75 /// @brief value constructor
77  FragSetOP const & frag,
78  Real const rmsd,
79  Real const ratio ):
80  rmsd_cutoff_goodfrag_( rmsd ),
81  ratio_cutoff_goodfrag_( ratio ),
82  total_goodfrags_( 0 ),
83  coverage_( 0 ),
84  frag_( frag ),
85  begin_( 0 ),
86  end_( 0 ),
87  verbose_( false )
88 {
89  goodfrags_.clear();
90 }
91 
92 /// @brief copy constructor
94  Super(),
95  rmsd_cutoff_goodfrag_( rval.rmsd_cutoff_goodfrag_ ),
96  ratio_cutoff_goodfrag_( rval.ratio_cutoff_goodfrag_ ),
97  total_goodfrags_( rval.total_goodfrags_ ),
98  coverage_( rval.coverage_ ),
99  goodfrags_( rval.goodfrags_ ),
100  frag_( rval.frag_ ),
101  begin_( rval.begin_ ),
102  end_( rval.end_ ),
103  verbose_( rval.verbose_ )
104 {}
105 
106 /// @brief destructor
108 
109 
110 /// @brief set fragments
111 void
113 {
114  frag_ = frag;
115 }
116 
117 /// @brief rmsd cutoff of good fragments
118 void
120 {
121  rmsd_cutoff_goodfrag_ = val;
122 }
123 
124 /// @brief
125 void
127 {
129 }
130 
131 /// @brief
132 void
133 FragQualCalculator::set_region( Size const val1, Size const val2 )
134 {
135  begin_ = val1;
136  end_ = val2;
137 }
138 
139 /// @brief
140 void
142  String const & key,
143  MetricValueBase * valptr
144 ) const
145 {
146  using namespace core;
147  if ( key == "num_goodfrag" ) {
148  basic::check_cast( valptr, &total_goodfrags_, "number of fragments within rmsd cutoff " );
149  (static_cast<basic::MetricValue<Real> *>(valptr))->set( total_goodfrags_ );
150  } else if (key == "coverage" ) {
151  basic::check_cast( valptr, &coverage_, "ratio of the region where good fragments are included more than XXX% " );
152  (static_cast<basic::MetricValue<Real> *>(valptr))->set( coverage_ );
153  } else {
154  TR << "FragQualCalculator cannot compute the requested metric " << key << std::endl;
155  utility_exit();
156  }
157 
158 } //lookup
159 
160 
161 // @brief
163 FragQualCalculator::print( String const & key ) const
164 {
165  String result;
166  if ( key == "num_goodfrag" ) {
167  result = utility::to_string( total_goodfrags_ );
168  } else if ( key == "coverage" ) {
169  result = utility::to_string( coverage_ );
170  } else {
171  basic::Error() << "FragQualCalculator cannot compute metric " << key << std::endl;
172  }
173  return result;
174 } // apply
175 
176 
177 /// @brief recomute ncontacts
178 void
180 {
181  using ObjexxFCL::fmt::RJ;
182  using ObjexxFCL::fmt::F;
185 
186  // initialization
187  if( begin_ == 0 ) begin_ = 1;
188  if( end_ == 0 ) end_ = pose.total_residue();
189  total_goodfrags_ = 0;
190  coverage_ = 0;
191 
192  goodfrags_.resize( pose.total_residue() );
193  for( Size i=1; i<=pose.total_residue(); i++ ) {
194  goodfrags_[ i ] = 0;
195  }
196  utility::vector1< bool > frag_region( pose.total_residue(), false );
197  utility::vector1< bool > is_covered( pose.total_residue(), false );
198 
199  Pose input_pose( pose ), test_pose( pose );
202 
203  for ( FrameIterator frame = frag_->begin(); frame != frag_->end(); ++frame ) {
204 
205  Size const start ( frame->start() );
206  runtime_assert( start <= pose.total_residue() );
207 
208  if( begin_ > start || end_ < start ) continue;
209  frag_region[ start ] = true;
210 
211  for ( Size i=1; i<=frame->nr_frags(); i++ ) {
212  // insert fragment
213  frame->apply( i, test_pose );
214  // calc rmsd
215  Real rmsd = CA_rmsd( input_pose, test_pose, start, start + frame->length() - 1 );
216  if( rmsd <= rmsd_cutoff_goodfrag_ ) {
217  goodfrags_[ start ] += 1;
218  }
219  if( verbose_ ) {
220  TR << "FRAG_SCORE " << RJ( 6, frame->length() ) << RJ( 6, frame->start() ) << RJ( 6, i ) << F( 10, 4, rmsd ) << std::endl;
221  }
222  }
223 
224  if( goodfrags_[ start ] >= frame->nr_frags()*ratio_cutoff_goodfrag_ ) {
225  is_covered[ start ] = true;
226  }
227  } // FrameIterator
228 
229  // calc coverage
230  Size count( 0 );
231  for( Size i=1; i<=pose.total_residue(); i++ ) {
232 
233  if( frag_region[ i ] ) {
234  count ++;
235  if( is_covered[ i ] ) {
236  coverage_++;
237  }
238  }
239  TR.Debug << i << " " << goodfrags_[ i ] << std::endl;
240  total_goodfrags_ += Real( goodfrags_[ i ] );
241  }
242 
243  coverage_ = coverage_ / count;
244 
245 }
246 
247 /// @brief parse xml
248 void
250  TagPtr const tag,
251  DataMap & data,
252  Filters_map const &,
253  Movers_map const &,
254  Pose const & pose )
255 {
256  rmsd_cutoff_goodfrag_ = tag->getOption<Real>( "rmsd_cutoff", 1.0 );
257  ratio_cutoff_goodfrag_ = tag->getOption<Real>( "ratio_cutoff", 0.3 );
258 
259  begin_ = tag->getOption<Size>( "begin", 1 );
260  end_ = tag->getOption<Size>( "end", pose.total_residue() );
261 
262  String const fset_string ( tag->getOption<String>( "frag", "" ) );
263  runtime_assert( ! fset_string.empty() );
264  if ( data.has( "fragsets", fset_string ) ) {
265  frag_ = data.get< FragSet* >( "fragsets", fset_string );
266  } else {
267  throw utility::excn::EXCN_RosettaScriptsOption("fragsets " + fset_string + " not found in DataMap.");
268  }
269 
270  verbose_ = tag->getOption<bool>( "verbose", 0 );
271 }
272 
273 
274 } // filters
275 } // fldsgn
276 } // protocols
277