22 #include <utility/exit.hh>
24 #include <basic/Tracer.hh>
25 #include <boost/unordered_map.hpp>
27 #include <utility/vector0.hh>
28 #include <utility/vector1.hh>
32 static basic::Tracer
tr(
"protocols.sparta");
48 GDBfileName = fileName;
59 GDBfileName = fileName;
61 ifstream file(fileName.c_str());
62 if (! file.is_open() ){
63 tr.Error <<
"\tCan't open file " << fileName <<
" for reading" << endl;
69 bool DATA_START =
false;
71 while (! file.eof() ) {
73 if (str.empty() || str.size() == 0)
continue;
77 if ( fields.size() == 0)
continue;
80 if ( DATA_START && VarsNumber > 0 && (
int) fields.size() == VarsNumber )
82 for(
int i = 0; i < VarsNumber; i++)
84 Entries[ entry_count ][ VARS[i] ] = fields[i];
90 if ( fields[0] ==
"REMARK" )
92 REMARKS.push_back( str.substr( fields[0].length()+1, str.length() ) );
94 else if ( fields[0] ==
"DATA" ) {
96 text = str.substr( fields[0].length()+1, str.length() );
97 DATA.push_back( text );
98 }
else if ( fields[0] ==
"VARS" ) {
100 text = str.substr(fields[0].length(), str.length());
102 VARS_str_parser(VARS_str);
103 }
else if ( fields[0].
compare(
"FORMAT") == 0 ) {
104 FORMAT_str = str.substr(fields[0].length(), str.length());
105 FORMAT_str_parser(FORMAT_str);
113 string seq = getData(
"SEQUENCE");
114 string firstResS = getData(
"FIRST_RESID");
116 firstResID = (firstResS.length() > 0)? atoi( firstResS.c_str() ):1;
117 if ( seq.length() > 0 )
119 for(
int i = 0; i < (
int) seq.length(); i++)
121 if ( !(seq[i]>=
'A' && seq[i]<
'Z') && seq[i]!=
'c' && seq[i]!=
'p' && seq[i]!=
'?')
continue;
122 residList[residList.size()+firstResID] = seq.substr(i,1);
132 ofstream out(fileName.c_str(), ios::trunc);
135 tr.Error <<
"\tCan't save file " << fileName.c_str() << endl;
143 for(
int i = 0; i < (
int)REMARKS.size(); i++) {
144 out <<
"REMARK " << REMARKS[i] << endl;
148 for(
int i = 0; i < (
int)DATA.size(); i++) {
149 int pos = DATA[i].find_first_of(
' ');
150 string name = DATA[i].substr(0,pos);
152 if ( name ==
"SEQUENCE" ) {
154 int len = seq.length();
155 if (len <= 0)
continue;
157 for(
int i = 0; i<= len/55; i++) {
158 string temp = seq.substr(i*55, 55);
159 out <<
"DATA SEQUENCE " << temp.c_str() << endl;
161 }
else out <<
"DATA " << DATA[i] << endl;
165 boost::unordered_map<int, string>::iterator iterR;
167 for ( iterR = VARS.begin(); iterR != VARS.end(); iterR++ )
168 out << iterR->second.c_str() <<
" ";
172 for ( iterR = FORMAT.begin(); iterR != FORMAT.end(); iterR++ )
173 out << iterR->second.c_str();
178 boost::unordered_map< int, boost::unordered_map<string, string> >::iterator it;
182 for(
int i = 0; i < (
int) VARS.size(); i++) {
183 if (
contains(FORMAT[i],
's') == 1) {
184 sprintf(buf, FORMAT[i].c_str(), ent[ VARS[i] ].c_str() ) ;
186 }
else if (
contains(FORMAT[i],
'd') == 1) {
187 sprintf(buf, FORMAT[i].c_str(), atoi(ent[ VARS[i] ].c_str() )) ;
189 }
else if (
contains(FORMAT[i],
'f') == 1) {
190 sprintf(buf, FORMAT[i].c_str(), atof(ent[ VARS[i] ].c_str() )) ;
213 boost::unordered_map< int, boost::unordered_map<string, string> >::iterator it;
217 if ( ent[VName] == VVal ) count++;
219 if ( count == index && index > 0 )
return ent;
234 boost::unordered_map< int, boost::unordered_map<string, string> >::iterator it;
239 if ( ent[VName1] == VVal1 && ent[VName2] == VVal2 ) count++;
241 if ( count == index && index > 0 )
return ent;
253 return residList[rNum];
268 const string & VarName,
269 const string & VarVal
271 boost::unordered_map<int, string>::iterator it_V;
273 for( it_V = VARS.begin(); it_V != VARS.end(); it_V++ )
274 if ( it_V->second == VarName )
break;
276 if ( it_V != VARS.end() ) {
277 (
Entries[ index ])[VarName.c_str()] = VarVal.c_str();
279 string const msg(
"\tInvalid variable name '" + VarName +
"'\n" );
282 utility_exit_with_message(msg);
291 setEntry(
Entries.size()+1, VarName, VarVal);
297 void GDB::addVAR(
const string &VAR_Name,
const string &FORMAT_Name)
299 int size = VARS.size();
301 if ( !checkFormat(FORMAT_Name) )
302 tr.Error <<
"\tBad format syntax '" << FORMAT_Name <<
"'" << endl;
303 else if (
contains(VAR_Name,
' ') > 0)
304 tr.Error <<
"\tInvalid varible name '" << VAR_Name <<
"' (with space)" << endl;
309 FORMAT[0] = FORMAT_Name;
314 for(i=0; i<
size; i++)
315 if (VARS[i] == VAR_Name)
break;
318 FORMAT[i] = FORMAT_Name;
329 void GDB::setVAR(
int index,
const string &VAR_Name,
const string &FORMAT_Name)
331 int size = VARS.size();
333 if ( !checkFormat(FORMAT_Name) )
334 tr.Error <<
"\tBad format syntax '" << FORMAT_Name <<
"'" << endl;
335 else if (
contains(VAR_Name,
' ') > 0)
336 tr.Error <<
"\tInvalid varible name '" << VAR_Name <<
"' (with space)" << endl;
338 if (index > size+1 || index < 1)
339 tr.Error <<
"\tPlease use number 1-" << size+1 <<
" as index for varible '" << VAR_Name <<
"' with format '" << FORMAT_Name <<
"'" << endl ;
341 VARS[index-1] = VAR_Name;
342 FORMAT[index-1] = FORMAT_Name;
343 if (index == size+1) VarsNumber++;
353 REMARKS.push_back(str);
360 DATA.push_back( DataName+
" "+DataVal );
369 for(
int i = 0; i < (
int) DATA.size(); i++)
371 int pos = DATA[i].find_first_of(
' ');
373 if (DATA[i].substr(0,pos) == DataName )
374 data = data+ DATA[i].substr( pos+1,DATA[i].length()-pos-1 );
384 if (
contains(FORMAT[index],
'f') == 1)
return true;
393 boost::unordered_map<int, string>::iterator it_V;
395 for( it_V = VARS.begin(); it_V != VARS.end(); it_V++ )
397 if ( it_V->second == VarName )
return isVarFloat(it_V->first);
407 if (
contains(FORMAT[index],
'd') == 1)
return true;
416 boost::unordered_map<int, string>::iterator it_V;
418 for( it_V = VARS.begin(); it_V != VARS.end(); it_V++ )
420 if ( it_V->second == VarName )
return isVarInt(it_V->first);
430 if (
contains(FORMAT[index],
's') == 1)
return true;
439 boost::unordered_map<int, string>::iterator it_V;
441 for( it_V = VARS.begin(); it_V != VARS.end(); it_V++ )
443 if ( it_V->second == VarName )
return isVarString(it_V->first);
455 int last = str.length()-1;
457 if (
contains(str,
'%') != 1 || str[0] !=
'%')
return false;
459 if ( str[last] !=
's' && str[last] !=
'd' && str[last] !=
'f' )
return false;
461 for(
int i=0; i< (
int)str.length();i++)
463 if ( str[i] !=
'%' && str[i] !=
's' && str[i] !=
'd' && str[i] !=
'f' && str[i] !=
'-' && str[i] !=
'.' && !
isDigit(str[i]) )
465 else if ( (str[i] ==
's' || str[i] ==
'd' || str[i] ==
'f') && i != last)
480 VarsNumber = V_Fields.size();
482 for(
int i = 0; i < VarsNumber; i++)
483 VARS[i] = V_Fields[i];
496 if (
contains(temp,
'%') == VarsNumber) {
497 for(
int i = 0; i < VarsNumber; i++) {
498 string f_str =
"%" + (
string)
section(temp,
'%',buf,i+1, i+1);
500 if ( checkFormat(f_str) )
503 tr.Error <<
"\tBad format syntax '" << f_str <<
"'" << endl;
514 if (ClassName ==
"TALOS_SHIFT" ){
515 ClassType =
"TALOS_SHIFT";
517 VARS_str_parser(
"RESID RESNAME ATOMNAME SHIFT");
518 FORMAT_str_parser(
"%4d %1s %4s %8.3f");
520 else if (ClassName ==
"TALOS_PRED" ){
521 ClassType =
"TALOS_PRED";
523 VARS_str_parser(
"INDEX PHI PSI DIST W R1 R2 R3 SOURCE");
524 FORMAT_str_parser(
"%2d %9.3f %9.3f %8.3f %5.3f %-4s %-4s %-4s %s");