40 #include <ObjexxFCL/FArray2D.hh>
41 #include <ObjexxFCL/format.hh>
44 #include <numeric/constants.hh>
45 #include <numeric/conversions.hh>
48 #include <basic/Tracer.hh>
52 #include <utility/vector1.hh>
64 using namespace ObjexxFCL::fmt;
67 namespace optimization {
70 static basic::Tracer
TR(
"core.optimization.symmetry");
133 using namespace conformation::symmetry;
137 dynamic_cast<SymmetricConformation &> ( pose.
conformation()) );
142 dE_dvars.resize( symm_min_map.
nangles() );
180 it != ite; ++it, ++imap ) {
211 using namespace conformation::symmetry;
212 using namespace scoring;
213 using namespace scoring::symmetry;
216 dynamic_cast<SymmetricConformation const &> ( pose.
conformation()) );
221 SymmetricEnergies
const & symm_energies( dynamic_cast< SymmetricEnergies const & > (pose.
energies()) );
223 assert( symm_energies.minimization_graph() );
224 assert( symm_energies.derivative_graph() );
237 edgeit = mingraph->const_edge_list_begin(), edgeit_end = mingraph->const_edge_list_end();
238 edgeit != edgeit_end; ++edgeit ) {
248 r1_min_data, r2_min_data, pose, scorefxn.
weights(),
254 edgeit = dmingraph->const_edge_list_begin(), edgeit_end = dmingraph->const_edge_list_end();
255 edgeit != edgeit_end; ++edgeit ) {
265 r1_min_data, r2_min_data, pose, scorefxn.
weights(),
276 iter != iter_e; ++iter ) {
279 core::Real dof_wt_i = symm_info->get_dof_derivative_weight( dof_node.
dof_id(), symm_conf );
283 Vector f1(0,0,0), f2(0,0,0);
285 for ( DOF_Node::AtomIDs::const_iterator it1=dof_node.
atoms().begin(),
286 it1e = dof_node.
atoms().end(); it1 != it1e; ++it1 ) {
300 dof_node.
F1() += dof_wt_i * f1;
301 dof_node.
F2() += dof_wt_i * f2;
304 iter != iter_e; ++iter ) {
307 core::Real dof_wt_i = symm_info->get_dof_derivative_weight( dof_node.
dof_id(), symm_conf );
311 Vector f1(0,0,0), f2(0,0,0);
313 for ( DOF_Node::AtomIDs::const_iterator it1=dof_node.
atoms().begin(),
314 it1e = dof_node.
atoms().end(); it1 != it1e; ++it1 ) {
326 Size master_jump = symm_info->jump_follows( this_jump );
337 symm_dof_node->F1() += dof_wt_i * f1;
338 symm_dof_node->F2() += dof_wt_i * f2;
348 abs_deriv_dev( nangles ),
349 rel_deriv_dev( nangles )
392 Real const increment = 0.0005;
393 Size const n_increment = 5;
395 for (
Size i=1; i<= n_increment; ++i ) {
396 dE_dvars_numeric[i].resize( nangles, 0.0 );
411 Real const f00 = func( vars );
415 iter_end= min_map.
end(); iter != iter_end; ++iter, ++ii ) {
416 DOF_Node const & dof_node( **iter );
418 Real deriv_dev = 10000.0;
419 for (
Size j = 1,factor=1; j <= n_increment; ++j ) {
422 vars[ii] = start_vars[ii] + factor * increment;
423 Real const f11 = func( vars );
425 vars[ii] = start_vars[ii] - factor * increment;
426 Real const f22 = func( vars );
428 Real const deriv = ( f11 - f22 ) / ( factor * 2 * increment );
430 dE_dvars_numeric[j][ii] = deriv;
432 deriv_dev = std::min( deriv_dev, std::abs( deriv - dE_dvars[ii] ) );
434 vars[ii] = start_vars[ii];
436 Real const ratio( std::abs( dE_dvars[ii] ) < 0.001 ? 0.0 :
437 deriv / dE_dvars[ii] );
440 ( std::abs(dE_dvars[ii]) > 0.001 || std::abs(deriv) > 0.001 ) ) {
443 static bool ratio_header_output(
false );
444 if ( !ratio_header_output ) {
445 ratio_header_output =
true;
455 A( 10,
"numeric" ) <<
456 A( 10,
"analytic" ) <<
461 A( 10,
"vars[ii]" ) << std::endl;
465 if ( dof_node.
parent() ) {
466 parent_id = dof_node.
parent()->dof_id();
471 I( 4, dof_node.
rsd() ) <<
472 I( 4, dof_node.
type() ) <<
473 I( 4, dof_node.
atomno() ) <<
474 I( 5, parent_id.
rsd() ) <<
475 I( 5, parent_id.
type() ) <<
476 I( 5, parent_id.
atomno() ) <<
477 I( 5, dof_node.
atoms().size()) <<
479 F( 10, 4, dE_dvars[ii] ) <<
484 F( 10, 4, start_vars[ii] ) << std::endl;
489 Real const ratio( std::abs( dE_dvars[ii] ) < 0.001 ? 0.0 :
490 deriv_dev / std::abs( dE_dvars[ii] ) );
498 TR <<
"deriv_dev:" << SS(ii) << SS(nangles) << SS(f00) <<
499 SS( dof_node.
type() ) << SS( dof_node.
atomno() ) <<
500 SS( dof_node.
rsd() ) <<
501 SS( dE_dvars[ii] ) << SS( deriv_dev ) << SS(ratio) << std::endl;
509 for (
Size i=1; i<= nangles; ++i ) {
510 norm += dE_dvars[i] * dE_dvars[i];
511 for (
Size j=1; j<= n_increment; ++j ) {
512 dot[j] += dE_dvars[i] * dE_dvars_numeric[j][i];
513 norm_numeric[j] += dE_dvars_numeric[j][i] * dE_dvars_numeric[j][i];
516 norm = std::sqrt( norm );
523 for (
Size j=1; j<= n_increment; ++j ) {
524 norm_numeric[j] = std::sqrt( norm_numeric[j] );
528 if ( norm < 0.001 && norm_numeric[j] < 0.001 ) {
529 log_norm_ratio = 1.0;
530 }
else if ( norm < 0.001 ) {
531 log_norm_ratio = 100.0;
532 }
else if ( norm_numeric[j] < 0.001 ) {
533 log_norm_ratio = -100.0;
535 log_norm_ratio = std::log( norm_numeric[j] / norm );
538 Real const cos_theta( dot[j] / ( norm * norm_numeric[j]) );
541 " norm: " << j <<
' ' << F(12,4,norm) <<
542 " norm_numeric: " << F(12,4,norm_numeric[j]) <<
543 " cos_theta: " << F(7,4,cos_theta) <<
544 " log_norm_ratio: " << F(9,4,log_norm_ratio) << std::endl;