Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PairingLibrary.cc
Go to the documentation of this file.
1 // -*- mode:c++;tab-width:2;indent-tabs-mode:t;show-trailing-whitespace:t;rm-trailing-spaces:t -*-
2 // vi: set ts=2 noet:
3 //
4 // (c) Copyright Rosetta Commons Member Institutions.
5 // (c) This file is part of the Rosetta software suite and is made available under license.
6 // (c) The Rosetta software is developed by the contributing members of the Rosetta Commons.
7 // (c) For more information, see http://www.rosettacommons.org. Questions about this can be
8 // (c) addressed to University of Washington UW TechTransfer, email: license@u.washington.edu.
9 
10 /// @brief
11 /// @detailed
12 ///
13 /// @author Bjorn Wallner
14 /// @author Christopher Miles (cmiles@uw.edu)
15 
16 // Unit Headers
18 
19 // Package Headers
21 
22 // Project Headers
23 #include <core/pose/Pose.hh>
24 #include <core/pose/util.hh>
25 #include <core/types.hh>
27 #include <core/kinematics/Jump.hh>
29 #include <core/kinematics/Stub.hh>
30 #include <core/id/NamedStubID.hh>
31 
32 #ifdef WIN32
33 #include <core/fragment/FragID.hh>
34 #endif
36 #include <core/fragment/FragSet.hh>
41 
42 // ObjexxFCL Headers
43 #include <ObjexxFCL/FArray2A.hh>
44 
45 // Utility headers
46 #include <utility/vector1.fwd.hh>
47 #include <utility/io/izstream.hh>
48 #include <basic/Tracer.hh>
49 #include <basic/database/open.hh>
50 
51 // numeric headers
52 #include <numeric/random/random.hh>
53 #include <numeric/xyzMatrix.hh>
54 #include <numeric/xyzMatrix.fwd.hh>
55 
56 // C++ headers
57 #include <cstdlib>
58 #include <string>
59 
61 #include <utility/vector1.hh>
62 #include <numeric/xyz.functions.hh>
63 
64 static basic::Tracer tr("protocols.jumping");
65 
66 using core::Real;
67 using namespace core;
68 using namespace basic;
69 using namespace ObjexxFCL;
70 
71 namespace protocols {
72 namespace jumping {
73 
74 static numeric::random::RandomGenerator RG(9238); // <- Magic number, do not change it, huaah hah ha!
75 
76 BasePairingLibrary::~BasePairingLibrary() {}
77 
78 //------------------------------------------------------------------------------
79 // the x-axis of this coordinate system is along the p(*,2) -> p(*,1) bond vector
80 // the y-axis is in the p(*,*) plane, with positive dot product to p(*,2) -> p(*,3) vector
81 
82 // m(*,1) is the x-axis unit vector of this new coord system expressed in
83 // the absolute coordinates defining the positions p(*,j)
84 // this corresponds to a column in the matrix m (non-CHarlie convention)
85 //
86 // thus multiplication by m can be interpreted as taking a vector in the
87 // local coordinate system defined by m and expressing it in the absolute
88 // coordinate system in which the coords p are defined
89 //
90 // by multiplication I mean non-charlie multiplication (row,col) indexing
91 //
92 // likewise, multiplication by m^t = m inverse can be thought of
93 // as expressing a vector given in absolute coords in terms of the
94 // local coordinate system defined by m
95 //
96 
97 void
99  numeric::xyzMatrix_double const & p, // input
100  numeric::xyzMatrix_double & m // output
101 )
102 {
103  using namespace numeric;
104 
105  xyzVector_double a1 = p.col_x() - p.col_y();
106  xyzVector_double a2 = p.col_z() - p.col_y();
107  a1.normalize();
108  xyzVector_double a3 = cross( a1, a2 );
109  a3.normalize();
110  a2 = cross( a3, a1 );
111 
112  m = xyzMatrix_double::cols( a1, a2, a3 );
113 }
114 
115 void
117  FArray2A_float pos,
118  numeric::xyzMatrix_double & p
119 )
120 {
121  pos.dimension( 3, 5 );
122  using namespace numeric;
123 
124  xyzVector_double n( &pos(1,1) );
125  xyzVector_double ca( &pos(1,2) );
126  xyzVector_double c( &pos(1,4) );
127 
128  p = xyzMatrix_double::cols( n, ca, c );
129 
130 }
131 
132 numeric::xyzMatrix_double
133 get_ncac ( FArray2A_float pos )
134 {
135  pos.dimension( 3, 5 );
136  using namespace numeric;
137 
138  xyzVector_double n( &pos(1,1) );
139  xyzVector_double ca( &pos(1,2) );
140  xyzVector_double c( &pos(1,4) );
141 
142  return xyzMatrix_double::cols( n, ca, c );
143 }
144 
145 
146 //helper code to make an RT from two Epos
147 // does this live somewhere else in mini, haven't found it !
149 RT RT_from_epos( FArray2A_float Epos1, FArray2A_float Epos2)
150 {
151  /// rotation matrix, written in stub1 frame
152  RT::Matrix rotation( 0.0 ); // 3x3
153  /// tranlsation vector, written in stub1 frame
154  RT::Vector translation( 0.0 ); // 3
155 
156  Size const MAX_POS( 5 ); // param::MAX_POS
157  Epos1.dimension(3,MAX_POS);
158  Epos2.dimension(3,MAX_POS);
159 
160  numeric::xyzMatrix_double p1, p2, m1, m2;
161 
162  // get coordinate systems from both residues
163  get_ncac(Epos1,p1);
164  get_ncac(Epos2,p2);
165  get_coordinate_system(p1,m1);
166  get_coordinate_system(p2,m2);
167 
168  // consider this: |xx xy xz|
169  // coordinate frame M = |yx yy yz|
170  // |zx zy zz|
171  // each column is a unit vector written in genuine frame.
172  //
173  // vector A in frame M can be rewritten as B in genuine frame
174  // by the formula B = M x A, thus A = M^T x B
175  // a simple example of this would be: the unit vector (1,0,0) in frame M
176  // is actually (xx,yx,zx) in genuine frame. mathematically,
177  // |xx| |xx xy xz| |1|
178  // |yx| = |yx yy yz| x |0| ==> B = M x A
179  // |zx| |zx zy zz| |0|
180  //
181  // the above formula has another layer of meaning: rotation
182  // keeping the genuine frame fixed, a vector can be rotated by applying
183  // matrix M onto it, e.g., (1,0,0) rotated to (xx,yx,zx)
184 
185  numeric::xyzVector_double e1( &Epos1(1,2) );
186  numeric::xyzVector_double e2( &Epos2(1,2) );
187 
188  // ( e2 - e1 ) is the vector in genuine frame,
189  // translation is the vector in m1 frame. so m1^T is multiplied.
190  translation = m1.transposed() * ( e2 - e1 );
191 
192  // let's look at the rotation matrix
193  // A, B, C are three vectors in genuine frame and are related by rotation
194  // B = M1 x A; C = M2 x A;
195  // ==> A = M1^T x B = M2^T x C
196  // ==> C = M2 x M1^T x B
197  // but note that C and B are both in genuine frame and we want a rotation
198  // matrix to be applied onto a vector in M1 frame, so comes another step of
199  // conversion -- left-multiply M1^T on both sides:
200  // M1^T x C = M1^T x M2 x M1^T x B
201  // C' = M1^T x M2 x B', as C' and B' are written in M1 frame.
202  // so we get the rotation matrix as M1^T x M2.
203  // but wait a minute, what Phil orginally got below is M2^T x M1 and it is
204  // impossible for that to be wrong, then what happens?
205 
206  // It turns out when this rotation matrix is further applied to a vector,
207  // it uses Charlies' (col,row) convention (see Dvect_multiply()
208  // in RT::make_jump) which means there is one more transpose to do.
209  // Now an agreement is reached:
210  // (M2^T x M1)^T = M1^T x (M2^T)^T = M1^T x M2
211  // since xyzMatrix uses the normal (row,col) convention, we will switch to
212  // rotation = M1^T x M2
213 
214  rotation = m1.transposed() * m2;
215  RT rt;
216  rt.set_translation( translation );
217  rt.set_rotation( rotation );
218 
219  return rt;
220 #if 0
221  if (local_debug ) {
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;
228  // debug building: ////////////////
229  FArray2D_float tmp_pos1(3,MAX_POS), tmp_pos2(3,MAX_POS);
230 
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);
235  }
236  }
237 
238  double forward_dev(0), forward_dev2(0), backward_dev(0);
239 
240  // first: make the jump forward
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) );
248  }
249  }
250  }
251 
252  // now make backward:
253  reverse();
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) );
261  }
262  }
263  }
264 
265  //restore original direction
266  reverse();
267 
268  // final sanity check:
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) );
276  }
277  }
278  }
279 
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;
284  } // if (local_debug )
285 #endif
286 }
287 
288 
289 PairingTemplate::PairingTemplate ( std::string const& s1, std::string const& s2, std::string const& s3 ) :
290  phi ( 2, 0.0 ),
291  psi ( 2, 0.0 ),
292  omega( 2, 0.0 ),
293  secstruct(2,'H')
294 {
295  atoms_downstream_.reserve(3);
296  atoms_downstream_.push_back( s1 );
297  atoms_downstream_.push_back( s2 );
298  atoms_downstream_.push_back( s3 );
300 }
301 
303  phi ( 2, 0.0 ),
304  psi ( 2, 0.0 ),
305  omega( 2, 0.0 ),
306  secstruct(2,'H')
307 {
308  atoms_downstream_.reserve(4);
309  atoms_downstream_.push_back( c );
310  atoms_downstream_.push_back( s1 );
311  atoms_downstream_.push_back( s2 );
312  atoms_downstream_.push_back( s3 );
314 }
315 
316 ///////////////////////////////////////////////////////////////////////////////
317 void
319 {
320  const float MAX_NO_DIST ( 3.1 );
321  std::string line;
322  std::string tag,filename;
323  int pos1,pos2;
324  float o,p1,p2,mn_dist,mx_dist,
325  phi1,psi1,omega1,phi2,psi2,omega2;
326  Size const MAX_POS( 5 ); // param::MAX_POS
327  FArray2D_float Epos1(3,MAX_POS), Epos2(3,MAX_POS);
328  utility::io::izstream data( fn ); //or from database file
329 
330  while ( getline( data,line ) ) {
331  std::istringstream is( line );
332  Vector n1, ca1, c1;
333  Vector n2, ca2, c2;
334  is >> tag >> filename >> pos1 >> pos2 >> mn_dist >> mx_dist >>
335  o >> p1 >> p2 >>
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) >>
342 
343  phi1 >> psi1 >> omega1 >>
344  phi2 >> psi2 >> omega2;
345 
346  RT this_rt(RT_from_epos(Epos1,Epos2));
347 
348  if ( is.fail() || tag != "PAIR" ) continue;
349 
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 );
353 
354  // filter
355  // note that the filename contains info about the scop class so you could
356  // in principle filter for b,c,or d class proteins individually
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;
362 
363  // fill in a new beta-pairing template
364  PairingTemplate t("CA","N","CA","C");
365  t.rt_ = this_rt;
366  t.phi (1) = phi1;
367  t.phi (2) = phi2;
368  t.psi (1) = psi1;
369  t.psi (2) = psi2;
370  t.omega (1) = omega1;
371  t.omega (2) = omega2;
372 
373  this_rt.reverse();
374  PairingTemplate t_reverse("CA","N","CA","C");
375  t_reverse.rt_ = this_rt;
376  t_reverse.phi (1) = phi2; //reverse... also put torsions on the right side of jump
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 ); // orientation
383  const int p_key( ( p1 < 0.0 ) ? 1 : 2 ); // pleating
384  Vector dNN = n1-ca1;
385  Vector dNC = n1-c1;
386  Vector dCCA = c1-ca1;
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 );
389 
390  //each "view" gives a different result, it cannot be decided a-priori which one will be more appropriate
392  }
393 }
394 
395  ///////////////////////////////////////////////////////////////////////////////
396  void
398  {
399  std::string line;
400  std::string tag,filename;
401  int pos1,pos2;
402  float o,p1,p2,mn_dist,mx_dist,
403  phi1,psi1,omega1,phi2,psi2,omega2;
404  Size const MAX_POS( 5 ); // param::MAX_POS
405  FArray2D_float Epos1(3,MAX_POS), Epos2(3,MAX_POS);
406  utility::io::izstream data( fn ); //or from database file
407  std::ofstream template_infofile("jump_TMH_templates.dat.info");
408  while ( getline( data,line ) ) {
409  std::istringstream is( line );
410  Vector n1, ca1, c1;
411  Vector n2, ca2, c2;
412  is >> tag >> filename >> pos1 >> pos2 >> mn_dist >> mx_dist >>
413  o >> p1 >> p2 >>
414 
415  n1.x() >> n1.y() >> n1.z() >>
416  ca1.x() >> ca1.y() >> ca1.z() >>
417  c1.x() >> c1.y() >> c1.z() >>
418 
419  n2.x() >> n2.y() >> n2.z() >>
420  ca2.x() >> ca2.y() >> ca2.z() >>
421  c2.x() >> c2.y() >> c2.z() >>
422 
423  phi1 >> psi1 >> omega1 >>
424  phi2 >> psi2 >> omega2;
425 
426  RT this_rt( kinematics::Stub( ca1, n1, ca1, c1 ), kinematics::Stub( ca2, n2, ca2, c2) );
427 
428  // fill in a new beta-pairing template
429  char ss1,ss2;
430  if ( p1 == 'E' || p1 == 1 ) {
431  ss1 = 'E';
432  } else if ( p1 == 'H' || p1 == 2) {
433  ss1 = 'H';
434  } else if ( p1 == 'L' || p1 == 3) {
435  ss1 = 'L';
436  }else {
437  std::cout << "bad secstruct: " << p1 << std::endl;
438  continue;
439  }
440  if ( p2 == 'E' || p2 == 1 ) {
441  ss2 = 'E';
442  } else if ( p2 == 'H' || p2 == 2) {
443  ss2 = 'H';
444  } else if ( p2 == 'L' || p2 == 3) {
445  ss2 = 'L';
446  }else {
447  std::cout << "bad secstruct: " << p2 << std::endl;
448  continue;
449  }
450 
451  template_infofile << fn << ' ' << this_rt << "\n";
452 
453  PairingTemplate t("CA","N","CA","C");
454  t.rt_ = this_rt;
455  t.phi (1) = phi1;
456  t.phi (2) = phi2;
457  t.psi (1) = psi1;
458  t.psi (2) = psi2;
459  t.omega (1) = omega1;
460  t.omega (2) = omega2;
461  t.secstruct(1)=ss1;
462  t.secstruct(2)=ss2;
463 
464  // bw for TMH the jump library are specific to the positions. these are defined in the template file to 1 or 2.
465  if(pos1==0 && pos2 == 1)
466  {
467  const int o_key = (int)o;
468  const int p_key = 0; //p1;
469 
470  // This is for generic use in case pos1,pos2 from pairings_file is not defined in the jump library.
471  pairings_[ std::make_pair( o_key, p_key ) ].push_back( t );
473  } else {
474  const int o_key = (int)o;
475  const int p_key = 0; //p1;
476  std::cout << t.rt_ << "\n";
477 
478  // This is when we want to test a number of different jump for a particular position.
479  pairings_[ std::make_pair( pos1, pos2 ) ].push_back( t );
480 
481  //Put all in generic library as well...
482  pairings_[ std::make_pair( o_key, p_key ) ].push_back( t );
485  }
486  }
487  template_infofile.close();
488  }
489 
490 ///////////////////////////////////////////////////////////////////////////////
493  int const orientation,
494  int const pleating
495 ) const
496 {
497  runtime_assert( pairings_.size() > 0 );
498 
499  // key for looking up the template geometry:
500  std::pair<int,int> key( orientation, pleating );
501 
502  // HACK to get it to compile -- fix this later
503  runtime_assert ( pairings_.count( key ) == 1 );
504 
505  const PairingTemplateList & templates
506  ( pairings_.find( key )->second );
507 
508  const int ntemplates ( templates.size() );
509 
510  int const index( static_cast<int>( RG.uniform() * ntemplates ) );
511  const PairingTemplate &t ( templates[ index ] );
512 
513  return t.rt_;
514 }
515 
516  ///////////////////////////////////////////////////////////////////////////////
518  PairingLibrary::get_random_tmh_jump(int const orientation,
519  int const pos1,
520  int const pos2
521  ) const
522  {
523  assert( pairings_.size() > 0 );
524 
525  // key for looking up the template geometry:
526  std::pair<int,int> generic_key (orientation,0);
527  std::pair<int,int> specific_key (pos1,pos2);
528  // std::pair<int,int> key (specific_key); // Unused variable causes warning.
529 
530  const PairingTemplateList & templates
531  ( pairings_.find( specific_key )->second );
532 
533  const int ntemplates ( templates.size() );
534  if(ntemplates>0) {
535  int const index( static_cast<int>( RG.uniform() * ntemplates ) );
536  const PairingTemplate &t ( templates[ index ] );
537  return t.rt_;
538  } else { // use the generic key
539  std::cout << "No key found for " << pos1 << ' ' << pos2 << " using the generic template\n";
540  const PairingTemplateList & templates_generic( pairings_.find( generic_key )->second );
541  const int ntemplates_generic ( templates_generic.size() );
542  int const index( static_cast<int>( RG.uniform() * ntemplates_generic) );
543  const PairingTemplate &t ( templates[ index ] );
544  return t.rt_;
545  }
546  }
547 
548  ///////////////////////////////////////////////////////////////////////////////
549  void
551  int const jump_number,
552  int const orientation,
553  int const pos1,
554  int const pos2
555  ) const
556  {
557  assert( pairings_.size() > 0 );
558 
559  // key for looking up the template geometry:
560  std::pair<int,int> generic_key (orientation,0);
561  std::pair<int,int> specific_key (pos1,pos2);
562  // std::pair<int,int> key (specific_key); // Unused variable causes warning.
563 
564  const PairingTemplateList & templates
565  ( pairings_.find( specific_key )->second );
566 
567  const int ntemplates ( templates.size() );
568  if(ntemplates>0) {
569  int const index( static_cast<int>( RG.uniform() * ntemplates ) );
570  const PairingTemplate &t ( templates[ index ] );
571  std::cout << jump_number << "\n";
572  std::cout << t.rt_;
573 
574  pose.set_phi(pos1,t.phi(1));
575  pose.set_phi(pos2,t.phi(2));
576  pose.set_psi(pos1,t.psi(1));
577  pose.set_psi(pos2,t.psi(2));
578  pose.set_omega(pos1,t.omega(1));
579  pose.set_omega(pos2,t.omega(2));
580  pose.set_secstruct(pos1,t.secstruct(1));
581  pose.set_secstruct(pos2,t.secstruct(2));
582 
583  id::StubID up_stub( core::pose::named_stub_id_to_stub_id( core::id::NamedStubID( "CA","N","CA","C", pos1 ), pose ) );
584  id::StubID down_stub( core::pose::named_stub_id_to_stub_id( core::id::NamedStubID( "CA","N","CA","C", pos2 ), pose ) );
585  pose.conformation().set_stub_transform( up_stub, down_stub, t.rt_ );
586  } else { // use the generic key
587  std::cout << "No key found for " << pos1 << ' ' << pos2 << " using the generic template\n";
588  const PairingTemplateList & templates_generic( pairings_.find( generic_key )->second );
589  const int ntemplates_generic ( templates_generic.size() );
590  int const index( static_cast<int>( RG.uniform() * ntemplates_generic) );
591  const PairingTemplate &t ( templates[ index ] );
592  std::cout << jump_number << "\n";
593  std::cout << t.rt_;
594 
595  pose.set_phi(pos1,t.phi(1));
596  pose.set_phi(pos2,t.phi(2));
597  pose.set_psi(pos1,t.psi(1));
598  pose.set_psi(pos2,t.psi(2));
599  pose.set_omega(pos1,t.omega(1));
600  pose.set_omega(pos2,t.omega(2));
601  pose.set_secstruct(pos1,t.secstruct(1));
602  pose.set_secstruct(pos2,t.secstruct(2));
603 
604  id::StubID up_stub( core::pose::named_stub_id_to_stub_id( core::id::NamedStubID( "CA","N","CA","C", pos1 ), pose ) );
605  id::StubID down_stub( core::pose::named_stub_id_to_stub_id( core::id::NamedStubID( "CA","N","CA","C", pos2 ), pose ) );
606  pose.conformation().set_stub_transform( up_stub, down_stub, t.rt_ );
607  }
608  }
609 
610 /// @details puts all jump-geometries that fit the orientation and pleating into
611 /// list of FragData's. Try to reuse these FragData for different Frames that have same orientation and pleating
613  int const orientation,
614  int const pleating,
615  bool bWithTorsion,
617 ) const {
618  using namespace core::fragment;
619 
620  // read_jump_templates(); // self-initializing
621  runtime_assert( pairings_.size() > 0 );
622 
623  // key for looking up the template geometry:
624  std::pair<int,int> key( orientation, pleating );
625 
626  // HACK to get it to compile -- fix this later
627  runtime_assert ( pairings_.count( key ) == 1 );
628 
629  const PairingTemplateList & templates
630  ( pairings_.find( key )->second );
631 
632  const int ntemplates ( templates.size() );
633  const int iStart( 1 ); // in templates start residue is number 1
634  const int iStop ( 2 ); // in templates stop residue is number 2
635  frags.reserve( ntemplates );
636  for ( PairingTemplateList::const_iterator it=templates.begin(), eit=templates.end();
637  it!=eit; ++it ) {
638  frags.push_back( new FragData );
639  if ( bWithTorsion ) {
640  BBTorsionSRFDOP start = new BBTorsionSRFD( 3, 'E', 'X' );
641  start->set_torsion( 1, it->phi( iStart ) );
642  start->set_torsion( 2, it->psi( iStart ) );
643  start->set_torsion( 3, it->omega( iStart ) );
644 
645  frags.back()->add_residue( start );
646  }
647 
648  frags.back()->add_residue( new UpJumpSRFD() );
649  frags.back()->add_residue( new DownJumpSRFD( it->rt_, it->atoms_downstream_, it->atoms_upstream_, 'X' ) );
650 
651  if ( bWithTorsion ) {
652  BBTorsionSRFDOP stop = new BBTorsionSRFD( 3, 'E', 'X' );
653  stop->set_torsion( 1, it->phi( iStop ) );
654  stop->set_torsion( 2, it->psi( iStop ) );
655  stop->set_torsion( 3, it->omega( iStop ) );
656 
657  frags.back()->add_residue( stop );
658  }
659  frags.back()->set_valid(); // yes there is data in this Fragment
660  } // for-loop
661 } // create_jump_fragments
662 
663 void
665  core::scoring::dssp::PairingsList const& pairings,
666  kinematics::MoveMap const& mm,
667  bool bWithTorsion,
668  core::fragment::FragSet& frags_accumulator
669 ) {
670  runtime_assert( has_orientation_and_pleating( pairings ) );
671 
672  // find out how many different kind of fragments are we interested in:
673  // max of four: A 1 , A 2, P 1, P 2
675  typedef std::map< std::pair< Size, Size >, JumpList > JumpOrientations;
676  JumpOrientations jump_kind;
677  Size jump_nr ( 1 );
678  for ( core::scoring::dssp::PairingsList::const_iterator it = pairings.begin(), eit = pairings.end();
679  it != eit; ++it ) {
680  Size o_key ( it->Orientation() ); // < 0 ? 1 : 2 );
681  Size p_key ( it->Pleating() ); // < 0 ? 1 : 2 );
682  jump_kind[ std::make_pair( o_key, p_key ) ].push_back( jump_nr++ );
683  }
684 
685  // now generate fragments for each of the maximum four JumpOrientations present
686  for ( JumpOrientations::const_iterator it=jump_kind.begin(), eit=jump_kind.end();
687  it!=eit;
688  ++it )
689  {
690  Size o_key( it->first.first ); //orientation
691  Size p_key( it->first.second ); //pleating ... believe me or not, it is in first.second
692  fragment::FragDataList frag_data;
693  create_jump_fragments( o_key, p_key, bWithTorsion, frag_data );
694  for ( JumpList::const_iterator jit=it->second.begin(), ejit=it->second.end();
695  jit!=ejit; ++jit ) {
696  int const jump_nr ( *jit );
697  int const startpos( pairings[ jump_nr ].Pos1() );
698  int const endpos( pairings[ jump_nr ].Pos2() );
699 
700  if ( mm.get_bb( startpos ) && mm.get_bb( endpos ) ) {
701  Size const length( bWithTorsion ? 4 : 2 );
702  runtime_assert( length == frag_data.front()->size() );
703  fragment::JumpingFrameOP frame = generate_empty_jump_frame( startpos, endpos, length );
704  frame->add_fragment( frag_data );
705  frags_accumulator.add( frame );
706  } else {
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");
710  }
711  } // for JumpList iteration
712  } // loop over orientations and pleatings
713 } // method
714 
716 
718  if ( instance_ == NULL ) {
719  instance_ = new StandardPairingLibrary();
720  instance_->read_from_file( basic::database::full_name("scoring/score_functions/jump_templates_SSpairs_v2.dat") );
721  };
722  return instance_;
723 }
724 
725 } // jumping
726 } // protocols