41 #include <ObjexxFCL/format.hh>
44 #include <basic/Tracer.hh>
45 #include <utility/io/izstream.hh>
46 #include <utility/vector1.hh>
49 #include <numeric/random/random.hh>
65 using namespace fragment;
66 using namespace ObjexxFCL;
68 static basic::Tracer
tr(
"protocols.jumping");
74 FrameList jump_geometries;
80 frags->add( jump_geometries );
86 utility::io::izstream data( fname.c_str() );
87 tr.Info <<
"read jump-definitions from " << fname << std::endl;
89 std::cerr <<
"ERROR:: Unable to open constraints file: "
90 << fname << std::endl;
96 while ( getline(data, line ) ) {
97 std::istringstream in( line );
108 using namespace ObjexxFCL::fmt;
109 tr.Debug <<
"read Jumps: " << RJ(4, jump.
start_) << RJ( 4, jump.
end_ ) << RJ( 4, cuts.
start_ ) << RJ( 4, cuts.
end_ )<< std::endl;
110 add_jump( jump, cuts );
118 : total_weight_( 0 ), min_loop_length_( 5 ), loop_extension_(2), nr_jumps_min_(3), nr_jumps_max_(6) {}
120 : secstruct_( ss), total_weight_( 0 ), min_loop_length_( 5 ), loop_extension_(2), nr_jumps_min_(3), nr_jumps_max_(6) {}
127 utility::io::izstream data( fname.c_str() );
128 tr.Info <<
"read jump-definitions from " << fname << std::endl;
130 utility_exit_with_message(
"ERROR: could not open file " + fname );
135 while ( getline(data, line ) ) {
136 if ( line.find(
"nr_jumps") !=std::string::npos ) {
137 std::istringstream in( line );
140 tr.Debug <<
"read nr_jumps: min " <<
nr_jumps_min_ <<
"... max " << nr_jumps_max_ << std::endl;
142 }
else if ( line.find(
"loop_params") !=std::string::npos ) {
143 std::istringstream in( line );
146 tr.Debug <<
"read min_loop_length: " <<
min_loop_length_ <<
" loop_extension " << loop_extension_ << std::endl;
149 std::istringstream in( line );
157 using namespace ObjexxFCL::fmt;
158 tr.Debug <<
"read Jumps: " << RJ(7, jump.
start_) << RJ( 7, jump.
end_ ) << RJ( 7, weight ) <<std::endl;
165 out <<
"r_fold_cst: ";
166 for (
Size i = 1; i<=nres; i++ ) {
167 if ( (i-1)%10 == 0 ) { out << i;
continue; }
169 if ( (i>=10) && (i-2)%10 == 0 ) {
continue; }
170 if ( (i>=100) && (i-3)%10 == 0 ) {
continue; }
171 if ( (i>=1000) && (i-4)%10 == 0 ) {
continue; }
174 out <<
"\nr_fold_cst: ";
175 for (
Size i = 1; i<=nres; i++ ) {
176 if ( tags( i ) <= -10 ) out <<
'C';
177 if ( tags( i ) == -1 ) out <<
'L';
178 if ( tags( i ) == 0 ) out <<
'.';
179 if ( tags( i ) > 0 ) out << tags( i );
187 while ( tags( pos ) >= -1 ) {
189 if ( --pos == 0 )
break;
193 runtime_assert( pos == 0 || tags( pos ) == -10 );
195 while ( tags( pos ) >= -1 ) {
197 if ( pos > nres )
break;
200 runtime_assert( pos > nres || tags( pos ) <= -10 );
205 static numeric::random::RandomGenerator
RG(489134);
219 tr.Info <<
"generate " << nr_jumps <<
"jumps for following secstruct:\n";
223 FArray1D_int tags( nres , 0 );
224 for (
Size i = 0; i < nres; i++ ) {
226 for (
int ii=std::max((
int)i-(
int)
loop_extension_,0); ii<= std::min( (
int) i + (
int)loop_extension_, (
int) nres-1); ii++) {
231 if (
tr.Trace.visible() )
dump_tags_( tags, nres, std::cout );
234 for (
Size i = 1; i <= nres; i++ ) {
236 if ( tags( i ) == -10 ) {
240 if ( tags( j ) > -10 ) {
245 while ( tags( i ) == -10 ) {
246 if ( bShort ) tags( i ) = -1;
248 if ( i > nres )
break;
254 Size min_free_size_ = 1;
255 for (
Size i = 1; i<=nres; i++ ) {
256 if ( tags( i ) == 0 ) {
258 while ( tags( i+ct ) == 0 ) { ct++;
if ( ct+i > nres )
break; }
259 if ( ct <= min_free_size_ ) {
260 for (
Size jj=0; jj<ct; jj++) {
268 if (
tr.Trace.visible() )
dump_tags_( tags, nres, std::cout );
272 while ( nr < nr_jumps && attempts < 1000 ) {
275 int start_tag = tags( aJump.
start_ );
276 int stop_tag = tags( aJump.
end_ );
278 if ( start_tag == stop_tag && start_tag > 0 )
continue;
279 if ( start_tag < 0 || stop_tag < 0 )
continue;
282 int new_tag = start_tag;
283 int replace_tag = stop_tag;
284 if ( new_tag < stop_tag ) {
286 replace_tag = start_tag;
289 if ( new_tag == 0 ) new_tag = nr;
290 if ( replace_tag > 0 ) {
292 for (
Size i = 1; i <= nres; i++ ) {
293 if ( tags( i ) == replace_tag ) tags(i) = new_tag;
296 tr.Info <<
"after " << attempts <<
" attempts, jump at " << aJump.
start_ <<
" -- " << aJump.
end_ <<
" with tag " << new_tag << std::endl ;
299 if (
tr.Trace.visible() )
dump_tags_( tags, nres, std::cout );
300 jump_list.push_back( aJump );
302 if ( attempts >= 1000 )
tr.Warning <<
"failed to find " << nr_jumps <<
" jumps in "
303 <<attempts<<
" attempts. Only " << nr <<
" possible jumps found\n";
310 MetaCutList all_cuts;
311 std::map< int, bool > tag_list;
312 for (
Size pos=1; pos <= nres; pos ++ ) {
313 if ( tags( pos ) > 0 ) {
315 tag_list[ tags( pos ) ] =
true;
318 while ( tags( pos ) > 0 ) { ++pos;
if ( pos > nres)
break; };
319 if ( pos > nres )
break;
321 runtime_assert ( tags( pos ) <= 0 );
324 while ( tags( pos ) <= 0 ) {
327 while ( tags( pos ) > -10 ) { ++pos;
if ( pos > nres)
break; };
328 if ( pos > nres )
break;
331 runtime_assert ( tags( pos ) == -10 );
336 while ( tags( pos ) == -10 ) { ++pos;
if ( pos > nres)
break; };
337 if ( pos > nres )
break;
339 runtime_assert( tags( pos-1 ) == -10 && tags( pos ) > -10 );
341 cut_list.push_back( cut );
342 tr.Trace <<
"cut: possible " << cut.
start_ <<
" " << cut.
end_ << std::endl;
344 if ( pos > nres )
break;
345 runtime_assert( tags( pos ) > 0 );
348 bool bConnected =
false;
349 for ( std::map< int , bool>::const_iterator it = tag_list.begin(), eit = tag_list.end();
350 it!=eit && !bConnected;
352 for (
Size ii = pos; ii<=nres && !bConnected; ii++ ) {
353 if ( it->first == tags ( ii ) ) bConnected =
true;
354 if ( bConnected )
tr.Trace <<
"add cuts since tag " << it->first <<
" has been found at pos " << ii << std::endl;
357 if ( bConnected ) all_cuts.push_back( cut_list );
361 runtime_assert( all_cuts.size() >= jump_list.size() );
362 MetaCutList::const_iterator cut_pool_it = all_cuts.begin();
364 for ( JumpList::const_iterator it = jump_list.begin(), eit = jump_list.end();
366 int cut_frame_num =
static_cast< int >(
RG.uniform() * cut_pool_it->size() ) + 1;
367 tr.Trace <<
"chosen jump-cut: " << it->start_ <<
" " << it->end_ <<
" cut:" << (*cut_pool_it)[cut_frame_num].start_
368 <<
" " << (*cut_pool_it)[cut_frame_num].end_ << std::endl;
369 my_jumps.
add_jump( *it, (*cut_pool_it)[cut_frame_num] );
387 cumsum += it->weight_;
388 while ( cumsum < ran ) {
389 runtime_assert ( it != eit );
391 cumsum += it->weight_;
394 runtime_assert( it != eit );