bool CReactionInterface::loadMappingAndValues(const CReaction & rea) { bool success = true; std::vector< std::vector<std::string> >::const_iterator it; std::vector< std::vector<std::string> >::const_iterator iEnd; std::vector<std::string>::const_iterator jt; std::vector<std::string>::const_iterator jEnd; size_t i; std::string metabName; const CModelEntity* pObj; std::vector<std::string> SubList; SubList.resize(1); SubList[0] = "unknown"; mNameMap.resize(size()); for (i = 0; i != size(); ++i) { mNameMap[i] = SubList; } mValues.resize(size(), 0.1); mIsLocal.resize(size(), false); it = rea.getParameterMappings().begin(); iEnd = rea.getParameterMappings().end(); for (i = 0; it != iEnd; ++it, ++i) { if (isVector(i)) { assert((getUsage(i) == CFunctionParameter::SUBSTRATE) || (getUsage(i) == CFunctionParameter::PRODUCT) || (getUsage(i) == CFunctionParameter::MODIFIER)); SubList.clear(); for (jt = it->begin(), jEnd = it->end(); jt != jEnd; ++jt) { metabName = CMetabNameInterface::getDisplayName(mpModel, *jt, true); assert(metabName != ""); SubList.push_back(metabName); } } else { assert(it->size() == 1); SubList.resize(1); SubList[0] = "unknown"; switch (getUsage(i)) { case CFunctionParameter::SUBSTRATE: case CFunctionParameter::PRODUCT: case CFunctionParameter::MODIFIER: metabName = CMetabNameInterface::getDisplayName(mpModel, *(it->begin()), true); // assert(metabName != ""); SubList[0] = metabName; //TODO: check if the metabolite is in the chemical equation with the correct rule break; case CFunctionParameter::VOLUME: pObj = dynamic_cast<const CCompartment*>(CCopasiRootContainer::getKeyFactory()->get(*(it->begin()))); assert(pObj); SubList[0] = pObj->getObjectName(); break; case CFunctionParameter::TIME: pObj = dynamic_cast<const CModel*>(CCopasiRootContainer::getKeyFactory()->get(*(it->begin()))); assert(pObj); SubList[0] = pObj->getObjectName(); break; case CFunctionParameter::PARAMETER: { const CCopasiParameter * pParameter = rea.getParameters().getParameter(getParameterName(i)); if (pParameter != NULL) { mValues[i] = * pParameter->getValue().pDOUBLE; } else { mValues[i] = std::numeric_limits< C_FLOAT64 >::quiet_NaN(); } mIsLocal[i] = rea.isLocalParameter(i); if (!mIsLocal[i]) { pObj = dynamic_cast<const CModelValue*>(CCopasiRootContainer::getKeyFactory()->get(*(it->begin()))); if (pObj) { SubList[0] = pObj->getObjectName(); mValues[i] = pObj->getInitialValue(); } } } break; default: break; } } mNameMap[i] = SubList; } return success; }
bool CODEExporterC::exportTitleData(const CModel* copasiModel, std::ostream & os) { size_t metab_size = copasiModel->getMetabolitesX().size(); size_t indep_size = copasiModel->getNumIndependentReactionMetabs(); size_t ode_size = copasiModel->getNumODEMetabs(); size_t comps_size = copasiModel->getCompartments().size(); size_t modvals_size = copasiModel->getModelValues().size(); size_t reacs_size = copasiModel->getReactions().size(); size_t i, j, num_params, count; const CCopasiVector< CReaction > & reacs = copasiModel->getReactions(); CReaction* reac; count = 0; for (i = 0; i < reacs_size; ++i) { reac = reacs[i]; num_params = reac->getParameters().size(); for (j = 0; j < num_params; ++j) { if (reac->isLocalParameter(j)) ++count; } } size_t numX = 0; size_t numY = 0; size_t numXC = 0; size_t numYC = 0; size_t numPC = 0; size_t numP = 0; size_t numDX = 0; size_t numCT = 0; std::ostringstream p_names; p_names << "const char* p_names[] = {"; std::ostringstream x_names; x_names << "const char* x_names[] = {"; std::ostringstream y_names; y_names << "const char* y_names[] = {"; std::ostringstream xc_names; xc_names << "const char* xc_names[] = {"; std::ostringstream pc_names; pc_names << "const char* pc_names[] = {"; std::ostringstream yc_names; yc_names << "const char* yc_names[] = {"; std::ostringstream dx_names; dx_names << "const char* dx_names[] = {"; std::ostringstream ct_names; ct_names << "const char* ct_names[] = {"; CKeyFactory* kf = CCopasiRootContainer::getKeyFactory(); std::map< std::string, std::string >::const_iterator it = NameMap.begin(); std::map< std::string, std::string > reverse_map; while (it != NameMap.end()) { const std::string& abbrev = it->second; const std::string& key = it->first; if (startsWith(abbrev, "p[")) { reverse_map[abbrev] = key; ++numP; } else if (startsWith(abbrev, "x[")) { reverse_map[abbrev] = key; ++numX; } else if (startsWith(abbrev, "y[")) { reverse_map[abbrev] = key; ++numY; } else if (startsWith(abbrev, "dx[")) { reverse_map[abbrev] = key; ++numDX; } else if (startsWith(abbrev, "ct[")) { reverse_map[abbrev] = key; ++numCT; } else if (startsWith(abbrev, "x_c[")) { CCopasiObject* obj = kf->get(key); if (obj != NULL) { reverse_map[abbrev] = obj->getObjectName(); } else { reverse_map[abbrev] = key; } ++numXC; } else if (startsWith(abbrev, "p_c[")) { CCopasiObject* obj = kf->get(key); if (obj != NULL) { reverse_map[abbrev] = obj->getObjectName(); } else { reverse_map[abbrev] = key; } ++numPC; } else if (startsWith(abbrev, "y_c[")) { CCopasiObject* obj = kf->get(key); if (obj != NULL) { reverse_map[abbrev] = obj->getObjectName(); } else { reverse_map[abbrev] = key; } ++numYC; } ++it; } for (size_t i = 0; i < numP; ++i) { std::stringstream str; str << "p[" << i << "]"; printNameForKey(p_names, kf, reverse_map[str.str()]); } for (size_t i = 0; i < numX; ++i) { std::stringstream str; str << "x[" << i << "]"; printNameForKey(x_names, kf, reverse_map[str.str()]); } for (size_t i = 0; i < numY; ++i) { std::stringstream str; str << "y[" << i << "]"; printNameForKey(y_names, kf, reverse_map[str.str()]); } for (size_t i = 0; i < numDX; ++i) { std::stringstream str; str << "dx[" << i << "]"; printNameForKey(dx_names, kf, reverse_map[str.str()]); } for (size_t i = 0; i < numCT; ++i) { std::stringstream str; str << "ct[" << i << "]"; printNameForKey(ct_names, kf, reverse_map[str.str()]); } for (size_t i = 0; i < numXC; ++i) { std::stringstream str; str << "x_c[" << i << "]"; xc_names << "\"" << reverse_map[str.str()] << "\", "; } for (size_t i = 0; i < numPC; ++i) { std::stringstream str; str << "p_c[" << i << "]"; pc_names << "\"" << reverse_map[str.str()] << "\", "; } for (size_t i = 0; i < numYC; ++i) { std::stringstream str; str << "y_c[" << i << "]"; yc_names << "\"" << reverse_map[str.str()] << "\", "; } os << "#ifdef SIZE_DEFINITIONS" << std::endl; os << "#define N_METABS " << metab_size << std::endl; os << "#define N_ODE_METABS " << ode_size << std::endl; os << "#define N_INDEP_METABS " << indep_size << std::endl; os << "#define N_COMPARTMENTS " << comps_size << std::endl; os << "#define N_GLOBAL_PARAMS " << modvals_size << std::endl; os << "#define N_KIN_PARAMS " << count << std::endl; os << "#define N_REACTIONS " << reacs_size << std::endl << std::endl; os << "#define N_ARRAY_SIZE_P " << numP << "\t// number of parameters" << std::endl; os << "#define N_ARRAY_SIZE_X " << numX << "\t// number of initials" << std::endl; os << "#define N_ARRAY_SIZE_Y " << numY << "\t// number of assigned elements" << std::endl; os << "#define N_ARRAY_SIZE_XC " << numXC << "\t// number of x concentration" << std::endl; os << "#define N_ARRAY_SIZE_PC " << numPC << "\t// number of p concentration" << std::endl; os << "#define N_ARRAY_SIZE_YC " << numYC << "\t// number of y concentration" << std::endl; os << "#define N_ARRAY_SIZE_DX " << numDX << "\t// number of ODEs " << std::endl; os << "#define N_ARRAY_SIZE_CT " << numCT << "\t// number of conserved totals" << std::endl << std::endl; os << "#endif // SIZE_DEFINITIONS" << std::endl; os << std::endl; os << "#ifdef TIME" << std::endl; os << "#define T <set here a user name for the time variable> " << std::endl; os << "#endif // TIME" << std::endl; os << std::endl; os << "#ifdef NAME_ARRAYS" << std::endl; os << p_names.str() << " \"\" };" << std::endl; os << x_names.str() << " \"\" };" << std::endl; os << y_names.str() << " \"\" };" << std::endl; os << xc_names.str() << " \"\" };" << std::endl; os << pc_names.str() << " \"\" };" << std::endl; os << yc_names.str() << " \"\" };" << std::endl; os << dx_names.str() << " \"\" };" << std::endl; os << ct_names.str() << " \"\" };" << std::endl; os << "#endif // NAME_ARRAYS" << std::endl; return true; }