39 #include <utility/vector1.fwd.hh>
40 #include <utility/io/izstream.hh>
41 #include <utility/io/ozstream.hh>
42 #include <utility/pointer/owning_ptr.hh>
43 #include <basic/Tracer.hh>
50 #include <utility/vector1.hh>
56 static basic::Tracer
tr(
"core.io.fragments");
83 FrameTypes::const_iterator
const iter (
frame_types_.find( type ) );
85 return iter->second->clone();
92 SRFD_Types::const_iterator
const iter (
frag_types_.find( frag_name ) );
94 return iter->second->clone();
106 if ( !next_line.size() )
continue;
108 std::istringstream line_stream( next_line );
112 new_frame->read( line_stream );
113 tr.Trace <<
"read frame " << *new_frame << std::endl;
114 next_frames.push_back( new_frame );
116 if ( line_stream.fail() ) data.setstate( std::ios_base::failbit );
117 }
while ( getline( data, next_line ) );
121 if ( !new_frames.size() )
return;
122 Size const length( new_frames[ 1 ]->length() );
123 tr.Trace <<
"frags in frame at beginning: " << new_frames[ 1 ]->nr_frags() << std::endl;
127 if ( !next_line.size() )
continue;
128 if ( next_line ==
"ENDFRAME" ) {
129 getline( data, next_line );
132 if ( next_line ==
"FRAME" ) {
140 std::istringstream line_stream( next_line +
" " );
141 line_stream >> pos >> pdb_pos >> pdb_id >> tag;
142 if ( line_stream.fail() )
break;
145 if (
top_ && (*new_frames.begin())->nr_frags() >=
top_ *
ncopies_ )
continue;
147 if ( !current_fragment ) {
149 else current_fragment =
new FragData;
154 tr.Error <<
"ERROR: tag " << tag <<
" not known by frag_factory" << std::endl;
157 line_stream >> *new_srfd;
158 if ( line_stream.fail() ) {
159 tr.Error <<
"ERROR: reading of " << tag <<
" failed in line: " << next_line << std::endl;
160 data.setstate( std::ios_base::failbit );
163 current_fragment->add_residue( new_srfd );
164 if ( current_fragment->size() == length ) {
165 current_fragment->set_valid();
166 tr.Trace <<
"read FragData" << std::endl << *current_fragment << std::endl;
167 for ( FrameList::iterator frame = new_frames.begin(), eframe = new_frames.end();
168 frame != eframe; ++frame ) {
171 if ( !(*frame)->add_fragment( current_fragment ) ) {
172 tr.Error <<
"failed to add " << *current_fragment <<
" to frame " << (**frame) << std::endl;
173 data.setstate( std::ios_base::failbit );
176 (*frame)->add_fragment( current_fragment );
180 current_fragment = NULL;
182 }
while ( getline( data, next_line ) );
183 if ( data.fail() && data.eof() && !data.bad() ) {
184 tr.Debug <<
"End of fragment file during fragment reading... set eofbit" << std::endl;
185 data.clear( std::ios_base::eofbit );
187 if ( current_fragment ) {
188 tr.Error <<
"ERROR: read incomplete fragment at line" << next_line << std::endl;
189 data.setstate( std::ios_base::failbit );
194 tr.Info <<
" read fragments options: top = " <<
top_ <<
" copies: " <<
ncopies_
195 <<
" annotate: " << (
bAnnotate_ ?
"yes" :
"no" ) << std::endl;
198 while ( data.good() ) {
202 if ( new_frames.size() == 0 )
tr.Debug <<
"found no new FRAME entry ... finished. " << std::endl;
203 if ( data.eof() )
tr.Debug <<
" reached EOF during reading of FRAME entries " << std::endl;
204 if ( !data || new_frames.size() == 0 )
break;
207 if ( data.fail() )
break;
209 for ( FrameList::iterator frame = new_frames.begin(), eframe = new_frames.end();
210 frame != eframe; ++frame ) {
211 if ( (*frame)->nr_frags() ) {
212 all_frames.push_back( *frame );
216 if ( data.fail() || data.bad() ) {
217 tr.Error <<
"reading failed at line " << next_line << std::endl;
231 utility::io::izstream data( filename );
233 utility_exit_with_message(
"ERROR: FragmentIO: could not open file " + filename );
235 tr.Info <<
"reading fragments from file: " << filename <<
" ... " << std::endl;
236 getline( data, line );
237 std::istringstream
str( line );
240 if ( tag ==
"position:" ) {
241 tr.Info <<
"rosetta++ fileformat detected! Calling legacy reader... "
256 frags->add( frames );
264 if ( it->second->ref_count() == 1 ) {
265 tr.Info <<
"GARBAGE COLLECTION: remove " << it->first <<
" from frag_cache " << std::endl;
272 utility::io::izstream data( filename );
273 if ( !data.good() ) utility_exit_with_message(
"ERROR: FragmentIO: could not open file " + filename );
274 tr.Info <<
"reading fragment frames from file: " << filename <<
" ... " << std::endl;
278 utility_exit_with_message(
"failed to read fragments from file " + filename );
283 utility::io::ozstream out( file );