34 #include <ObjexxFCL/string.functions.hh>
37 #include <utility/vector1.fwd.hh>
38 #include <utility/io/izstream.hh>
39 #include <utility/pointer/owning_ptr.hh>
40 #include <basic/Tracer.hh>
50 #include <utility/vector1.hh>
52 namespace ObjexxFCL {
namespace fmt { } }
using namespace ObjexxFCL::fmt;
57 using namespace kinematics;
58 using namespace ObjexxFCL;
60 static basic::Tracer
tr(
"core.fragments.ConstantLengthFragSet");
62 ConstantLengthFragSet::~ConstantLengthFragSet() {}
65 set_max_frag_length( frag_length );
66 read_fragment_file(filename);
70 ConstantLengthFragSet::ConstantLengthFragSet(
FragSet const& fragments ) {
72 Parent::add( fragments );
76 Size ConstantLengthFragSet::region(
85 for (
Size pos=start; pos<=frames_.size() && pos<=
end; pos++ ) {
87 if ( frames_[pos]->is_applicable( mm ) && frames_[pos]->is_valid() ) {
88 frames.push_back( frames_[ pos ] );
99 void ConstantLengthFragSet::add_(
FrameOP aframe ) {
100 if ( max_frag_length() ) runtime_assert( aframe->length() == max_frag_length() );
101 Size seqpos( aframe->start() );
102 if ( frames_.size() < seqpos ) {
103 frames_.resize( seqpos, NULL );
105 runtime_assert( frames_[ seqpos ] == 0 );
106 frames_[ seqpos ] = aframe;
113 utility::io::izstream data( filename );
114 if ( !data.good() ) {
115 cerr <<
"Open failed for file: " << data.filename() << endl;
116 utility::exit( EXIT_FAILURE, __FILE__, __LINE__);
119 read_fragment_stream(data,top25,ncopies,bAnnotation);
122 void ConstantLengthFragSet::read_fragment_stream( utility::io::izstream & data,
Size top25,
Size ncopies,
bool bAnnotation ) {
123 using namespace ObjexxFCL;
124 using namespace ObjexxFCL::fmt;
126 using std::istringstream;
132 Size insertion_pos = 1;
137 while ( getline( data, line ) ) {
139 if ( line ==
"" || line ==
" " ) {
141 if ( current_fragment && frame ) {
142 if ( !top25 || frame->nr_frags() < top25*ncopies ) {
143 current_fragment->set_valid();
144 if ( !frame->add_fragment( current_fragment ) ) {
145 tr.Fatal <<
"Incompatible Fragment in file: " << data.filename() << endl;
146 utility::exit( EXIT_FAILURE, __FILE__, __LINE__);
148 for (
Size i = 2; i <= ncopies; i++ ) frame->add_fragment( current_fragment );
154 current_fragment = NULL;
160 if ( line.substr(0,1) ==
"#" ) {
161 istringstream in( line );
166 if (tag ==
"score" && !in.eof()) {
174 if ( line.length() < 22 ) {
175 tr.Warning <<
"line too short: Skipping line '" << line <<
"'" << endl;
180 if ( line.find(
"position") != string::npos ) {
181 istringstream in( line );
187 if ( frame && frame->is_valid() ) {
189 n_frags = std::max( n_frags, frame->nr_frags() );
191 frame =
new Frame( insertion_pos );
196 string pdbid = line.substr(1, 4);
197 char chain = char_of(line.substr(6, 1));
198 int aa_index = int_of(line.substr(8, 5));
199 char aa = char_of(line.substr(14, 1));
200 char ss = char_of(line.substr(16, 1));
201 Real phi = float_of(line.substr(18, 9));
202 Real psi = float_of(line.substr(27, 9));
203 Real omega = float_of(line.substr(36, 9));
208 res->set_torsion(1, phi);
209 res->set_torsion(2, psi);
210 res->set_torsion(3, omega);
213 if (line.length() > 45) {
214 Real x = float_of(line.substr(45, 9));
215 Real y = float_of(line.substr(54, 9));
216 Real z = float_of(line.substr(64, 9));
217 res->set_coordinates(x, y, z);
222 res->set_secstruct(ss);
224 if ( !current_fragment ) {
232 current_fragment->add_residue(res);
233 current_fragment->set_score(score);
236 if ( frame && frame->is_valid() ) {
238 n_frags = std::max( n_frags, frame->nr_frags() );
241 tr.Info <<
"finished reading top " << n_frags <<
" "
242 << max_frag_length() <<
"mer fragments from file " << data.filename()