std::vector<std::string> StringBuilder::tokenise( const std::string &_delimiters ) const { std::vector<std::string> parts; size_t i; size_t j = 0; size_t x = 0; StringBuilder sub; while( SIZE_T_FAIL != (i = XthOf(x++,_delimiters) ) ) { sub.setTo(*this,j,i-j); j = i; sub.Trim(_delimiters); if( sub.size() > 0 ) { parts.push_back(sub.toString()); } } if( j != m_pos ) { sub.setTo(*this,j,m_pos-j); sub.Trim(_delimiters); if( sub.size() > 0 ) { parts.push_back(sub.toString()); } } return parts; }
void RotLibConvert_Dunbrack_BBInd::readLib( const std::string& _LibraryFilename, RotamerLibrary& _RotLib ) { StringBuilder sb; std::ifstream* p_torsionFile; try { if( _RotLib.isFinalised() ) throw ProcedureException("readLib() is not allowed, the rotamer library has been finalised, no further import can occur"); // Mappings for things like HIS -> HIE HID HIP _RotLib.addIonisationAliasWorkingDefaults(); // Make sure Alanine and Glycine are defined non-rotamer residues (the library itself ignores them) _RotLib.addAsBlankRotamer("ALA"); _RotLib.addAsBlankRotamer("GLY"); p_torsionFile = new std::ifstream(_LibraryFilename.c_str(), std::ifstream::in); std::ifstream& torsionFile = *p_torsionFile; if( !torsionFile.is_open() ) throw(IOException( "Dunbrack BB-independent torsional definition file not found: '" + _LibraryFilename + "'!" )); sb << torsionFile; ASSERT( sb.size() >= 36 && sb.compare("Backbone-independent rotamer library",0,36,0,false), ParseException, "The input coordinate file does not appear to be in Dunbrack BB-independent format"); const char* initLine = "Res Rotamer n(r1) n(r1234) p(r1234) sig p(r234|r1) sig chi1 sig chi2 sig chi3 sig chi4 sig"; int initLineLength = strlen(initLine); bool begun = false; while( sb << torsionFile ) { if( sb.size() >= initLineLength && sb.compare( initLine, 0, initLineLength, 0 ) ) { begun = true; break; } } ASSERT(begun,ParseException,"Unexpected EOF whilst parsing the Dunbrack BB-independent format library"); sb << torsionFile; // Two blanking lines are present here sb << torsionFile; // So eradicate them - mwa ha ha ha! while( sb << torsionFile ) { sb.Trim(); if( sb.size() == 0 ) continue; readDefinition( sb, _RotLib ); } // Ensure file-handle cleanup p_torsionFile->close(); delete p_torsionFile; } catch( ExceptionBase ex ) { // Ensure file-handle cleanup p_torsionFile->close(); delete p_torsionFile; throw ex; } }
void RotLibConvert_Dunbrack_BBDep::readLib( const std::string& _LibraryFilename, RotamerLibrary& _RotLib ) { StringBuilder sb; std::ifstream* p_torsionFile; try { if( _RotLib.isFinalised() ) throw ProcedureException("readLib() is not allowed, the rotamer library has been finalised, no further import can occur"); // Mappings for things like HIS -> HIE HID HIP _RotLib.addIonisationAliasWorkingDefaults(); // Make sure Alanine and Glycine are defined non-rotamer residues (the library itself ignores them) _RotLib.addAsBlankRotamer("ALA"); _RotLib.addAsBlankRotamer("GLY"); p_torsionFile = new std::ifstream(_LibraryFilename.c_str(), std::ifstream::in); std::ifstream& torsionFile = *p_torsionFile; if( !torsionFile.is_open() ) throw(IOException( "Dunbrack BB-independent torsional definition file not found: '" + _LibraryFilename + "'!" )); ParseData pd; ContainerType data; StringBuilder prevResName(3); StringBuilder currResName(4); StringBuilder cacheLine; while( true ) { if( cacheLine.size() > 0 ) { sb.setTo(cacheLine); cacheLine.clear(); } else if( !(sb << torsionFile) ) { break; } sb.Trim(); if( sb.size() == 0 ) continue; // blank line currResName.setTo(sb,0,3); if( prevResName.size() == 0 ) { prevResName.setTo( currResName ); ASSERT( pd.parse( sb ), ParseException, "Malformed line"); data.push_back( pd ); } else if( prevResName.compare( currResName, 0, 3, 0 ) ) { // Woooo - we found one :-D ASSERT( pd.parse( sb ), ParseException, "Malformed line"); data.push_back( pd ); } else { if( data.size() > 0 ) { processResData( prevResName.toString(), data, _RotLib, switchImportMode ); ASSERT( data.size() == 0, CodeException, "CodeFail"); } prevResName.setTo( currResName ); cacheLine.setTo( sb ); // we havent actually processed the current line! Store it. } } if( data.size() > 0 ) { processResData( prevResName.toString(), data, _RotLib, switchImportMode ); ASSERT( data.size() == 0, CodeException, "CodeFail"); } // Ensure file-handle cleanup p_torsionFile->close(); delete p_torsionFile; } catch( ExceptionBase ex ) { // Ensure file-handle cleanup p_torsionFile->close(); delete p_torsionFile; throw ex; } }