Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Resonance.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
11 /// @brief
12 /// @detailed
13 ///
14 ///
15 ///
16 /// @author Oliver Lange
17 
18 // Unit Headers
20 
21 // Package Headers
24 
25 // AUTO-REMOVED #include <protocols/noesy_assign/Exceptions.hh>
26 #include <core/id/NamedAtomID.hh>
27 // Project Headers
28 #include <core/chemical/AA.hh>
29 
30 // Utility headers
31 #include <ObjexxFCL/format.hh>
32 
33 // #include <utility/exit.hh>
34 // #include <utility/excn/Exceptions.hh>
35 // #include <utility/vector1.fwd.hh>
36 // #include <utility/pointer/ReferenceCount.hh>
37 // #include <numeric/numeric.functions.hh>
38 // #include <basic/prof.hh>
39 #include <basic/Tracer.hh>
40 // #include <basic/options/option.hh>
41 // #include <basic/options/keys/abinitio.OptionKeys.gen.hh>
42 // #include <basic/options/keys/run.OptionKeys.gen.hh>
43 //#include <basic/options/keys/templates.OptionKeys.gen.hh>
44 
45 //// C++ headers
46 // AUTO-REMOVED #include <cstdlib>
47 #include <string>
48 // AUTO-REMOVED #include <deque>
49 
50 #include <utility/vector1.hh>
51 
52 
53 
54 static basic::Tracer tr("protocols.noesy_assign.resonances");
55 
56 using core::Real;
57 using namespace core;
58 using namespace basic;
59 //using namespace basic::options;
60 //using namespace basic::options::OptionKeys;
61 
62 namespace protocols {
63 namespace noesy_assign {
64 
65 Resonance::Resonance() {}
66 
67 Resonance::Resonance( core::Size label, core::Real freq, core::Real error, core::id::NamedAtomID const& id, core::chemical::AA aa, core::Real intensity ) :
68  label_ ( label ),
69  freq_( freq ),
70  error_( error ),
71  atom_( id ),
72  aa_( aa ),
73  intensity_( intensity )
74 {
75  is_proton_ = ( id.atom()[ 0 ]=='Q' || id.atom().find("H") != std::string::npos );
77 }
78 
80 
81 core::Real Resonance::pmatch( core::Real peakfreq, core::Real error, FoldResonance const& folder ) const {
82  return _pmatch( peakfreq, error, folder );
83 }
84 
85 core::Real Resonance::_pmatch( core::Real peakfreq, core::Real error, FoldResonance const& folder ) const {
86  return std::abs( folder( freq() ) - peakfreq ) / std::max( error, tolerance() );
87 }
88 
89 void Resonance::_write_to_stream( std::ostream& os ) const {
90  os << ObjexxFCL::fmt::RJ( 10, label_ ) << " ";
91  os << ObjexxFCL::fmt::F( 10, 3, freq_ ) << " " << ObjexxFCL::fmt::F( 10, 3, error_ ) << " ";
92  os << ObjexxFCL::fmt::RJ( 5, atom_.atom() ) << " " << ObjexxFCL::fmt::RJ( 8, atom_.rsd() );
93 }
94 
95 void Resonance::write_to_stream( std::ostream& os ) const {
96  _write_to_stream( os );
97  os << " "<< intensity();
98 }
99 
100 void Resonance::write_to_stream( std::ostream& os, core::chemical::AA aa ) const {
101  _write_to_stream( os );
102  os << " " << name_from_aa( aa ) << " " << oneletter_code_from_aa( aa );
103  os << " "<< intensity();
104 }
105 
106 void Resonance::combine( std::deque< ResonanceOP >& last_resonances, bool drain=false ) {
107  //is this a HB1, HG1 or a 1HG2 type of name ?
108  bool single_char ( name().size() == 3 );
109  std::string combine_name;
110  Size str_cmp_length( 1 );
111 
112  std::string pseudo_letter( "Q" ); //default, single methyl group, proton
113  if ( name().substr(0,1)=="C" ) pseudo_letter = "C"; //not default, we don't have a proton
114  if ( name().substr(0,1)=="Q" ) pseudo_letter = "QQ"; //not default, this is a double-methyl...
115  //if the two protons stuffed into the ambiguity queue are, .e.g, QG1 + QG2 --> QQG
116 
117  core::Real intensity_sum( intensity() );
118 
119 //do we have enough protons for a QQX type of combined atom. (2 methyl groups... )
120  bool double_methyl( last_resonances.size() == (6 - (drain ? 1 : 0)) );
121 
122 // construct combined atom name, QX, QQX
123  if ( single_char ) { //things like HB1+HB2 or QG1+QG2
124  combine_name=pseudo_letter+name().substr(1,1);
125  } else if ( double_methyl ) { //-->QQX
126  combine_name=pseudo_letter+pseudo_letter+name().substr(1,1);
127  } else { // HG11+HG12+HG13 --> QG1
128  combine_name=pseudo_letter+name().substr(1,2);
129  str_cmp_length=2;
130  }
131 
132  //now figure out, how many atoms can be combined...
133  Size limit( drain ? 0 : 1 ); //should we go to the very end, or leave last atom behind...
134  while( last_resonances.size() > limit ) {//check others
135  if ( name().substr( 1, str_cmp_length ) == last_resonances.front()->name().substr( 1, str_cmp_length ) ) {
136  intensity_sum+=last_resonances.front()->intensity();
137  last_resonances.pop_front();
138  } else { //could not combine...
139  combine_name = name();
140  break;
141  }
142  } //now replace front of deque with the combined atom
143  atom_ = core::id::NamedAtomID( combine_name, resid() );
144  intensity_ = intensity_sum;
145 }
146 
147 
148 } //NoesyAssign
149 } //devel