39 #include <basic/Tracer.hh>
44 #include <basic/prof.hh>
45 #include <ObjexxFCL/FArray2D.hh>
56 #include <utility/vector1.hh>
63 static basic::Tracer
tr(
"protocols.noesy_assign.assignments");
67 using namespace basic;
72 namespace noesy_assign {
74 PeakAssignmentResidueMap::PeakAssignmentResidueMap() {}
75 PeakAssignmentResidueMap::~PeakAssignmentResidueMap() {}
78 Size const res1( assignment->resid( 1 ) );
79 Size const res2( assignment->resid( 2 ) );
80 while ( residues_.size() < res1 ) {
83 PeakAssignmentMap::iterator res2_entry( residues_[ res1 ].
insert( PeakAssignmentMap::value_type( res2,
PeakAssignments() ) ).first );
85 res2_entry->second.push_back( assignment );
87 while ( atoms_.size() < res1 ) {
90 while ( atoms_.size() < res2 ) {
93 atoms_[ res1 ].insert( assignment->atom( 1 ) );
94 atoms_[ res2 ].insert( assignment->atom( 2 ) );
98 void PeakAssignmentResidueMap::add_all_atoms(
ResonanceList const& rslist ) {
100 Size res1( it->second->resid() );
101 while ( atoms_.size() < res1 ) {
104 atoms_[ res1 ].insert( it->second->atom() );
109 Size const res1( assignment.
resid( 1 ) );
110 Size const res2( assignment.
resid( 2 ) );
113 bool success(
false );
114 for ( PeakAssignments::iterator it = res2_entry.begin(); !success && it != res2_entry.end(); ++it ) {
116 if ( assi == assignment ) {
117 res2_entry.erase( it );
122 throw EXCN_AssignmentNotFound( assignment,
"remove: PeakAssignment not found -- no entry with exact assignment" );
127 basic::ProfileThis doit( basic::NOESY_ASSIGN_NETWORK_FIND_RAW_ASSIGN );
128 if ( residues_.size() < res1 || res1 <= 0) {
131 PeakAssignmentMap::const_iterator res2_entry( residues_[ res1 ].find( res2 ) );
132 if ( res2_entry == residues_[ res1 ].
end() ) {
135 return res2_entry->second;
139 basic::ProfileThis doit( basic::NOESY_ASSIGN_NETWORK_FIND_RAW_ASSIGN );
140 if ( residues_.size() < res1 || res1 <= 0) {
143 PeakAssignmentMap::iterator res2_entry( residues_[ res1 ].find( res2 ) );
144 if ( res2_entry == residues_[ res1 ].
end() ) {
147 return res2_entry->second;
151 basic::ProfileThis doit( basic::NOESY_ASSIGN_NETWORK_FIND_RAW_ASSIGN );
152 if ( residues_.size() < res1 || res1 <= 0 ) {
153 return BOGUS_ASSIGNMENTS;
155 PeakAssignmentMap::iterator res2_entry( residues_[ res1 ].find( res2 ) );
156 if ( res2_entry == residues_[ res1 ].
end() ) {
157 return BOGUS_ASSIGNMENTS;
159 return res2_entry->second;
163 return _assignments( res1, res2 ).size();
167 for ( CrossPeakList::CrossPeaks::const_iterator it = cpl.
peaks().begin(); it != cpl.
peaks().end(); ++it ) {
168 for ( CrossPeak::PeakAssignments::const_iterator ait = (*it)->assignments().begin(); ait != (*it)->assignments().end(); ++ait ) {
210 void PeakAssignmentResidueMap::check_for_symmetric_peaks(
CrossPeakList& cpl,
bool accumulate_symmetry ) {
211 for ( CrossPeakList::CrossPeaks::const_iterator it = cpl.
peaks().begin(); it != cpl.
peaks().end(); ++it ) {
213 for ( CrossPeak::PeakAssignments::const_iterator ait = assignments.begin(); ait!=assignments.end(); ++ait ) {
221 PeakAssignments symmetric_candidates_inv( _assignments( res1, res2 ) );
222 if ( symmetric_candidates_inv.size() ) {
223 for ( PeakAssignments::iterator sym_it = symmetric_candidates_inv.begin(); sym_it != symmetric_candidates_inv.end(); ++sym_it ) {
225 if ( (*sym_it)->is_symmetric_partner_of( current ) ) {
227 if ( !accumulate_symmetry ) {
232 found += (*sym_it)->normalized_peak_volume();
238 if ( symmetric_candidates.size() ) {
239 for ( PeakAssignments::iterator sym_it = symmetric_candidates.begin(); sym_it != symmetric_candidates.end(); ++sym_it ) {
241 if ( (*sym_it)->is_symmetric_partner_of( current ) ) {
243 if ( !accumulate_symmetry ) {
248 found += (*sym_it)->normalized_peak_volume();
260 basic::ProfileThis doit( basic::NOESY_ASSIGN_NETWORK_RETRIEVE_ASSIGN );
261 for ( PeakAssignments::const_iterator it = list.begin(); it != list.end(); ++it ) {
262 if ( ( (*it)->resonance_id( 1 ) == resonance_id1 && (*it)->resonance_id( 2 ) == resonance_id2 )
263 && ( (*it)->resonance_id( 1 ) == resonance_id2 && (*it)->resonance_id( 2 ) == resonance_id1 ) ) {
264 intra_res_NOEs.push_back( *it );
270 Real intra_sumV( 0.0 );
271 for ( PeakAssignments::const_iterator it = list.begin(); it != list.end(); ++it ) {
272 if ( ( (*it)->atom( 1 ) == atom1 && (*it)->
atom( 2 ) == atom2 )
273 && ( (*it)->atom( 1 ) == atom2 && (*it)->
atom( 2 ) == atom1 ) ) {
274 intra_sumV+=(*it)->normalized_peak_volume();
282 basic::ProfileThis doit( basic::NOESY_ASSIGN_NETWORK_FIND_RAW_ASSIGN );
283 if ( res1 <= 0 || res2 <= 0 )
return;
284 if ( residues_.size() < res1 ) {
287 PeakAssignmentMap::const_iterator res2_entry( residues_[ res1 ].find( res2 ) );
288 if ( res2_entry == residues_[ res1 ].
end() ) {
291 copy( res2_entry->second.begin(), res2_entry->second.end(), back_inserter( collector ) );
295 void PeakAssignmentResidueMap::fill_covalent_gammas(
Size alpha_resid, std::map< core::id::NamedAtomID, bool >& collector )
const {
296 basic::ProfileThis doit( basic::NOESY_ASSIGN_NETWORK_FILL_COV_GAMMA );
298 for (
Size resid = (alpha_resid > 1 ? alpha_resid - 1 : alpha_resid);
299 resid <= ( alpha_resid < atoms_.size() ? alpha_resid + 1 : atoms_.size() ); ++resid ) {
301 for ( AtomList::const_iterator it = atoms_[ resid ].begin(); it != atoms_[ resid ].end(); ++it ) {
307 collector.insert( std::make_pair( *it,
false ) );
325 Real PeakAssignmentResidueMap::compute_Nk(
334 Real longrange_peak_volume
336 basic::ProfileThis doit( basic::NOESY_ASSIGN_NETWORK_COMPUTE_NK );
349 Real intra_sumV_ag( 0.0 );
350 if ( connect_in_i ) intra_sumV_ag =
sum_IntraNOE( close_to_i_assignments, alpha_beta.
atom( 1 ), gamma_atom );
357 Real intra_sumV_bg( 0.0 );
358 if ( connect_in_j ) intra_sumV_bg =
sum_IntraNOE( close_to_j_assignments, alpha_beta.
atom( 2 ), gamma_atom );
366 Real const Vcc_ag( is_covalent_ag ? vmax : ( ( connect_in_i || sequential ) ? vmin : 0 ) );
367 Real const Vcc_bg( is_covalent_bg ? vmax : ( ( connect_in_j || sequential ) ? vmin : 0 ) );
368 Real const vag( std::max( Vcc_ag, connect_in_i ? intra_sumV_ag : longrange_peak_volume ) );
369 Real const vbg( std::max( Vcc_bg, connect_in_j ? intra_sumV_bg : longrange_peak_volume ) );
374 if ( vag < vmin || vbg < vmin )
return 0.0;
375 return sqrt( vag*vbg );
380 Real intra_sumV( 0.0 );
381 for ( PeakAssignments::const_iterator it = list.begin(); it != list.end(); ++it ) {
382 if ( (*it)->resonance_id( 1 ) == i && (*it)->resonance_id( 2 ) == j ) {
383 intra_sumV+=(*it)->normalized_peak_volume();
389 void PeakAssignmentResidueMap::network_analysis2(
ResonanceList const& resonances ) {
390 tr.Info <<
"start network analysis (type2)..." << std::endl;
391 typedef std::pair< core::Size, core::Size > ResonancePair;
392 typedef std::map< ResonancePair, core::Real > AnchorMap;
395 AnchorMap anchor_weights;
401 for ( ResidueList::const_iterator it = residues_.begin(); it != residues_.end(); ++it ) {
402 for ( PeakAssignmentMap::const_iterator mit = it->begin(); mit != it->end(); ++mit ) {
407 PeakAssignment const& first_assignment( **assignments_ij.begin() );
408 Size const resi( first_assignment.resid( 1 ) );
409 Size const resj( first_assignment.resid( 2 ) );
415 bool sequential( std::abs( (
int) resi- (
int) resj ) <= 1 );
416 for ( PeakAssignments::const_iterator ait = assignments_ij.begin(); ait != assignments_ij.end(); ++ait ) {
419 core::Size const i( (*ait)->resonance_id( 1 ) );
420 core::Size const j( (*ait)->resonance_id( 2 ) );
421 bool covalent(
false );
425 ResonancePair ij( i,j );
426 ResonancePair ji( j,i );
427 if ( anchor_weights.find(ij) == anchor_weights.end() ) {
431 core::Real n_ij = std::max( sum_pv, cov_contrib );
432 if ( n_ij < params.
vmin_ ) {
435 anchor_weights[ij]= n_ij;
436 anchor_weights[ji]= n_ij;
444 for ( ResidueList::const_iterator it = residues_.begin(); it != residues_.end(); ++it ) {
445 for ( PeakAssignmentMap::const_iterator mit = it->begin(); mit != it->end(); ++mit ) {
450 PeakAssignment const& first_assignment( **assignments_ij.begin() );
451 Size const resi( first_assignment.resid( 1 ) );
452 Size const resj( first_assignment.resid( 2 ) );
455 bool sequential( std::abs( (
int) resi- (
int) resj ) <= 1 );
459 std::set< core::Size > neighbor_residues;
460 for (
Size i = ( resi > 1 ? resi -1 : resi ); i<= ( resi < atoms_.size() ? resi + 1 : resi ); ++i ) {
461 neighbor_residues.insert( i );
463 for (
Size i = ( resj > 1 ? resj -1 : resj ); i<= ( resj < atoms_.size() ? resj + 1 : resj ); ++i ) {
464 neighbor_residues.insert( i );
466 for ( std::set< core::Size >::const_iterator sit=neighbor_residues.begin(); sit!=neighbor_residues.end(); ++sit ) {
469 copy( retrieved.begin(), retrieved.end(), back_inserter( resK ) );
476 for ( PeakAssignments::const_iterator ait = assignments_ij.begin(); ait != assignments_ij.end(); ++ait ) {
477 core::Size const i( (*ait)->resonance_id( 1 ) );
478 core::Size const j( (*ait)->resonance_id( 2 ) );
481 for ( ResonanceList::Resonances::const_iterator itK = resK.begin(); itK != resK.end(); ++itK ) {
482 if ( !(*itK)->is_proton() )
continue;
483 if ( (*itK)->label() == i || (*itK)->label() == j )
continue;
485 ResonancePair ik( i,k );
486 ResonancePair kj( k,j );
490 AnchorMap::const_iterator nik( anchor_weights.find(ik) );
491 if ( nik == anchor_weights.end() ) {
492 bool sequential = std::abs( (
int) resi - (
int) (*itK)->resid() ) <= 1;
493 bool covalent(
false );
497 wik = covalent ? params.
vmax_ : ( sequential ? params.
vmin_ : 0 );
498 anchor_weights[ik] = wik;
499 anchor_weights[ResonancePair(k,i)] = wik;
501 wik=std::max( wik, nik->second );
504 AnchorMap::const_iterator nkj( anchor_weights.find(kj) );
505 if ( nkj == anchor_weights.end() ) {
506 bool sequential = std::abs( (
int) resj - (
int) (*itK)->resid() ) <= 1;
507 bool covalent(
false );
511 wkj = covalent ? params.
vmax_ : ( sequential ? params.
vmin_ : 0 );
512 anchor_weights[kj] = wkj;
513 anchor_weights[ResonancePair(j,k)] = wkj;
515 wkj = std::max( wkj, nkj->second );
517 sumNK += sqrt( wik*wkj );
520 (*ait)->set_network_anchoring( sumNK );
524 residue_sum( resi, resj )+=sumNK_resij;
525 residue_sum( resj, resi )+=sumNK_resij;
528 for ( ResidueList::const_iterator it = residues_.begin(); it != residues_.end(); ++it ) {
529 for ( PeakAssignmentMap::const_iterator mit = it->begin(); mit != it->end(); ++mit ) {
532 PeakAssignment const& first_assignment( **assignments_ij.begin() );
533 Size const resi( first_assignment.resid( 1 ) );
534 Size const resj( first_assignment.resid( 2 ) );
535 for ( PeakAssignments::const_iterator ait = assignments_ij.begin(); ait != assignments_ij.end(); ++ait ) {
542 void PeakAssignmentResidueMap::network_analysis(
Size nr_assignments ) {
543 tr.Info <<
"network_analysis..." << std::endl;
544 PROF_START( NOESY_ASSIGN_NETWORK );
551 Size ct_respair_buf( 0 );
560 for ( ResidueList::const_iterator it = residues_.begin(); it != residues_.end(); ++it ) {
561 for ( PeakAssignmentMap::const_iterator mit = it->begin(); mit != it->end(); ++mit ) {
563 runtime_assert( assignments_ij.size() > 0 );
565 PeakAssignment const& first_assignment( **assignments_ij.begin() );
566 Size const resi( first_assignment.resid( 1 ) );
567 Size const resj( first_assignment.resid( 2 ) );
574 assignments( resi-1, resj-1, assignments_around_ij );
575 assignments( resi-1, resj, assignments_around_ij );
576 assignments( resi-1, resj+1, assignments_around_ij );
577 assignments( resi , resj-1, assignments_around_ij );
578 assignments( resi , resj, assignments_around_ij );
579 assignments( resi , resj+1, assignments_around_ij );
580 assignments( resi+1, resj-1, assignments_around_ij );
581 assignments( resi+1, resj, assignments_around_ij );
582 assignments( resi+1, resj+1, assignments_around_ij );
619 assignments( resi, resi-1, close_to_i_assignments );
620 assignments( resi, resi, close_to_i_assignments );
621 assignments( resi, resi+1, close_to_i_assignments );
624 assignments( resj-1, resj, close_to_j_assignments );
625 assignments( resj, resj, close_to_j_assignments );
626 assignments( resj+1, resj, close_to_j_assignments );
629 for ( PeakAssignments::const_iterator ait = assignments_ij.begin(); ait != assignments_ij.end(); ++ait ) {
634 bool is4D( (*ait)->crosspeak().is4D() );
637 Nk_buf[ ct_buf++ ]=sum_Nk;
638 reswise_Nk_buf[ ct_respair_buf ] += sum_Nk;
644 Size const alpha_resid( (*ait)->resid( 1 ) );
645 Size const beta_resid( (*ait)->resid( 2 ) );
656 core::Size const seq_dist( resi < resj ? resj - resi : resi - resj );
657 std::map< id::NamedAtomID, bool > covalent_gammas;
658 if ( seq_dist <= 2 ) {
659 fill_covalent_gammas( alpha_resid, covalent_gammas );
660 fill_covalent_gammas( beta_resid, covalent_gammas );
669 std::map< std::string, core::Size > offset_map;
670 std::map< core::Size, core::Size > peak_count_map;
673 { basic::ProfileThis doit( basic::NOESY_ASSIGN_NETWORK_PEAK_COUNT );
674 offset_map[ (*ait)->crosspeak().filename() ] = 0;
675 peak_count_map[ 0+(*ait)->crosspeak().peak_id() ] = 1;
676 for ( PeakAssignments::const_iterator yit = assignments_around_ij.begin(); yit != assignments_around_ij.end(); ++yit ) {
677 std::map< std::string, core::Size >::iterator file_it = offset_map.find( (*yit)->crosspeak().filename() );
679 if ( file_it != offset_map.end() ) {
680 offset = file_it->second;
682 offset_map[ (*yit)->crosspeak().filename() ] = last_offset;
683 offset = last_offset;
684 last_offset += next_offset;
686 peak_count_map[ offset+(*yit)->crosspeak().peak_id() ] += 1;
690 for ( PeakAssignments::const_iterator yit = assignments_around_ij.begin(); yit != assignments_around_ij.end(); ++yit ) {
693 if ( 0+(*ait)->crosspeak().peak_id() == (offset_map[ (*yit)->crosspeak().filename() ]+(*yit)->crosspeak().peak_id()) ) {
700 bool connect_in_i(
false );
701 bool connect_in_j(
false );
702 bool sequential(
false );
713 if ( g_atom1 != alpha_atom && g_atom2 == beta_atom ) {
715 connect_in_j =
false;
720 if ( g_atom2 != alpha_atom && g_atom1 == beta_atom ) {
722 connect_in_j =
false;
732 if ( g_atom1 == alpha_atom && g_atom2 != beta_atom ) {
733 connect_in_i =
false;
739 if ( g_atom2 == alpha_atom && g_atom1 != beta_atom ) {
740 connect_in_i =
false;
749 if ( !gamma_sel )
continue;
750 int const gamma_resid( (*yit)->resid( gamma_sel ) );
751 sequential = ( std::abs( (
int) my_res - gamma_resid) <= 1 );
796 if ( seq_dist <= 2 ) covalent_gammas[ gamma_atom ] =
true;
798 Size ambiguity_factor( peak_count_map[ (*yit)->crosspeak().peak_id() + offset_map[ (*yit)->crosspeak().filename() ]] );
806 sum_Nk += 1.0/ambiguity_factor* compute_Nk( **ait, gamma_atom, connect_in_i, connect_in_j,
807 sequential, close_to_i_assignments, close_to_j_assignments, (*yit)->normalized_peak_volume() );
813 for ( std::map< core::id::NamedAtomID, bool >::const_iterator cgit = covalent_gammas.begin(); cgit != covalent_gammas.end(); cgit++ ) {
814 if ( cgit->second )
continue;
816 int gamma_resid( gamma_atom.
rsd() );
817 int res1( resi < resj ? resi : resj );
818 int res2( resi >= resj ? resi : resj );
819 bool connect_in_i(
true );
820 bool connect_in_j(
true );
823 if ( seq_dist == 2 ) {
824 if ( !( gamma_resid-res1 == 1 || res2 - gamma_resid == 1 ) )
continue;
829 if ( seq_dist == 1 ) {
830 if ( gamma_resid != (
int) resi && gamma_resid != (
int) resj )
continue;
835 sum_Nk += compute_Nk( **ait, gamma_atom, connect_in_i, connect_in_j,
true, close_to_i_assignments, close_to_j_assignments, 0.0 );
838 Nk_buf[ ct_buf++ ]=sum_Nk;
839 reswise_Nk_buf[ ct_respair_buf ] += sum_Nk;
848 for ( ResidueList::const_iterator it = residues_.begin(); it != residues_.end(); ++it ) {
849 for ( PeakAssignmentMap::const_iterator mit = it->begin(); mit != it->end(); ++mit ) {
853 for ( PeakAssignments::const_iterator ait = assignments_ij.begin(); ait != assignments_ij.end(); ++ait ) {
854 (*ait)->set_network_anchoring( Nk_buf[ ct_buf++ ] );
855 (*ait)->set_network_anchoring_per_residue( reswise_Nk_buf[ ct_respair_buf ] );
861 PROF_STOP( NOESY_ASSIGN_NETWORK );