32 #include <basic/options/option.hh>
33 #include <basic/options/keys/constraints.OptionKeys.gen.hh>
44 #include <utility/pointer/ReferenceCount.hh>
45 #include <utility/io/izstream.hh>
46 #include <utility/io/ozstream.hh>
48 #include <basic/Tracer.hh>
50 #include <utility/vector1.hh>
53 static basic::Tracer
tr(
"core.io.constraints");
57 namespace constraints {
87 tr.Debug <<
"ConstraintIO::read_cst_atom_pairs" << std::endl;
89 while( getline( data, line ) ) {
95 std::istringstream line_stream( line );
104 if ( name1.find(
"[" )!=std::string::npos ) {
105 tr.Debug <<
"section end detected in line " << line << std::endl;
106 next_section_name = line;
109 tr.Debug <<
"read: " << name1 <<
" " << name2 <<
" "
110 << res1 <<
" " << res2 <<
" func: " << func_type
118 tr.Error <<
"error in constraint (no such atom in pose!)"
119 << name1 <<
" " << name2 <<
" " << res1 <<
" " << res2 <<
" func: " << func_type << std::endl;
120 utility_exit_with_message (
"Constraint data referred to atom which is not present in pose");
128 aFunc->read_data( line_stream );
130 if (
tr.Debug.visible() ) {
131 aFunc->show_definition(
tr.Debug );
tr.Debug << std::endl;
136 tr.Debug <<
"end of file reached" << std::endl;
137 next_section_name =
"";
158 tr.Info <<
"read: " << name1 <<
" " << name2 <<
" "
159 << res1 <<
" " << res2 <<
" func: " << func_type
162 tr.Warning <<
"ignored constraint (no such atom in pose!)"
163 << name1 <<
" " << name2 <<
" " << res1 <<
" " << res2 << std::endl;
171 aFunc->read_data( data );
173 if (
tr.Debug.visible() ) {
174 aFunc->show_definition(
tr.Debug );
tr.Debug<<std::endl;
189 tr.Debug <<
"ConstraintIO::read_cst_coordinate" << std::endl;
191 while( getline( data, line ) ) {
199 std::istringstream line_stream( line );
204 if ( name1.find(
"[" )!=std::string::npos ) {
205 tr.Debug <<
"section end detected in line " << line << std::endl;
206 next_section_name = line;
215 tr.Debug <<
"read: " << name1 <<
" " << name2 <<
" "
216 << res1 <<
" " << res2 <<
" func: " << func_type
223 tr.Error <<
"error in constraint (no such atom in pose!)"
224 << name1 <<
" " << name2 <<
" " << res1 <<
" " << res2 <<
" func: " << func_type << std::endl;
225 utility_exit_with_message (
"Constraint data referred to atom which is not present in pose");
233 aFunc->read_data( line_stream );
236 aFunc->show_definition( std::cout ); std::cout<<std::endl;
239 Vector transform( x, y, z );
243 tr.Debug <<
"end of file reached" << std::endl;
244 next_section_name =
"";
252 Size fixed_res, other_res;
259 >> fixed_res_name >> tempfixed_res
260 >> other_res_name >> tempother_res
267 tr.Debug <<
"read: " << fixed_res_name <<
" " << other_res_name <<
" "
268 << fixed_res <<
" " << other_res <<
" func: " << func_type << std::endl;
270 tr.Warning <<
"ignored constraint (no such atom in pose!)"
271 << fixed_res_name <<
" " << other_res_name <<
" "
272 << fixed_res <<
" " << other_res << std::endl;
280 aFunc->read_data( data );
282 if (
tr.Debug.visible() ) {
283 aFunc->show_definition(
tr.Debug );
tr.Debug << std::endl;
286 Vector transform( x, y, z );
299 tr.Debug <<
"ConstraintIO::read_cst_angles" << std::endl;
301 while( getline( data, line ) ) {
302 Size res1, res2, res3;
307 std::istringstream line_stream( line );
318 if ( name1.find(
"[" )!=std::string::npos ) {
319 tr.Debug <<
"section end detected in line " << line << std::endl;
320 next_section_name = line;
327 tr.Debug <<
"read: " << name1 <<
" " << res1 <<
" " << name2 <<
" "
328 << res2 <<
" " << name3 <<
" " << res3 << std::endl;
330 aFunc->read_data( line_stream );
332 if (
tr.Debug.visible() ) {
333 aFunc->show_definition(
tr.Debug );
tr.Debug<<std::endl;
337 tr.Warning <<
"ignored constraint" << name1 <<
" " << name2 <<
" "
338 << res1 <<
" " << res2 << std::endl;
344 tr.Debug <<
"end of file reached" << std::endl;
345 next_section_name =
"";
396 if ( line.size() == 0 )
return line;
397 std::istringstream line_stream( line );
405 std::string::size_type start = tok.find(
"[");
406 if ( start != 0 )
return "NO_SECTION";
411 std::string::size_type loc = tok.find(
"]");
412 if ( loc != std::string::npos ) {
415 return tok.substr(start,loc);
426 tr.Debug <<
"ConstraintIO::read_cst_angles" << std::endl;
428 while( getline( data, line ) ) {
432 std::istringstream line_stream( line );
433 if ( line.find(
"[" )!=std::string::npos ) {
434 tr.Debug <<
"section end detected in line " << line << std::endl;
435 next_section_name = line;
457 tr.Debug <<
"end of file reached" << std::endl;
458 next_section_name =
"";
467 std::streampos original_pos = data.tellg();
471 while ( section.size() ) {
472 tr.Info <<
"read constraints section --" << section <<
"---" << std::endl;
473 if ( section ==
"atompairs" ) {
475 }
else if ( section ==
"coordinates" ) {
477 }
else if ( section ==
"angles" ) {
479 }
else if ( section ==
"bindingsites" ) {
481 }
else if ( section ==
"NO_SECTION" ) {
482 tr.Info <<
" no section header [ xxx ] found, try reading line-based format... DON'T MIX"
488 assert( dynamic_cast< zlib_stream::zip_istream * > ( &data ) == 0 );
490 data.seekg( original_pos );
493 utility_exit_with_message(
494 "constraint-file: section " + section +
" not recognized!"
497 tr.Trace <<
"pre_read: " << pre_read << std::endl;
515 utility::io::izstream data( fname.c_str() );
516 tr.Info <<
"read constraints from " << fname << std::endl;
518 utility_exit_with_message(
"[ERROR] Unable to open constraints file: "+ fname );
525 if ( section ==
"NO_SECTION" ) {
542 utility::io::izstream data( fname.c_str() );
543 tr.Info <<
"read constraints from " << fname << std::endl;
545 utility_exit_with_message(
"[ERROR] Unable to open constraints file: " + fname );
555 Size count_constraints(0);
556 while( data.good() ) {
562 cset->add_constraint( cst_op );
563 }
else if ( ! data.eof() ) {
564 tr.Error <<
"ERROR: reading constraints from file" << std::endl;
568 tr.Info <<
"Read in " << count_constraints <<
" constraints" << std::endl;
588 cst_op->read_def( data, pose, func_factory );
593 if ( !data.good() && !data.eof()) {
594 error_msg +=
"ERROR: reading of " + tag +
" failed.\n";
595 tr.Error << error_msg << std::endl;
599 error_msg +=
"ERROR: constraint type " + tag +
" not known.\n";
600 tr.Error << error_msg << std::endl;
604 using namespace basic::options;
605 using namespace basic::options::OptionKeys;
606 if ( option[ OptionKeys::constraints::exit_on_bad_read ]() ) {
609 utility_exit_with_message( error_msg );
632 char c = data.peek();
633 if ( c ==
'#' || c ==
'\n' ) {
634 while( data.good() && (data.get() !=
'\n') ) {}
637 if ( data.eof() )
return NULL;
640 tr.Error <<
"can't read constraint type" << std::endl;
645 if (( tag.substr(0,3) ==
"END" )||( tag.substr(0,3) ==
"End" ))
return NULL;
656 utility::io::ozstream dump_cst( filename );
678 std::stringstream data;
682 data.str( residue_string );
686 if ( !(data >> chain).fail() ) {
687 residue_num = pose.
pdb_info()->pdb2pose( chain, resnum );
688 }
else residue_num = resnum;