34 #include <ObjexxFCL/format.hh>
35 #include <utility/string_util.hh>
42 #include <basic/Tracer.hh>
53 #include <utility/vector1.hh>
54 #include <boost/tokenizer.hpp>
57 static basic::Tracer
tr(
"protocols.noesy_assign.resonances");
61 using namespace basic;
66 namespace noesy_assign {
69 ResonanceList::ResonanceList(
std::string const& sequence ) : sequence_( sequence )
76 runtime_assert( resi <=
sequence_.size() );
99 last_resonances.pop_front();
100 first_res->combine( last_resonances, drain );
101 last_resonances.push_front( first_res );
144 using namespace core::chemical;
147 std::deque< ResonanceOP > last_resonances;
148 while( getline( is, line ) ) {
155 std::istringstream line_stream( line );
158 tr.Trace <<
"read line: " << line << std::endl;
159 line_stream >> label >> freq >> error >> name;
163 if ( !line_stream.good() ) {
164 tr.Info <<
"ignore line : " << line << std::endl;
168 if ( name==
"" )
break;
173 line_stream >> aa_name;
176 if ( line_stream.good() ) {
177 if ( aa_name.size() == 1 ) {
179 }
else if ( aa_name.size() == 3 ) {
182 throw utility::excn::EXCN_BadInput(
"did not recognize aminoacid: " + aa_name);
188 tr.Warning <<
"sequence mismatch!! check your data: found " <<
name_from_aa( aa ) <<
" in line " << line
194 line_stream >> aa_name;
196 Real intensity( 1.0 );
197 line_stream >> intensity;
198 if ( !line_stream ) {
203 line_stream >> fl_tag;
204 typedef std::set< core::Size > FloatList;
207 if ( fl_tag[0]!=
'#' && fl_tag[0]!=
'[' ) {
208 throw utility::excn::EXCN_BadInput(
"did not recognize item " +fl_tag +
" in line " + line );
210 std::stringstream float_info;
212 bool closed(
false );
213 if ( fl_tag[ fl_tag.size()-1 ]==
']' ) {
214 fl_tag.replace( fl_tag.size()-1, 1,
" ");
217 float_info << fl_tag;
218 while ( line_stream && !closed ) {
219 line_stream >> fl_tag;
220 if ( fl_tag[ fl_tag.size()-1 ]==
']' ) {
221 fl_tag.replace( fl_tag.size()-1, 1,
" ");
224 float_info << fl_tag;
227 throw utility::excn::EXCN_BadInput(
"expect closing ] in line " + line );
230 while ( float_info.getline(cstr, 50,
',' ) ) {
231 tr.Debug <<
"add " << cstr <<
" to float group for resonance " << label << std::endl;
232 floats.insert( utility::string2int( cstr ));
233 tr.Debug << floats.size() << std::endl;
240 if ( name ==
"HN" ) name =
"H";
241 if ( aa ==
aa_leu && name ==
"HD1" ) name =
"QD1";
242 if ( aa ==
aa_leu && name ==
"HD2" ) name =
"QD2";
243 if ( aa ==
aa_val && name ==
"HG1" ) name =
"QG1";
244 if ( aa ==
aa_val && name ==
"HG2" ) name =
"QG2";
245 if ( aa ==
aa_thr && name ==
"HG2" ) name =
"QG2";
246 if ( aa ==
aa_ala && name ==
"HB" ) name =
"QB";
247 if ( aa ==
aa_gly && name ==
"HA" ) name =
"QA";
248 if ( aa ==
aa_ile && name ==
"HG1" ) name =
"QG1";
249 if ( aa ==
aa_ile && name ==
"HG2" ) name =
"QG2";
250 if ( aa ==
aa_ile && name ==
"HD1" ) name =
"QD1";
253 if ( floats.size() ) {
258 last_resonances.push_back( save_resonance );
259 if ( freq != last_resonances.front()->freq() ) {
261 map_[ last_resonances.front()->label() ] = last_resonances.front();
262 last_resonances.pop_front();
268 map_[ last_resonances.front()->label() ]= last_resonances.front();
271 runtime_assert( last_resonances.size() == 1 );
274 if ( is.fail() && is.eof() && is.bad() ) {
275 tr.Error <<
"[ERROR WHILE READING]" << std::endl;
283 for ( ResonanceIDs::const_iterator it =
map_.begin(); it !=
map_.end(); ++it ) {
286 parse_NMR_name( it->second->name(), it->second->resid(), it->second->aa(), atoms );
287 it->second->set_intensity( atoms.size() );
292 for ( ResonanceIDs::const_iterator it =
map_.begin(); it !=
map_.end(); ++it ) {
300 for ( ResonanceIDs::const_iterator it =
map_.begin(); it !=
map_.end(); ++it ) {
301 runtime_assert( it->first == it->second->label() );
303 using namespace core::chemical;
305 it->second->write_to_stream( os, aa );
307 it->second->write_to_stream( os );
316 utility_exit_with_message(
"sequence information required to write TALOS format -- use -in:file:fasta" );
320 Size const TALOS_SEQ_LINE_LEN( 50 );
321 Size const TALOS_SEQ_BLCK_SIZE( 10 );
323 if ( ct % TALOS_SEQ_LINE_LEN == 0 && ct > 1 ) os <<
"\n";
324 if ( ct % TALOS_SEQ_LINE_LEN == 0 ) os <<
"DATA SEQUENCE";
325 if ( ct % TALOS_SEQ_BLCK_SIZE == 0 ) os <<
" ";
331 os <<
"VARS RESID RESNAME ATOMNAME SHIFT\n";
332 os <<
"FORMAT %4d %1s %4s %8.3f\n";
337 for ( ResonanceIDs::const_iterator it =
map_.begin(); it !=
map_.end(); ++it ) {
338 runtime_assert( it->first == it->second->label() );
339 if (
sequence_.size() < it->second->resid() ) {
340 tr.Error <<
" no sequence information for residue " << it->second->resid() << std::endl;
341 utility_exit_with_message(
"sequence information required for all residues to write TALOS format -- use -in:file:fasta" );
343 using namespace core::chemical;
347 bool const is_backbone(
348 atom==
"H" || atom==
"HN" ||
349 atom==
"CA" || atom==
"CB" ||
351 atom==
"1HA" || atom==
"2HA" || atom==
"3HA" );
353 if ( is_backbone || !backbone_only ) {
354 if ( atom==
"1HA" ) atom=
"HA3";
355 if ( atom==
"2HA" ) atom=
"HA2";
356 if ( atom==
"3HA" ) atom=
"HA1";
358 os << ObjexxFCL::fmt::RJ( 5, it->second->resid() ) <<
" ";
360 os << ObjexxFCL::fmt::RJ( 3, atom==
"H" ?
"HN" : atom ) <<
" ";
361 os << ObjexxFCL::fmt::F( 7, 3, it->second->freq() ) << std::endl;
370 ResidueMap::const_iterator it_res(
by_resid_.find( atom.
rsd() ) );
372 Resonances const& reso_list( it_res->second );
373 for ( Resonances::const_iterator it = reso_list.begin(); it != reso_list.end(); ++it ) {
374 if ( (*it)->atom() == atom )
return **it;
378 return *(
map_.begin()->second);
383 ResonanceIDs::const_iterator iter =
map_.find( key );
384 if ( iter ==
map_.end() ) {
387 return *(iter->second);
393 for ( ResonanceIDs::const_iterator it =
map_.begin(); it !=
map_.end(); ++it ) {
394 runtime_assert( it->first == it->second->label() );
395 by_resid_[ it->second->resid() ].push_back( it->second );
401 ResidueMap::const_iterator it_res(
by_resid_.find( resid ) );
403 return it_res->second;