21 #include <basic/Tracer.hh>
23 #include <boost/lexical_cast.hpp>
24 #include <basic/options/option.hh>
25 #include <basic/options/keys/lh.OptionKeys.gen.hh>
31 #include <utility/vector1.hh>
35 using namespace core::pose;
36 using namespace kinematics;
37 using namespace basic::options;
38 using namespace basic::options::OptionKeys;
43 static basic::Tracer
TR(
"BackboneDB");
46 while( angle > 180.0) angle -= 360.0;
47 while( angle <-180.0) angle += 360.0;
49 short result = short( angle * 182.0 );
73 std::sort( cuts_in.begin(), cuts_in.end() );
76 for (
Size i=1; i<=cuts_in.size(); ++i) {
77 if (cuts_in[i]<=jr && cuts_in[i]>=ir) {
78 TR.Error <<
"ERROR -- residue range crosses cut IR: " << ir <<
" JR: " << jr <<
" CUT: " << cuts_in[i] << std::endl;
83 if (cuts_in[i]==ir-1) {
84 TR.Error <<
"ERROR -- startres immediately follows cut IR: " << ir <<
" CUT: " << cuts_in[i] << std::endl;
93 for (
Size i=1; i<=cuts_in.size(); ++i) {
94 if (cuts_in[i] >= nres)
break;
95 if (cutpoint > last_cut && cutpoint < cuts_in[i]) {
96 f.add_edge( last_cut+1, ir, Edge::PEPTIDE );
97 f.add_edge( ir, cutpoint, Edge::PEPTIDE );
98 f.add_edge( cutpoint + 1, jr, Edge::PEPTIDE );
99 f.add_edge( jr, cuts_in[i] , Edge::PEPTIDE );
100 f.add_edge( ir, jr, 1 );
101 if (last_cut!=0) f.add_edge( 1, last_cut+1, jump_num++);
103 f.add_edge( last_cut+1, cuts_in[i], Edge::PEPTIDE );
104 if (last_cut!=0) f.add_edge( 1, last_cut+1, jump_num++);
106 last_cut = cuts_in[i];
108 if (last_cut+1 <= nres) {
109 if (cutpoint > last_cut && cutpoint < nres) {
110 f.add_edge( last_cut+1, ir, Edge::PEPTIDE );
111 f.add_edge( ir, cutpoint, Edge::PEPTIDE );
112 f.add_edge( cutpoint + 1, jr, Edge::PEPTIDE );
113 f.add_edge( jr, nres , Edge::PEPTIDE );
114 f.add_edge( ir, jr, 1 );
115 if (last_cut!=0) f.add_edge( 1, last_cut+1, jump_num++);
117 f.add_edge( last_cut+1, nres, Edge::PEPTIDE );
118 if (last_cut!=0) f.add_edge( 1, last_cut+1, jump_num++);
122 f.add_edge( 1, i, jump_num++ );
126 if( newroot>0 ) theroot = newroot;
127 if( f.reorder(theroot) == false ){
128 TR.Error <<
"ERROR During reordering of fold tree - am ignoring this LOOP ! bailing: The root: " << theroot <<
" NRES " << pose.
total_residue() <<
" IR: " << ir <<
" JR: " << jr << std::endl;
154 phi_. push_back( pose.
phi( ires ));
155 psi_. push_back( pose.
psi( ires ));
156 omega_.push_back( pose.
omega( ires ));
160 void BackboneSegment::print()
const {
161 for( std::vector<core::Real>::const_iterator it = phi_.begin(); it != phi_.end(); ++it ) TR << *it <<
" " ;
162 for( std::vector<core::Real>::const_iterator it = psi_.begin(); it != psi_.end(); ++it ) TR << *it <<
" " ;
163 for( std::vector<core::Real>::const_iterator it = omega_.begin(); it != omega_.end(); ++it ) TR << *it <<
" " ;
170 if( bs1.
phi().size() != bs2.
phi().size() )
return false;
171 if( bs1.
psi().size() != bs2.
psi().size() )
return false;
172 if( bs1.
omega().size() != bs2.
omega().size() )
return false;
174 for(
core::Size i = 0; i < bs1.
phi().size(); i++ )
if( (bs1.
phi()[i] - bs2.
phi()[i]) > tolerance )
return false;
175 for(
core::Size i = 0; i < bs1.
psi().size(); i++ )
if( (bs1.
psi()[i] - bs2.
psi()[i]) > tolerance )
return false;
183 if( bs1.
phi().size() != bs2.
phi().size() )
return false;
184 if( bs1.
psi().size() != bs2.
psi().size() )
return false;
185 if( bs1.
omega().size() != bs2.
omega().size() )
return false;
187 for(
core::Size i = 0; i < bs1.
phi().size(); i++ )
if( bs1.
phi()[i] == bs2.
phi()[i] )
return false;
188 for(
core::Size i = 0; i < bs1.
psi().size(); i++ )
if( bs1.
psi()[i] == bs2.
psi()[i] )
return false;
197 if( bs1.
phi().size() != bs2.
phi().size() )
return -1;
199 if( bs1.
phi()[i] == 0 || bs2.
phi()[i] == 0 )
continue;
201 while( diff > 180 ) diff -= 360;
202 while( diff < -180 ) diff += 360;
206 if( bs1.
psi().size() != bs2.
psi().size() )
return -1;
208 if( bs1.
psi()[i] == 0 || bs2.
psi()[i] == 0 )
continue;
210 while( diff > 180 ) diff -= 360;
211 while( diff < -180 ) diff += 360;
215 if( bs1.
omega().size() != bs2.
omega().size() )
return -1;
217 if( bs1.
omega()[i] == 0 || bs2.
omega()[i] == 0 )
continue;
219 while( diff > 180 ) diff -= 360;
220 while( diff < -180 ) diff += 360;
231 if( index >= data_.size() ) utility_exit_with_message(
"Out of bounds error" );
232 if( offset >= data_[index].
angles.size() ) utility_exit_with_message(
"Out of bounds error" );
240 if( ! extra_ ) extra_ =
true;
241 index = data_.size();
251 extra_data.
sequence = chunk->get_sequence();
252 extra_data.
pdb_id = chunk->get_pdb_id() + chunk->get_chain_id();
257 extra_data.
pdb_id = pose_id;
259 new_protein.
extra_key = extra_data_.size();
260 extra_data_.push_back( extra_data );
261 data_.push_back( new_protein );
266 protein.
extra_key = data_[index].extra_key;
267 protein.
angles = data_[index].angles;
271 extra = extra_data_[index];
274 void BackboneDB::add_protein(
BBData new_protein ) {
275 data_.push_back( new_protein );
279 if( ! extra_ ) extra_ =
true;
280 extra_data_.push_back( extra );
284 BackboneDB::get_backbone_segment(
291 std::vector<core::Real>
phi;
292 std::vector<core::Real>
psi;
293 std::vector<core::Real>
omega;
305 std::ofstream file( filename.c_str() );
307 if( data_.size() == 0 ){
312 for (
core::Size i = 0; i < data_.size(); i++ ) {
313 file <<
"pdb " << extra_data_[ data_[i].extra_key ].pdb_id << std::endl;
314 file <<
"seq " << extra_data_[ data_[i].extra_key ].sequence << std::endl;
316 for (
core::Size j = 0; j < extra_data_[ data_[i].extra_key ].rotamer_id.size(); j++ ) {
317 file << extra_data_[ data_[i].extra_key ].rotamer_id[j] <<
" ";
321 for (
core::Size j = 0; j < data_[i].angles.size(); j++ ) {
322 file << data_[i].angles[j] <<
" ";
333 FILE *file = fopen( filename.c_str(),
"r" );
338 data_.push_back( new_protein );
340 while( !feof( file ) ){
342 TR.Debug <<
"C: " << count << std::endl;
343 const unsigned int bufsize = 16384;
344 short bufferdata[16384];
345 size_t readshorts = fread(&bufferdata[0],
sizeof(
short),bufsize,file);
346 for(
unsigned i = 0; i< readshorts; i ++ ){
347 data_[0].angles.push_back( bufferdata[i] );
351 TR.Debug <<
"End of read_db_from_binary" << std::endl;
357 std::pair< core::Size, core::Size > & loopdb_range,
358 std::map< core::Size, bool > & homolog_index )
360 std::ifstream file( filename.c_str() );
363 if( option[ lh::exclude_homo ]() ) {
364 TR <<
"Reading in homolog file" << std::endl;
373 while( getline(file, line) ) {
378 core::Size begin = assigned_num * num_lines / 4 / num_partitions;
379 core::Size end = ( assigned_num + 1 ) * num_lines / 4 / num_partitions;
381 loopdb_range.first = begin;
382 loopdb_range.second =
end;
384 TR.Info <<
"Reading in proteins " << begin <<
" to " << end <<
" out of " << num_lines / 4 <<
" , partition: " << assigned_num+1 <<
"/"<< num_partitions << std::endl;
387 file.seekg( 0, std::ios_base::beg );
392 int line_counter = -1;
393 bool is_homolog =
false;
395 unsigned int stat_count_protein = 0;
396 while( getline( file, line ) ) {
398 if( line_counter / 4 <
int(begin) )
continue;
399 if( line_counter / 4 >=
int(end) &&
int(end) != 0 )
continue;
401 command = line.substr(0,3);
405 if( command ==
"pdb" ) {
406 new_protein.
extra_key = extra_data_.size();
407 extra_data.
pdb_id = line.substr( 4 );
408 stat_count_protein++;
409 if( homologs_.find( extra_data.
pdb_id ) != homologs_.end() ) is_homolog =
true;
412 if( command ==
"seq" ) {
413 extra_data.
sequence = line.substr( 4 );
415 if( command ==
"rot" ) {
417 std::stringstream ss( line.substr( 4 ) );
419 extra_data.
rotamer_id.push_back( boost::lexical_cast< int >( buf ) );
422 if( command ==
"ang" ) {
424 std::stringstream ss( line.substr( 4 ) );
425 while ( ss >> buf ) new_protein.
angles.push_back( boost::lexical_cast< short >( buf ) );
429 new_protein.
angles.clear();
431 homolog_index[ data_.size() ] =
true;
432 TR <<
"Homolog " << extra_data.
pdb_id <<
" rejected." << std::endl;
434 data_.push_back(new_protein);
436 new_protein.
angles.clear();
440 extra_data_.push_back( extra_data );
445 TR.Info <<
"Read in " << stat_count_protein <<
" proteins" << std::endl;
446 TR.Info <<
"Data_ size " << data_.size() << std::endl;
450 void BackboneDB::read_homologs()
452 std::ifstream file( option[ lh::homo_file ]().c_str() );
455 while( getline( file, line) ) {
459 TR <<
"Adding homolog: " << homolog_pdb_code_and_chain << std::endl;
460 homologs_[homolog_pdb_code_and_chain] =
true;
461 if( homolog_pdb_code_and_chain.size() == 5 ) {
462 if( homolog_pdb_code_and_chain[4] ==
'A' || homolog_pdb_code_and_chain[4] ==
'a' ) homologs_[ homolog_pdb_code_and_chain.replace( 4, 1, 1,
'_' ) ] =
true;
463 if( homolog_pdb_code_and_chain[4] ==
'_' ) homologs_[ homolog_pdb_code_and_chain.replace( 4, 1, 1,
'A' ) ] =
true;
468 TR <<
"Homolog exclusion: ";
469 for( std::map< std::string, bool >::const_iterator hom = homologs_.begin(); hom != homologs_.end(); ++hom){
470 TR << hom->first <<
" ";