37 #include <ObjexxFCL/FArray3D.hh>
38 #include <ObjexxFCL/FArray2D.hh>
39 #include <ObjexxFCL/format.hh>
42 #include <basic/Tracer.hh>
43 #include <utility/exit.hh>
44 #include <utility/excn/Exceptions.hh>
45 #include <numeric/model_quality/rms.hh>
46 #include <basic/options/option_macros.hh>
54 #include <utility/vector1.hh>
76 NEW_OPT( dist_cst::max_dist,
"only use distances whose average distance is less than", 10 );
77 NEW_OPT( dist_cst::sd,
"curvature for BoundFunc after ub is reached",1 );
78 NEW_OPT( dist_cst::ub_fact,
"multiply this to sqrt of distance variance to get upper bound", 0.05 );
79 NEW_OPT( dist_cst::lb_fact,
"multiply this to sqrt of distance variance to get lower bound", 0.02 );
80 NEW_OPT( dist_cst::grow_fact,
"grow IN (positive) or OUTWARD( negative ) by grow_fact*(ub-lb)", -0.05 );
81 NEW_OPT( dist_cst::max_spread,
"omit constraints with more than X between ub and lb (suggest: 5-7A) ", 5.0 );
82 NEW_OPT( dist_cst::min_spread,
"enforce minimum flat bottom of X ", 2.0 );
83 NEW_OPT( dist_cst::min_ub,
"make upper bound at least " , 0.0);
84 NEW_OPT( dist_cst::grow_fact_lb,
"on top of grow_fact also grow_fact_lb only for the lb side", 0.00 );
85 NEW_OPT( dist_cst::min_seq_sep,
"only constraints if residues are x apart", 4 );
86 NEW_OPT( dist_cst::median,
"base bounds on sorted distances",
false );
87 NEW_OPT( dist_cst::dump,
"put all dists into this file to play around in matlab or R",
"coords.dat" );
88 NEW_OPT( dist_cst::excl_rigid,
"exclude constraints between residues that are in rigid core",
"core.rigid" );
95 using namespace ObjexxFCL;
97 static basic::Tracer
tr(
"protocols.toolbox.DecoySetEvaluation",basic::t_info);
100 using namespace numeric::model_quality;
125 utility_exit_with_message(
"can't insert poses with varying sizes into DecoySetEvaluation" );
131 throw utility::excn::EXCN_RangeError(
"you can't add any more decoys to DecoySetEvaluation ");
188 std::cerr <<
"DSE erasing the last decoy in the set: " <<
n_decoys_ << std::endl;
190 std::cerr <<
"DSE now has " <<
n_decoys_ << std::endl;
191 std::cerr <<
"DSE redimensioning: old dimension: " <<
coords_.u1() <<
" " <<
coords_.u2() <<
" " <<
coords_.u3() << std::endl;
193 std::cerr <<
"DSE new dimensions : " <<
coords_.u1() <<
" " <<
coords_.u2() <<
" " <<
coords_.u3() << std::endl;
197 Size const n_new_decoys( sfd.
size() );
202 if (
n_atoms() )
tr.Warning <<
"Overriding n_atom in DecoySetEvaluation " << std::endl;
207 FArray1D_double
const weights(
n_atoms_, 1.0 );
216 FArray1D_double transvec( 3 );
225 for (
Size d = 1; d<=3; ++d ) {
226 rmsd += ( xx( d, n ) - xx_ref( d, n ) ) * ( xx( d, n ) - xx_ref( d, n ) ) * invn *
weights_( n );
229 return rmsd = sqrt( rmsd );
235 tr.Debug <<
"superimpose with " <<
n_decoys() <<
" with " << icenter <<
" as reference structure " << std::endl;
238 for (
Size ni = icenter; ni <= go_around; ++ni ) {
239 Size n( ni - offset );
250 if ( n != icenter ) {
259 FArray1D_double
const weights(
n_atoms_, 1.0 );
265 FArray1D_double transvec( 3 );
278 for (
Size d = 1; d<=3; ++d ) {
287 Real best_dist( 100000000 );
288 Size closest_structure( 1 );
293 for (
Size d=1; d<=3; ++d ) {
294 dist2 += (average_structure( d, iatom ) -
coords_( d, iatom, n ))*(average_structure( d, iatom ) -
coords_( d, iatom, n ));
297 tr.Trace <<
"dist to average " << dist2 << std::endl;
298 if ( dist2 < (best_dist - 0.01) ) {
300 closest_structure = n;
303 return closest_structure;
311 for (
Size idecoy = 1; idecoy <=
n_decoys(); ++idecoy ) {
312 for (
Size d = 1; d<=3; ++d ) {
314 rmsd_x( d ) += dx * dx * invn;
315 rmsd_av( d ) += dx * invn;
319 for (
Size d = 1; d<=3; ++d ) {
320 rms += rmsd_x( d ) - rmsd_av( d )*rmsd_av( d );
330 result.push_back(
rmsf( pos ) );
336 result( pos ) =
rmsf( pos );
349 Size max_iter( 100 );
350 tr.Debug <<
"run wRMSD iterations with " <<
n_decoys() <<
" decoys of " <<
n_atoms() <<
" atoms " << std::endl;
351 tr.Info <<
"wRMSD: iter wsum wRMSD icenter " << std::endl;
352 while ( ( std::abs( wsum_old - wsum ) > tolerance ) && ( --max_iter > 0 ) ) {
362 Real di2 = weights( i )*weights( i );
363 weights( i ) = exp( - di2 / sigma2 );
364 wsum += weights( i )*invn;
365 wMSD += weights( i ) * di2;
367 tr.Info <<
"wRMSD: " << ++ct <<
" " << wsum <<
" " << sqrt( wMSD ) <<
" " << i_center << std::endl;
386 FArray1D_double transvec( 3 );
389 for (
Size j = 1; j<i; j++ ) {
396 for (
Size d = 1; d<=3; ++d ) {
397 rmsd += ( xx( d, n ) - xx2( d, n ) ) * ( xx( d, n ) - xx2( d, n ) ) * invn *
weights_( n );
406 if ( count % 50000 == 0 ) {
407 Real const percent_done ( 200.0 * static_cast< Real > ( count ) / ( (
n_decoys() - 1) *
n_decoys() ) );
410 <<
" ( " << ObjexxFCL::fmt::F(8,1,percent_done) <<
"% )"
423 using namespace basic::options;
424 using namespace basic::options::OptionKeys;
427 if ( option[ dist_cst::median ]() ) {
442 Real dist = xi.distance(xj);
443 var += dist * dist * invn;
446 ivm( j, i ) = var - av*av;
447 ivm( i, j ) = ivm( j, i);
448 tr.Debug << i <<
" " << j <<
" " << ivm( i, j ) <<
"\n";
449 if ( av < option[ dist_cst::max_dist ] && ( (
int) j - (
int) i) >= option[ dist_cst::min_seq_sep ]) {
450 using namespace scoring::constraints;
451 Real const lb( sqrt( ivm( i,j ) )*option[ dist_cst::lb_fact ] );
452 Real const ub( sqrt( ivm( i,j ) )*option[ dist_cst::ub_fact ] );
453 Real const sd( option[ dist_cst::sd ] );
457 new BoundFunc( av - lb, av + ub, sd,
"CM_DECOYS" )
461 cst.
show_def( std::cout, dummy_pose );
465 tr.Debug << std::endl;
472 using namespace basic::options;
473 using namespace basic::options::OptionKeys;
477 Size const Nlb( static_cast< Size > ( std::ceil(
n_decoys()*option[ dist_cst::lb_fact ] )));
478 Size const Nub( static_cast< Size > ( std::ceil(
n_decoys()*option[ dist_cst::ub_fact ] )));
479 Real const grow_fact( option[ dist_cst::grow_fact ] );
480 Real const grow_fact_lb( option[ dist_cst::grow_fact_lb ] );
482 if ( option[ dist_cst::excl_rigid ].user() ) {
483 std::ifstream is( option[ dist_cst::excl_rigid ]().name().c_str() );
486 utility_exit_with_message(
"[ERROR] Error opening RBSeg file '" + option[ dist_cst::excl_rigid ]().name() +
"'" );
492 is, option[ dist_cst::excl_rigid ](),
false );
498 if ( rigid.size() && rigid.is_loop_residue( i ) && rigid.is_loop_residue( j ) )
continue;
506 Real dist = xi.distance(xj);
509 dist_sorted[ n - 1 ]=dist;
511 if ( av < option[ dist_cst::max_dist ] && ( (
int) j - (
int) i) >= option[ dist_cst::min_seq_sep ]) {
512 std::sort( dist_sorted, dist_sorted +
n_decoys() );
513 tr.Debug <<
"Nlb: " << Nlb <<
" "<< dist_sorted[ Nlb ] <<
" Nub: " << Nub <<
" " << dist_sorted[
n_decoys()-Nub ] << std::endl;
514 Real lb( dist_sorted[ Nlb ] );
516 lb = lb + (ub-lb)*(grow_fact + grow_fact_lb );
517 ub = ub - (ub-lb)*grow_fact;
518 if ( ub - lb < option[ dist_cst::max_spread ]() ) {
519 if ( ub < option[ dist_cst::min_ub ] ) ub = option[ dist_cst::min_ub ];
520 if ( (ub - lb) < option[ dist_cst::min_spread ]() ) {
521 ub = (ub+lb)*0.5 + 0.5*option[ dist_cst::min_spread ]();
522 lb = (ub+lb)*0.5 - 0.5*option[ dist_cst::min_spread ]();
524 Real const sd( option[ dist_cst::sd ] );
525 using namespace scoring::constraints;
533 cst.
show_def( std::cout, dummy_pose );
536 delete[] dist_sorted;
539 tr.Debug << std::endl;
548 using namespace basic::options;
549 using namespace basic::options::OptionKeys;
553 Size const Nub( static_cast< Size > ( std::ceil(
n_decoys()*option[ dist_cst::ub_fact ] )));
555 utility_exit_with_message(
"set ub_fact to 0.05 such that e.g., 5% of decoys are allowed to violate upper bound." );
557 Real const grow_fact( option[ dist_cst::grow_fact ] );
558 Real const min_ub( option[ dist_cst::min_ub ] );
566 for (
Size d = 1; d<=3; ++d ) {
568 xyz_av( d ) += dx * invn;
573 typedef std::list< std::pair< core::Real, Size > >
PointList;
574 PointList sorted_points;
577 Real dist = xyz_av.distance(xi);
578 sorted_points.push_back( std::make_pair( dist, n ) );
580 sorted_points.sort();
584 Size const N_find_center( static_cast< Size >( std::ceil(
n_decoys()*0.7 )));
585 tr.Debug <<
"use " << N_find_center <<
" points to compute average " << std::endl;
587 for ( PointList::const_iterator it = sorted_points.begin(); ct<=N_find_center; ++ct, ++it ) {
588 for (
Size d = 1; d<=3; ++d ) {
590 xyz_av( d ) += dx / N_find_center;
594 sprintf( buf,
"%8.3f%8.3f%8.3f",xyz_av.x(),xyz_av.y(),xyz_av.z() );
595 std::cout <<
"ATOM " << ObjexxFCL::fmt::RJ( 5, pos) <<
" CA " <<
" ALA A " << ObjexxFCL::fmt::RJ( 3, pos) <<
" " << std::setw( 3) <<
602 Real dist = xyz_av.distance(xi);
603 tr.Debug <<
"push_dist " << dist << std::endl;
604 dist_sorted[ n - 1 ]=dist;
607 std::sort( dist_sorted, dist_sorted +
n_decoys() );
611 delete[] dist_sorted;
612 tr.Debug <<
"ub-raw " << ub << std::endl;
613 ub = ub - ub*grow_fact;
614 if ( ub <= min_ub ) ub = min_ub;
615 using namespace scoring::constraints;
620 new BoundFunc( lb, ub, 1.0,
"CM_DECOYS" )