20 #include <boost/math/special_functions/round.hpp>
22 return boost::math::iround(x); }
38 #include <basic/Tracer.hh>
39 #include <utility/vector1.hh>
45 static basic::Tracer
tr(
"protocols.noesy_assign.calibration");
49 using namespace basic;
54 namespace noesy_assign {
59 void StructureDependentPeakCalibrator::init_calibrator() {
60 generate_constraints();
63 void StructureDependentPeakCalibrator::generate_constraints() {
65 constraints_.resize( npeaks, NULL );
69 runtime_assert( structures_.size() )
72 (*it)->create_fa_and_cen_constraint( constraints_[ ct ], dummy, pose, dummy_pose, 1, 0.0 ,
true );
78 Real inv_n_struct( 1.0 / structures_.size() );
79 runtime_assert( peak <= peaks().
size() );
80 runtime_assert( constraints_.size() == peaks().size() );
85 if ( constraints_[ peak ] &&
87 for ( PoseVector::const_iterator pose_it = structures_.begin(); pose_it != structures_.end(); ++pose_it, ++pose_ct ) {
88 Real dist( constraints_[ peak ]->dist( **pose_it ) );
91 violated += ( dist - peaks()[ peak ]->distance_bound() ) > dcalibrate_;
95 stddev = stddev*inv_n_struct - mean*mean;
98 collect_target_statistics( violated*inv_n_struct, types );
109 void StructureDependentPeakCalibrator::eliminate_violated_constraints() {
115 RealVector distance_deltas( structures_.size(), 0.0 );
119 if ( !constraints_[ ct ] )
continue;
123 for ( PoseVector::const_iterator pose_it = structures_.begin(); pose_it != structures_.end(); ++pose_it, ++pose_ct ) {
124 Real delta( constraints_[ ct ]->dist( **pose_it ) - peaks()[ ct ]->distance_bound() );
125 distance_deltas[ pose_ct ] = delta;
126 violated += delta > params.
dcut_;
130 tr.Trace <<
"Check peak " << (*it)->peak_id() <<
" for nudging... "<< std::endl;
131 Real const CORRECTION_STEP( 0.1 );
133 Real const old_violated( violated );
134 for (
Real correction = 0.1; correction <= max_correction; correction += CORRECTION_STEP ) {
137 for ( PoseVector::const_iterator pose_it = structures_.begin(); pose_it != structures_.end(); ++pose_it, ++pose_ct ) {
138 Real delta( distance_deltas[ pose_ct ] - correction );
139 violated += delta > params.
dcut_;
142 peaks()[ ct ]->nudge_distance_bound( correction );
143 for ( PoseVector::const_iterator pose_it = structures_.begin(); pose_it != structures_.end(); ++pose_it, ++pose_ct ) {
144 distance_deltas[ pose_ct ] -= correction;
146 tr.Debug <<
"peak: " << (*it)->peak_id() <<
" " << (*it)->filename()
147 <<
" original violations: " << old_violated
148 << std::setprecision(2) <<
" new distance: " << peaks()[ ct ]->distance_bound()
149 <<
" nudged by: " << correction
150 << std::setprecision(2) <<
" of max " << max_correction
151 <<
" new violations: " << violated << std::endl;
154 violated=old_violated;
159 tr.Debug <<
"peak: " << (*it)->peak_id() <<
" " << (*it)->filename() <<
" violations: " << violated << std::endl;
161 std::ostringstream elim_msg;
162 elim_msg << violated <<
" ("<<distance_deltas.size()<<
") violated by >" << distance_deltas[1] <<
"A (" << params.
dcut_ <<
"A) ";
163 (*it)->set_elimination_comment( elim_msg.str() );
167 std::sort( distance_deltas.begin(), distance_deltas.end() );
172 Size const low_quartil_pos( lrint( 1.0*distance_deltas.size()*0.25 ) );
173 Real const low_quartil_dist( distance_deltas[ low_quartil_pos ]+(*it)->distance_bound() );
174 tr.Debug <<
"peak: " << (*it)->peak_id() <<
" " << (*it)->filename() <<
" check " << num_element_cluster <<
" of a total " << distance_deltas.size() <<
" distances for max-extension " << std::endl;
175 Real max_extension( 1000 );
177 tr.Debug <<
"peak: " << (*it)->peak_id() <<
" " << (*it)->filename() <<
" dist " << (*it)->distance_bound() <<
" REMOVED due to large Q1 dist of " << low_quartil_dist << std::endl;
178 (*it)->set_eliminated_due_to_dist_violations(
true );
179 std::ostringstream elim_msg;
180 elim_msg <<
"Q1 dist to high: " << low_quartil_dist;
181 (*it)->set_elimination_comment( elim_msg.str() );
183 for (
Size start_cluster = 1; start_cluster+num_element_cluster-1 <= distance_deltas.size(); start_cluster++ ) {
184 Real ext = distance_deltas[ start_cluster+num_element_cluster-1 ] - distance_deltas[ start_cluster ];
185 if ( max_extension > ext ) max_extension = ext;
188 tr.Debug << num_element_cluster <<
" distances are in an interval of only " << max_extension <<
" with a Q1 dist of " << low_quartil_dist << std::endl;
198 Size viol_count( 0 );
199 tr.Trace <<
" dist: " << (*it)->distance_bound() <<
"| " ;
201 for ( RealVector::const_iterator delta_it = distance_deltas.begin(); delta_it != distance_deltas.end(); ++delta_it ) {
202 tr.Trace <<
" " << *delta_it;
203 viol_count += ( *delta_it > violation_cutoff ) ? 1 : 0;
205 tr.Trace << std::endl;
207 tr.Debug <<
"peak: " << (*it)->peak_id() <<
" " << (*it)->filename() <<
" dist: " << (*it)->distance_bound()
208 <<
" max_extension " << max_extension <<
" viol_count " << viol_count
211 (*it)->set_eliminated_due_to_dist_violations( viol_count > ( params.
nr_conformers_violatable_*distance_deltas.size() ) );
212 std::ostringstream elim_msg;
213 elim_msg << viol_count <<
" ("<<distance_deltas.size()<<
") violated by >" << distance_deltas[1] <<
"A (" << violation_cutoff <<
"A) ";
214 (*it)->set_elimination_comment( elim_msg.str() );