17 #include <basic/options/option.hh>
29 #include <numeric/random/random_permutation.hh>
30 #include <numeric/random/random.hh>
31 #include <basic/Tracer.hh>
33 #include <ObjexxFCL/FArray2D.hh>
36 #include <basic/options/keys/constraints.OptionKeys.gen.hh>
38 #include <utility/vector0.hh>
39 #include <utility/vector1.hh>
43 namespace constraints {
45 static numeric::random::RandomGenerator
RG(42015512);
48 static basic::Tracer
tr(
"core.scoring.constraints");
57 static Real sqrt_2pi = 2.50662721600161;
59 Real answer = log(weight / (sd * sqrt_2pi)) - ( r * r / (2*sd*sd) );
70 Real answer = - (r / (sd*sd) );
78 if ( weight < 1e-10 ) {
84 static Real sqrt_2pi = 2.50662721600161;
85 Real answer = weight * (1 / (sd * sqrt_2pi)) * exp( -1 * r * r / (2*sd*sd) );
93 assert( weight >= 0.0 && weight <= 1.0 );
95 if ( weight < 1e-10 ) {
100 Real r = abs( x - mean );
101 Real answer =
dgaussian( x, mean, sd , weight ) * ( 1 / ( sd * sd ) ) * r;
109 assert( weight >= 0.0 && weight <= 1.0 );
110 if ( weight < 1e-10 ) {
115 Real r = abs( x - anchor );
116 Real answer = weight * rate * exp( -1 * rate * r );
124 if ( weight < 1e-10 ) {
129 Real r = abs( x - anchor );
130 return weight * rate * rate * exp( -1 * rate * r );
141 if ( x_val == x1 )
return y1;
142 if ( x_val == x2 )
return y2;
145 Real slope = ( y2 - y1 ) / ( x2 - x1 );
147 return (x_val - x1) * slope;
158 for ( ConstraintCOPs::const_iterator it = target_list.begin(),
159 eit = target_list.end(); it != eit; ++it ) {
160 if ( (*it)->show_violations(
tr.Debug, filter_pose, 1, threshold ) == 0 ) {
161 culled_list.push_back( *it );
169 using namespace basic::options;
172 if ( cst_files.size() > 1 ) choice=
core::Size(
RG.random_range( 1,cst_files.size() ) );
173 tr.Info <<
"Constraint choice: " << cst_files[choice] << std::endl;
174 return cst_files[choice];
179 using namespace basic::options;
180 using namespace core::scoring::constraints;
181 if ( option[ OptionKeys::constraints::cst_file ].user() ) {
189 using namespace basic::options;
190 if ( option[ OptionKeys::constraints::cst_weight ].user() ) {
206 using namespace basic::options;
208 = option[ OptionKeys::constraints::cst_fa_file ]();
210 if ( cst_files.size() > 1 ) choice=
core::Size(
RG.random_range( 2,cst_files.size() ) );
211 tr.Info <<
"Constraint choice: " << cst_files[choice] << std::endl;
212 return cst_files[choice];
219 using namespace basic::options;
220 using namespace core::scoring::constraints;
221 if ( option[ OptionKeys::constraints::cst_fa_file ].user() ) {
231 using namespace basic::options;
232 if ( option[ OptionKeys::constraints::cst_fa_weight ].user() ) {
254 using namespace core::id;
255 using namespace core::conformation;
256 using namespace core::scoring::constraints;
258 Size const my_anchor( 1 );
263 for (
Size i=1; i<= nres; ++i ) {
267 for (
Size ii = 1; ii<= i_rsd.nheavyatoms(); ++ii ) {
279 if ( exclude_res.size() == 0 )
return true;
281 for(
core::Size i(1); i <= pos_list.size(); ++i ) {
282 Size const seqpos( pos_list[i] );
283 runtime_assert( seqpos <= exclude_res.size() );
284 if ( !exclude_res[ seqpos ] ) {
301 if ( sep < 5 )
return 1;
302 if ( sep < 20 )
return 2;
303 if ( sep < 50 )
return 3;
315 tr.Info <<
" combine constraints " << combine_ratio <<
" -> 1 " << std::endl;
316 using namespace scoring::constraints;
317 if ( combine_ratio <= 1 )
return;
319 tr.Trace <<
"figure out sequence-separation bins" << std::endl;
321 typedef std::map< core::Size, ConstraintCOPs > SeqSepMap;
322 SeqSepMap seq_sep_map;
325 seq_sep_map[ seq_bin ].push_back( *it );
328 tr.Trace <<
"combine within bins..."<< std::endl;
331 for ( SeqSepMap::iterator bin_it=seq_sep_map.begin(); bin_it != seq_sep_map.end(); ++bin_it ) {
333 random_permutation( bin_it->second,
RG );
334 random_permutation( bin_it->second,
RG );
335 random_permutation( bin_it->second,
RG );
341 Size ct( combine_ratio );
343 for ( ; ct > 0 && it != bin_it->second.end(); ++it ) {
344 tr.Trace <<
" add constraint " << ct << std::endl;
347 combined_cst->add_individual_constraint( *it );
350 out.push_back( *it );
355 tr.Trace <<
" fill last Ambiguous constraint " << ct << std::endl;
356 for ( ConstraintCOPs::const_iterator it2 = bin_it->second.begin(); ct > 0 && it2 != bin_it->second.end(); ++it2 ) {
359 combined_cst->add_individual_constraint( *it2 );
363 combined_cst->choose_effective_sequence_separation( sp_in,
RG );
364 out.push_back( combined_cst );
376 if ( pos_list.size() != 2 ) {
377 tr.Error <<
"problems understanding constraint in skip_redundant_constraints ... ignore and keep this one" << std::endl;
379 tr.Debug <<
" resid: " << *it << std::endl;
385 for (
int i=pos_list[1]-influence_width; i<= pos_list[1]+ (
int) influence_width ; ++i ) {
386 for (
int j=pos_list[2]-influence_width; j<= pos_list[2]+ (
int) influence_width ; ++j ) {
387 if ( i < 1 || j < 1 || i > (
int) total_residue || j > (
int) total_residue )
continue;
388 count_matrix( i, j ) = std::max( count_matrix( i,j ), redundant ? 1 : 2 );
389 count_matrix( j, i ) = count_matrix( i,j );
400 if ( pos_list.size() != 2 ) {
401 tr.Error <<
"problems understanding constraint in skip_redundant_constraints ... ignore and keep this one" << std::endl;
406 if ( ( !redundant && count_matrix( pos_list[1],pos_list[2] ) == 3 ) || count_matrix( pos_list[1],pos_list[2] ) == ( redundant ? 1 : 2 ) ) {
408 for (
int i=pos_list[1]-influence_width; i<= pos_list[1]+ (
int) influence_width ; ++i ) {
409 for (
int j=pos_list[2]-influence_width; j<= (
int) pos_list[2]+ (
int)influence_width ; ++j ) {
410 if ( i < 1 || j < 1 || i > (
int) total_residue || j > (
int) total_residue )
continue;
411 count_matrix( i, j ) += 2;
412 count_matrix( j, i ) = count_matrix( i,j );
422 if ( influence_width == 0 )
return;
424 tr.Info <<
" skip redundant constraints... starting with " << in.size() <<
" constraints" << std::endl;
425 using namespace scoring::constraints;
427 ObjexxFCL::FArray2D_int count_matrix( total_residue, total_residue, 0 );
429 random_permutation( in,
RG );
430 random_permutation( in,
RG );
431 random_permutation( in,
RG );
436 if ( cst_in_casted ) {
437 tr.Debug <<
"casted to AmbiguousNMRConstraint: " << std::endl;
439 count_constraint( *multi_it, cst_in_casted->member_constraints().size() > 1 , count_matrix, influence_width, total_residue );
442 count_constraint( *it,
false, count_matrix, influence_width, total_residue );
446 if (
tr.Trace.visible() ) {
447 for (
Size i=1; i<=total_residue; ++i ) {
448 for (
Size j=i+1; j<=total_residue; ++j ) {
449 tr.Trace << i <<
" " << j <<
" " << count_matrix( i, j ) << std::endl;
459 if ( cst_in_casted ) {
461 keep |=
keep_constraint( *multi_it, cst_in_casted->member_constraints().size() > 1, count_matrix, influence_width, total_residue );
464 keep =
keep_constraint( *it,
false, count_matrix, influence_width, total_residue );
468 out.push_back( *it );
474 if (
tr.Trace.visible() ) {
475 for (
Size i=1; i<=total_residue; ++i ) {
476 for (
Size j=i+1; j<=total_residue; ++j ) {
477 tr.Trace << i <<
" " << j <<
" " << count_matrix( i, j ) << std::endl;
481 tr.Info <<
"remaining non-redundant constraints " << in.size() << std::endl;
487 if (
RG.uniform() >= drop_rate ) {
488 out.push_back( *it );