29 #include <ObjexxFCL/FArray1D.hh>
30 #include <ObjexxFCL/FArray2D.hh>
31 #include <ObjexxFCL/FArray1A.hh>
32 #include <ObjexxFCL/FArray2A.hh>
35 #include <utility/vector1.fwd.hh>
36 #include <utility/pointer/ReferenceCount.hh>
37 #include <basic/Tracer.hh>
40 #include <numeric/xyzVector.hh>
46 #include <utility/vector1.hh>
55 static basic::Tracer
tr(
"protocols.simple_filters.SheetFilter");
59 using namespace basic;
60 using namespace ObjexxFCL;
63 namespace simple_filters {
67 if ( !AbinitioBaseFilter::apply( pose ) )
return false;
68 if ( sstype_ ==
"fail" )
return true;
70 if ( beta_ < 20 || beta_ratio_ <= 0.2 )
return true;
80 float const distance_cutoff = { 6.5 };
89 int local_pairs,nonlocal_pairs;
101 FArray2D_float position( 3, max_pos*max_res );
103 for (
int i = 1; i <= max_res; i += 1) {
104 int const itemp = max_pos*(i-1)+1;
106 position(1,itemp) = pose.
residue(i).
xyz(
"N").x();
107 position(2,itemp) = pose.
residue(i).
xyz(
"N").y();
108 position(3,itemp) = pose.
residue(i).
xyz(
"N").z();
109 position(1,itemp+1) = pose.
residue(i).
xyz(
"CA").x();
110 position(2,itemp+1) = pose.
residue(i).
xyz(
"CA").y();
111 position(3,itemp+1) = pose.
residue(i).
xyz(
"CA").z();
115 position(1,itemp+3) = pose.
residue(i).
xyz(
"C").x();
116 position(2,itemp+3) = pose.
residue(i).
xyz(
"C").y();
117 position(3,itemp+3) = pose.
residue(i).
xyz(
"C").z();
118 position(1,itemp+4) = pose.
residue(i).
xyz(
"O").x();
119 position(2,itemp+4) = pose.
residue(i).
xyz(
"O").y();
120 position(3,itemp+4) = pose.
residue(i).
xyz(
"O").z();
123 res_num = FArray1D_int( max_pos * max_res );
124 isN = FArray1D_int( max_pos * max_res );
125 isC = FArray1D_int( max_pos * max_res );
126 isCA = FArray1D_int( max_pos * max_res );
128 for (
int i = 1, e = max_pos*max_res; i<= e; i+= max_pos ) {
147 for (
int j = 0; j < max_pos; ++j ) {
148 res_num(i+j) = (i/max_pos) + 1;
152 FArray1D_int ss( max_res );
154 for (
int i = 1; i <= max_res; ++i ) {
165 handedness_score_ = 0.0;
169 ingo_sheet_stuff(max_res, ss, max_res*max_pos, position, isN, isCA, isC,
170 res_num, distance_cutoff, nstrands, nsheets, max_distance,
171 min_dotprod, local_pairs, nonlocal_pairs, result);
178 if ( result == 3 )
return false;
179 if ( result == 4 )
return false;
180 if ( result == 6 )
return false;
181 if ( result == 7 )
return false;
182 if ( result == 9 )
return false;
227 SheetFilter::ingo_diamers(
231 FArray2D_float
const & atmps,
235 FArray2A_float strdm,
239 strnm.dimension( nres );
241 rnm.dimension( natm );
242 indC.dimension( natm );
243 indN.dimension( natm );
244 strdm.dimension( nres, 3 );
245 inddm.dimension( nres );
248 for (
int k = 1; k <= nres; ++k ) {
255 for (
int k = 1; k <= natm; ++k ) {
256 if ( rnm(k) < nres ) {
257 if ( ( strnm(rnm(k)) > 0 ) && ( strnm(rnm(k)+1) > 0 ) ) {
258 if ( indN(k) == 1 ) {
259 float x1 = atmps(1,k);
260 float y1 = atmps(2,k);
261 float z1 = atmps(3,k);
264 while ( next_carbon == 0 ) {
265 if ( indC(k+i) == 1 ) {
266 float x2 = atmps(1,k+i);
267 float y2 = atmps(2,k+i);
268 float z2 = atmps(3,k+i);
269 strdm(rnm(k),1) = 0.5*(x1+x2);
270 strdm(rnm(k),2) = 0.5*(y1+y2);
271 strdm(rnm(k),3) = 0.5*(z1+z2);
316 SheetFilter::ingo_find_dir(
323 FArray2A_float strdr,
325 FArray1A_int directions
329 slct.dimension( hm );
330 order.dimension( hm );
331 strlbl.dimension( nstr );
332 strdr.dimension( nstr, 3 );
333 directions.dimension( hm );
335 FArray2D_float centers( max_nstr, 3 );
340 for (
int j = 1; j <= nstr; ++j ) {
341 if ( strlbl(j) == shnm ) {
350 for (
int i = 1; i <= hm; ++i ) {
351 for (
int j = 1; j <= 3; ++j ) {
352 centers(i,j) = strdr(slct(i),j);
364 directions(
order(1)) = 0;
366 for (
int i = 2; i <= hm; ++i ) {
371 if ( dot_prod < 0.0 ) {
372 int const dir1 = directions(
order(i-1)) - 1;
373 directions(
order(i)) = dir1 * dir1;
375 directions(
order(i)) = directions(
order(i-1));
413 SheetFilter::ingo_find_ord(
418 FArray2A_float dstrmin,
421 FArray1A_int sequence,
427 strlbl.dimension( nstr );
428 dstrmin.dimension( nstr, nstr );
429 order.dimension( hm );
430 sequence.dimension( hm );
431 slct.dimension( hm );
434 int cnt,cnt1,cnt2,i,j,proper,token;
435 FArray1D_int nghbrs_cnt( max_nstr );
436 FArray1D_int taken( max_nstr );
437 FArray2D_float nghbrs( max_nstr, max_nstr );
438 FArray2D_float nghbrs_d( max_nstr, max_nstr );
442 for ( j = 1; j <= nstr; ++j ) {
443 if ( strlbl(j) == shnm ) {
451 for ( i = 1; i <= hm; ++i ) {
454 for ( j = 1; j <= hm; ++j ) {
455 nghbrs_d(i,j) = dstrmin(slct(i),slct(j));
457 if ( nghbrs_d(i,j) <= ngbhct ) {
467 for ( j = 1; j <= hm; ++j ) {
468 if ( nghbrs_cnt(j) == 1 ) {
471 }
else if ( nghbrs_cnt(j) == 2 ) {
476 if ( cnt1 == 2 && cnt2 == hm-2 ) {
480 while ( token == 0 ) {
482 if ( nghbrs_cnt(cnt) == 1 ) token = 1;
486 while ( token < hm ) {
487 for ( j = 1; j <= hm; ++j ) {
488 if ( nghbrs(
order(token),j) == 1 && taken(j) == 0 ) {
496 while ( token < hm ) {
498 for ( j = 1; j <= hm; ++j ) {
499 if (
order(j) == token ) sequence(token) = j;
508 if ( proper != 1 ) rubbish = 7;
514 if ( ( proper != 1 ) && ( hm > 4 ) ) rubbish = 8;
556 SheetFilter::ingo_hand(
564 FArray2A_float strdr,
567 FArray1A_int sequence,
568 FArray1A_int directions,
571 bool const use_whole_helix,
575 stpppt.dimension( nstr );
576 strtpt.dimension( nstr );
577 order.dimension( hm );
578 strdr.dimension( nstr, 3 );
579 sequence.dimension( hm );
580 directions.dimension( hm );
581 scstr.dimension( nres );
582 lctn.dimension( nres, 3 );
585 int cnt, i, j, ll, str_ib;
588 FArray1D_float midpoint( 3 );
589 FArray1D_float midpoint_loop( 3 );
590 FArray1D_float vector0( 3 );
592 FArray1D_float vector2( 3 );
593 FArray1D_float vector3( 3 );
598 ll = strtpt(str2) - stpppt(str1) - 1;
601 if ( ll < 5 )
return;
611 if ( directions(k-1) != directions(k) )
return;
629 for ( j = stpppt(str1) + 1; j <= strtpt(str2) - 1; ++j ) {
631 if ( scstr(j) == 2 ) str_ib = 1;
633 if ( str_ib == 1 )
return;
637 if (!use_whole_helix) {
639 for ( i = 1; i <= 3; ++i ) {
640 midpoint_loop(i) = 0.0;
642 for ( j = stpppt(str1) + 1; j <= stpppt(str1) + 3; ++j ) {
644 midpoint_loop(i) += lctn(j,i);
648 for ( j = strtpt(str2) - 3; j < strtpt(str2); ++j ) {
649 midpoint_loop(i) += lctn(j,i);
652 midpoint_loop(i) /= cnt;
655 for ( i = 1; i <= 3; ++i ) {
656 midpoint_loop(i) = 0.0;
659 for ( j = stpppt(str1) + 1; j <= stpppt(str2) - 1; ++j ) {
660 midpoint_loop(i) += lctn(j,i);
663 midpoint_loop(i) /= cnt;
667 for ( i = 1; i <= 3; ++i ) {
670 midpoint(i) = lctn(strtpt(str1),i) + lctn(strtpt(str2),i) +
671 lctn(stpppt(str1),i) + lctn(stpppt(str2),i);
677 vector0(i) = midpoint_loop(i)-midpoint(i);
680 for ( i = 1; i <= 3; ++i ) {
681 vector1(i) = lctn(stpppt(str1),i) + lctn(stpppt(str2),i) -
682 lctn(strtpt(str1),i) - lctn(strtpt(str2),i);
684 vector2(i) = lctn(strtpt(str2),i) + lctn(stpppt(str2),i) -
685 lctn(strtpt(str1),i) - lctn(stpppt(str1),i);
689 vector3(1) = vector2(2)*vector1(3)-vector2(3)*vector1(2);
690 vector3(2) = vector2(3)*vector1(1)-vector2(1)*vector1(3);
691 vector3(3) = vector2(1)*vector1(2)-vector2(2)*vector1(1);
693 dot_prod = vector0(1)*vector3(1)+vector0(2)*vector3(2)+vector0(3)*vector3(3);
697 if ( dot_prod < 0 ) rubbish = 6;
699 if (dot_prod < 0 && use_whole_helix) {
701 handedness_score_ += 0.1*std::fabs(dot_prod);
736 SheetFilter::ingo_ident_sheets(
738 FArray2A_float dstrmin,
748 dstrmin.dimension( nstr, nstr );
749 strprs.dimension( nstr, nstr );
750 strsht.dimension( nstr );
751 strlbl.dimension( nstr );
754 int cnt,lb1,lb2,lbmn,memo,strsm,smm;
755 FArray1D_int fnlbl( max_nstr, 0 );
756 FArray1D_int fncnt( max_nstr, 0 );
757 FArray1D_int strlblord( nstr, 0 );
762 for (
int i = 1; i <= nstr; ++i ) {
764 for (
int j = 1; j <= nstr; ++j ) {
765 if ( dstrmin(i,j) < ngbhct ) strprs(i,j) = 1;
770 for (
int i = 1; i <= nstr; ++i ) {
772 for (
int j = 1; j <= nstr; ++j ) {
798 for (
int j = 1; j <= nstr; ++j ) {
802 for (
int i = 1; i <= (nstr-1); ++i ) {
803 for (
int j = (i+1); j <= nstr; ++j ) {
804 if ( strprs(i,j) == 1 ) {
805 if ( strlbl(i) != strlbl(j) ) {
807 strsm = strsht(i)+strsht(j);
810 lbmn = std::min(strlbl(i),strlbl(j));
811 for (
int k = 1; k <= nstr; ++k ) {
812 if ( strlbl(k) == lb1 || strlbl(k) == lb2 ) {
825 for (
int j = 1; j <= nstr; ++j ) {
829 for (
int j = 1; j <= nstr; ++j ) {
830 fnlbl(strlbl(j)) = 1;
835 for (
int j = 1; j <= nstr; ++j ) {
837 if ( fnlbl(j) == 1 ) {
839 strsht(cnt) = fncnt(j);
844 for (
int j = 1; j <= nstr; ++j ) {
848 for (
int j = 1; j <= (nstr-1); ++j ) {
849 if ( (strlbl(j) > 0) && (strlblord(j) == 0) ) {
852 for (
int k = j+1; k <= nstr; ++k ) {
853 if ( strlbl(j) == strlbl(k) ) {
863 while ( cnt < nsht ) {
864 for (
int j = 1; j <= nstr; ++j ) {
865 if ( strlbl(j) > cnt ) {
872 for (
int j = 1; j <= nstr; ++j ) {
873 if ( strlbl(j) == memo ) strlbl(j) = cnt;
907 SheetFilter::ingo_lnl(
914 order.dimension( hm );
916 for (
int i = 2; i <= hm; ++i ) {
952 SheetFilter::ingo_locations(
955 FArray1D_int & indCA,
956 FArray2D_float
const & atmps,
960 indCA.dimension( natm );
962 lctn.dimension( nres, 3 );
965 for (
int j = 1; j <= natm; ++j ) {
966 if ( indCA(j) == 1 ) {
968 for (
int k = 1; k <= 3; ++k ) {
969 lctn(cnt,k) = atmps(k,j);
1001 SheetFilter::ingo_number_of_strands(
1007 scstr.dimension( nres );
1010 for (
int j = 1; j <= (nres-1); ++j ) {
1011 if ( scstr(j) == 2 && scstr(j+1) != 2 ) ++nstr;
1013 if ( scstr(nres) == 2 ) ++nstr;
1056 SheetFilter::ingo_proper_sheets(
1060 FArray2A_float dstrmin,
1061 FArray2A_float strdr,
1062 FArray1A_int strsht,
1063 FArray1A_int strlbl,
1066 float & mindotprodabs,
1067 FArray1A_int strtpt,
1068 FArray1A_int stpppt,
1069 FArray2A_int locdsm,
1070 FArray2A_float lctn,
1074 dstrmin.dimension( nstr, nstr );
1075 strdr.dimension( nstr, 3 );
1076 strsht.dimension( nstr );
1077 strlbl.dimension( nstr );
1078 strtpt.dimension( nstr );
1079 stpppt.dimension( nstr );
1080 locdsm.dimension( nstr, nstr );
1081 lctn.dimension( nres, 3 );
1083 float dot_prod, ln1, ln2;
1085 FArray1D_float dir1( 3 );
1086 FArray1D_float dir2( 3 );
1093 if ( nstr < 2 ) rubbish = 3;
1097 for (
int j = 1; j <= nsht; ++j ) {
1098 if ( strsht(j) < 2 ) rubbish = 4;
1101 if ( rubbish == 0 ) {
1102 mindotprodabs = 1.0;
1105 for (
int i = 1; i <= nsht; ++i ) {
1107 for (
int j = 1; j <= (nstr-1); ++j ) {
1108 if ( strlbl(j) != lbbl )
goto L7777;
1109 if ( stpppt(j)-strtpt(j) < 6 )
goto L7777;
1110 for (
int k = (j+1); k <= nstr; ++k ) {
1111 if ( strlbl(k) != lbbl )
goto L8888;
1112 if ( stpppt(k)-strtpt(k) < 6 )
goto L8888;
1113 if ( dstrmin(j,k) < ngbhct ) {
1114 maxdist = std::max(dstrmin(j,k),maxdist);
1116 for (
int l = 1; l <= 3; ++l ) {
1119 pick1 = locdsm(j,k);
1120 pick2 = locdsm(k,j);
1121 if ( locdsm(j,k) <= 3 ) pick1 = 4;
1122 if ( locdsm(j,k) >= nres-3 ) pick1 = nres-4;
1123 if ( locdsm(k,j) <= 3 ) pick2 = 4;
1124 if ( locdsm(k,j) >= nres-3 ) pick2 = nres-4;
1125 dir1(l) = lctn(pick1+3,l)-lctn(pick1-3,l);
1126 dir2(l) = lctn(pick2+3,l)-lctn(pick2-3,l);
1128 dot_prod = dir1(1)*dir2(1) + dir1(2)*dir2(2) + dir1(3)*dir2(3);
1130 ( dir1(1) * dir1(1) ) +
1131 ( dir1(2) * dir1(2) ) +
1132 ( dir1(3) * dir1(3) ) );
1134 ( dir2(1) * dir2(1) ) +
1135 ( dir2(2) * dir2(2) ) +
1136 ( dir2(3) * dir2(3) ) );
1137 dot_prod /= (ln1*ln2);
1138 if ( std::abs(dot_prod) < mindotprodabs ) {
1139 mindotprodabs = std::abs(dot_prod);
1195 SheetFilter::ingo_sheet_stuff(
1199 FArray2D_float
const & atmps,
1200 FArray1D_int & indN,
1201 FArray1D_int & indCA,
1202 FArray1D_int & indC,
1216 scstr.dimension( nres );
1218 indN.dimension( natm );
1219 indCA.dimension( natm );
1220 indC.dimension( natm );
1221 rnm.dimension( natm );
1285 ingo_clean_ss(nres,scstr);
1286 ingo_number_of_strands(nres,scstr,nstr);
1289 }
else if ( nstr == 1 ) {
1292 FArray1D_int inddm( nres, 0 );
1293 FArray1D_int strnm( nres, 0 );
1294 FArray1D_int directions( nstr );
1295 FArray1D_int
order( nstr );
1296 FArray1D_int slct( nstr );
1297 FArray1D_int sequence( nstr );
1298 FArray1D_int strlbl( nstr, 0 );
1299 FArray1D_int strsht( nstr, 0 );
1300 FArray1D_int strtpt( nstr, 0 );
1301 FArray1D_int stpppt( nstr, 0 );
1302 FArray2D_int locdsm( nstr, nstr, 0 );
1303 FArray2D_int strprs( nstr, nstr, 0 );
1304 FArray2D_float dstrmin( nstr, nstr, 0.0 );
1305 FArray2D_float lctn( nres, 3, 0.0 );
1306 FArray2D_float strdm( nres, 3, 0.0 );
1307 FArray2D_float strdr( nstr, 3, 0.0 );
1309 ingo_start_stop(nres,scstr,nstr,strnm,strtpt,stpppt);
1310 ingo_diamers(nres,strnm,natm,atmps,rnm,indC,indN,strdm,inddm);
1311 ingo_locations(nres,natm,indCA,atmps,lctn);
1312 ingo_strand_dirs(nres,nstr,strtpt,stpppt,lctn,strdr);
1313 ingo_strand_dists_min(nres,nstr,inddm,strnm,strdm,dstrmin,locdsm);
1314 ingo_ident_sheets(nstr,dstrmin,ngbhct,strprs,nsht,strsht,strlbl,
1318 ingo_proper_sheets(nstr,nsht,ngbhct,dstrmin,strdr,strsht,strlbl,
1319 rubbish,maxdt,mindp,strtpt,stpppt,locdsm,lctn,nres);
1323 for (
int j = 1; j <= nsht; ++j ) {
1329 int const hm = strsht(j);
1330 for (
int k = 1; k <= hm; ++k ) {
1336 ingo_find_ord(j,hm,nstr,strlbl,dstrmin,ngbhct,order,sequence,slct,
1341 if ( rubbish > 6 )
goto L1234;
1342 ingo_lnl(hm,order,nloc,nnloc);
1343 ingo_find_dir(j,hm,nstr,slct,order,strlbl,strdr,directions);
1344 bool use_whole_helix (
false);
1345 for (
int k = 2; k <= hm; ++k ) {
1346 ingo_hand(k,hm,stpppt,strtpt,slct(k-1),slct(k),order,strdr,
1347 nstr,nres,sequence,directions,scstr,lctn,use_whole_helix,rubbish);
1354 use_whole_helix =
true;
1355 for (
int k = 2; k <= hm; ++k ) {
1356 ingo_hand(k,hm,stpppt,strtpt,slct(k-1),slct(k),order,strdr,
1357 nstr,nres,sequence,directions,scstr,lctn,use_whole_helix,rubbish);
1394 SheetFilter::ingo_start_stop(
1399 FArray1A_int strtpt,
1403 scstr.dimension( nres );
1404 strnm.dimension( nres );
1405 strtpt.dimension( nstr );
1406 stpppt.dimension( nstr );
1411 if ( scstr(1) == 2 ) start = 1;
1413 while ( j < (nres-1) ) {
1416 if ( scstr(j) == 2 ) {
1417 if ( start == 0 ) start = j;
1419 if ( scstr(j) != scstr(j+1) ) {
1422 strtpt(cnt) =
start;
1423 stpppt(cnt) = stopp;
1430 if ( scstr(nres) == 2 ) {
1432 strtpt(cnt) =
start;
1465 SheetFilter::ingo_strand_dirs(
1468 FArray1A_int strtpt,
1469 FArray1A_int stpppt,
1470 FArray2A_float lctn,
1471 FArray2A_float strdr
1474 strtpt.dimension( nstr );
1475 stpppt.dimension( nstr );
1476 lctn.dimension( nres, 3 );
1477 strdr.dimension( nstr, 3 );
1479 for (
int i = 1; i <= nstr; ++i ) {
1480 for (
int j = 1; j <= 3; ++j ) {
1481 strdr(i,j) = lctn(stpppt(i),j)-lctn(strtpt(i),j);
1515 SheetFilter::ingo_strand_dists_min(
1520 FArray2A_float strdm,
1521 FArray2A_float dstrmin,
1525 inddm.dimension( nres );
1526 strnm.dimension( nres );
1527 strdm.dimension( nres, 3 );
1528 dstrmin.dimension( nstr, nstr );
1529 locdsm.dimension( nstr, nstr );
1531 for (
int i = 1; i <= nstr; ++i ) {
1532 for (
int j = 1; j <= nstr; ++j ) {
1534 dstrmin(i,j) = 10000.0;
1538 for (
int i = 1; i <= nres; ++i ) {
1539 if ( inddm(i) > 0 ) {
1540 float const si1 = strdm(i,1);
1541 float const si2 = strdm(i,2);
1542 float const si3 = strdm(i,3);
1543 for (
int j = 1; j <= nres; ++j ) {
1544 if ( (inddm(j) > 0) && (strnm(j) != strnm(i)) ) {
1545 float const sd1 = si1 - strdm(j,1);
1546 float const sd2 = si2 - strdm(j,2);
1547 float const sd3 = si3 - strdm(j,3);
1549 std::sqrt( ( sd1 * sd1 ) + ( sd2 * sd2 ) + ( sd3 * sd3 ) );
1550 if ( dist < dstrmin(strnm(i),strnm(j)) ) {
1551 dstrmin(strnm(i),strnm(j)) = dist;
1552 locdsm(strnm(i),strnm(j)) = i;
1553 locdsm(strnm(j),strnm(i)) = j;
1622 SheetFilter::ingo_clean_ss(
1627 scstr.dimension( nres );
1630 if ( scstr(nres) == 2 && scstr(nres-1) != 2 ) {
1633 if ( scstr(1) == 2 && scstr(2) != 2 ) {
1638 for (
int j = 2; j <= (nres-1); ++j ) {
1639 if ( scstr(j-1) == 2 && scstr(j) != 2 && scstr(j+1) == 2 ) {
1643 for (
int j = 2; j <= (nres-1); ++j ) {
1644 if ( scstr(j-1) != 2 && scstr(j) == 2 && scstr(j+1) != 2 ) {
1645 scstr(j) = scstr(j-1);