22 #include <basic/Tracer.hh>
26 #include <numeric/random/random.hh>
36 #include <utility/vector1.hh>
41 namespace rbsegment_relax {
45 basic::Tracer
TR_seg(
"RBSegment");
47 static numeric::random::RandomGenerator
RG(431112);
63 std::string::size_type lastPos = str.find_first_not_of(delimiters, 0);
64 std::string::size_type pos = str.find_first_of(delimiters, lastPos);
66 while (std::string::npos != pos || std::string::npos != lastPos) {
67 tokens.push_back(str.substr(lastPos, pos - lastPos));
68 lastPos = str.find_first_not_of(delimiters, pos);
69 pos = str.find_first_of(delimiters, lastPos);
75 if (sigOffAxisR == 0 && sigOffAxisT == 0) {
76 TR_seg <<
"Setting movement parameters: [" << segments_[1].start() <<
"...] :"
77 << sigAxisR <<
" , " << sigAxisT << std::endl;
79 TR_seg <<
"Setting movement parameters: [" << segments_[1].start() <<
"...] :"
80 << sigAxisR <<
" , " << sigAxisT <<
" , " << sigOffAxisR <<
" , " << sigOffAxisT << std::endl;
84 sigOffAxisR_ = sigOffAxisR;
85 sigOffAxisT_ = sigOffAxisT;
91 sigOffAxisR = sigOffAxisR_;
92 sigOffAxisT = sigOffAxisT_;
104 bool autoGenerateLoops ,
111 std::ifstream infile( filename.c_str() );
113 if (!infile.good()) {
114 TR_seg <<
"[ERROR] Error opening RBSeg file '" << filename <<
"'" << std::endl;
122 std::map < int, RBSegment > simple_segments;
128 while( getline(infile,line) ) {
131 if( tokens.size() > 0 ) {
134 if ( tokens[1] ==
"SEGMENT" || tokens[1] ==
"SEG" ) {
135 if ( tokens.size() < 5 ) {
136 TR_seg <<
"[ERROR] Error parsing line '" << line <<
"'" << std::endl;
139 int id = atoi( tokens[2].c_str() );
140 if (simple_segments.find(
id ) != simple_segments.end() ) {
141 TR_seg <<
"[ERROR] Segment id " <<
id <<
" defined twice in RBSeg file!" << std::endl;
144 int seg_start=atoi( tokens[3].c_str() ), seg_end = atoi( tokens[4].c_str() );
145 char ss_key = tokens[5][0];
146 simple_segments[id] =
RBSegment( seg_start, seg_end, ss_key );
148 if (tokens.size() == 7)
149 simple_segments[
id].set_movement( atof( tokens[6].c_str() ),
150 atof( tokens[7].c_str() ) );
151 else if (tokens.size() == 9)
152 simple_segments[
id].set_movement( atof( tokens[6].c_str() ),
153 atof( tokens[7].c_str() ),
154 atof( tokens[8].c_str() ),
155 atof( tokens[9].c_str() ) );
157 simple_seg_list.push_back( simple_segments[
id] );
160 }
else if ( tokens[1] ==
"LOCKED" ) {
161 if ( tokens.size() < 5 ) {
162 TR_seg <<
"[ERROR] Error parsing line '" << line <<
"'" << std::endl;
167 thisLock.push_back( atoi( tokens[i].c_str() ) );
168 locked_segments.push_back( thisLock );
170 locked_mvmt.push_back(
171 std::pair< core::Real, core::Real > ( atof( tokens[2].c_str() ), atof( tokens[3].c_str() ) ) );
174 }
else if ( tokens[1] ==
"COMPOUND" ) {
188 TR_seg.Error <<
"[ERROR] compund segments unsupported ... ignoring line '" << line <<
"'" << std::endl;
189 }
else if ( tokens[1] ==
"LOOP" ) {
190 if ( autoGenerateLoops ) {
191 TR_seg.Warning <<
"[WARNING] LOOP specified in RBSegment file but autoGenerateLoops is true!"
192 <<
" Ignoring line." << std::endl;
196 if ( tokens.size() < 3 ) {
197 TR_seg <<
"[ERROR] Error parsing line '" << line <<
"'" << std::endl;
205 bool extend_loop =
false;
207 if (tokens.size() > 3)
209 if (tokens.size() > 4)
210 skip_rate = atof(tokens[5].c_str());
211 if (tokens.size() > 5)
212 extend_loop_str = tokens[6];
214 if (extend_loop_str.length() > 0)
218 }
else if ( tokens[1][0] !=
'#' ) {
219 TR_seg <<
"[WARNING] Skipping line '" << line <<
"'" << std::endl;
225 if ( autoGenerateLoops && simple_seg_list.size() > 0 ) {
226 std::sort( simple_seg_list.begin(), simple_seg_list.end(),
RB_lt());
227 int start_res=1, end_res=simple_seg_list[1][1].start()-1;
229 int nsegs = simple_seg_list.size();
231 if (end_res > start_res)
233 else if (end_res == start_res)
235 for (
int i=1; i<nsegs; ++i) {
236 start_res = simple_seg_list[i][1].end()+1;
237 end_res = simple_seg_list[i+1][1].start()-1;
239 if (end_res > start_res)
241 else if (end_res == start_res)
246 start_res = simple_seg_list[nsegs][1].end()+1;
249 if (end_res > start_res)
251 else if (end_res == start_res)
255 std::sort( cutpoints.begin(), cutpoints.end() );
256 for (
int i=1; i<=(
int)cutpoints.size(); ++i) {
257 for (
int j=1; j<=(
int)loops.
size(); ++j) {
258 if (cutpoints[i] > loops[j].
start() && cutpoints[i] < loops[j].stop()) {
272 for (
core::Size i=1; i<=locked_segments.size(); ++i) {
274 for (
core::Size j=1; j<=locked_segments[i].size(); ++j) {
275 int id = locked_segments[i][j];
276 if (simple_segments.find(
id ) == simple_segments.end() ) {
277 TR_seg <<
"[ERROR] Segment id " <<
id <<
" undefined or used in multiple locked compound segments" << std::endl;
280 thisLockSeg.push_back( simple_segments[
id ] );
281 simple_segments.erase(
id );
284 toAdd.
set_movement( locked_mvmt[i].first, locked_mvmt[i].second );
285 rbsegs.push_back( toAdd );
289 for (
core::Size i=1; i<=compound_segments.size(); ++i) {
291 for (
core::Size j=1; j<=compound_segments[i].size(); ++j) {
292 int id = compound_segments[i][j];
293 if (simple_segments.find(
id ) == simple_segments.end() ) {
294 TR_seg <<
"[ERROR] Segment id " <<
id <<
" undefined or used in multiple locked compound segments" << std::endl;
297 thisCompoundSeg.push_back( simple_segments[
id ] );
300 toAdd.
set_movement( compound_mvmt[i].first, compound_mvmt[i].second );
301 rbsegs.push_back( toAdd );
306 for ( std::map < int, RBSegment >::iterator i=simple_segments.begin(); i!=simple_segments.end(); ++i ) {
307 rbsegs.push_back( i->second );
311 std::sort( rbsegs.begin(), rbsegs.end(),
RB_lt());
316 if (rbsegs[i].isSimple()) {
317 TR_seg <<
"[debug] SIMPLE rb " << rbsegs[i][1].start() <<
"--" << rbsegs[i][1].end() <<
" [type " << (
int)rbsegs[i][1].type() <<
"] " <<
" r = " << rbsegs[i].getSigAxisR()
318 <<
" t = " << rbsegs[i].getSigAxisT()
319 <<
" r_o = " << rbsegs[i].getSigOffAxisR()
320 <<
" t_o = " << rbsegs[i].getSigOffAxisT() << std::endl;
322 TR_seg <<
"[debug] COMPOUND rb r = " << rbsegs[i].getSigAxisR()
323 <<
" t = " << rbsegs[i].getSigAxisT()
324 <<
" r_o = " << rbsegs[i].getSigOffAxisR()
325 <<
" t_o = " << rbsegs[i].getSigOffAxisT() << std::endl;
326 for (
core::Size j=1; j<=rbsegs[i].nContinuousSegments(); ++j) {
327 TR_seg << rbsegs[i][j].start() <<
"--" << rbsegs[i][j].end() <<
" [type " << (
int)rbsegs[i][j].type() <<
"] ";
333 TR_seg <<
"[debug] LOOP " << loops[i].start() <<
"--" << loops[i].stop()
334 <<
" " << loops[i].cut() <<
" [skip " << loops[i].skip_rate() <<
"]" << std::endl;
349 rbsegs_selected.clear();
350 loops_selected.
clear();
352 int nRBSegs = (
int)rbsegs_in.size();
360 k =
RG.random_range(1, nRBSegs);
362 rbsegs_selected.push_back( rbsegs_in[k] );
366 for (
core::Size j=1; j<=rbsegs_in[k].nContinuousSegments(); ++j) {
367 bool adjLoopN = loops_in[i].stop() == rbsegs_in[k][j].start()-1;
368 bool adjLoopC = loops_in[i].start() == rbsegs_in[k][j].end()+1;
369 if ( adjLoopN || adjLoopC ) {
372 loops_selected.
push_back( bounding_loop );
377 std::cerr << rbsegs_selected.size() <<
" rigid body segments input\n";
378 std::cerr << loops_selected.
size() <<
" loops\n";
385 for (
core::Size i=1 ; i<=segments_.size(); ++i ) {
386 int oldS = (
int)segments_[i].
start(),
387 oldE = (
int)segments_[i].
end();
390 if (mapping[ oldS ] != 0 ) {
391 newS = mapping[ oldS ];
393 TR_seg <<
"[ ERROR ] mapping(" << segments_[i].start() <<
") not found!" << std::endl;
397 if (mapping[ oldE ] != 0 ) {
398 newE = mapping[ oldE ];
400 TR_seg <<
"[ ERROR ] mapping(" << segments_[i].end() <<
") not found!" << std::endl;
403 TR_seg <<
"[ DEBUG ] remapping(" << oldS <<
"," << oldE <<
") to (" << newS <<
"," << newE <<
")" << std::endl;
405 remappedSimpleSegs.push_back(
RBSegment( newS, newE, segments_[i].type() ) );
412 for (
core::Size i=1; i<=segs_in.size(); ++i) {
413 if (!segs_in[i].isSimple()) {
414 TR_seg <<
"[ ERROR ] Error parsing RBSeg file: trying to nest compound segments." << std::endl;
417 segments_.push_back( segs_in[i][1] );
420 sigAxisR_ = sigAxisT_ = sigOffAxisR_ = sigOffAxisT_ = 0.0;