43 #include <ObjexxFCL/FArray2A.hh>
46 #include <utility/vector1.fwd.hh>
47 #include <utility/io/izstream.hh>
48 #include <basic/Tracer.hh>
49 #include <basic/database/open.hh>
52 #include <numeric/random/random.hh>
53 #include <numeric/xyzMatrix.hh>
54 #include <numeric/xyzMatrix.fwd.hh>
61 #include <utility/vector1.hh>
62 #include <numeric/xyz.functions.hh>
64 static basic::Tracer
tr(
"protocols.jumping");
68 using namespace basic;
69 using namespace ObjexxFCL;
74 static numeric::random::RandomGenerator
RG(9238);
76 BasePairingLibrary::~BasePairingLibrary() {}
99 numeric::xyzMatrix_double
const & p,
100 numeric::xyzMatrix_double & m
103 using namespace numeric;
105 xyzVector_double a1 = p.col_x() - p.col_y();
106 xyzVector_double a2 = p.col_z() - p.col_y();
108 xyzVector_double a3 = cross( a1, a2 );
110 a2 = cross( a3, a1 );
112 m = xyzMatrix_double::cols( a1, a2, a3 );
118 numeric::xyzMatrix_double & p
121 pos.dimension( 3, 5 );
122 using namespace numeric;
124 xyzVector_double n( &pos(1,1) );
125 xyzVector_double ca( &pos(1,2) );
126 xyzVector_double
c( &pos(1,4) );
128 p = xyzMatrix_double::cols( n, ca, c );
132 numeric::xyzMatrix_double
135 pos.dimension( 3, 5 );
136 using namespace numeric;
138 xyzVector_double n( &pos(1,1) );
139 xyzVector_double ca( &pos(1,2) );
140 xyzVector_double
c( &pos(1,4) );
142 return xyzMatrix_double::cols( n, ca, c );
156 Size const MAX_POS( 5 );
157 Epos1.dimension(3,MAX_POS);
158 Epos2.dimension(3,MAX_POS);
160 numeric::xyzMatrix_double p1, p2, m1, m2;
185 numeric::xyzVector_double e1( &Epos1(1,2) );
186 numeric::xyzVector_double e2( &Epos2(1,2) );
190 translation = m1.transposed() * ( e2 - e1 );
214 rotation = m1.transposed() * m2;
222 std::cout <<
" p1:\n" << p1 << std::endl;
223 std::cout <<
" p2:\n" << p2 << std::endl;
224 std::cout <<
" m1:\n" << m2 << std::endl;
225 std::cout <<
" m2:\n" << m2 << std::endl;
226 std::cout <<
" translation:\n" << translation << std::endl;
227 std::cout <<
" rotation:\n" << rotation << std::endl;
229 FArray2D_float tmp_pos1(3,MAX_POS), tmp_pos2(3,MAX_POS);
231 for (
int i=1; i<= MAX_POS; ++i ) {
232 for (
int j=1; j<= 3; ++j ) {
233 tmp_pos1(j,i) = Epos1(j,i);
234 tmp_pos2(j,i) = Epos2(j,i);
238 double forward_dev(0), forward_dev2(0), backward_dev(0);
241 make_jump( tmp_pos1, tmp_pos2 );
242 std::cout <<
"tmp_pos1:\n" << tmp_pos1 << std::endl;
243 std::cout <<
"tmp_pos2:\n" << tmp_pos2 << std::endl;
244 for (
int i=1; i<= MAX_POS; ++i ) {
245 if ( i==1 || i==2 || i == 4 ) {
246 for (
int j=1; j<= 3; ++j ) {
247 forward_dev += std::abs( Epos2(j,i) - tmp_pos2(j,i) );
254 make_jump( tmp_pos2, tmp_pos1 );
255 std::cout <<
"tmp_pos1:\n" << tmp_pos1 << std::endl;
256 std::cout <<
"tmp_pos2:\n" << tmp_pos2 << std::endl;
257 for (
int i=1; i<= MAX_POS; ++i ) {
258 if ( i==1 || i==2 || i == 4 ) {
259 for (
int j=1; j<= 3; ++j ) {
260 backward_dev += std::abs( Epos1(j,i) - tmp_pos1(j,i) );
269 make_jump( tmp_pos1, tmp_pos2 );
270 std::cout <<
"tmp_pos1:\n" << tmp_pos1 << std::endl;
271 std::cout <<
"tmp_pos2:\n" << tmp_pos2 << std::endl;
272 for (
int i=1; i<= MAX_POS; ++i ) {
273 if ( i==1 || i==2 || i == 4 ) {
274 for (
int j=1; j<= 3; ++j ) {
275 forward_dev2 += std::abs( Epos2(j,i) - tmp_pos2(j,i) );
280 std::cout <<
"RT::RT: debug make_jump:"
281 <<
" fdev= " << F(9,6,forward_dev)
282 <<
" bdev= " << F(9,6,backward_dev)
283 <<
" fdev2= " << F(9,6,forward_dev2) << std::endl;
320 const float MAX_NO_DIST ( 3.1 );
324 float o,p1,p2,mn_dist,mx_dist,
325 phi1,psi1,omega1,phi2,psi2,omega2;
326 Size const MAX_POS( 5 );
327 FArray2D_float Epos1(3,MAX_POS), Epos2(3,MAX_POS);
328 utility::io::izstream data( fn );
330 while ( getline( data,line ) ) {
331 std::istringstream is( line );
334 is >> tag >> filename >> pos1 >> pos2 >> mn_dist >> mx_dist >>
336 Epos1(1,1) >> Epos1(2,1) >> Epos1(3,1) >>
337 Epos1(1,2) >> Epos1(2,2) >> Epos1(3,2) >>
338 Epos1(1,4) >> Epos1(2,4) >> Epos1(3,4) >>
339 Epos2(1,1) >> Epos2(2,1) >> Epos2(3,1) >>
340 Epos2(1,2) >> Epos2(2,2) >> Epos2(3,2) >>
341 Epos2(1,4) >> Epos2(2,4) >> Epos2(3,4) >>
343 phi1 >> psi1 >> omega1 >>
344 phi2 >> psi2 >> omega2;
348 if ( is.fail() || tag !=
"PAIR" )
continue;
350 runtime_assert ( pos1 < pos2 && p1 * p2 > 0.0 &&
351 std::abs(phi1) < 185 && std::abs(psi1) < 185 && std::abs(omega1) < 185 &&
352 std::abs(phi2) < 185 && std::abs(psi2) < 185 && std::abs(omega2) < 185 );
357 if ( mx_dist > MAX_NO_DIST ||
358 phi1 > 0.0 || phi2 > 0.0 ||
359 psi1 < 50.0 || psi2 < 50.0 ||
360 std::abs( omega1 ) < 90 ||
361 std::abs( omega2 ) < 90 )
continue;
370 t.
omega (1) = omega1;
371 t.
omega (2) = omega2;
375 t_reverse.
rt_ = this_rt;
376 t_reverse.
phi (1) = phi2;
377 t_reverse.
phi (2) = phi1;
378 t_reverse.
psi (1) = psi2;
379 t_reverse.
psi (2) = psi1;
380 t_reverse.
omega (1) = omega2;
381 t_reverse.
omega (2) = omega1;
382 const int o_key( ( o < 0.0 ) ? 1 : 2 );
383 const int p_key( ( p1 < 0.0 ) ? 1 : 2 );
387 pairings_[ std::make_pair( o_key, p_key ) ].push_back( t );
388 pairings_[ std::make_pair( o_key, p_key ) ].push_back( t_reverse );
402 float o,p1,p2,mn_dist,mx_dist,
403 phi1,psi1,omega1,phi2,psi2,omega2;
404 Size const MAX_POS( 5 );
405 FArray2D_float Epos1(3,MAX_POS), Epos2(3,MAX_POS);
406 utility::io::izstream data( fn );
407 std::ofstream template_infofile(
"jump_TMH_templates.dat.info");
408 while ( getline( data,line ) ) {
409 std::istringstream is( line );
412 is >> tag >> filename >> pos1 >> pos2 >> mn_dist >> mx_dist >>
415 n1.x() >> n1.y() >> n1.z() >>
416 ca1.x() >> ca1.y() >> ca1.z() >>
417 c1.x() >> c1.y() >> c1.z() >>
419 n2.x() >> n2.y() >> n2.z() >>
420 ca2.x() >> ca2.y() >> ca2.z() >>
421 c2.x() >> c2.y() >> c2.z() >>
423 phi1 >> psi1 >> omega1 >>
424 phi2 >> psi2 >> omega2;
430 if ( p1 ==
'E' || p1 == 1 ) {
432 }
else if ( p1 ==
'H' || p1 == 2) {
434 }
else if ( p1 ==
'L' || p1 == 3) {
437 std::cout <<
"bad secstruct: " << p1 << std::endl;
440 if ( p2 ==
'E' || p2 == 1 ) {
442 }
else if ( p2 ==
'H' || p2 == 2) {
444 }
else if ( p2 ==
'L' || p2 == 3) {
447 std::cout <<
"bad secstruct: " << p2 << std::endl;
451 template_infofile << fn <<
' ' << this_rt <<
"\n";
459 t.
omega (1) = omega1;
460 t.
omega (2) = omega2;
465 if(pos1==0 && pos2 == 1)
467 const int o_key = (
int)o;
471 pairings_[ std::make_pair( o_key, p_key ) ].push_back( t );
474 const int o_key = (
int)o;
476 std::cout << t.
rt_ <<
"\n";
479 pairings_[ std::make_pair( pos1, pos2 ) ].push_back( t );
482 pairings_[ std::make_pair( o_key, p_key ) ].push_back( t );
487 template_infofile.close();
493 int const orientation,
500 std::pair<int,int> key( orientation, pleating );
503 runtime_assert (
pairings_.count( key ) == 1 );
508 const int ntemplates ( templates.size() );
510 int const index( static_cast<int>(
RG.uniform() * ntemplates ) );
526 std::pair<int,int> generic_key (orientation,0);
527 std::pair<int,int> specific_key (pos1,pos2);
531 (
pairings_.find( specific_key )->second );
533 const int ntemplates ( templates.size() );
535 int const index( static_cast<int>(
RG.uniform() * ntemplates ) );
539 std::cout <<
"No key found for " << pos1 <<
' ' << pos2 <<
" using the generic template\n";
541 const int ntemplates_generic ( templates_generic.size() );
542 int const index( static_cast<int>(
RG.uniform() * ntemplates_generic) );
551 int const jump_number,
552 int const orientation,
560 std::pair<int,int> generic_key (orientation,0);
561 std::pair<int,int> specific_key (pos1,pos2);
565 (
pairings_.find( specific_key )->second );
567 const int ntemplates ( templates.size() );
569 int const index( static_cast<int>(
RG.uniform() * ntemplates ) );
571 std::cout << jump_number <<
"\n";
587 std::cout <<
"No key found for " << pos1 <<
' ' << pos2 <<
" using the generic template\n";
589 const int ntemplates_generic ( templates_generic.size() );
590 int const index( static_cast<int>(
RG.uniform() * ntemplates_generic) );
592 std::cout << jump_number <<
"\n";
613 int const orientation,
618 using namespace core::fragment;
624 std::pair<int,int> key( orientation, pleating );
627 runtime_assert (
pairings_.count( key ) == 1 );
632 const int ntemplates ( templates.size() );
633 const int iStart( 1 );
634 const int iStop ( 2 );
635 frags.reserve( ntemplates );
636 for ( PairingTemplateList::const_iterator it=templates.begin(), eit=templates.end();
639 if ( bWithTorsion ) {
641 start->set_torsion( 1, it->phi( iStart ) );
642 start->set_torsion( 2, it->psi( iStart ) );
643 start->set_torsion( 3, it->omega( iStart ) );
645 frags.back()->add_residue( start );
648 frags.back()->add_residue(
new UpJumpSRFD() );
649 frags.back()->add_residue(
new DownJumpSRFD( it->rt_, it->atoms_downstream_, it->atoms_upstream_,
'X' ) );
651 if ( bWithTorsion ) {
653 stop->set_torsion( 1, it->phi( iStop ) );
654 stop->set_torsion( 2, it->psi( iStop ) );
655 stop->set_torsion( 3, it->omega( iStop ) );
657 frags.back()->add_residue( stop );
659 frags.back()->set_valid();
675 typedef std::map< std::pair< Size, Size >, JumpList > JumpOrientations;
676 JumpOrientations jump_kind;
678 for ( core::scoring::dssp::PairingsList::const_iterator it = pairings.begin(), eit = pairings.end();
680 Size o_key ( it->Orientation() );
681 Size p_key ( it->Pleating() );
682 jump_kind[ std::make_pair( o_key, p_key ) ].push_back( jump_nr++ );
686 for ( JumpOrientations::const_iterator it=jump_kind.begin(), eit=jump_kind.end();
690 Size o_key( it->first.first );
691 Size p_key( it->first.second );
694 for ( JumpList::const_iterator jit=it->second.begin(), ejit=it->second.end();
696 int const jump_nr ( *jit );
697 int const startpos( pairings[ jump_nr ].Pos1() );
698 int const endpos( pairings[ jump_nr ].Pos2() );
701 Size const length( bWithTorsion ? 4 : 2 );
702 runtime_assert( length == frag_data.front()->size() );
704 frame->add_fragment( frag_data );
705 frags_accumulator.
add( frame );
707 utility_exit_with_message(
"need to implement this: make ss-library fragments that only contain those torsions for residues\
708 that can move according to movemap -- call this function with \
709 bWithTorsions = false ... and it works for now");
718 if ( instance_ == NULL ) {
720 instance_->read_from_file( basic::database::full_name(
"scoring/score_functions/jump_templates_SSpairs_v2.dat") );