36 #include <basic/Tracer.hh>
37 #include <numeric/angle.functions.hh>
38 #include <numeric/random/random.hh>
39 #include <utility/vector1.hh>
40 #include <utility/io/izstream.hh>
46 #define foreach BOOST_FOREACH
49 namespace import_pose {
50 namespace atom_tree_diffs {
92 in_.open(filename.c_str());
94 std::set<std::string> used_tags;
97 std::map< std::string, core::Real >
scores;
100 long curr_pos =
in_.tellg();
106 if( used_tags.count(tag) > 0 ) {
107 basic::Error() <<
"Tag " << tag <<
" appears at least twice in the atom_tree_diff file! Discarding structure..." << std::endl;
111 if( end == std::string::npos){
112 utility_exit_with_message(tag+
" doesn't end with a 4-digit code");
115 if( scores.find(
"is_reference_pose") != scores.end() ) {
121 ref_tag= ref_tag.substr(start+1);
123 basic::Error() <<
"Tag " << ref_tag <<
" appears at least twice in the atom_tree_diff file! Discarding reference structure..." << std::endl;
129 scores_.push_back( std::make_pair(tag, scores) );
142 in_.open(filename.c_str());
177 utility_exit_with_message(
"No reference pose available for "+tag);
188 utility_exit_with_message(
"Unable to seek in input file!");
194 utility_exit_with_message(
"Seek took us to the wrong entry!");
204 utility_exit_with_message(
"No reference pose available for "+tag);
213 std::map< std::string, core::Real >
const & scores
218 out <<
"SCORES " << pose_tag;
225 if( std::abs(val) < 1e-8 ) val = 0.0;
226 out <<
' ' << pair.first <<
' ' << val;
243 out <<
"POSE_TAG " << pose_tag <<
'\n';
245 Scores mod_scores = scores;
246 mod_scores[
"is_reference_pose"] = 1;
249 out <<
"BEGIN_PDB_FORMAT " << pose_tag <<
'\n';
251 out <<
"END_PDB_FORMAT " << pose_tag <<
'\n';
264 out <<
"END_POSE_TAG " << pose_tag <<
'\n';
280 std::map< std::string, core::Real >
const & scores,
285 int bondlen_precision
290 using basic::Warning;
291 using namespace core::id;
292 using namespace core::scoring;
294 if(bb_precision < sc_precision) Warning() <<
"Crazy fool, bb_precision should be >= sc_precision!" << std::endl;
295 Real bb_tol = 1.0, sc_tol = 1.0, bondlen_tol = 1.0;
296 for(
int i = 0; i < bb_precision; ++i) bb_tol /= 10.0;
297 for(
int i = 0; i < sc_precision; ++i) sc_tol /= 10.0;
298 for(
int i = 0; i < bondlen_precision; ++i) bondlen_tol /= 10.0;
303 out <<
"POSE_TAG " << pose_tag <<
'\n';
311 using namespace core::conformation;
324 std::ios_base::fmtflags orig_flags = out.flags();
325 std::streamsize orig_precision = out.precision();
326 out.setf( std::ios_base::fixed );
330 bool const is_jump_residue = foldtree.is_jump_point(rsd);
331 for(
Size atom = 1, atom_end = pose.
residue(rsd).
natoms(); atom <= atom_end; ++atom) {
334 if( atom_tree.atom(aid).is_jump() ) {
341 bool is_backbone = is_jump_residue
343 int precision = (is_backbone ? bb_precision : sc_precision);
344 Real tol = (is_backbone ? bb_tol : sc_tol);
346 Real before_phi = ref_pose.
dof(dof_phi), before_theta = ref_pose.
dof(dof_theta), before_d = ref_pose.
dof(dof_d);
347 Real after_phi = pose.
dof(dof_phi), after_theta = pose.
dof(dof_theta), after_d = pose.
dof(dof_d);
352 bool const changed_phi = (std::abs(numeric::nearest_angle_radians(after_phi, before_phi) - before_phi) > tol);
353 bool const changed_theta = (std::abs(after_theta - before_theta) > tol);
354 bool const changed_d = (std::abs(after_d - before_d) > bondlen_tol);
355 if( changed_phi || changed_theta || changed_d ) {
356 out.precision( precision );
357 out << rsd <<
' ' << atom;
359 out <<
' ' << after_phi;
360 if( changed_theta || changed_d ) {
361 out <<
' ' << after_theta;
363 out.precision( bondlen_precision );
364 out <<
' ' << after_d;
374 for(
int jump = 1, jump_end = pose.
num_jump(); jump <= jump_end; ++jump) {
375 out <<
"JUMP " << jump;
377 for (
int i = 1; i <= 3; ++i ) {
378 for (
int j = 1; j <= 3; ++j ) {
383 for (
int i = 1; i <= 3; ++i ) {
393 out <<
"END_POSE_TAG " << pose_tag <<
'\n';
396 out.flags( orig_flags );
397 out.precision( orig_precision );
411 bool found_tag =
false, found_scores =
false;
412 while( in.good() && !( found_tag && found_scores ) ) {
416 if( in.fail() )
return false;
417 std::istringstream is(line);
419 if( key ==
"POSE_TAG" ) {
422 }
else if ( key ==
"SCORES" ) {
427 if( is.fail() )
break;
428 scores_out[ key ] = value;
433 return ( found_tag && found_scores );
449 using namespace core::id;
450 using namespace core::scoring;
455 static basic::Tracer
TR(
"core.import_pose.atom_tree_diffs.atom_tree_diff.pose_from_atom_tree_diff");
460 TR <<
"getline() failed" << std::endl;
464 std::istringstream is(line);
467 is >> rsd_no >> atom_no;
472 is.seekg(0, std::ios::beg);
474 if( key ==
"END_POSE_TAG" )
return true;
477 else if( key ==
"JUMP" || key ==
"jump" ) {
480 if( is.fail() || jump_no < 1 || jump_no > pose.
num_jump() ) {
481 TR <<
"uh-oh, pose doesn't have a jump " << jump_no << std::endl;
486 for (
int i = 1; i <= 3; ++i ) {
487 for (
int j = 1; j <= 3; ++j ) {
491 for (
int i = 1; i <= 3; ++i ) {
495 TR <<
"error reading in jump data for jump " << jump_no << std::endl;
497 jump.set_rotation(mat);
498 jump.set_translation(vec);
502 }
else if( key ==
"MUTATE" ) {
505 is >> resnum >> resname;
507 TR <<
"error reading sequence mutation data" << std::endl;
509 TR <<
"d'oh, pose doesn't have a residue " << resnum << std::endl;
511 TR <<
"unrecognized residue type name '" << resname <<
"'" << std::endl;
515 TR.Debug <<
"ignoring no-op mutation: MUTATE " << resnum <<
" " << resname << std::endl;
517 using namespace core::conformation;
524 }
else if( key ==
"FOLD_TREE" ) {
528 is.seekg(0, std::ios::beg);
533 TR <<
"danger danger, error reading fold tree" << std::endl;
535 }
else if( key ==
"BEGIN_PDB_FORMAT" ) {
539 using namespace core::chemical;
540 using namespace core::import_pose;
542 std::vector< io::pdb::Record > pdb_data;
546 TR <<
"getline() failed while reading embedded PDB" << std::endl;
549 if( line.size() >= end_pdb_key.size() && line.compare(0, end_pdb_key.size(), end_pdb_key) == 0 )
break;
555 fd.filename =
"atom_tree_diff.pdb";
561 TR <<
"uh-oh, pose doesn't have a residue " << rsd_no << std::endl;
563 TR <<
"uh-oh, residue " << rsd_no <<
" doesn't have an atom " << atom_no << std::endl;
567 AtomID aid(atom_no, rsd_no);
572 pose.
set_dof( dof_phi, phi_value );
576 pose.
set_dof( dof_theta, theta_value );
580 pose.
set_dof( dof_d, d_value );
584 else TR <<
"somebody screwed up ... no phi to set for " << rsd_no <<
" " << atom_no <<
" !" << std::endl;
589 TR <<
"beeg trouble for moose and squirrel -- reached EOF" << std::endl;
602 using namespace core::scoring;
609 ScoreTypeVec score_types;
616 foreach(
ScoreType score_type, score_types){
646 using basic::Warning;
648 using namespace core::id;
649 using namespace core::scoring;
651 if(bb_precision < sc_precision) Warning() <<
"Crazy fool, bb_precision should be >= sc_precision!" << std::endl;
652 Real bb_tol = 1.0, sc_tol = 1.0;
653 for(
int i = 0; i < bb_precision; ++i) bb_tol /= 10.0;
654 for(
int i = 0; i < sc_precision; ++i) sc_tol /= 10.0;
662 for(
Size atom = 1, atom_end = pose.
residue(rsd).
natoms(); atom <= atom_end; ++atom) {
665 if( atom_tree.atom(aid).is_jump() ) {
672 bool is_backbone = is_jump_residue
675 Real tol = (is_backbone ? bb_tol : sc_tol);
678 pose.
set_dof(dof_phi, pose.
dof(dof_phi) + tol * (
RG.uniform() - 0.5));
679 pose.
set_dof(dof_theta, pose.
dof(dof_theta) + tol * (
RG.uniform() - 0.5));
680 pose.
set_dof(dof_d, pose.
dof(dof_d) + tol * (
RG.uniform() - 0.5));
685 T(
"rms_error_with_noise") <<
"bb=" << bb_precision <<
"," << bb_tol <<
" sc=" << sc_precision <<
"," << sc_tol
693 utility::io::izstream infile( filename );
701 std::streampos startpos(in.tellg());