Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
MethylNames.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 /// @author Oliver Lange
11 
12 
13 // Unit Headers
15 
16 // Package Headers
18 
19 // Project Headers
20 #include <core/chemical/AA.hh>
21 
22 #include <basic/database/open.hh>
23 #include <basic/Tracer.hh>
24 
25 // Utility headers
26 #include <utility/io/izstream.hh>
27 
28 // C++ headers
29 
30 
31 static basic::Tracer tr("protocols.noesy_assign.crosspeaks");
32 
33 namespace protocols {
34 namespace noesy_assign {
35 
36 using namespace core;
37 
38 MethylNameLibrary* MethylNameLibrary::instance_( 0 );
39 
41  load_database_table();
42 }
43 
45  if ( instance_ == 0 ) {
46  instance_ = new MethylNameLibrary();
47  }
48  return instance_;
49 }
50 
52  MethylNameTable::const_iterator it = methyl_names_.find( aa );
53  if ( it == methyl_names_.end() ) {
54  utility_exit_with_message( name_from_aa( aa )+ " is not a known aminoacid-type in NMR proton Database" );
55  }
56  return it->second;
57 }
58 
60  utility::io::izstream db_stream;
61  basic::database::open(db_stream, "chemical/residue_type_sets/fa_standard/nmr_nameing_conventions.txt" );
62  std::string line;
63  std::string last_aa( "X" );
64  std::string aa_name;
65  MethylNameTable::iterator current;
66  while ( getline( db_stream, line ) ) {
67  if ( line[0] == '#' ) continue;
68  std::istringstream line_stream( line );
69  line_stream >> aa_name;
70  if ( !line_stream.good() && aa_name.size() != 1 ) continue;
71  if ( last_aa != aa_name ) {
72  last_aa = aa_name;
74  methyl_names_[ aa ] = MethylNames( aa );
75  current = methyl_names_.find( aa );
76  }
77  std::string nmr, rosetta;
78  line_stream >> nmr >> rosetta;
79  if ( nmr.size() && rosetta.size() ) {
80  current->second.add_proton( nmr, rosetta);
81  }
82 
83  std::string tag, methyl;
84  line_stream >> tag >> methyl;
85  tr.Trace << "read: " << tag << " " << methyl << std::endl;
86  if ( !line_stream.bad() && tag == ">" ) {
87  current->second.add_methyl( methyl, rosetta );
88  }
89  if ( line_stream.good() ) {
90  line_stream >> methyl;
91  if ( !line_stream.bad() ) {
92  current->second.add_methyl( methyl, rosetta );
93  }
94  }
95  }
96 }
97 
98 MethylNames::MethylNames() : aa_( chemical::aa_unk ) {}
99 
101 
102 void MethylNames::add_proton( std::string const& nmr, std::string const& rosetta ) {
103  tr.Trace << aa_ << " add proton " << nmr << " " << rosetta << std::endl;
104  rosetta2nmr_[ rosetta ] = nmr;
105  nmr2rosetta_[ nmr ] = AtomList( 1, rosetta );
106 }
107 
108 void MethylNames::add_methyl( std::string const& methyl, std::string const& rosetta ) {
109  tr.Trace << aa_ << " add methyl " << methyl << " " << rosetta << std::endl;
110 
111  NameTable::iterator rit = rosetta2methyl_.find( rosetta );
112  if ( rit != rosetta2methyl_.end() ) {
113  rit->second.push_back( methyl );
114  } else {
115  rosetta2methyl_[ rosetta ] = AtomList( 1, methyl );
116  }
117 
118  NameTable::iterator it = nmr2rosetta_.find( methyl );
119  if ( it != nmr2rosetta_.end() ) {
120  it->second.push_back( rosetta );
121  } else {
122  nmr2rosetta_[ methyl ] = AtomList( 1, rosetta );
123  }
124 }
125 
127  return name_from_aa( aa_ );
128 }
129 
130 std::string const& MethylNames::rosetta2nmr( std::string const& proton ) const {
131  std::map< std::string, std::string >::const_iterator it = rosetta2nmr_.find( proton );
132  if ( it == rosetta2nmr_.end() ) {
133  throw EXCN_UnknownAtomname("proton_name " + proton + " not recognized for aminoacid " + aa_name() );
134  }
135  return it->second;
136 }
137 
139  NameTable::const_iterator it = nmr2rosetta_.find( proton );
140  if ( it == nmr2rosetta_.end() ) {
141  throw EXCN_UnknownAtomname("proton_name " + proton + " not recognized for aminoacid " + aa_name() );
142  }
143  return it->second;
144 }
145 
147  NameTable::const_iterator it = rosetta2methyl_.find( proton );
148  if ( it == rosetta2methyl_.end() ) {
149  throw EXCN_UnknownAtomname("proton_name " + proton + " not recognized for aminoacid " + aa_name() );
150  }
151  return it->second;
152 }
153 
155  Size ct( 1 );
156  for ( NameTable::const_iterator it = begin(); it != end(); ++it, ++ct ) {
157  if ( it->first == proton ) return ct;
158  }
159  throw EXCN_UnknownAtomname("proton_name " + proton + " not recognized for aminoacid " + aa_name() );
160  return 0;
161 }
162 
163 }
164 }