29 #include <basic/database/open.hh>
32 #include <basic/Tracer.hh>
34 #include <basic/options/option.hh>
35 #include <basic/options/keys/score.OptionKeys.gen.hh>
39 #include <utility/OrderedTuple.hh>
40 #include <utility/fixedsizearray1.hh>
41 #include <utility/vector1.hh>
42 #include <basic/datacache/CacheableData.hh>
51 namespace custom_pair_distance {
108 static basic::Tracer
tr(
"core.scoring.custom_pair_distance.FullatomCustomPairDistanceEnergy");
119 pair_and_func_map_( src.pair_and_func_map_ ),
120 max_dis_( src.max_dis_ )
146 PairFuncMap::const_iterator respairiter =
find( rsd1, rsd2 );
148 assert( (*respairiter).second );
150 for ( std::list<atoms_and_func_struct>::const_iterator
151 atom_func_iter = (*respairiter).second->ats_n_func_list().begin(),
152 atom_func_iter_end = (*respairiter).second->ats_n_func_list().end();
153 atom_func_iter != atom_func_iter_end; ++atom_func_iter) {
154 Vector const& atom_a_xyz( rsd1.
xyz((*atom_func_iter).resA_atom_index_));
155 Vector const& atom_b_xyz( rsd2.
xyz((*atom_func_iter).resB_atom_index_));
156 score += (*atom_func_iter).func_->func(atom_a_xyz.distance_squared(atom_b_xyz));
177 bool res_moving_wrt_eachother
207 for ( std::list< atoms_and_func_struct >::const_iterator
208 atom_func_iter = respair_intxns.apfc_list().ats_n_func_list().begin(),
209 atom_func_iter_end = respair_intxns.apfc_list().ats_n_func_list().end();
210 atom_func_iter != atom_func_iter_end; ++atom_func_iter) {
211 Vector const& atom_a_xyz( rsd1.
xyz((*atom_func_iter).resA_atom_index_));
212 Vector const& atom_b_xyz( rsd2.
xyz((*atom_func_iter).resB_atom_index_));
213 score += (*atom_func_iter).func_->func(atom_a_xyz.distance_squared(atom_b_xyz));
238 respair_intxns->apfc_list( apfclist );
261 for ( std::list< atoms_and_func_struct >::const_iterator
262 atom_func_iter = respair_intxns.apfc_list().ats_n_func_list().begin(),
263 atom_func_iter_end = respair_intxns.apfc_list().ats_n_func_list().end();
264 atom_func_iter != atom_func_iter_end; ++atom_func_iter) {
265 Vector const & atom_a_xyz = rsd1.
xyz( atom_func_iter->resA_atom_index_ );
266 Vector const & atom_b_xyz = rsd2.
xyz( atom_func_iter->resB_atom_index_ );
268 Real dist_sq = atom_a_xyz.distance_squared(atom_b_xyz);
269 if ( dist_sq < atom_func_iter->func_->min_dis() || dist_sq > atom_func_iter->func_->max_dis() )
continue;
271 Vector f1( atom_a_xyz.cross( atom_b_xyz ));
272 Vector f2( atom_a_xyz - atom_b_xyz );
273 Real const dist( f2.length() );
274 if ( dist == 0.0 )
continue;
276 Real deriv = (*atom_func_iter).func_->dfunc(dist_sq);
290 r1_atom_derivs[ atom_func_iter->resA_atom_index_ ].f1() += f1;
291 r1_atom_derivs[ atom_func_iter->resA_atom_index_ ].f2() += f2;
292 r2_atom_derivs[ atom_func_iter->resB_atom_index_ ].f1() -= f1;
293 r2_atom_derivs[ atom_func_iter->resB_atom_index_ ].f2() -= f2;
386 FullatomCustomPairDistanceEnergy::PairFuncMap::const_iterator
393 respair[1] = rsd1.
type();
394 respair[2] = rsd2.
type();
411 using namespace basic::options;
412 using namespace basic::options::OptionKeys;
413 using namespace chemical;
415 std::string pairfuncfile = (option[score::fa_custom_pair_distance_file].user()) ?
416 option[score::fa_custom_pair_distance_file]() :
417 basic::database::full_name(
"scoring/score_functions/custom_pair_distance/fa_custom_pair_distance" );
419 tr.Debug <<
"Reading fa_custom_pair_distance_file: " << pairfuncfile << std::endl;
421 utility::io::izstream in( pairfuncfile );
423 utility_exit_with_message(
"Unable to open fa_custom_pair_distance file: " + pairfuncfile );
425 std::string line, residue_type_set, score_function_name;
429 while ( getline( in, line ) ) {
430 if ( line.size() < 1 || line[0] ==
'#' )
continue;
431 std::istringstream l( line );
434 if (tag ==
"RESIDUE_TYPE_SET") {
435 resA.clear(); resB.clear(); atomA.clear(); atomB.clear();
436 l >> residue_type_set;
437 tr.Debug <<
"Residue type set: " << residue_type_set << std::endl;
444 pair_cols.push_back( buf );
446 if (pair_cols.size() == 4) {
447 resA.push_back( pair_cols[1] );
448 atomA.push_back( pair_cols[2] );
449 resB.push_back( pair_cols[3] );
450 atomB.push_back( pair_cols[4] );
451 tr.Debug <<
"Pair: " << pair_cols[1] <<
" " << pair_cols[2] <<
" " << pair_cols[3] <<
" " << pair_cols[4] << std::endl;
455 if (tag ==
"SCORE_FUNCTION") {
456 l >> score_function_name;
462 tr.Debug <<
"SCORE_FUNCTION: " << score_function_name <<
" (min: " <<
463 pair_func.
func_->min_dis() <<
" max: " << pair_func.
func_->max_dis() <<
")" << std::endl;
469 for (
Size i = 1; i <= resA.size(); ++i) {
470 ResidueTypeCOPs const & possible_res_types_a = restype_set->name3_map( resA[i] );
471 ResidueTypeCOPs const & possible_res_types_b = restype_set->name3_map( resB[i] );
472 for (
Size j = 1; j <= possible_res_types_a.size(); ++j ) {
474 Size atom_index_a = rsd_type_a->atom_index( atomA[i] );
475 for (
Size k = 1; k <= possible_res_types_b.size(); ++k ) {
477 Size atom_index_b = rsd_type_b->atom_index( atomB[i] );
480 respair[1] = rsd_type_a;
481 respair[2] = rsd_type_b;
485 if ( ! atpairlist ) {
492 atpairlist->add_interaction( pair_func );
498 if (rsd_type_a != rsd_type_b) {
499 respair[1] = rsd_type_b;
500 respair[2] = rsd_type_a;
504 if ( ! atpairlist ) {
508 atpairlist->add_interaction( pair_func );
526 utility::io::izstream scores_stream;
527 basic::database::open( scores_stream,
"scoring/score_functions/custom_pair_distance/" + name);
528 scores_hist_ =
new numeric::interpolation::Histogram<Real,Real>( scores_stream() );
529 scores_stream.close();
535 if ( dist_sq < scores_hist_->minimum() ||
536 dist_sq > scores_hist_->maximum() )
return e;
537 scores_hist_->interpolate(dist_sq,e);
542 Real df(0.0), e(0.0);
543 if ( dist_sq < scores_hist_->minimum() ||
544 dist_sq > scores_hist_->maximum() )
return df;
545 scores_hist_->interpolate(dist_sq,e,df);
550 return scores_hist_->maximum();
554 return scores_hist_->minimum();