48 #include <numeric/random/random.hh>
51 #include <ObjexxFCL/format.hh>
56 #include <utility/vector1.hh>
57 #include <basic/Tracer.hh>
62 #include <basic/options/option.hh>
63 #include <basic/options/keys/templates.OptionKeys.gen.hh>
64 #include <basic/options/keys/jumps.OptionKeys.gen.hh>
78 static basic::Tracer
tr(
"protocols.abinitio.PairingStats");
80 using namespace basic;
81 using namespace basic::options;
82 using namespace ObjexxFCL::fmt;
85 using namespace basic::options;
86 using namespace basic::options::OptionKeys;
87 option.add_relevant( templates::force_native_topology );
88 option.add_relevant( templates::topology_rank_cutoff );
94 static numeric::random::RandomGenerator
RG(5651234);
98 using namespace basic::options;
99 using namespace basic::options::OptionKeys;
103 PairingStatEntry::PairingStatEntry() {}
106 strand_pairing_( strand ),
114 bool success(
true );
121 if ( success )
models_.push_back(
id );
131 for ( ModelList::const_iterator it =
models_.begin(), eit =
models_.end(); it != eit; ++it ) {
132 if ( model == *it )
return true;
150 StatEntries::iterator itentry =
entries_.find( ps );
151 bool merged(
false );
154 merged = itentry->second.add_pairing( ps,
id );
159 if ( merged && ( !
entries_.key_eq()( new_pairing, key ) ) ) {
178 tr.Trace <<
"adding stand pairing to hash.. " << *it << std::endl;
189 Template const& model( *it->second );
194 model_freq[ model.
name().substr(0,4) ] += 1;
203 model_freq[
"SING" ] = 1;
210 StatEntries::const_iterator itentry =
entries_.find( pairing );
212 return itentry->second.weight();
226 if ( top->second==
id )
return top->first;
228 utility_exit_with_message(
"Model name not known: " +
id );
233 Real const contact_order_weight( basic::options::option[ basic::options::OptionKeys::jumps::contact_score ] );
234 std::list< std::pair< core::Real, Model > > weight_list;
235 for ( Topologies::const_iterator top =
topols_.begin(), etop=
topols_.end();
236 top != etop; ++top ) {
238 Real const norm( sqrt( (
Real) model_freq[ top->first.substr(0,4) ] ) );
241 epairing = top->second.end(); pairing != epairing; ++pairing ) {
243 StatEntries::iterator itentry =
entries_.find( *pairing );
245 Real const weight( 1.0/norm * itentry->second.frequency() * ( itentry->second.size()-1.0
246 + contact_order_weight * ( std::max( 0, (
int) itentry->second.contact_order() - 20)) ) );
247 itentry->second.set_weight( weight );
264 weight_list.push_back( std::make_pair( score, top->first ) );
268 weight_list.reverse();
270 copy( weight_list.begin(), weight_list.end(), std::back_inserter(
model_weight_ ) );
277 if ( !option[ templates::force_native_topology ] ) {
278 Real const rel_rank_cutoff( option[ templates::topology_rank_cutoff ] );
281 utility_exit_with_message(
"The array model_weight_[] has 0 members, yet we need one. The topology is: " + topol_id );
283 Real const rank_cutoff(
weight( 1 )*rel_rank_cutoff );
286 if ( rel_rank_cutoff >= 0.99 ) {
289 for ( top_max = 1; (top_max < nr_models) && weight( top_max ) > rank_cutoff; top_max++ ) {};
291 Size const rg_topol ( static_cast< int >(
RG.uniform() * top_max ) + 1 );
293 runtime_assert( topol_id !=
"BOGUS" );
294 tr.Info <<
"cutoff: " << rank_cutoff <<
" use topology ** " << rg_topol <<
": " << topol_id <<
" ** to select pairings " << std::endl;
321 out <<
"\nSTRAND_TOPOLOGY " <<
" " << ps.
topology( it->second ).
size() <<
" " << it->first <<
" " << it->second;
323 eisp = ps.
topology( it->second ).
end(); isp != eisp; ++isp ) {
324 if ( !isp->range_check() ) {
325 tr.Error <<
"[ERROR] skip inconsistent pairing... " << *isp << std::endl;
328 out <<
"\nPAIRSTAT_ENTRY: ";
342 tr.Error <<
"[ERROR] skip inconsistent pairing... " <<
strand_pairing_ << std::endl;
346 for ( ModelList::const_iterator it =
models_.begin(), eit =
models_.end();
355 if ( tag !=
"PAIRSTAT_ENTRY:" ) {
356 tr.Trace <<
"failed reading PAIRSTAT_ENTRY: --- found instead: " << tag << std::endl;
357 is.setstate( std::ios_base::failbit );
362 for (
Size ct = 1; ct <= nr_models; ct ++) {
370 for ( StatEntries::const_iterator it = ps.begin(), eit = ps.end();
372 out << it->second <<
"\n";
390 if ( tag !=
"PAIRING_STATISTICS" ) {
391 tr.Trace <<
"failed reading PAIRING_STATISTIC --- found instead: " << tag << std::endl;
392 is.setstate( std::ios_base::failbit );
395 tr.Trace <<
" read " << ntops <<
" topologies from file... " << std::endl;
401 for (
Size ct_top = 1; ct_top <= ntops; ct_top++ ) {
405 is >> tag >> nstrand >> model_weight >> model_ID;
406 if ( tag !=
"STRAND_TOPOLOGY" ) {
407 tr.Trace <<
"failed reading STRAND_TOPOLOGY --- found instead: " << tag << std::endl;
408 is.setstate( std::ios_base::failbit );
411 tr.Debug <<
"reading strand-topology " << model_ID <<
" with " << nstrand <<
" strands... "<<std::endl;
413 for (
Size ct = 1; ct <= nstrand; ct++ ) {
418 is >> entry_tag >> weight >> ntag >> pairing;
419 if ( is.fail() )
return is;
420 if ( !pairing.range_check() ) {
421 tr.Error <<
"[ERROR] read inconsistent pairing in " << tag <<
" " << model_weight <<
" " << model_ID << std::endl;
422 tr.Error <<
"offending pairing " << pairing << std::endl;
423 is.setstate( std::ios_base::failbit );
426 if ( entry_tag !=
"PAIRSTAT_ENTRY:" ) {
427 tr.Trace <<
"failed reading PAIRSTAT_ENTRY: --- found instead: " << entry_tag << std::endl;
428 is.setstate( std::ios_base::failbit );
431 runtime_assert( pairing.range_check() );
450 StatEntries::iterator try_entry = ps.
entries_.find( pairing );
451 if ( try_entry != ps.
entries_.end() ) {
452 if ( try_entry->second.weight() != weight ) {
453 tr.Warning <<
"inconsistent weights in topology " << try_entry->second << std::endl;
454 tr.Warning <<
"new weight is ignored: " << weight <<
" for strand " << pairing <<
"which had weight " << try_entry->second.weight() << std::endl;
456 try_entry->second.models().push_back( model_ID );
459 entry.
models().reserve( ntops );
466 ps.
model_weight_.push_back( std::make_pair( model_weight, model_ID ) );