31 #include <ObjexxFCL/char.functions.hh>
32 #include <ObjexxFCL/string.functions.hh>
39 #include <basic/Tracer.hh>
40 #include <basic/datacache/BasicDataCache.hh>
41 #include <basic/datacache/CacheableString.hh>
42 #include <basic/datacache/CacheableStringFloatMap.hh>
44 #include <basic/options/option.hh>
69 #include <basic/options/keys/out.OptionKeys.gen.hh>
70 #include <basic/options/keys/in.OptionKeys.gen.hh>
72 #include <utility/vector1.hh>
75 #include <ObjexxFCL/format.hh>
82 static basic::Tracer
tr(
"core.io.silent");
93 : strict_column_mode_(false), nres_(0), decoy_tag_(
""), sequence_(
""), precision_(3), scoreline_prefix_(
"SCORE: ")
119 runtime_assert(
nres_ != 0 );
120 using namespace core::chemical;
133 tr.Error <<
"SilentStruct::fill_pose method stubbed out!" << std::endl;
140 using namespace basic::options;
141 using namespace basic::options::OptionKeys;
145 if ( option[ in::file::keep_input_scores ]() ) {
146 tr.Debug <<
"keep input scores... call energies into pose " << std::endl;
153 tr.Debug <<
"reading sequence from " << line << std::endl;
154 std::istringstream line_stream( line );
158 line_stream >> tag >> temp_seq;
159 if ( line_stream.fail() || tag !=
"SEQUENCE:" ) {
160 tr.Error <<
"bad format in sequence line of silent file" << std::endl;
161 tr.Error <<
"line = " << line << std::endl;
162 tr.Error <<
"tag = " << tag << std::endl;
171 std::istringstream score_line_stream( line );
172 tr.Debug <<
"reading score names from " << line << std::endl;
174 score_line_stream >> tag;
175 if ( score_line_stream.fail() || tag !=
"SCORE:" ) {
176 tr.Error <<
"bad format in second line of silent file" << std::endl;
177 tr.Error <<
"tag = " << tag << std::endl;
178 tr.Error <<
"line = " << line << std::endl;
181 score_line_stream >> tag;
182 while ( ! score_line_stream.fail() ) {
183 energy_names.push_back( tag );
184 score_line_stream >> tag;
190 enames ->energy_names( energy_names );
191 seqdata->set_sequence(
sequence() );
208 using namespace ObjexxFCL::fmt;
213 out <<
" " <<
A( it->width(), it->name() );
216 using namespace basic::options;
217 using namespace basic::options::OptionKeys;
219 if ( option[ out::user_tag ].user() ) {
221 int width = std::max( 11, static_cast< int > (tag.size()) );
222 out <<
' ' <<
A( width,
"user_tag" );
226 if ( width < 11 ) width = 11;
227 out <<
' ' <<
A( width,
"description" ) << std::endl;
232 using namespace basic::options;
233 using namespace basic::options::OptionKeys;
234 using namespace ObjexxFCL;
235 using namespace ObjexxFCL::fmt;
244 if ( it->string_value() ==
"" ){
246 if ( option[ out::file::weight_silent_scores ]() ) {
247 weight = it->weight();
249 out <<
" " << F( it->width(),
precision(), it->value() * weight );
251 out <<
" " << std::setw( it->width() ) << it->string_value() <<
" ";
256 if ( option[ out::user_tag ].user() ) {
258 int width = std::min( 11, static_cast< int > (tag.size()) );
259 out <<
' ' <<
A( width, tag );
263 if ( width < 11 ) width = 11;
264 out <<
' ' <<
A( width,
decoy_tag() ) <<
"\n";
272 string const remark(
"REMARK" );
274 typedef map< string, string >::const_iterator c_iter;
278 out << remark <<
' ' << it->first <<
' ' << it->second << std::endl;
284 if( score_energy1.
name() ==
"score" )
return true;
285 if( score_energy2.
name() ==
"score" )
return false;
287 return score_energy1.
name() < score_energy2.
name();
299 if ( it->name() == scorename )
313 if ( it->name() == scorename ) {
321 int width = std::max( 10, (
int) scorename.length() + 3 );
337 if ( it->name() == scorename ) {
345 int width = std::max( 10, (
int) scorename.length() + 3 );
378 if ( it->name() == scorename )
return *it;
393 if ( *it ==
"description" )
continue;
398 new_energies.push_back( ener );
419 if ( it2->name() == it->name() ) {
420 it2->value( it->value() );
435 std::istringstream line_stream( line );
437 line_stream >> remark_tag;
440 if ( line_stream.fail() ) {
441 tr.Error <<
"[ERROR] reading comment from line: " << line << std::endl;
444 if ( val ==
"SILENTFILE" ) {
445 tr.Debug <<
"ignoring silent struct type specifier when reading comments: " << line << std::endl;
448 line_stream >> dummy;
449 while( line_stream.good() ) {
452 line_stream >> dummy;
466 std::map< std::string, std::string >::const_iterator entry
470 comment = entry->second;
486 std::istream & input,
491 Size input_count = 0;
492 Size const energy_names_count( energy_names.size() );
494 using namespace ObjexxFCL;
495 for ( energy_iter = energy_names.begin();
496 energy_iter != energy_names.end();
500 if ( is_float( tag ) ) {
501 Real score_val =
static_cast< Real > ( float_of( tag ) );
503 }
else if ( *energy_iter ==
"description" ) {
511 if ( energy_names_count != input_count ) {
512 tr.Warning <<
"Warning: I have " << energy_names_count
513 <<
" energy names but I have " << input_count
514 <<
" energy values." << std::endl;
528 score += it->weight() * it->value();
535 using namespace core::pose::datacache;
547 for ( emap_iter = emap.begin(), wts_iter = wts.begin();
548 emap_iter != emap.end() && wts_iter!= wts.end();
549 ++emap_iter && ++wts_iter
553 if ( *wts_iter != 0.0 ) {
558 int width = std::max( 10, (
int) name.length() + 3 );
559 SilentEnergy new_se( name, *emap_iter, *wts_iter, width );
568 if ( pose.
data().has( CacheableDataType::ARBITRARY_FLOAT_DATA ) ) {
569 basic::datacache::CacheableStringFloatMapCOP data
570 =
dynamic_cast< basic::datacache::CacheableStringFloatMap
const *
>
571 ( pose.
data().get_raw_const_ptr(CacheableDataType::ARBITRARY_FLOAT_DATA) );
575 for ( map< string, float >::const_iterator iter = data->map().begin(),
576 end = data->map().end(); iter !=
end; iter++
579 if ( iter->first ==
"score" )
continue;
581 iter->first, iter->second, 1.0,
582 static_cast< int > (iter->first.size() + 3)
584 tr.Trace <<
" score energy from pose-cache: " << iter->first <<
" " << iter->second << std::endl;
593 for ( map< string, string >::const_iterator it = comments.begin(),
594 end = comments.end(); it !=
end; ++it
600 map< string, string > score_line_strings(
603 for ( map< string, string >::const_iterator it = score_line_strings.begin(),
604 end = score_line_strings.end();
613 using namespace basic::options;
614 using namespace basic::options::OptionKeys;
615 using namespace core::pose::datacache;
616 using namespace core::scoring;
620 if ( !pose.
data().has( ( CacheableDataType::ARBITRARY_FLOAT_DATA ) ) ){
622 CacheableDataType::ARBITRARY_FLOAT_DATA,
623 new basic::datacache::CacheableStringFloatMap()
627 basic::datacache::CacheableStringFloatMapOP data
628 =
dynamic_cast< basic::datacache::CacheableStringFloatMap *
>
629 ( pose.
data().get_raw_ptr(CacheableDataType::ARBITRARY_FLOAT_DATA) );
631 runtime_assert( data.get() != NULL );
636 string const input_score_prefix( option[ in::file::silent_score_prefix ]() );
639 std::set< string > wanted_scores;
640 if ( option[ in::file::silent_scores_wanted ].user() ) {
645 wanted_scores.insert( *it );
651 for ( elist::const_iterator it = es.begin(),
end = es.end();
655 if ( wanted_scores.size() > 0 &&
656 wanted_scores.find(it->name()) == wanted_scores.end()
662 string const proper_name( input_score_prefix + it->name() );
665 emap [ sc_type ] = it->value();
666 weights[ sc_type ] = it->weight();
667 }
else if ( it->string_value() !=
"" ) {
668 tr.Trace <<
"add score line string : " << proper_name <<
" " << it->string_value() << std::endl;
670 pose, proper_name, it->string_value()
673 tr.Trace <<
"add score : " << proper_name <<
" " << it->value() << std::endl;
674 data->map()[ proper_name ] = it->value();
679 pose.
data().set( CacheableDataType::ARBITRARY_FLOAT_DATA, data );
684 for ( map< string, string >::const_iterator it = comments.begin(),
685 end = comments.end(); it !=
end; ++it
688 if ( wanted_scores.size() > 0 &&
689 wanted_scores.find(it->first) == wanted_scores.end()
691 string const proper_name( input_score_prefix + it->first );
701 end = se.end(); it !=
end; ++it
703 names.push_back( it->name() );
714 static map< string, string > scorename_conversions;
715 static bool init(
false );
717 scorename_conversions[
"cb"] =
"cbeta";
718 scorename_conversions[
"hs"] =
"hs_pair";
719 scorename_conversions[
"ss"] =
"ss_pair";
723 map< string, string >::const_iterator conv_it,
724 conv_end( scorename_conversions.end() );
728 conv_it = scorename_conversions.find( it->name() );
729 if ( conv_it != conv_end ) {
730 it->name( conv_it->second );
738 using namespace core::pose::datacache;
740 if ( pose.
data().has( CacheableDataType::JOBDIST_OUTPUT_TAG ) ) {
742 static_cast< basic::datacache::CacheableString
const &
>
743 ( pose.
data().get( CacheableDataType::JOBDIST_OUTPUT_TAG ) ).
str();
821 if (
sequence().is_patched( pos ) )
return;
828 tr.Debug <<
"found less than 7 atoms on " <<
sequence().
one_letter( pos ) <<
" switch to centroid mode" << std::endl;
829 }
else if ( natoms>=9 ) {
830 tr.Debug <<
"found " << natoms <<
" atoms (more than 8) on " <<
sequence().
one_letter( pos ) <<
" switch to fullatom mode" << std::endl;
842 string const remark(
"PARENT REMARK" );
844 typedef map< string, string >::const_iterator c_iter;
846 out << remark <<
' ' << it->first <<
' ' << it->second << std::endl;
855 if(
parent_remarks_map_.count(name)==0) utility_exit_with_message(
"The key (" + name +
") doesn't exist in the parent_remarks_map_!");
857 std::map< std::string, std::string >::const_iterator entry=
parent_remarks_map_.find( name );
860 utility_exit_with_message(
"entry == parent_remarks_map_.end() for the the key (" + name +
").");
865 return parent_remark;
881 tr <<
"The key (" + name +
") already exist in the parent_remarks_map_!";
892 std::istringstream line_stream( line );
895 line_stream >> remark_tag;
899 if ( line_stream.fail() ) utility_exit_with_message(
"[ERROR] reading REMARK from line: " + line );
901 if(remark_tag!=
"REMARK") utility_exit_with_message(remark_tag!=
"REMARK");
905 line_stream >> dummy;
906 while( line_stream.good() ) {
907 std::cout <<
"Extra characters in REMARK LINE!" << std::endl;
908 std::cout <<
"remark_tag= " << remark_tag << std::endl;
909 std::cout <<
"key= " << key << std::endl;
910 std::cout <<
"val= " << val << std::endl;
911 std::cout <<
"dummy= " << dummy << std::endl;
912 utility_exit_with_message(
"Extra characters in REMARK LINE!");