Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CrossPeakList.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 FragmentSampler.cc
11 /// @brief ab-initio fragment assembly protocol for proteins
12 /// @detailed
13 /// Contains currently: Classic Abinitio
14 ///
15 ///
16 /// @author Oliver Lange
17 
18 // Unit Headers
20 
21 // Package Headers
27 
28 // AUTO-REMOVED #include <protocols/noesy_assign/DistanceScoreMover.hh>
29 
30 // Project Headers
32 // AUTO-REMOVED #include <core/io/silent/SilentFileData.hh>
33 #include <core/pose/Pose.hh>
34 
35 // AUTO-REMOVED #include <core/scoring/constraints/AmbiguousNMRConstraint.hh>
36 #include <core/id/Exceptions.hh>
37 // AUTO-REMOVED #include <core/scoring/constraints/AmbiguousNMRDistanceConstraint.hh> // REQUIRED FOR WINDOWS
38 
39 // for switching residue type set to centroid
40 // AUTO-REMOVED #include <core/chemical/util.hh>
42 // for error output
44 
45 // Utility headers
46 #include <basic/Tracer.hh>
47 #include <basic/prof.hh>
48 
49 //// C++ headers
50 // AUTO-REMOVED #include <math.h> //for isnan
51 
52 // AUTO-REMOVED #include <core/pose/util.hh>
54 #include <utility/io/ozstream.hh>
55 #include <utility/file/FileName.hh>
56 
57 #include <utility/vector1.hh>
58 
59 //Auto Headers
61 #include <core/kinematics/Jump.hh>
63 
64 
65 
66 static basic::Tracer tr("protocols.noesy_assign.crosspeaks");
67 
68 using core::Real;
69 using namespace core;
70 using namespace basic;
71 
72 namespace protocols {
73 namespace noesy_assign {
74 
75 CrossPeakList::CrossPeakList() :
76  assignments_()
77 {}
78 
80 
82  Size total_size( 0 );
83  for ( const_iterator it = begin(); it != end(); ++it ) {
84  total_size+=(*it)->assignments().size();
85  }
86  return total_size;
87 }
88 
90  tr.Info << "remove diagonal peaks..." << std::endl;
91 
92  for ( iterator it = begin(); it != end(); ) {
93  bool delete_peak( false );
94  for ( CrossPeak::iterator ait = (*it)->begin(); ait != (*it)->end(); ++ait ) {
95  if ( (*ait)->resonance_id( 1 )==(*ait)->resonance_id( 2 ) ) {
96  delete_peak = true;
97  break;
98  }
99  }
100  if ( delete_peak ) {
101  tr.Debug << "remove peak because it might be a diagonal peak " << (*it)->peak_id() << std::endl;
102  it = peaks_.erase( it );
103  continue;
104  }
105  ++it;
106  }
107  assignments_ = NULL;
108 }
109 
110 void CrossPeakList::read_from_stream( std::istream& is, PeakFileFormat& input_adaptor, ResonanceListOP resonances ) {
111  std::string new_peak_line ="";
112  while ( is.good() ) {
113  input_adaptor.read_header( is, new_peak_line );
114  input_adaptor.output_diagnosis( tr.Debug );
115  CrossPeakOP cp;
116  if ( !is.good() ) {
117  utility_exit_with_message( "nothing to read after peak-file header" );
118  }
119  while ( is.good() && ( cp = input_adaptor.read_peak( is, new_peak_line )) ) {
120  cp->set_resonances( resonances );
121  input_adaptor.write_peak( tr.Debug, cp->peak_id(), *cp );
122  tr.Debug << std::endl;
123  if ( std::abs( cp->volume() ) < 0.1 ) {
124  tr.Warning << "ignored peak: zero intensity for peak " << cp->peak_id() << std::endl;
125  continue;
126  }
127  if ( cp->volume() < 0 && input_adaptor.ignore_negative_intensity() ) {
128  tr.Warning << "ignored peak [#IGNORE_NEGATIVE_INTENSITY]: negative intensity for peak " << cp->peak_id() << std::endl;
129  continue;
130  }
131  peaks_.push_back( cp );
132  }
133  }
134 
135  if ( is.fail() && is.eof() && is.bad() ) {
136  tr.Error << "[ERROR WHILE READING]" << std::endl;
137  }
138 }
139 
140 void CrossPeakList::write_to_stream( std::ostream& os, PeakFileFormat& output_adaptor ) const {
141  output_adaptor.set_format_from_peak( **peaks_.begin() );
142  output_adaptor.write_header( os );
143  Size last_peak_id( 0 );
144  for ( CrossPeaks::const_iterator it = peaks_.begin(); it != peaks_.end(); ++it ) {
145  if ( last_peak_id > (*it)->peak_id() ) {
146  output_adaptor.set_format_from_peak( **it );
147  output_adaptor.write_header( os );
148  }
149  last_peak_id=(*it)->peak_id();
150  output_adaptor.write_peak( os, (*it)->peak_id(), **it );
151  os << std::endl;
152  }
153 }
154 
155 void open_stream( utility::io::ozstream& os, std::string const& prefix, std::string const& peak_filename ) {
156  utility::file::FileName pre_fn( prefix );
157  std::string filename( pre_fn.base() + "_" +peak_filename +".peaks" );
158  os.open(filename);
159 }
160 
161 void CrossPeakList::write_peak_files( std::string const& prefix, PeakFileFormat& output_adaptor ) const {
162  output_adaptor.set_format_from_peak( **peaks_.begin() );
163  std::string filename( (**peaks_.begin()).filename() );
164 
165  utility::io::ozstream os;
166  open_stream( os, prefix, filename );
167 
168  output_adaptor.write_header( os );
169  Size last_peak_id( 0 );
170  for ( CrossPeaks::const_iterator it = peaks_.begin(); it != peaks_.end(); ++it ) {
171  if ( last_peak_id > (*it)->peak_id() ) {
172  output_adaptor.set_format_from_peak( **it );
173  std::string filename( (**it).filename() );
174  os.close();
175  open_stream( os, prefix, filename );
176  output_adaptor.write_header( os );
177  }
178  last_peak_id=(*it)->peak_id();
179  output_adaptor.write_peak( os, (*it)->peak_id(), **it );
180  os << std::endl;
181  }
182 }
183 
185  tr.Info << "determine initial assignments..." << std::endl;
186 
187  for ( CrossPeaks::const_iterator it = peaks_.begin(); it != peaks_.end(); ++it ) {
188  (*it)->find_assignments();
189  }
190  assignments_ = NULL;
191 }
192 
195  assignments_->add( *this );
196 
198  if ( params.network_use_all_covalent_atoms_ ) { //mainly for backwards compatibility in network analysis. put all atoms in list for cov. analysis
199  if ( peaks().begin() != peaks().end() ) {
200  assignments_->add_all_atoms( (*peaks().begin())->resonances() );
201  }
202  }
203 }
204 
206  PROF_START( NOESY_ASSIGN_UPDATE_PEAK_VOL );
207  tr.Info << "update peak volumina..." << std::endl;
208  for ( CrossPeakList::iterator it = begin(); it != end(); ++it ) {
209  Real sum_volume( 0.0 );
210  for ( CrossPeak::iterator ait = (*it)->begin(); ait != (*it)->end(); ++ait ) {
211  sum_volume+=(*ait)->peak_volume();
212  }
213  (*it)->set_cumulative_peak_volume( sum_volume );
214  }
215  PROF_STOP( NOESY_ASSIGN_UPDATE_PEAK_VOL );
216 }
217 
219  tr.Info << "compute chemical shift score..." << std::endl;
220  for ( CrossPeakList::iterator it = begin(); it != end(); ++it ) {
221  for ( CrossPeak::iterator ait = (*it)->begin(); ait != (*it)->end(); ++ait ) {
222  (*ait)->update_chemshiftscore_from_peak();
223  }
224  }
225 }
226 
228  tr.Info << "compute uppder distance (covalent) score " << std::endl;
229  for ( CrossPeakList::iterator it = begin(); it != end(); ++it ) {
230  for ( CrossPeak::iterator ait = (*it)->begin(); ait != (*it)->end(); ++ait ) {
231  (*ait)->update_upperdistance_score();
232  }
233  }
234 }
235 
236 
237 
239  tr.Info << "set trivial 1/n decoy compatibility" << std::endl;
240  for ( CrossPeakList::iterator it = begin(); it != end(); ++it ) {
241  Real invn = 1.0/(*it)->n_assigned();
242  for ( CrossPeak::iterator ait = (*it)->begin(); ait != (*it)->end(); ++ait ) {
243  (*ait)->set_decoy_compatibility( invn );
244  }
245  }
246 }
247 
248 
250  tr.Info << " symmetry score " << std::endl;
252  runtime_assert( assignments_ );
254  Real const min_sym_cont( params.min_contribution_symmetric_peaks_ );
255  assignments().check_for_symmetric_peaks( *this, min_sym_cont < 0.99 );
256 }
257 
259  tr.Info << " network analysis ... " << std::endl;
261  runtime_assert( assignments_ );
263  if ( params.network_mode_ == "orig" ) {
264  Size n_assignments( count_assignments() );
265  assignments_->network_analysis( n_assignments );
266  } else if ( params.network_mode_ == "clean" ) {
267  assignments_->network_analysis2( resonances );
268  } else {
269  utility_exit_with_message(" network mode " + params.network_mode_ + " is unknown " );
270  }
271 }
272 
274  for ( CrossPeakList::iterator it = begin(); it != end(); ++it ) {
275  (*it)->eliminated( true /*recompute*/ );
276  }
277 }
278 
280  Real average_dist( 0.0 );
281  Size ct( 0 );
282  for ( CrossPeakList::iterator it = begin(); it != end(); ++it ) {
283  PeakCalibrator::TypeCumulator calibration_types;
284  (*it)->calibrate( calibrator, calibration_types );
285  average_dist += (*it)->distance_bound();
286  ct += ( (*it)->distance_bound() > 0.0 );
287  }
288  if ( ct == 0 ) return 0.0;
289  return average_dist / ct;
290 }
291 
295  core::pose::Pose const& pose,
296  core::pose::Pose const& centroid_pose,
297  core::Size min_seq_separation,
298  core::Size min_quali,
299  core::Size max_quali,
300  core::Real padding,
301  bool ignore_elimination_candidates, /*default = true */
302  bool elimination_candidates /* default = false */
303 ) const {
304  //count for normalization:
305  core::Size ct( 0 );
306  for ( CrossPeakList::const_iterator it = begin(); it != end(); ++it ) {
307  if ( (*it)->eliminated() ) continue;
308  if ( (*it)->min_seq_separation_residue_assignment( 0.1 ) < min_seq_separation ) continue; //ignore peaks that have confident intra-residue assignment
309  // if ( !(*it)->has_inter_residue_assignment( resonances(), 0.1 ) ) continue; //ignore peaks that have confident intra-residue assignment
310  if ( max_quali+1 < CrossPeak::MAX_CLASS ) {
311  Size const quality( (*it)->quality_class() );
312  if ( quality < min_quali || quality > max_quali ) continue;
313  }
314  ++ct;
315  }
316  for ( CrossPeakList::const_iterator it = begin(); it != end(); ++it ) {
317  if ( (*it)->eliminated() ) continue;
318  if ( (*it)->min_seq_separation_residue_assignment( 0.1 ) < min_seq_separation ) continue; //ignore peaks that have confident intra-residue assignment
319  if ( max_quali+1 < CrossPeak::MAX_CLASS ) {
320  Size const quality( (*it)->quality_class() );
321  if ( quality < min_quali || quality > max_quali ) continue;
322  }
323  if ( !ignore_elimination_candidates ) {
324  if ( (*it)->is_elimination_candidate() != elimination_candidates ) continue;
325  }
326  try {
329  (*it)->create_fa_and_cen_constraint( fa_cst, cen_cst, pose, centroid_pose, ct, padding );
330  runtime_assert( fa_cst && cen_cst );
331  fa_set->add_constraint( fa_cst );
332  cen_set->add_constraint( cen_cst );
333  } catch ( core::id::EXCN_AtomNotFound& excn ) {
334  tr.Error << "failed to generate " << "constraint for peak: " << (**it) << std::endl;
335  tr.Error << excn << std::endl;
336  tr.Info << " residue-type in pose: " << pose.residue_type( excn.atom().rsd() ).name3() << " " << excn.atom().rsd() << std::endl;
337  tr.Debug << " with these atoms ";
338  pose.residue_type( excn.atom().rsd() ).show_all_atom_names( tr.Debug );
339 
340  tr.Info << " residue-type in centroid_pose: " << centroid_pose.residue_type( excn.atom().rsd() ).name3() << " " << excn.atom().rsd() << std::endl;
341  tr.Debug << " with these atoms ";
342  centroid_pose.residue_type( excn.atom().rsd() ).show_all_atom_names( tr.Debug );
343  }
344  }
345 }
346 
347 #if 0
348 core::scoring::constraints::ConstraintSetOP CrossPeakList::generate_constraints( core::pose::Pose const& pose, bool centroid, core::Size min_seq_separation ) const {
349  using namespace core::scoring::constraints;
350  ConstraintSetOP cstset = new ConstraintSet;
351  core::pose::Pose centroid_pose;
352 
353  if ( tr.Debug.visible() ) pose.dump_pdb("pose_in_generate_constraints.pdb");
354 
355  if ( centroid ) {
356  centroid_pose = pose;
358  if ( tr.Debug.visible() ) {
359  centroid_pose.dump_pdb( "centroid_pose.pdb" );
360  }
361  }
362  //count for normalization:
363  core::Size ct( 0 );
364  for ( CrossPeakList::const_iterator it = begin(); it != end(); ++it ) {
365  if ( (*it)->eliminated() ) continue;
366  if ( (*it)->min_seq_separation_residue_assignment( 0.1 ) < min_seq_separation ) continue; //ignore peaks that have confident intra-residue assignment
367  // if ( !(*it)->has_inter_residue_assignment( resonances(), 0.1 ) ) continue; //ignore peaks that have confident intra-residue assignment
368  ++ct;
369  }
370 
371 
372  for ( CrossPeakList::const_iterator it = begin(); it != end(); ++it ) {
373  if ( (*it)->eliminated() ) continue;
374  if ( (*it)->min_seq_separation_residue_assignment( 0.1 ) < min_seq_separation ) continue; //ignore peaks that have confident intra-residue assignment
375  try {
376  if ( !centroid ) cstset->add_constraint( (*it)->create_constraint( pose, ct ) );
377  else cstset->add_constraint( (*it)->create_centroid_constraint( pose, centroid_pose, ct ) );
378  } catch ( core::id::EXCN_AtomNotFound& excn ) {
379  tr.Error << "failed to generate " << ( centroid ? "centroid " : "full-atom " ) << "constraint for peak: " << (**it) << std::endl;
380  tr.Error << excn << std::endl;
381  core::pose::Pose const & current_pose = ( centroid ? centroid_pose : pose );
382  tr.Info << " residue-type in pose: " << current_pose.residue_type( excn.atom().rsd() ).name3() << " " << excn.atom().rsd() << std::endl;
383  tr.Debug << " with these atoms ";
384  current_pose.residue_type( excn.atom().rsd() ).show_all_atom_names( tr.Debug );
385  }
386  }
387  return cstset;
388 }
389 #endif
390 
391 }
392 }