32 #include <basic/options/option.hh>
33 #include <basic/options/keys/templates.OptionKeys.gen.hh>
54 #include <numeric/random/random.hh>
59 #include <utility/io/izstream.hh>
61 #include <utility/vector1.hh>
62 #include <basic/Tracer.hh>
76 static basic::Tracer
tr(
"protocols.abinitio.Templates");
78 using namespace basic;
79 using namespace basic::options;
84 using namespace basic::options;
85 using namespace basic::options::OptionKeys;
88 option.add_relevant( templates::no_culling );
89 option.add_relevant( templates::helix_pairings );
90 option.add_relevant( templates::prefix );
92 option.add_relevant( templates::cst::topN );
93 option.add_relevant( templates::cst::wTopol );
94 option.add_relevant( templates::cst::wExtern );
96 option.add_relevant( templates::fragsteal::topN );
97 option.add_relevant( templates::fragsteal::wTopol );
98 option.add_relevant( templates::fragsteal::wExtern );
103 namespace protocols {
106 static numeric::random::RandomGenerator
RG(12598234);
108 using namespace core;
109 using namespace jumping;
110 using namespace basic::options;
111 using namespace basic::options::OptionKeys;
115 StructureMap::const_iterator iter = poses_.find( name );
116 return ( iter != poses_.end() );
120 StructureMap::const_iterator iter = poses_.find( name );
121 if ( iter != poses_.end() ) {
122 return (iter->second);
134 if ( !has( file_name) ) {
146 poses_[ file_name ]=pose;
150 Templates::~Templates() {}
152 using namespace core;
153 using namespace fragment;
157 utility::io::izstream in( config_file);
158 tr.Info <<
"read homolog-template information from " << config_file << std::endl;
160 utility_exit_with_message(
"ERROR:: Unable to open template-config file: "+config_file);
165 while ( getline( in, line) ) {
166 std::istringstream line_stream( line );
168 int offset;
Real score;
169 line_stream >> name >> pdb >> align >> offset >> score;
171 if ( !line_stream.fail() && ( pdb.size() >= 1 ) ) {
172 if ( option[ templates::prefix ].user() ) {
173 std::string const prefix( option[ templates::prefix ]() );
174 pdb = prefix+
"/"+pdb;
175 align = prefix+
"/"+align;
177 tr.Info <<
"add Template " << name <<
" ..." << std::endl;
178 if ( !pose_store.
has( pdb ) ) pose_store.
add( pdb );
179 tr.Info <<
"template " << name <<
" read template structure " << pdb <<
" with offset " << offset << std::endl;
181 theTemplate =
new Template( name, pose_store[pdb], align, offset, score );
182 if( !theTemplate->is_good() ){
188 tr.Warning <<
"[WARNING] the query sequence " << theTemplate->query_sequence() <<
" is different than previous " << std::endl;
191 templates_.insert( TemplateMap::value_type( name, theTemplate ) );
195 while ( line_stream >> tag ) {
196 if ( tag ==
"C" || tag ==
"SC" )
cull_list_.push_back( theTemplate );
199 if ( tag ==
"CST" || tag ==
"SCST" ) {
201 line_stream >> cst_file;
202 if ( option[ templates::prefix ].user() ) {
203 std::string const prefix( option[ templates::prefix ]() );
204 cst_file = prefix +
"/" + cst_file;
206 if ( !line_stream.fail() ) {
207 tr.Info <<
"read constraints " << cst_file <<
"..." << std::endl;
208 theTemplate->read_constraints( cst_file );
217 tr.Info <<
"statistics of pairings: \n\n\n" << *
strand_stats_ << std::endl;
220 for (
Size i = 1; i <= strand_stats->nr_models(); i++ ) {
221 templates_[ strand_stats->ranked_model( i ) ]->topology_score( strand_stats->weight( i ) );
224 if ( option[ templates::fragsteal::topN ].user() ) {
227 tr.Info <<
"helixjump_list \n";
230 tr.Info << (*it)->name() <<
"\n";
232 tr.Info << std::endl;
245 bool bScoreFilter =
false;
246 Real wTopol( 0.0 ), wExtern( 0.0 );
247 if ( option[ templates::cst::topN ].user() ) {
249 wTopol = option[ templates::cst::wTopol ];
250 wExtern = option[ templates::cst::wExtern ];
254 for ( TemplateMap::const_iterator it=
templates_.begin(),
258 if ( aTemplate->has_constraints() ) {
259 cst_list.push_back( aTemplate );
262 if ( !bScoreFilter )
return;
264 _get_scored_list( cst_list, option[ templates::cst::topN ], wTopol, wExtern );
265 cull_list = cst_list;
274 Real wTopol( 0.0 ), wExtern( 0.0 );
275 if ( option[ templates::fragsteal::topN ].user() ) {
277 wTopol = option[ templates::fragsteal::wTopol ];
278 wExtern = option[ templates::fragsteal::wExtern ];
281 for ( TemplateMap::const_iterator it=
templates_.begin(),
283 frag_list.push_back( it->second );
285 _get_scored_list( frag_list, option[ templates::fragsteal::topN ], wTopol, wExtern );
293 Real sum_extern2 = 0;
298 bool bScoreFilter =
true;
301 for ( TemplateMap::const_iterator it=
templates_.begin(),
304 if ( bScoreFilter ) {
305 sum_extern += aTemplate->external_score();
306 sum_extern2 += aTemplate->external_score()*aTemplate->external_score();
307 sum_topol += aTemplate->topology_score();
308 sum_topol2 += aTemplate->topology_score()*aTemplate->topology_score();
312 if ( n == 0 )
return;
313 if ( !bScoreFilter )
return;
315 Real mean_topol = sum_topol / n;
316 Real mean_extern = sum_extern / n;
317 Real std_topol = std::sqrt( sum_topol2 / n - mean_topol*mean_topol );
318 Real std_extern = std::sqrt( sum_extern2 / n - mean_extern*mean_extern );
320 std::list< std::pair< core::Real, TemplateCOP > > weight_list;
321 for ( TemplateList::const_iterator it = cst_list.begin(), eit = cst_list.end();
323 Real score = ( (*it)->topology_score() - mean_topol ) / std_topol * wTopol
324 + ( (*it)->external_score() - mean_extern ) / std_extern * wExtern;
325 weight_list.push_back( std::make_pair( score, *it ) );
328 weight_list.reverse();
330 std::list< std::pair< core::Real, TemplateCOP > >
::const_iterator iter = weight_list.begin();
331 for (
Size i = 1; i <= topN && iter != weight_list.end(); i++, iter++ ) {
332 cst_list.push_back( iter->second );
343 tr.Info <<
"pick frames for target position 1 -> " << nframes <<
" from templates" << std::endl;
344 for (
Size pos =1; pos<=nframes; pos ++ ) {
345 FrameOP frame =
new Frame( pos, frag_type );
346 frames.push_back( frame );
351 tr.Info <<
"pick from template " << (*it)->name() << std::endl;
352 Size nr_frags = (*it)->steal_frags( frames, frag_set, ncopies );
353 tr.Info <<
"found " << nr_frags <<
" new fragments " << std::endl;
364 ConstantLengthFragSet template_frags;
366 total =
pick_frags( template_frags, frag_type, ncopies );
369 FragSetOP merged_frags = frag_set->empty_clone();
371 Size total_fill( 0 );
374 FrameList template_frames;
375 template_frags.frames( pos, template_frames );
376 merged_frags->add( template_frames );
377 Size nr_frags( template_frames.flat_size() );
378 tr.Info << nr_frags <<
" fragments at pos " << pos <<
". required: " << min_nr_frags << std::endl;
379 if ( nr_frags < min_nr_frags ) {
380 Size nr_fill ( min_nr_frags - nr_frags );
381 FrameList standard_frames;
382 frag_set->frames( pos, standard_frames );
383 if ( standard_frames.size() ) {
384 tr.Info <<
"attempt to fill up with " << nr_fill <<
" frags at position " << pos <<
" ... ";
385 for ( FragID_Iterator it = standard_frames.begin(), eit = standard_frames.end();
386 it != eit && nr_fill; ++it, --nr_fill ) {
387 merged_frags->add( *it );
391 tr.Info << nr_fill <<
" fragments short " << std::endl;
393 tr.Info <<
"succeeded! " << std::endl;
398 tr.Info <<
"found " << total <<
" fragments from homologs. supplemented by " << total_fill <<
" frags from standard library " << std::endl;
417 tr.Info <<
"pick large frag from template " << (*it)->name() << std::endl;
418 Size nr_frags = (*it)->pick_large_frags( frag_set, frag_type, ncopies );
419 tr.Info <<
"found " << nr_frags <<
" new fragments " << std::endl;
430 utility::io::izstream in( filename );
432 utility_exit_with_message(
"ERROR Unable to open pairings file "+filename);
440 tr.Debug <<
" read pairings for template " << pdb <<
"\n" << raw_pairings << std::endl;
443 utility_exit_with_message(
"unrecognized template name "+pdb+
" --- this name has to be in template:config file");
445 iter->second->map_pairings2target( raw_pairings, pairings );
446 tr.Debug <<
" mapped pairings for target\n " <<
pairings_ << std::endl;
451 using namespace fragment;
452 tr.Info <<
"TemplateJumpSetup will be initialized with secondary structure from homologs " << std::endl;
453 ConstantLengthFragSet fragset;
454 pick_frags( fragset,
new FragData(
new SecstructSRFD, 1 ) );
462 if ( option[ templates::helix_pairings ].user() )
read_pairings( option[ templates::helix_pairings ], helix_pairings );
470 using namespace scoring::constraints;
471 using namespace basic::options;
472 using namespace basic::options::OptionKeys;
476 AtomPairConstraintList full_list;
482 tr.Info <<
"pick constraints from " << cst_list.size() <<
" models " << std::endl;
484 for ( TemplateList::const_iterator it=cst_list.begin(),
485 eit = cst_list.end(); it!=eit; ++it ) {
486 tr.Info <<
"pick constraints from template " << (*it)->name() << std::endl;
491 NamedAtomPairConstraintList new_constraints;
494 tr.Info <<
"have " << new_constraints.size() <<
" constraints; start culling... " << std::endl;
496 if ( !option[ templates::no_culling ] ) {
498 for ( TemplateList::const_iterator it=cull_list.begin(),
499 eit = cull_list.end(); it!=eit; ++it ) {
500 NamedAtomPairConstraintList culled_constraints;
501 tr.Info <<
"cull with template " << (*it)->name() << std::endl;
502 (*it)->cull_violators( new_constraints, culled_constraints );
503 new_constraints = culled_constraints;
504 tr.Info << (*it)->name() <<
" leaves " << new_constraints.size() <<
" unviolated " << std::endl;
509 for ( NamedAtomPairConstraintList::const_iterator it = new_constraints.begin(),
510 eit = new_constraints.end(); it!=eit; ++it ) {
512 if ( cst ) full_list.push_back( cst );
515 cstset->add_constraints( full_list );