51 #include <basic/Tracer.hh>
53 #include <numeric/random/random.hh>
54 #include <numeric/xyzVector.io.hh>
56 #include <utility/vector1.hh>
57 #include <utility/io/ozstream.hh>
58 #include <utility/io/izstream.hh>
59 #include <utility/string_util.hh>
61 #include <ObjexxFCL/string.functions.hh>
70 static numeric::random::RandomGenerator
RG(482136);
71 static basic::Tracer
tr(
"protocols.noesy_assign.FragsToAtomDist");
75 using namespace core::pose;
76 using namespace core::id;
77 using namespace fragment;
78 using namespace core::chemical;
81 namespace noesy_assign {
86 typedef std::map< core::id::AtomID, FragsToAtomDist::DistanceRecord >
InnerMap;
91 core::Real FragsToAtomDist::DistanceRecord::popular_bin()
const {
94 std::map< core::Real, core::Size >::const_iterator it;
95 tr.Info <<
"size of hist_dist_ "<< hist_dist_.size() <<std::endl;
96 for ( it=hist_dist_.begin(); it !=hist_dist_.end(); it++ ) {
97 tr.Info <<
" it->second "<< it->second<<std::endl;
98 tr.Info <<
" max_bin "<< max_bin<<std::endl;
99 if ( it->second > max_bin ) {
100 tr.Info <<
" it->first "<< it->first<<std::endl;
105 tr.Info <<
" pop_dist "<< pop_dist<<std::endl;
110 return os <<
" " << setw(10) << setprecision(4) << dr.
average_dist6()
111 <<
" " << setw(10) << setprecision(4) << dr.
average_dist()
112 <<
" " << setw(10) << setprecision(4) << dr.
min_dist()
113 <<
" " << setw(10) << setprecision(4) << dr.
popular_bin();
117 is >> t1 >> t2 >> t3;
122 void FragsToAtomDist::DistanceRecord::record_inv6(
core::Real inv6 ) {
123 core::Real const dist( std::pow( inv6, -1.0/6.0 ) );
126 min_dist_ = std::min( min_dist_, dist );
134 void FragsToAtomDist::DistanceRecord::record(
core::Real dist ) {
135 core::Real const inv6( std::pow( dist, -6.0 ) );
138 min_dist_ = std::min( min_dist_, dist );
153 MethylNames const& methyls( methyl_lib[ rsd.aa() ] );
157 tr.Info <<
"pos " << pos <<
" " << it->first <<
" ";
158 for ( MethylNames::AtomList::const_iterator ait = it->second.begin(); ait != it->second.end(); ++ait ) {
160 if ( pos == 1 && atom ==
"H" ) {
163 indices.push_back( rsd.atom_index( atom ) );
164 tr.Info << atom <<
" ";
166 new_grps.push_back( std::make_pair<std::string, SizeList >( it->first, indices ) );
168 tr.Info << std::endl;
170 tr.Info <<
"generated " << new_grps.size() <<
" proton-groups for position " << pos << std::endl;
171 grp_list.push_back( new_grps );
175 bool FragsToAtomDist::check_sequence(
std::string const& other_sequence)
const {
176 if (sequence_.compare(other_sequence)==0) {
184 swap_atoms( atom1, atom2 );
185 NamedDistanceMap::const_iterator it1 = named_distmap_.find( atom1 );
186 if ( it1 != named_distmap_.end() ) {
187 NamedInnerMap::const_iterator it2 = it1->second.find( atom2 );
188 if ( it2 != it1->second.end() ) {
195 void FragsToAtomDist::write_to_stream(std::ostream& output)
const {
197 for (std::string::const_iterator i = sequence_.begin();i != sequence_.end();++i) {
198 if ( count%50 == 1 ) {
199 output <<
"DATA SEQUENCE ";
202 if ( count%50 == 0 ) {
205 if ( count%10 == 0 && count%50 != 0 ) {
210 output << endl << endl;
217 output <<
"VARS RESID1 ATOMNAME1 RESID2 ATOMNAME2 DIST_R6_AVERAGED DIST_AVERAGED DIST_MIN DIST_POP" << endl << endl;
218 NamedDistanceMap::const_iterator iter1;
219 NamedInnerMap::const_iterator iter2;
220 for ( iter1 = named_distmap_.begin(); iter1 != named_distmap_.end(); iter1++ ) {
221 for (iter2 = iter1->second.begin(); iter2 != iter1->second.end(); iter2++ ) {
222 if ( iter2->second.is_valid() ) {
223 output << setw(5)<<iter1->first.rsd()
224 << setw(5)<<iter1->first.atom()
225 << setw(5)<<iter2->first.rsd()
226 << setw(8)<<iter2->first.atom()
227 << setw(8)<< setprecision(14)<< iter2->second <<endl;
234 utility::io::ozstream output( filename );
235 write_to_stream(output);
238 void FragsToAtomDist::read_from_stream(std::istream& input) {
240 while ( getline( input, line ) ) {
241 if ( line.size() == 0 )
continue;
242 std::istringstream tag_stream( line );
243 if (line.substr(0,4)==
"DATA") {
244 if (line.substr(0,13)==
"DATA SEQUENCE") {
246 for (std::string::iterator i = line.begin();i != line.end();++i) {
259 else if ( line.substr(0,4) !=
"VARS" && line.length()>10 ) {
260 int residue1,residue2;
263 tag_stream >> residue1 >> name1 >> residue2 >> name2 >> dist;
266 named_distmap_[atom1][atom2]=dist;
272 utility::io::izstream input( filename );
273 read_from_stream( input );
280 set_sequence(sequence);
282 compute_average_distances( cycles, cycle_mod );
286 generate_from_fragments( FragmentIO().read_data( filename ), sequence, cycles, cycle_mod);
292 if ( atom1.
rsd() > atom2.
rsd() ) {
294 }
else if ( atom1.
rsd() == atom2.
rsd() ) {
298 if ( methyl_lib[aa].proton_index( atom1.
atom() ) > methyl_lib[ aa ].proton_index( atom2.
atom() ) ) {
302 excn.add_msg(
"cannot find proton/methyl name at position "+ObjexxFCL::string_of( atom1.
rsd() ) );
318 DistanceMap::const_iterator iter1;
319 InnerMap::const_iterator iter2;
320 for ( iter1 = distmap.begin(); iter1 != distmap.end(); iter1++) {
321 for (iter2=iter1->second.begin(); iter2 != iter1->second.end();iter2++) {
328 named_distmap[named_atom_1][named_atom_2]=iter2->second;
342 for (
core::Size rsd1 =1; rsd1<=short_size; rsd1++) {
343 AtomGrps const& group1( grps[ rsd1+start-1 ] );
344 for (
core::Size igrp1 =1; igrp1<=group1.size(); igrp1++ ) {
345 for (
core::Size rsd2 =rsd1; rsd2<=short_size; rsd2++) {
346 AtomGrps const& group2( grps[ rsd2+start-1 ] );
347 for (
core::Size igrp2 = ( rsd2==rsd1 ? igrp1+1 : 1 ); igrp2<=group2.size(); igrp2++ ) {
349 for ( SizeList::const_iterator atom1 = group1[igrp1].second.begin(); atom1 != group1[igrp1].second.end(); ++atom1 ) {
351 for ( SizeList::const_iterator atom2 = group2[igrp2].second.begin(); atom2 != group2[igrp2].second.end(); ++atom2 ) {
353 Real const inv_dist2( 1.0/xyz_1.distance_squared( xyz_2 ) );
354 Real const inv_dist6( inv_dist2 * inv_dist2 * inv_dist2 );
355 cumdist += inv_dist6;
360 distmap[ grpid1 ][ grpid2 ].record_inv6( cumdist );
368 using namespace protocols::simple_moves;
387 for ( FrameIterator frame = frags_->begin(), eframe=frags_->end();
388 frame != eframe; ++frame ) {
392 sequence_.substr( frame->start()-1, frame->length() ),
397 Size const short_size( frame->length() );
399 Size const short_start( frame->start() );
400 tr.Info <<
"frame position: " << frame->start() << std::endl;
406 for (
Size ifrag=1; ifrag<=frame->nr_frags(); ifrag++ ) {
407 if ( ifrag % 10 == 0 )
tr.Info <<
"fragment (" << ifrag <<
"," << frame->nr_frags() <<
")" << std::endl;
408 frame->apply( ifrag, short_pose );
409 core::Real score_old(scorefxn->score(short_pose));
412 for (
core::Size cycle = 1; cycle<=cycles; cycle++ ) {
415 Size const irsd(
RG.random_range(1, short_size) );
421 if ( n_chi_angles != 0 ) {
422 jrmover.make_chi_move(rsd,old_chi,new_chi);
426 for (
core::Size ichi = 1; ichi<=n_chi_angles; ichi++) {
427 short_pose.
set_chi(ichi,irsd,new_chi[ ichi ]);
431 core::Real score_new(scorefxn->score(short_pose));
432 if ( score_new > score_old ) {
433 core::Real Delta_score(score_new - score_old);
435 if (
RG.uniform() > p) {
436 for (
core::Size ichi = 1; ichi<=n_chi_angles; ichi++) {
437 short_pose.
set_chi(ichi,irsd,old_chi[ ichi ]);
440 score_old = score_new;
444 score_old = score_new;
448 if (cycle%dump_freq == 0 ) {