32 #include <numeric/random/random.hh>
33 #include <numeric/random/random_permutation.hh>
36 #include <utility/io/izstream.hh>
37 #include <utility/vector1.hh>
38 #include <basic/Tracer.hh>
39 #include <utility/io/util.hh>
46 #include <utility/vector0.hh>
49 static basic::Tracer
tr(
"protocols.abinitio.Templates");
54 static numeric::random::RandomGenerator
RG(1259812489);
57 using namespace fragment;
58 using namespace jumping;
68 ) : templates_( templates ),
69 secstruct_( secstruct ),
70 strand_stats_( strand_stats ),
71 helix_pairings_( helix_pairings )
77 tr.Debug <<
"create JumpSample from Templates: nres = " <<
templates_->target_total_residue() <<
"\n" <<
templates_->pairings() << std::endl;
89 tr.Debug <<
"topology selected! " << target_strands << std::endl;
90 if ( !target_strands.size() ) {
97 Real total_weight(0.0);
98 for (
Size i = 1; i <= target_strands.size(); i ++ ) {
99 total_weight +=
strand_stats_->strand_weight( target_strands.strand_pairing( i ) );
100 strand_ids.push_back( i );
103 numeric::random::random_permutation( strand_ids,
RG );
104 numeric::random::random_permutation( strand_ids,
RG );
105 tr.Debug <<
"total weight: " << total_weight <<
" size: " << target_strands.size() <<
"strand_ids.size(): "
107 <<
" permutated sequence: ";
108 utility::io::write_vector(
tr.Debug, strand_ids );
109 tr.Debug << std::endl;
112 Size const rg_nrstrands( std::min( static_cast< int >(
RG.uniform() * (target_strands.size()) ) + 2 , (
int) target_strands.size() ) );
113 tr.Debug <<
"random choice: aim for selection of " << rg_nrstrands << std::endl;
115 Size nstrand_selected( 0 );
116 for (
Size i = 1; i<= target_strands.size(); i++ ) {
118 Real weight(
strand_stats_->strand_weight( target_strands.strand_pairing( strand_ids[ i ] ) ) );
119 if ( total_weight > 0 && weight/total_weight < 0.005 )
continue;
121 tr.Debug <<
"pre-selected " << target_strands.strand_pairing( strand_ids[ i ] ) << std::endl;
123 target_strands.strand_pairing( strand_ids[ i ] ).get_beta_pairs( possible_pairings );
124 tr.Debug <<
"pre-selected " << target_strands.strand_pairing( strand_ids[ i ] )
125 <<
"provides: " << possible_pairings.size() <<
" pairings"<< std::endl;
128 if ( possible_pairings.size() > 2 ) {
129 Size const ori_size = possible_pairings.size();
130 for (
Size i=2; i<=ori_size - 1; i++) {
131 possible_pairings.push_back( possible_pairings[ i ] );
134 Size const rg_pairing( static_cast< int > (
RG.uniform() * possible_pairings.size() ) + 1 );
135 tr.Debug <<
"RANDOM: choose pairing " << rg_pairing << std::endl;
140 eit =
templates_->end(); it!=eit && !found; ++it ) {
143 found =
strand_stats_->topology( it->first ).has_pairing( possible_pairings[ rg_pairing ]);
146 if ( found || !
templates_ ) target_pairings.push_back( possible_pairings[ rg_pairing ]);
153 for ( core::scoring::dssp::PairingList::iterator it = target_pairings.begin(), eit = target_pairings.end();
156 bool ignore(
false );
159 if ( std::abs( (
int) it->Pos2() - (
int) it->Pos1() ) < 15 ) {
160 tr.Debug <<
"pairing " << *it <<
" is close in sequence..." << std::endl;
161 if (
RG.uniform() < 0.2 ) {
162 tr.Debug <<
"selected with 20% chance " << std::endl;
163 final_selection.push_back( *it );
164 }
else ignore =
true;
168 Size const my_reg = it->get_register();
170 for ( core::scoring::dssp::PairingList::iterator fit = final_selection.begin(), efit = final_selection.end();
171 fit!=efit && !ignore; ++fit ) {
172 if ( my_reg == fit->get_register() ) {
173 if ( std::abs( (
int) it->Pos1() - (
int) fit->Pos1() ) < 15
174 || std::abs( (
int) it->Pos1() - (
int) fit->Pos2() ) < 15
175 || std::abs( (
int) it->Pos2() - (
int) fit->Pos1() ) < 15
176 || std::abs( (
int) it->Pos2() - (
int) fit->Pos2() ) < 15 ) {
181 if ( !ignore ) final_selection.push_back( *it );
182 else tr.Debug <<
"pairing " << *it <<
" ignored because it is redundant " << std::endl;
186 Size const nr_helix_jumps(
189 numeric::random::random_permutation( perm ,
RG );
190 for (
Size i = 1; i<= nr_helix_jumps; i++ ) {
194 tr.Debug <<
"selected jumps: " << final_selection << std::endl;
218 for ( FrameList::iterator jump_frame = jump_frames.begin();
219 jump_frame != jump_frames.end(); ++jump_frame ) {
223 found = it->second.pairing().has_pairing( target_pairing );
226 filtered_jumps.push_back( target_pairing );
245 tr.Debug <<
" generate jump fragments... " << std::endl;
246 FragSetOP jump_frags =
new OrderedFragSet;
254 for ( FrameList::iterator jump_frame = jump_frames.begin();
255 jump_frame != jump_frames.end(); ++jump_frame ) {
258 tr.Debug <<
"get frags for pairing " << target_pairing << std::endl;
267 if (
strand_stats_->topology( model_id ).has_pairing( target_pairing ) ) {
269 FrameList aFrame; aFrame.push_back( *jump_frame );
270 it->second->steal_frags( aFrame, *jump_frags );
274 tr.Debug <<
"has been found in helix-list blindly collect all jump-geometries from models with an H" << std::endl;
275 FrameList aFrame; aFrame.push_back( *jump_frame );
276 for ( Templates::TemplateList::const_iterator it =
templates_->helixjump_picks().begin(),
277 eit =
templates_->helixjump_picks().end(); it != eit; ++it ) {
279 (*it)->steal_frags( aFrame, *jump_frags );
284 utility_exit_with_message(
"selected a pairing for which no pairing could be found in templates... shouldn't ever happen");
286 if ( nr_frags == 0 ) {
288 library_pairings.push_back( target_pairing );
309 jump_def_( jump_def )
316 jump_def_( jump_def )
329 Size const rg_nrstrands( std::min( static_cast< int >(
RG.uniform() * (target_strands.size()) ) + 2 , (
int) target_strands.size() ) );
330 tr.Debug <<
"random choice: aim for selection of " << rg_nrstrands << std::endl;
332 Size nstrand_selected( 0 );
333 for (
Size i = 1; i<= target_strands.size(); i++ ) {
335 Real weight( strand_stats_->strand_weight( target_strands.strand_pairing( strand_ids[ i ] ) ) );
336 if ( total_weight > 0 && weight*rg_nrstrands / total_weight <
RG.uniform() )
continue;
338 tr.Debug <<
"pre-selected " << target_strands.strand_pairing( strand_ids[ i ] ) << std::endl;
340 target_strands.strand_pairing( strand_ids[ i ] ).get_beta_pairs( possible_pairings );
341 tr.Debug <<
"pre-selected " << target_strands.strand_pairing( strand_ids[ i ] )
342 <<
"provides: " << possible_pairings.size() <<
" pairings"<< std::endl;
345 if ( possible_pairings.size() > 2 ) {
346 Size const ori_size = possible_pairings.size();
347 for (
Size i=2; i<=ori_size - 1; i++) {
348 possible_pairings.push_back( possible_pairings[ i ] );
351 Size const rg_pairing( static_cast< int > (
RG.uniform() * possible_pairings.size() ) + 1 );
352 tr.Debug <<
"RANDOM: choose pairing " << rg_pairing << std::endl;
356 for ( Templates::const_iterator it=templates_->begin(),
357 eit = templates_->end(); it!=eit && !found; ++it ) {
360 found = strand_stats_->topology( it->first ).has_pairing( possible_pairings[ rg_pairing ]);
364 if ( found || !templates_ ) target_pairings.push_back( possible_pairings[ rg_pairing ]);