int CobraToFbcConverter::convert() { int result = LIBSBML_OPERATION_FAILED; if (mDocument == NULL) { return LIBSBML_INVALID_OBJECT; } Model* mModel = mDocument->getModel(); if (mModel == NULL) { return LIBSBML_INVALID_OBJECT; } FbcModelPlugin *plugin = (FbcModelPlugin*)(mDocument->getModel()->getPlugin("fbc")); // if we have a fbc model we are done already if (plugin != NULL || mDocument->getLevel() == 3) { return LIBSBML_OPERATION_SUCCESS; } std::map<const string, int> chargeMap; std::map<const string, string> formulaMap; Model* model = mDocument->getModel(); for (unsigned int i = 0; i < model->getNumSpecies();++i) { Species* current = model->getSpecies(i); bool haveCharge = current->isSetCharge(); if (haveCharge) { chargeMap[current->getId()] = current->getCharge(); // need to unset the charge here, as it the call will // not work once this is an L3 model current->unsetCharge(); } if (current->isSetNotes()) { string originalNotes = current->getNotesString(); string notes(originalNotes); std::transform(notes.begin(), notes.end(), notes.begin(), ::toupper); size_t pos = notes.find("FORMULA:"); if (pos != string::npos) { size_t end = notes.find("</", pos+9); if (end != string::npos) { string formula = originalNotes.substr(pos + 9, end-(pos+9)); if (formula[0] != '<' && formula[0] != '/' ) { size_t pos = formula.find_first_not_of(" \n\t\r"); if (pos != std::string::npos) formulaMap[current->getId()] = formula; } } } // added chemical formula if present pos = notes.find("CHARGE:"); if (pos != string::npos && !haveCharge) { size_t end = notes.find("</", pos+8); if (end != string::npos) { string formula = originalNotes.substr(pos + 8, end-(pos+8)); if (formula[0] != '<' && formula[0] != '/' ) { size_t pos = formula.find_first_not_of(" \n\t\r"); if (pos != std::string::npos) { int charge; stringstream str; str << formula; str >> charge; if (charge != 0) chargeMap[current->getId()] = charge; } }