26 #include <basic/Tracer.hh>
32 #include <numeric/trig.functions.hh>
33 #include <numeric/deriv/angle_deriv.hh>
35 #include <utility/vector1.hh>
36 #include <utility/assert.hh>
40 namespace constraints {
42 static basic::Tracer
TRACER(
"core.io.constraints");
48 out <<
' ' <<
id.rsd() <<
' ' <<
id.atomno();
51 func_->show_definition(out);
60 func_->show_definition( out );
73 Size res1, res2, res3;
89 TRACER.Debug <<
"read: " << name1 <<
" " << name2 <<
" " << name3 <<
" "
90 << res1 <<
" " << res2 <<
" " << res3 <<
" func: " << func_type
93 TRACER.Warning <<
"ignored constraint (no such atom in pose!)"
94 << name1 <<
" " << name2 <<
" " << res1 <<
" " << res2 << std::endl;
95 data.setstate( std::ios_base::failbit );
103 TRACER.Warning <<
"Error reading atoms: read in atom names("
104 << name1 <<
"," << name2 <<
"," << name3 <<
"), "
105 <<
"and found AtomIDs (" <<
atom1_ <<
"," << atom2_ <<
"," << atom3_ <<
")"
107 data.setstate( std::ios_base::failbit );
112 func_->read_data( data );
115 while( data.good() && (data.get() !=
'\n') ) {}
117 if (
TRACER.Debug.visible() ) {
118 func_->show_definition( std::cout );
119 std::cout << std::endl;
155 if( !dynamic_cast< AngleConstraint const * > ( &other_cst ) )
return false;
157 AngleConstraint const & other( static_cast< AngleConstraint const & > (other_cst) );
178 Real const n1( u1.length() );
179 Real const n2( u2.length() );
180 if ( n1 > 1e-12 && n2 > 1e-12 ) {
181 Real const theta = numeric::arccos( dot( u1,u2 ) / ( n1 * n2 ) );
182 return func( theta );
184 std::cout <<
"AngleConstraint::score: warning: 0-length bonds!" << std::endl;
234 using numeric::conversions::radians;
238 static Real const small_angle( radians(
Real(0.1) ) );
239 static Real const big_angle( radians(
Real(179.9) ) );
240 static Real const max_x( std::cos( small_angle ));
241 static Real const min_x( std::cos( big_angle ));
247 Real const n1( v1.length() );
248 Real const n2( v2.length() );
249 if ( n1 < 1e-9 || n2 < 1e-9 ) {
255 Real x = dot(v1,v2)/(n1*n2);
264 Real const f = 1.0f / ( n1 * n2 );
265 helper( p1, f * v2, f1, f2 );
269 Real const f = -1.0f * x / ( n1 * n1 );
270 helper( p1, f * v1, f1, f2 );
273 x = std::min( std::max( min_x, x ), max_x );
274 Real const dtheta_dx = -1.0f / sqrt( 1.0f - x*x );
279 assert( f1.distance( cross(f2,p1) ) < 1e-3 &&
280 std::abs( dot( f2, v1 ) ) < 1e-3 &&
281 std::abs( dot( f2, cross( v1, v2 ) ) ) < 1e-3 );
286 ASSERT_ONLY(
Vector const u_phi( v2.normalized() );)
287 ASSERT_ONLY(
Vector const R_phi( p2 );)
288 ASSERT_ONLY(
Real const deriv = - dot( u_phi, f1 ) - dot( cross( u_phi, R_phi ), f2);)
289 assert( std::abs( deriv ) < 1e-3 );
314 Real const n1_n2( u1.length() * u2.length() );
315 if ( n1_n2 < 1e-12 ) {
316 std::cout <<
"AngleConstraint::p1_deriv: short bonds: " << n1_n2 <<
324 Real d( dot(u1,u2) / n1_n2 );
325 Real const tol(0.001);
326 if ( d <= -1.0 + tol ) {
329 }
else if ( d >= 1.0 - tol ) {
333 Real const theta = numeric::arccos( d );
341 F1 += dE_dtheta * f1;
342 F2 += dE_dtheta * f2;
357 Real const v12( v1.length() * v2.length() );
358 if ( v12 < 1e-12 )
return;
373 assert( std::abs( dot( f2, cross( v1,v2) ) ) < 1e-3 );
375 Real d( dot(v1,v2) / v12 );
376 Real const tol(0.001);
377 if ( d <= -1.0 + tol ) {
380 }
else if ( d >= 1.0 - tol ) {
384 Real const theta = numeric::arccos( d );
392 F1 += -1.0f * dE_dtheta * f1;
393 F2 += -1.0f * dE_dtheta * f2;
415 using numeric::deriv::angle_p1_deriv;
416 using numeric::deriv::angle_p2_deriv;
420 }
else if ( atom ==
atom2_ ) {
422 }
else if ( atom ==
atom3_ ) {
430 F1 += weights[ this->
score_type() ] * dfunc_dtheta * unweighted_F1;
431 F2 += weights[ this->
score_type() ] * dfunc_dtheta * unweighted_F2;
459 utility_exit_with_message(
"AngleConstraint::atom() bad argument" );
474 if (verbose_level > 80) {
475 out <<
"AngleConstraint ("
482 Vector const & p1( conformation.xyz(
atom1_ ) ), p2( conformation.xyz(
atom2_ ) ), p3( conformation.xyz(
atom3_ ) );
485 Real const n1( u1.length() );
486 Real const n2( u2.length() );
487 if ( n1 > 1e-12 && n2 > 1e-12 ) {
488 Real const theta = numeric::arccos( dot( u1,u2 ) / ( n1 * n2 ) );
491 return func_->show_violations( out, theta, verbose_level, threshold );
493 std::cout <<
"AngleConstraint::show_violations: error: 0-length bonds!"