29 #include <basic/Tracer.hh>
30 #include <basic/options/option.hh>
31 #include <basic/options/keys/loops.OptionKeys.gen.hh>
32 #include <numeric/xyzVector.hh>
33 #include <numeric/random/random.fwd.hh>
34 #include <numeric/random/random.hh>
35 #include <utility/exit.hh>
36 #include <utility/io/ozstream.hh>
37 #include <utility/string_util.hh>
38 #include <utility/vector1.hh>
50 using namespace ObjexxFCL;
52 static basic::Tracer
tr(
"loops");
53 static numeric::random::RandomGenerator
RG(430);
85 bool const read_loop_file_from_options,
91 if ( read_loop_file_from_options ) {
95 if ( passed_in_filename.compare(
"" ) != 0 )
105 using namespace basic::options;
106 if ( option[ OptionKeys::loops::loop_file ].user() ) {
108 if( loop_files.size() == 1 )
115 tr.Error <<
"Loop choice: " << loop_files[ choice ] <<
" " << choice << std::endl;
140 for (
Size j = i->start(); j <= i->stop(); ++j) {
141 (*center) += pose.
xyz(NamedAtomID(
"CA", j));
158 it->switch_movemap( movemap,
id, allow_moves );
165 os <<
"LOOP begin end cut skip_rate extended" << std::endl;
167 it != it_end; ++it ) {
168 os << *it << std::endl;
181 utility::io::ozstream data;
182 data.open( filename );
184 utility_exit_with_message(
"Couldn't write loops to file: "+filename );
201 it != it_end; ++it ) {
202 data << token <<
" " << it->start() <<
" " << it->stop() <<
" " << it->cut() <<
" "
203 << it->skip_rate() <<
" " << it->is_extended() << std::endl;
214 tr.Trace <<
"adding loop " << loop << std::endl;
217 it != it_end; ++it ) {
219 if(
stop+minimal_gap >= it->start() &&
start <= it->stop() + minimal_gap ) {
220 Loop new_loop( std::min( (
int)
start, (
int) it->start() ), std::max( (
int) it->stop(), (
int)
stop ), it->cut(), it->skip_rate() );
222 tr.Trace <<
"overlapping loop found: " << loop <<
" overlaps with " << *it <<
" create new loop " << new_loop << std::endl;
236 msg +=
"Loops::add_loop error -- bad loop definition\n";
237 msg +=
"begin/end/cut: " + string_of(
start) +
"/" + string_of(
stop) +
"/";
238 msg += string_of(cut) +
"\n";
241 utility_exit_with_message( msg );
255 add_loop(
Loop( start, stop, cut, skip_rate, extended ));
260 add_loop( it->start(), it->stop(), it->cut(),
261 it->skip_rate(), it->is_extended() );
266 add_loop( it->start(), it->stop(), it->cut(),
267 it->skip_rate(), it->is_extended() );
281 bool const extended ) {
282 add_loop( start, stop, cut, skip_rate, extended );
288 it != it_end; ++it ) {
300 std::vector<Size> loops_to_delete_start;
301 std::vector<Size> loops_to_delete_stop;
303 it != it_end; ++it ) {
305 if( temp_stop >= it->start() && temp_stop <= it->stop() ){
306 temp_stop = it->stop();
307 if( std::find( loops_to_delete_start.begin(), loops_to_delete_start.end(),
308 it->start() ) == loops_to_delete_start.end() )
310 loops_to_delete_start.push_back( it->start() );
311 loops_to_delete_stop.push_back( it->stop() );
314 if( temp_start <= it->
stop() && temp_start >= it->start()) {
315 temp_start = it->start();
316 if( std::find( loops_to_delete_start.begin(), loops_to_delete_start.end(),
317 it->start() ) == loops_to_delete_start.end() )
319 loops_to_delete_start.push_back( it->start() );
320 loops_to_delete_stop.push_back( it->stop() );
323 if( temp_start <= it->
start() && temp_stop >= it->stop() ){
324 if( std::find( loops_to_delete_start.begin(), loops_to_delete_start.end(),
325 it->start() ) == loops_to_delete_start.end() )
327 loops_to_delete_start.push_back( it->start() );
328 loops_to_delete_stop.push_back( it->stop() );
332 for(
Size d = 0; d < loops_to_delete_start.size(); ++d )
333 delete_loop(loops_to_delete_start[d], loops_to_delete_stop[d] );
352 runtime_assert( start < stop );
355 it != it_end; ++it ) {
356 if ( start == it->start() && stop == it->stop() ) {
366 runtime_assert( size > 0 );
368 Size const end =
static_cast< Size >( numeric::random::uniform()*
size );
370 while( index != end ) { ++index; ++it; }
378 runtime_assert( num > 0 && num <=
loops_.size() );
379 return loops_[num].size();
386 it != it_end; ++it ) {
404 if ( seqpos >= (it->start()+offset) && seqpos <= (it->stop()-offset) )
return true;
412 if ( seqpos >= it->start() && seqpos <= it->stop() ) {
424 if ( seqpos >= it->start() && seqpos <= it->stop() ) {
436 it != it_end; ++it ) {
437 if ( !it->is_terminal( pose ) ){
438 new_loops_.push_back( *it );
468 for( SerializedLoopList::const_iterator it=loop_data.begin(), it_end=loop_data.end(); it != it_end; ++it ) {
469 tmp_loops.push_back(
Loop( *it ) );
472 std::sort( tmp_loops.begin(), tmp_loops.end(),
Loop_lt() );
481 tr <<
"Loops object initializing itself from pose-numbered loop file named " <<
loop_file_name() <<
". This functionality is soon to be deprecated." << std::endl;
487 tr.Warning <<
"LOOP formats were recently reconciled - with *some* backwards compatibility. Please check your definition files!" << std::endl;
488 tr.Warning <<
"Please check that this is what you intended to read in: " << std::endl;
508 const Loop& first = copy[1];
509 if (first.
start() != 1) {
515 if (last.
stop() != num_residues) {
520 for (
unsigned i = 2; i <= copy.
num_loop(); ++i) {
521 const Loop& prev = copy[i - 1];
522 const Loop& curr = copy[i];
536 it->set_extended( input );
542 it->auto_choose_cutpoint( pose );
548 it->choose_cutpoint( pose );
558 if ( it->start() <= 0 ){
559 tr.Error <<
"ERROR invalid loop " << it->start() <<
" " << it->stop() <<
" " << it->cut() <<
": Beginning less than 1" << std::endl;
560 utility_exit_with_message(
"LoopRebuild::ERROR Loop definition out of boundary \n" );
562 if ( it->stop() > nres ){
563 tr.Error <<
"ERROR invalid loop " << it->start() <<
" " << it->stop() <<
" " << it->cut() <<
": End more than nres(" << nres <<
")" << std::endl;
564 utility_exit_with_message(
"LoopRebuild::ERROR Loop definition out of boundary \n" );
566 Size loopbegin_i = std::min( it->start() , (
Size)1 );
567 Size loopend_i = std::max( it->stop() , nres );
568 Size cutpt_i = it->cut();
569 if ( cutpt_i != 0 && ( cutpt_i > loopend_i || cutpt_i < loopbegin_i ) ) {
570 tr.Error <<
"ERROR invalid loop " << loopbegin_i <<
" " << loopend_i <<
" " << cutpt_i << std::endl;
571 utility_exit_with_message(
"LoopRebuild::ERROR Loop definition out of boundary \n" );
601 for (
int i=0; i<=magnitude; ++i)
605 for (
int i=0; i<=magnitude; ++i)
624 for (
int i=0; i<=magnitude; ++i)
628 for (
int i=0; i<=magnitude; ++i)
633 if((magR == 0) && (magL == 0)){
634 for (
int i=0; i<=magnitude; ++i)
638 for (
int i=0; i<=magnitude; ++i)
654 grow_loop(nres,loop,magnitude,magnitude);
664 Loop originalloop = loop;
668 tr.Debug <<
"GrowLoop: " << loop << std::endl;
671 numeric::random::uniform() * magL
674 numeric::random::uniform() * magR
677 if ( ( extend_start == 0 ) && ( extend_stop == 0 ) ) {
678 if ( numeric::random::uniform() > 0.5 && magL > 0)
686 Loop newloop( loop );
688 std::max( 1, (
int)loop.
start() - (
int)extend_start )
691 std::min( (
int)nres, (
int)loop.
stop() + (
int)extend_stop )
694 tr.Debug <<
"NewLoop before loop check: " << new_start <<
" " << new_stop << std::endl;
698 it != it_end; ++it ) {
699 if((*it) != originalloop ){
701 if ((new_start >= it->start())&&(new_start <= it->
stop())){
702 new_start = it->start();
703 tr.Warning <<
"Tried growing loop into previous loop:" << *it <<
" " << new_start <<
" " << new_stop << std::endl;
706 if ((new_stop <= it->
stop())&&(new_stop >= it->start())){
707 new_stop = it->stop();
708 tr.Warning <<
"Tried growing loop into next loop:" << *it <<
" " << new_start <<
" " << new_stop << std::endl;
713 tr.Debug <<
"NewLoop after loop check: " << new_start <<
" " << new_stop << std::endl;
715 if ( new_stop < loop.
stop() ) {
716 tr.Info <<
"Loop stops earlier than before ???" << std::endl;
717 new_stop = loop.
stop();
719 if ( new_start > loop.
start() ) {
720 tr.Info <<
"Loop starts later than before ???" << std::endl;
721 new_start = loop.
start();
727 if ( new_stop - new_start < 2 && new_start != 1 && new_stop != nres ) {
728 if (magL>0) new_start -= 1;
729 if (magR>0) new_stop += 1;
732 int final_extend_start = loop.
start()-new_start;
733 int final_extend_stop = new_stop-loop.
stop();
737 tr.Info <<
"Extended: (-" << final_extend_start <<
",+" << final_extend_stop
738 <<
") " << loop << std::endl;
744 it->get_residues( selection );
795 if ( other.
size() !=
size() )
return false;
798 if ( *other_it != *it )
return false;
805 return !( *
this == other);
812 it != it_end; ++it ) {
813 it->set_start(
core::Size( it->start() + shift ) );
814 it->set_stop( it->stop() + shift );
815 it->set_cut( it->cut() + shift );