bool CQModelValue::enterProtected() { mpModelValue = NULL; if (mObjectCNToCopy != "") { CObjectInterface::ContainerList List; List.push_back(mpDataModel); // This will check the current data model and the root container for the object; mpModelValue = dynamic_cast<CModelValue *>(const_cast< CDataObject * >(CObjectInterface::DataObject(CObjectInterface::GetObjectFromCN(List, mObjectCNToCopy)))); mObjectCNToCopy.clear(); } else { mpModelValue = dynamic_cast<CModelValue *>(mpObject); } if (!mpModelValue) { mpListView->switchToOtherWidget(ListViews::WidgetType::GlobalQuantities, std::string()); return false; } load(); mpModelValue = dynamic_cast<CModelValue *>(mpObject); return true; }
// virtual bool CMoietiesTask::process(const bool & /* useInitialValues */) { bool success = true; output(COutputInterface::BEFORE); success = static_cast< CMoietiesMethod * >(mpMethod)->process(); // The call to process may modify some object pointers. We therefore // have to recompile the output. if (mpOutputHandler != NULL) { CObjectInterface::ContainerList ListOfContainer; ListOfContainer.push_back(this); ListOfContainer.push_back(mpContainer); size_t Size = CCopasiMessage::size(); mpOutputHandler->compile(ListOfContainer); // Remove error messages created by setExpression as this may fail // due to incomplete model specification at this time. while (CCopasiMessage::size() > Size) CCopasiMessage::getLastMessage(); } output(COutputInterface::DURING); output(COutputInterface::AFTER); return success; }
C_FLOAT64 CExperimentObjectMap::CDataColumn::getDefaultScale() const { if (mpObjectCN == NULL) return std::numeric_limits<C_FLOAT64>::quiet_NaN(); CCopasiParameterGroup *pGroup = dynamic_cast< CCopasiParameterGroup * >(getObjectParent()); if (pGroup == NULL) return std::numeric_limits<C_FLOAT64>::quiet_NaN(); const CExperiment *pExperiment = dynamic_cast<const CExperiment * >(pGroup->getObjectParent()); if (pExperiment == NULL) return std::numeric_limits<C_FLOAT64>::quiet_NaN(); CObjectInterface::ContainerList ListOfContainer; ListOfContainer.push_back(getObjectDataModel()); const CCopasiObject * pObject = CObjectInterface::DataObject(CObjectInterface::GetObjectFromCN(ListOfContainer, *mpObjectCN)); if (pObject == NULL) return std::numeric_limits<C_FLOAT64>::quiet_NaN(); return pExperiment->getDefaultScale(pObject); }
bool CEvent::setPriorityExpressionPtr(CExpression* pExpression) { if (pExpression == mpPriorityExpression) return true; if (pExpression == NULL) return false; if (mpModel != NULL) { mpModel->setCompileFlag(true); } CExpression * pOld = mpPriorityExpression; mpPriorityExpression = pExpression; mpPriorityExpression->setObjectName("PriorityExpression"); add(mpPriorityExpression, true); CObjectInterface::ContainerList listOfContainer; listOfContainer.push_back(mpModel); if (mpPriorityExpression->compile(listOfContainer)) { pdelete(pOld); return true; } // If compile fails we do not take ownership // and we remove the object from the container remove(mpPriorityExpression); mpPriorityExpression->setObjectParent(NULL); mpPriorityExpression = pOld; return false; }
void test000052::test_bug988() { CDataModel* pDataModel = pCOPASIDATAMODEL; CPPUNIT_ASSERT(pDataModel->importSBMLFromString(MODEL_STRING)); CModel* pModel = pDataModel->getModel(); CPPUNIT_ASSERT(pModel != NULL); CPPUNIT_ASSERT(pModel->getQuantityUnitEnum() == CUnit::mMol); CPPUNIT_ASSERT(pModel->getVolumeUnitEnum() == CUnit::ml); CPPUNIT_ASSERT(pModel->getTimeUnitEnum() == CUnit::s); CPPUNIT_ASSERT(pModel->getCompartments().size() == 1); const CCompartment* pCompartment = pModel->getCompartments()[0]; CPPUNIT_ASSERT(pCompartment != NULL); CPPUNIT_ASSERT(pCompartment->getStatus() == CModelEntity::Status::FIXED); CPPUNIT_ASSERT(pModel->getMetabolites().size() == 1); CMetab* pA = pModel->getMetabolites()[0]; CPPUNIT_ASSERT(pA != NULL); CPPUNIT_ASSERT(pA->getStatus() == CModelEntity::Status::ASSIGNMENT); const CExpression* pExpr = pA->getExpressionPtr(); // check the expression const CEvaluationNode* pNode = pExpr->getRoot(); CPPUNIT_ASSERT(pNode != NULL); const CEvaluationNodeChoice* pChoiceNode = dynamic_cast<const CEvaluationNodeChoice*>(pNode); CPPUNIT_ASSERT(pChoiceNode != NULL); pNode = dynamic_cast<const CEvaluationNode*>(pChoiceNode->getChild()); CPPUNIT_ASSERT(pNode != NULL); const CEvaluationNodeLogical* pLogicalNode = dynamic_cast<const CEvaluationNodeLogical*>(pNode); CPPUNIT_ASSERT(pLogicalNode != NULL); CPPUNIT_ASSERT((pLogicalNode->subType()) == CEvaluationNode::SubType::LT); const CEvaluationNodeObject* pObjectNode = dynamic_cast<const CEvaluationNodeObject*>(pLogicalNode->getChild()); CPPUNIT_ASSERT(pObjectNode != NULL); CCommonName objectCN = pObjectNode->getObjectCN(); CPPUNIT_ASSERT(!objectCN.empty()); CObjectInterface::ContainerList listOfContainers; listOfContainers.push_back(pModel); const CDataObject* pObject = CObjectInterface::DataModel(pCOPASIDATAMODEL->getObjectFromCN(listOfContainers, objectCN)); CPPUNIT_ASSERT(pObject != NULL); CPPUNIT_ASSERT(pObject->hasFlag(CDataObject::Reference) == true); CPPUNIT_ASSERT(pObject->getObjectName() == std::string("Time")); CPPUNIT_ASSERT(pObject->getObjectParent() == pModel); const CEvaluationNodeNumber* pNumberNode = dynamic_cast<const CEvaluationNodeNumber*>(pObjectNode->getSibling()); CPPUNIT_ASSERT(pNumberNode != NULL); CPPUNIT_ASSERT((pNumberNode->subType()) == CEvaluationNode::SubType::DOUBLE); CPPUNIT_ASSERT(fabs((pNumberNode->getValue() - 5.0) / 5.0) < 1e-3); pNumberNode = dynamic_cast<const CEvaluationNodeNumber*>(pLogicalNode->getSibling()); CPPUNIT_ASSERT(pNumberNode != NULL); CPPUNIT_ASSERT((pNumberNode->subType()) == CEvaluationNode::SubType::DOUBLE); CPPUNIT_ASSERT(pNumberNode->getValue() < 1e-3); pNumberNode = dynamic_cast<const CEvaluationNodeNumber*>(pNumberNode->getSibling()); CPPUNIT_ASSERT(pNumberNode != NULL); CPPUNIT_ASSERT((pNumberNode->subType()) == CEvaluationNode::SubType::DOUBLE); CPPUNIT_ASSERT(fabs((pNumberNode->getValue() - 10.0) / 10.0) < 1e-3); CPPUNIT_ASSERT(pModel->getModelValues().size() == 0); CPPUNIT_ASSERT(pModel->getReactions().size() == 0); }
bool CMetab::compileInitialValueDependencies() { bool success = true; std::set<const CCopasiObject *> Dependencies; CObjectInterface::ContainerList listOfContainer; listOfContainer.push_back(getObjectAncestor("Model")); // If we have an assignment or a valid initial expression we must update both if (getStatus() == ASSIGNMENT || (mpInitialExpression != NULL && mpInitialExpression->getInfix() != "")) { // Initial concentration success &= mpInitialExpression->compile(listOfContainer); mpIConcReference->setDirectDependencies(mpInitialExpression->getDirectDependencies()); // Initial particle number Dependencies.insert(mpIConcReference); if (mpCompartment) Dependencies.insert(mpCompartment->getInitialValueReference()); mpIValueReference->setDirectDependencies(Dependencies); Dependencies.clear(); // If we have a valid initial expression, we update the initial value. // In case the expression is constant this suffices others are updated lated again. if (mpInitialExpression->isUsable()) mIConc = mpInitialExpression->calcValue(); return success; } // The context sensitivity is handle in the virtual method getDirectDependencies(); // Initial particle number Dependencies.insert(mpIConcReference); if (mpCompartment) Dependencies.insert(mpCompartment->getInitialValueReference()); mpIValueReference->setDirectDependencies(Dependencies); Dependencies.clear(); // Initial concentration Dependencies.insert(mpIValueReference); if (mpCompartment) Dependencies.insert(mpCompartment->getInitialValueReference()); mpIConcReference->setDirectDependencies(Dependencies); return success; }
void CQParameterGroupView::modifySelectCNs(CCopasiParameterGroup & group, const CCopasiParameter & cnTemplate) { // OpenSelectionDialog std::vector< const CDataObject * > Selection; CObjectInterface::ContainerList ContainerList; ContainerList.push_back(group.getObjectDataModel()); // Create the current selection CCopasiParameterGroup::elements::iterator it = group.beginIndex(); CCopasiParameterGroup::elements::iterator end = group.endIndex(); for (; it != end; ++it) { const CDataObject * pObject = CObjectInterface::DataObject(CObjectInterface::GetObjectFromCN(ContainerList, (*it)->getValue< CCommonName >())); if (pObject != NULL) { Selection.push_back(pObject); } } CModel * pModel = group.getObjectDataModel()->getModel(); std::vector<const CDataObject * > ValidObjects; const std::vector< std::pair < CCommonName, CCommonName > > & ValidValues = cnTemplate.getValidValues< CCommonName >(); std::vector< std::pair < CCommonName, CCommonName > >::const_iterator itValidValues = ValidValues.begin(); std::vector< std::pair < CCommonName, CCommonName > >::const_iterator endValidValues = ValidValues.end(); for (; itValidValues != endValidValues; ++itValidValues) { CObjectLists::ListType ListType = toEnum(itValidValues->first, CObjectLists::ListTypeName, CObjectLists::EMPTY_LIST); std::vector<const CDataObject * > Tmp = CObjectLists::getListOfConstObjects(ListType, pModel); ValidObjects.insert(ValidObjects.end(), Tmp.begin(), Tmp.end()); } std::vector< const CDataObject * > NewSelection = CCopasiSelectionDialog::getObjectVector(this, ValidObjects, &Selection); // Modify group parameters; mpParameterGroupDM->beginResetModel(); group.clear(); std::vector< const CDataObject * >::const_iterator itNew = NewSelection.begin(); std::vector< const CDataObject * >::const_iterator endNew = NewSelection.end(); for (; itNew != endNew; ++itNew) { group.addParameter("Reaction", CCopasiParameter::Type::CN, (*itNew)->getCN()); } mpParameterGroupDM->endResetModel(); }
bool CopasiWidget::update(ListViews::ObjectType objectType, ListViews::Action action, const CCommonName & cn) { // Assure that the object still exists CObjectInterface::ContainerList List; List.push_back(mpDataModel); // This will check the current data model and the root container for the object; mpObject = const_cast< CDataObject * >(CObjectInterface::DataObject(CObjectInterface::GetObjectFromCN(List, mObjectCN))); bool success = updateProtected(objectType, action, cn != mOldCN ? cn : mObjectCN); mOldCN = mObjectCN; return success; }
// virtual void CModelParameterReactionParameter::compile() { CModelParameter::compile(); mGlobalQuantityCN = std::string(); std::string Infix = getInitialExpression(); if (Infix.length() > 2) { // Infix: <CN,Reference=InitialValue> or <CN,Reference=Value> CCopasiObjectName Tmp = Infix.substr(1, Infix.length() - 2); std::string Separator = ""; for (; Tmp != ""; Tmp = Tmp.getRemainder()) { CCopasiObjectName Primary = Tmp.getPrimary(); if (Primary.getObjectType() == "Reference") { break; } mGlobalQuantityCN += Separator + Primary; Separator = ","; } setSimulationType(CModelEntity::ASSIGNMENT); } else { setSimulationType(CModelEntity::FIXED); } mpGlobalQuantity = this->getSet()->getModelParameter(mGlobalQuantityCN); if (mpGlobalQuantity != NULL) { mValue = mpGlobalQuantity->getValue(ParticleNumbers); } CObjectInterface::ContainerList ListOfContainer; CModel * pModel = getModel(); ListOfContainer.push_back(pModel); mpReaction = static_cast< CReaction * >(const_cast< CCopasiObject * >(CObjectInterface::DataObject(CObjectInterface::GetObjectFromCN(ListOfContainer, mpParent->getCN())))); }
bool CMathObject::setExpression(const std::string & infix, const bool & isBoolean, CMathContainer & container) { bool success = true; CExpression Expression; Expression.setIsBoolean(isBoolean); success &= Expression.setInfix(infix); CObjectInterface::ContainerList ListOfContainer; ListOfContainer.push_back(&container); success &= Expression.compile(ListOfContainer); success &= setExpression(Expression, container); return success; }
bool CopasiWidget::leave() { CObjectInterface::ContainerList List; List.push_back(mpDataModel); // This will check the current data model and the root container for the object; mpObject = const_cast< CDataObject * >(CObjectInterface::DataObject(CObjectInterface::GetObjectFromCN(List, mObjectCN))); if (mpObject != NULL) { bool success = leaveProtected(); mOldCN = mObjectCN; return success; } return true; }
void SliderDialog::addSlider(CSlider* pSlider) { if (mpParentWindow == NULL) return; // check if there already is a slider for this object CCopasiDataModel * pDataModel = pSlider->getObjectDataModel(); assert(pDataModel != NULL); SCopasiXMLGUI* pGUI = pDataModel->getGUI(); assert(pGUI); if (!equivalentSliderExists(pSlider)) { CObjectInterface::ContainerList listOfContainers; assert(CCopasiRootContainer::getDatamodelList()->size() > 0); listOfContainers.push_back(pDataModel->getModel()); pSlider->compile(listOfContainers); pGUI->getSliderList()->add(pSlider, true); } CopasiSlider* tmp = findCopasiSliderForCSlider(pSlider); if (!tmp) { setCurrentSlider(new CopasiSlider(pSlider, mpParentWindow->getDataModel(), mpSliderBox)); mpCurrSlider->installEventFilter(this); mpCurrSlider->setHidden(true); mpCurrSlider->updateSliderData(); // make sure the slider points to the correct object // for the currently set framework this->setCorrectSliderObject(this->mpCurrSlider); mSliderMap[mCurrentFolderId].push_back(mpCurrSlider); QBoxLayout* layout = static_cast<QBoxLayout*>(mpSliderBox->layout()); int childCount = layout->count() - 1; layout->insertWidget(childCount, mpCurrSlider); connect(mpCurrSlider, SIGNAL(valueChanged(double)), this , SLOT(sliderValueChanged())); connect(mpCurrSlider, SIGNAL(sliderReleased()), this, SLOT(sliderReleased())); connect(mpCurrSlider, SIGNAL(sliderPressed()), this, SLOT(sliderPressed())); connect(mpCurrSlider, SIGNAL(closeClicked(CopasiSlider*)), this, SLOT(removeSlider(CopasiSlider*))); connect(mpCurrSlider, SIGNAL(editClicked(CopasiSlider*)), this, SLOT(editSlider(CopasiSlider*))); mpCurrSlider->setHidden(false); mChanged = true; }
bool CopasiWidget::enter(const CCommonName & cn) { if (mpListView == NULL) { initContext(); } mObjectCN = cn; mOldCN = cn; CObjectInterface::ContainerList List; List.push_back(mpDataModel); // This will check the current data model and the root container for the object; mpObject = const_cast< CDataObject * >(CObjectInterface::DataObject(CObjectInterface::GetObjectFromCN(List, mObjectCN))); mObjectType = mpObject != NULL ? ListViews::DataObjectType.toEnum(mpObject->getObjectType(), ListViews::ObjectType::RESULT) : ListViews::ObjectType::RESULT; return enterProtected(); }
bool COutputHandler::compile(CObjectInterface::ContainerList listOfContainer) { CObjectInterface::ContainerList::const_iterator itContainer = listOfContainer.begin(); CObjectInterface::ContainerList::const_iterator endContainer = listOfContainer.end(); for (mpContainer = NULL; itContainer != endContainer && mpContainer == NULL; ++itContainer) { mpContainer = dynamic_cast< const CMathContainer * >(*itContainer); } assert(mpContainer != NULL); bool success = true; mObjects.clear(); std::set< COutputInterface *>::iterator it = mInterfaces.begin(); std::set< COutputInterface *>::iterator end = mInterfaces.end(); CObjectInterface::ObjectSet::const_iterator itObj; CObjectInterface::ObjectSet::const_iterator endObj; for (; it != end; ++it) { success &= (*it)->compile(listOfContainer); // Assure that this is the only one master. COutputHandler * pHandler = dynamic_cast< COutputHandler * >(*it); if (pHandler != NULL) pHandler->setMaster(this); // Collect the list of objects const CObjectInterface::ObjectSet & Objects = (*it)->getObjects(); for (itObj = Objects.begin(), endObj = Objects.end(); itObj != endObj; ++itObj) mObjects.insert(*itObj); } if (mpMaster == NULL) success &= compileUpdateSequence(listOfContainer); return success; }
void test000087::test_import_reaction_flux_reference_2() { try { CPPUNIT_ASSERT(pCOPASIDATAMODEL->importSBMLFromString(test000087::MODEL_STRING2)); } catch (...) { // there should not be an exception CPPUNIT_ASSERT(false); } CPPUNIT_ASSERT(pCOPASIDATAMODEL->getModel() != NULL); CPPUNIT_ASSERT(pCOPASIDATAMODEL->getModel()->getCompartments().size() == 1); CPPUNIT_ASSERT(pCOPASIDATAMODEL->getModel()->getMetabolites().size() == 2); CPPUNIT_ASSERT(pCOPASIDATAMODEL->getModel()->getModelValues().size() == 1); CPPUNIT_ASSERT(pCOPASIDATAMODEL->getModel()->getReactions().size() == 1); const CReaction* pReaction = pCOPASIDATAMODEL->getModel()->getReactions()[0]; CPPUNIT_ASSERT(pReaction != NULL); const CModelValue* pMV = pCOPASIDATAMODEL->getModel()->getModelValues()[0]; CPPUNIT_ASSERT(pMV != NULL); CPPUNIT_ASSERT(pMV->getStatus() == CModelEntity::ASSIGNMENT); const CExpression* pExpr = pMV->getExpressionPtr(); CPPUNIT_ASSERT(pExpr != NULL); const CEvaluationNode* pRoot = pExpr->getRoot(); CPPUNIT_ASSERT(pRoot != NULL); CPPUNIT_ASSERT(pRoot->mainType() == CEvaluationNode::T_OBJECT); const CEvaluationNodeObject* pObjectNode = dynamic_cast<const CEvaluationNodeObject*>(pRoot); CPPUNIT_ASSERT(pObjectNode != NULL); const CRegisteredObjectName cn = pObjectNode->getObjectCN(); CObjectInterface::ContainerList listOfContainers; listOfContainers.push_back(pCOPASIDATAMODEL->getModel()); const CCopasiObject* pObject = CObjectInterface::DataModel(pCOPASIDATAMODEL->getObjectFromCN(listOfContainers, cn)); CPPUNIT_ASSERT(pObject != NULL); CPPUNIT_ASSERT(pObject->isReference() == true); CPPUNIT_ASSERT(pObject->getObjectName() == "Flux"); CPPUNIT_ASSERT(pObject->getObjectParent() == pReaction); }
void CModelParameter::compile() { mpObject = NULL; mIsInitialExpressionValid = true; CObjectInterface::ContainerList ContainerList; ContainerList.push_back(getModel()); mpObject = const_cast< CCopasiObject * >(CObjectInterface::DataObject(CObjectInterface::GetObjectFromCN(ContainerList, mCN))); if (mpObject != NULL) { if (mType == unknown) { if (dynamic_cast< CModel * >(mpObject) != NULL) mType = Model; else if (dynamic_cast< CCompartment * >(mpObject) != NULL) mType = Compartment; else if (dynamic_cast< CMetab * >(mpObject) != NULL) mType = Species; else if (dynamic_cast< CModelValue * >(mpObject) != NULL) mType = ModelValue; else if (dynamic_cast< CCopasiParameter * >(mpObject) != NULL) mType = ReactionParameter; } } if (mpInitialExpression != NULL) { size_t Size = CCopasiMessage::size(); mIsInitialExpressionValid = mpInitialExpression->compile(); while (CCopasiMessage::size() > Size) CCopasiMessage::getLastMessage(); } }
void test000027::test_hasOnlySubstanceUnits() { CCopasiDataModel* pDataModel = pCOPASIDATAMODEL; CPPUNIT_ASSERT(pDataModel->importSBMLFromString(MODEL_STRING)); CModel* pModel = pDataModel->getModel(); CPPUNIT_ASSERT(pModel != NULL); CPPUNIT_ASSERT(pModel->getQuantityUnitEnum() == CUnit::mMol); CPPUNIT_ASSERT(pModel->getVolumeUnitEnum() == CUnit::ml); CPPUNIT_ASSERT(pModel->getTimeUnitEnum() == CUnit::s); CPPUNIT_ASSERT(pModel->getCompartments().size() == 1); const CCompartment* pCompartment = pModel->getCompartments()[0]; CPPUNIT_ASSERT(pCompartment != NULL); CPPUNIT_ASSERT(pCompartment->getStatus() == CModelEntity::FIXED); CPPUNIT_ASSERT(pModel->getMetabolites().size() == 2); CMetab* pA = pModel->getMetabolites()[0]; CPPUNIT_ASSERT(pA != NULL); CPPUNIT_ASSERT(pA->getStatus() == CModelEntity::REACTIONS); const CMetab* pB = pModel->getMetabolites()[1]; CPPUNIT_ASSERT(pB != NULL); CPPUNIT_ASSERT(pB->getStatus() == CModelEntity::REACTIONS); CPPUNIT_ASSERT(pModel->getModelValues().size() == 2); // check the kinetic law const CModelValue* pFactor = pModel->getModelValues()[1]; CPPUNIT_ASSERT(pFactor != NULL); CPPUNIT_ASSERT(pFactor->getStatus() == CModelEntity::FIXED); CPPUNIT_ASSERT(fabs((pFactor->getInitialValue() - pModel->getQuantity2NumberFactor()) / pModel->getQuantity2NumberFactor()) < 1e-3); const CModelValue* pModelValue = pModel->getModelValues()[0]; CPPUNIT_ASSERT(pModelValue != NULL); CPPUNIT_ASSERT(pModelValue->getStatus() == CModelEntity::ASSIGNMENT); const CExpression* pExpr = pModelValue->getExpressionPtr(); // check the expression const CEvaluationNode* pNode = pExpr->getRoot(); CPPUNIT_ASSERT(pNode != NULL); const CEvaluationNodeObject* pObjectNode = dynamic_cast<const CEvaluationNodeObject*>(pNode); CPPUNIT_ASSERT(pObjectNode != NULL); CCopasiObjectName objectCN = pObjectNode->getObjectCN(); CPPUNIT_ASSERT(!objectCN.empty()); CObjectInterface::ContainerList listOfContainers; listOfContainers.push_back(pModel); const CCopasiObject* pObject = CObjectInterface::DataModel(pCOPASIDATAMODEL->getObjectFromCN(listOfContainers, objectCN)); CPPUNIT_ASSERT(pObject != NULL); CPPUNIT_ASSERT(pObject->isReference() == true); CPPUNIT_ASSERT(pObject->getObjectName() == std::string("ParticleNumber")); CPPUNIT_ASSERT(pObject->getObjectParent() == pA); CPPUNIT_ASSERT(pModel->getReactions().size() == 2); const CReaction* pReaction1 = pModel->getReactions()[0]; CPPUNIT_ASSERT(pReaction1 != NULL); CPPUNIT_ASSERT(pReaction1->isReversible() == false); const CFunction* pKineticFunction = pReaction1->getFunction(); CPPUNIT_ASSERT(pKineticFunction != NULL); const CMassAction* pMassAction = dynamic_cast<const CMassAction*>(pKineticFunction); //FTB: this no longer is recognized as mass action reaction because of the // special case of a species with hOSU CPPUNIT_ASSERT(pMassAction == NULL); const CChemEq* pChemEq = &pReaction1->getChemEq(); CPPUNIT_ASSERT(pChemEq != NULL); CPPUNIT_ASSERT(pChemEq->getCompartmentNumber() == 1); CPPUNIT_ASSERT(pChemEq->getSubstrates().size() == 1); const CChemEqElement* pElement = pChemEq->getSubstrates()[0]; CPPUNIT_ASSERT(pElement != NULL); CPPUNIT_ASSERT(fabs(pElement->getMultiplicity() - 1.0) < 1e-3); CPPUNIT_ASSERT(pElement->getMetabolite() == pA); CPPUNIT_ASSERT(pChemEq->getProducts().size() == 0); CPPUNIT_ASSERT(pChemEq->getModifiers().size() == 0); const CReaction* pReaction2 = pModel->getReactions()[1]; CPPUNIT_ASSERT(pReaction2 != NULL); CPPUNIT_ASSERT(pReaction2->isReversible() == false); // check the kinetic law pKineticFunction = pReaction2->getFunction(); CPPUNIT_ASSERT(pKineticFunction != NULL); CPPUNIT_ASSERT(pKineticFunction->getObjectName() == std::string("Henri-Michaelis-Menten (irreversible)")); // check the function parameters one should be the reference to the substrate pChemEq = &pReaction2->getChemEq(); CPPUNIT_ASSERT(pChemEq != NULL); CPPUNIT_ASSERT(pChemEq->getCompartmentNumber() == 1); CPPUNIT_ASSERT(pChemEq->getSubstrates().size() == 1); pElement = pChemEq->getSubstrates()[0]; CPPUNIT_ASSERT(pElement != NULL); CPPUNIT_ASSERT(fabs(pElement->getMultiplicity() - 1.0) < 1e-3); CPPUNIT_ASSERT(pElement->getMetabolite() == pA); CPPUNIT_ASSERT(pChemEq->getProducts().size() == 1); pElement = pChemEq->getProducts()[0]; CPPUNIT_ASSERT(pElement != NULL); CPPUNIT_ASSERT(fabs(pElement->getMultiplicity() - 1.0) < 1e-3); CPPUNIT_ASSERT(pElement->getMetabolite() == pB); CPPUNIT_ASSERT(pChemEq->getModifiers().size() == 0); const std::vector<std::vector<std::string> > parameterMappings = pReaction2->getParameterMappings(); CPPUNIT_ASSERT(parameterMappings.size() == 3); CPPUNIT_ASSERT(parameterMappings[0].size() == 1); const std::string parameterKey = parameterMappings[0][0]; CPPUNIT_ASSERT(parameterKey == pA->getKey()); }
void test000043::test_hasOnlySubstanceUnits() { CCopasiDataModel* pDataModel = pCOPASIDATAMODEL; CPPUNIT_ASSERT(pDataModel->importSBMLFromString(MODEL_STRING)); CModel* pModel = pDataModel->getModel(); CPPUNIT_ASSERT(pModel != NULL); CPPUNIT_ASSERT(pModel->getQuantityUnitEnum() == CUnit::number); CPPUNIT_ASSERT(pModel->getVolumeUnitEnum() == CUnit::ml); CPPUNIT_ASSERT(pModel->getTimeUnitEnum() == CUnit::s); CPPUNIT_ASSERT(pModel->getCompartments().size() == 1); const CCompartment* pCompartment = pModel->getCompartments()[0]; CPPUNIT_ASSERT(pCompartment != NULL); CPPUNIT_ASSERT(pCompartment->getStatus() == CModelEntity::FIXED); CPPUNIT_ASSERT(pModel->getMetabolites().size() == 2); CMetab* pA = pModel->getMetabolites()[0]; CPPUNIT_ASSERT(pA != NULL); CPPUNIT_ASSERT(pA->getStatus() == CModelEntity::REACTIONS); const CMetab* pB = pModel->getMetabolites()[1]; CPPUNIT_ASSERT(pB != NULL); CPPUNIT_ASSERT(pB->getStatus() == CModelEntity::REACTIONS); CPPUNIT_ASSERT(pModel->getModelValues().size() == 1); const CModelValue* pModelValue = pModel->getModelValues()[0]; CPPUNIT_ASSERT(pModelValue != NULL); CPPUNIT_ASSERT(pModelValue->getStatus() == CModelEntity::FIXED); CPPUNIT_ASSERT(pModelValue->getInitialExpression() != ""); const CExpression* pExpr = pModelValue->getInitialExpressionPtr(); CPPUNIT_ASSERT(pExpr != NULL); // check the expression const CEvaluationNode* pNode = pExpr->getRoot(); CPPUNIT_ASSERT(pNode != NULL); const CEvaluationNodeObject* pObjectNode = dynamic_cast<const CEvaluationNodeObject*>(pNode); CPPUNIT_ASSERT(pObjectNode != NULL); CCopasiObjectName objectCN = pObjectNode->getObjectCN(); CPPUNIT_ASSERT(!objectCN.empty()); CObjectInterface::ContainerList listOfContainers; listOfContainers.push_back(pModel); const CCopasiObject* pObject = CObjectInterface::DataModel(pCOPASIDATAMODEL->getObjectFromCN(listOfContainers, objectCN)); CPPUNIT_ASSERT(pObject != NULL); CPPUNIT_ASSERT(pObject->isReference() == true); CPPUNIT_ASSERT(pObject->getObjectName() == std::string("InitialParticleNumber")); CPPUNIT_ASSERT(pObject->getObjectParent() == pA); // check the reactions CPPUNIT_ASSERT(pModel->getReactions().size() == 2); const CReaction* pReaction1 = pModel->getReactions()[0]; CPPUNIT_ASSERT(pReaction1 != NULL); CPPUNIT_ASSERT(pReaction1->isReversible() == false); // check the kinetic law const CFunction* pKineticFunction = pReaction1->getFunction(); CPPUNIT_ASSERT(pKineticFunction != NULL); const CMassAction* pMassAction = dynamic_cast<const CMassAction*>(pKineticFunction); //FTB: this no longer is recognized as mass action reaction because of the // special case of a species with hOSU CPPUNIT_ASSERT(pMassAction == NULL); const CChemEq* pChemEq = &pReaction1->getChemEq(); CPPUNIT_ASSERT(pChemEq != NULL); CPPUNIT_ASSERT(pChemEq->getCompartmentNumber() == 1); CPPUNIT_ASSERT(pChemEq->getSubstrates().size() == 1); const CChemEqElement* pElement = pChemEq->getSubstrates()[0]; CPPUNIT_ASSERT(pElement != NULL); CPPUNIT_ASSERT(fabs(pElement->getMultiplicity() - 1.0) < 1e-3); CPPUNIT_ASSERT(pElement->getMetabolite() == pA); CPPUNIT_ASSERT(pChemEq->getProducts().size() == 0); CPPUNIT_ASSERT(pChemEq->getModifiers().size() == 0); const CReaction* pReaction2 = pModel->getReactions()[1]; CPPUNIT_ASSERT(pReaction2 != NULL); CPPUNIT_ASSERT(pReaction2->isReversible() == false); // check the kinetic law pKineticFunction = pReaction2->getFunction(); CPPUNIT_ASSERT(pKineticFunction != NULL); CPPUNIT_ASSERT(pKineticFunction->getObjectName() == std::string("Function for reaction_1")); const CFunctionParameters* pFunctionParameters = &pKineticFunction->getVariables(); CPPUNIT_ASSERT(pFunctionParameters->size() == 4); const CFunctionParameter* pFunctionParameter = (*pFunctionParameters)[0]; CPPUNIT_ASSERT(pFunctionParameter != NULL); CPPUNIT_ASSERT(pFunctionParameter->getType() == CFunctionParameter::FLOAT64); CPPUNIT_ASSERT(pFunctionParameter->getUsage() == CFunctionParameter::PARAMETER); pFunctionParameter = (*pFunctionParameters)[1]; CPPUNIT_ASSERT(pFunctionParameter != NULL); CPPUNIT_ASSERT(pFunctionParameter->getType() == CFunctionParameter::FLOAT64); CPPUNIT_ASSERT(pFunctionParameter->getUsage() == CFunctionParameter::PARAMETER); pFunctionParameter = (*pFunctionParameters)[2]; CPPUNIT_ASSERT(pFunctionParameter != NULL); CPPUNIT_ASSERT(pFunctionParameter->getType() == CFunctionParameter::FLOAT64); CPPUNIT_ASSERT(pFunctionParameter->getUsage() == CFunctionParameter::VOLUME); pFunctionParameter = (*pFunctionParameters)[3]; CPPUNIT_ASSERT(pFunctionParameter != NULL); CPPUNIT_ASSERT(pFunctionParameter->getType() == CFunctionParameter::FLOAT64); CPPUNIT_ASSERT(pFunctionParameter->getUsage() == CFunctionParameter::SUBSTRATE); pNode = pKineticFunction->getRoot(); const CEvaluationNodeCall* pCallNode = dynamic_cast<const CEvaluationNodeCall*>(pNode); CPPUNIT_ASSERT(pCallNode != NULL); CPPUNIT_ASSERT((pCallNode->subType()) == CEvaluationNode::S_FUNCTION); CPPUNIT_ASSERT(pCallNode->getData() == std::string("Henri-Michaelis-Menten (irreversible)_2")); const CEvaluationNodeOperator* pOperatorNode = dynamic_cast<const CEvaluationNodeOperator*>(pCallNode->getChild()); CPPUNIT_ASSERT(pOperatorNode != NULL); CPPUNIT_ASSERT((pOperatorNode->subType()) == CEvaluationNode::S_MULTIPLY); const CEvaluationNodeVariable* pVariableNode = dynamic_cast<const CEvaluationNodeVariable*>(pOperatorNode->getChild()); CPPUNIT_ASSERT(pVariableNode != NULL); CPPUNIT_ASSERT(pVariableNode->getIndex() == 3); pVariableNode = dynamic_cast<const CEvaluationNodeVariable*>(pOperatorNode->getChild()->getSibling()); CPPUNIT_ASSERT(pVariableNode != NULL); CPPUNIT_ASSERT(pVariableNode->getIndex() == 2); pVariableNode = dynamic_cast<const CEvaluationNodeVariable*>(pCallNode->getChild()->getSibling()); CPPUNIT_ASSERT(pVariableNode != NULL); CPPUNIT_ASSERT(pVariableNode->getIndex() == 0); pVariableNode = dynamic_cast<const CEvaluationNodeVariable*>(pCallNode->getChild()->getSibling()->getSibling()); CPPUNIT_ASSERT(pVariableNode != NULL); CPPUNIT_ASSERT(pVariableNode->getIndex() == 1); pKineticFunction = dynamic_cast<const CFunction*>(pCallNode->getCalledTree()); CPPUNIT_ASSERT(pKineticFunction != NULL); CPPUNIT_ASSERT(pKineticFunction->getObjectName() == std::string("Henri-Michaelis-Menten (irreversible)_2")); pNode = pKineticFunction->getRoot(); CPPUNIT_ASSERT(pNode != NULL); pOperatorNode = dynamic_cast<const CEvaluationNodeOperator*>(pNode); CPPUNIT_ASSERT(pOperatorNode != NULL); CPPUNIT_ASSERT((pOperatorNode->subType()) == CEvaluationNode::S_DIVIDE); const CEvaluationNodeOperator* pOperatorNode2 = dynamic_cast<const CEvaluationNodeOperator*>(pOperatorNode->getChild()); CPPUNIT_ASSERT(pOperatorNode2 != NULL); CPPUNIT_ASSERT((pOperatorNode2->subType()) == CEvaluationNode::S_MULTIPLY); pVariableNode = dynamic_cast<const CEvaluationNodeVariable*>(pOperatorNode2->getChild()); CPPUNIT_ASSERT(pVariableNode != NULL); CPPUNIT_ASSERT(pVariableNode->getIndex() == 2); pVariableNode = dynamic_cast<const CEvaluationNodeVariable*>(pOperatorNode2->getChild()->getSibling()); CPPUNIT_ASSERT(pVariableNode != NULL); CPPUNIT_ASSERT(pVariableNode->getIndex() == 0); pOperatorNode2 = dynamic_cast<const CEvaluationNodeOperator*>(pOperatorNode->getChild()->getSibling()); CPPUNIT_ASSERT(pOperatorNode2 != NULL); CPPUNIT_ASSERT((pOperatorNode2->subType()) == CEvaluationNode::S_PLUS); pVariableNode = dynamic_cast<const CEvaluationNodeVariable*>(pOperatorNode2->getChild()); CPPUNIT_ASSERT(pVariableNode != NULL); CPPUNIT_ASSERT(pVariableNode->getIndex() == 1); pVariableNode = dynamic_cast<const CEvaluationNodeVariable*>(pOperatorNode2->getChild()->getSibling()); CPPUNIT_ASSERT(pVariableNode != NULL); CPPUNIT_ASSERT(pVariableNode->getIndex() == 0); // check the function parameters one should be the reference to the substrate pChemEq = &pReaction2->getChemEq(); CPPUNIT_ASSERT(pChemEq != NULL); CPPUNIT_ASSERT(pChemEq->getCompartmentNumber() == 1); CPPUNIT_ASSERT(pChemEq->getSubstrates().size() == 1); pElement = pChemEq->getSubstrates()[0]; CPPUNIT_ASSERT(pElement != NULL); CPPUNIT_ASSERT(fabs(pElement->getMultiplicity() - 1.0) < 1e-3); CPPUNIT_ASSERT(pElement->getMetabolite() == pA); CPPUNIT_ASSERT(pChemEq->getProducts().size() == 1); pElement = pChemEq->getProducts()[0]; CPPUNIT_ASSERT(pElement != NULL); CPPUNIT_ASSERT(fabs(pElement->getMultiplicity() - 1.0) < 1e-3); CPPUNIT_ASSERT(pElement->getMetabolite() == pB); CPPUNIT_ASSERT(pChemEq->getModifiers().size() == 0); const std::vector<std::vector<std::string> > parameterMappings = pReaction2->getParameterMappings(); CPPUNIT_ASSERT(parameterMappings.size() == 4); CPPUNIT_ASSERT(parameterMappings[2].size() == 1); std::string parameterKey = parameterMappings[2][0]; CPPUNIT_ASSERT(parameterKey == pCompartment->getKey()); CPPUNIT_ASSERT(parameterMappings[3].size() == 1); parameterKey = parameterMappings[3][0]; CPPUNIT_ASSERT(parameterKey == pA->getKey()); }
void test000087::test_simulate_reaction_flux_reference_1() { try { bool result = pCOPASIDATAMODEL->importSBMLFromString(test000087::MODEL_STRING5); CPPUNIT_ASSERT(result = true); } catch (...) { // there should be no exception CPPUNIT_ASSERT(false); } CModel* pModel = pCOPASIDATAMODEL->getModel(); CPPUNIT_ASSERT(pModel != NULL); CPPUNIT_ASSERT(pModel->getCompartments().size() == 1); CPPUNIT_ASSERT(pModel->getMetabolites().size() == 2); CPPUNIT_ASSERT(pModel->getModelValues().size() == 2); CPPUNIT_ASSERT(pModel->getReactions().size() == 1); const CReaction* pReaction = pModel->getReactions()[0]; CPPUNIT_ASSERT(pReaction != NULL); CModelValue* pConstParameter = NULL; CModelValue* pNonConstParameter = NULL; unsigned int i, iMax = pModel->getModelValues().size(); for (i = 0; i < iMax; ++i) { if (pModel->getModelValues()[i]->getStatus() == CModelEntity::FIXED) { pConstParameter = pModel->getModelValues()[i]; } if (pModel->getModelValues()[i]->getStatus() == CModelEntity::ASSIGNMENT) { pNonConstParameter = pModel->getModelValues()[i]; } } CPPUNIT_ASSERT(pConstParameter != NULL); CPPUNIT_ASSERT(pNonConstParameter != NULL); // check if the kinetic law is mass action with const global parameter as the kinetic constant CPPUNIT_ASSERT(pReaction->getChemEq().getSubstrates().size() == 1); CPPUNIT_ASSERT(pReaction->getChemEq().getProducts().size() == 1); CPPUNIT_ASSERT(pReaction->getChemEq().getModifiers().size() == 0); CPPUNIT_ASSERT(pReaction->isReversible() == false); const CFunction* pKineticLaw = pReaction->getFunction(); CPPUNIT_ASSERT(pKineticLaw != NULL); CPPUNIT_ASSERT(pKineticLaw->getType() == CEvaluationTree::MassAction); const std::vector< std::vector<std::string> > & parameterMappings = pReaction->getParameterMappings(); CPPUNIT_ASSERT(parameterMappings.size() == 2); CPPUNIT_ASSERT(parameterMappings[0].size() == 1); CPPUNIT_ASSERT(parameterMappings[0][0] == pConstParameter->getKey()); CPPUNIT_ASSERT(parameterMappings[1].size() == 1); std::string substrateKey = parameterMappings[1][0]; const CCopasiObject* pTempObject = CCopasiRootContainer::getKeyFactory()->get(substrateKey); CPPUNIT_ASSERT(pTempObject != NULL); const CMetab* pSubstrate = dynamic_cast<const CMetab*>(pTempObject); CPPUNIT_ASSERT(pSubstrate != NULL); // check that the assignment consists of only one object node that is a reference to the reaction flux const CExpression* pExpression = pNonConstParameter->getExpressionPtr(); CPPUNIT_ASSERT(pExpression != NULL); const CEvaluationNode* pRoot = pExpression->getRoot(); CPPUNIT_ASSERT(pRoot != NULL); CPPUNIT_ASSERT(pRoot->mainType() == CEvaluationNode::T_OBJECT); const CEvaluationNodeObject* pObjectNode = dynamic_cast<const CEvaluationNodeObject*>(pRoot); CPPUNIT_ASSERT(pObjectNode != NULL); const CRegisteredObjectName cn = pObjectNode->getObjectCN(); CObjectInterface::ContainerList listOfContainers; listOfContainers.push_back(pCOPASIDATAMODEL->getModel()); const CCopasiObject* pObject = CObjectInterface::DataModel(pCOPASIDATAMODEL->getObjectFromCN(listOfContainers, cn)); CPPUNIT_ASSERT(pObject != NULL); CPPUNIT_ASSERT(pObject->isReference() == true); CPPUNIT_ASSERT(pObject->getObjectName() == "Flux"); CPPUNIT_ASSERT(pObject->getObjectParent() == pReaction); // Simulate the model (5 steps, stepsize 1 and check that at each step, the value of the variable parameter // is the same as the flux through the reaction. std::ostringstream result; // create a report with the correct filename and all the species against // time. CReportDefinitionVector* pReports = pCOPASIDATAMODEL->getReportDefinitionList(); CReportDefinition* pReport = pReports->createReportDefinition("Report", "Output for simulation"); pReport->setTaskType(CCopasiTask::timeCourse); pReport->setIsTable(false); pReport->setSeparator(", "); std::vector<CRegisteredObjectName>* pHeader = pReport->getHeaderAddr(); std::vector<CRegisteredObjectName>* pBody = pReport->getBodyAddr(); pHeader->push_back(CCopasiStaticString("time").getCN()); pHeader->push_back(pReport->getSeparator().getCN()); pHeader->push_back(CCopasiStaticString("substrate").getCN()); pHeader->push_back(pReport->getSeparator().getCN()); pHeader->push_back(CCopasiStaticString("reaction flux").getCN()); pHeader->push_back(pReport->getSeparator().getCN()); pHeader->push_back(CCopasiStaticString("variable model value").getCN()); pBody->push_back(CCopasiObjectName(pCOPASIDATAMODEL->getModel()->getCN() + ",Reference=Time")); pBody->push_back(CRegisteredObjectName(pReport->getSeparator().getCN())); pBody->push_back(CCopasiObjectName(pSubstrate->getCN() + ",Reference=Concentration")); pBody->push_back(CRegisteredObjectName(pReport->getSeparator().getCN())); pBody->push_back(CCopasiObjectName(pReaction->getCN() + ",Reference=Flux")); pBody->push_back(CRegisteredObjectName(pReport->getSeparator().getCN())); pBody->push_back(CCopasiObjectName(pNonConstParameter->getCN() + ",Reference=Value")); // // create a trajectory task CTrajectoryTask* pTrajectoryTask = new CTrajectoryTask(); // use LSODAR from now on since we will have events pretty soon pTrajectoryTask->setMethodType(CCopasiMethod::LSODAR); pTrajectoryTask->getProblem()->setModel(pCOPASIDATAMODEL->getModel()); pTrajectoryTask->setScheduled(true); pTrajectoryTask->getReport().setReportDefinition(pReport); // the target needs to be set in order to get output on the stream // object passed to the task in the call to initialize below pTrajectoryTask->getReport().setTarget("test.tmp"); CTrajectoryProblem* pProblem = dynamic_cast<CTrajectoryProblem*>(pTrajectoryTask->getProblem()); pProblem->setStepNumber((const unsigned C_INT32)30); pCOPASIDATAMODEL->getModel()->setInitialTime((const C_FLOAT64)0.0); pProblem->setDuration((const C_FLOAT64)30); pProblem->setTimeSeriesRequested(true); CTrajectoryMethod* pMethod = dynamic_cast<CTrajectoryMethod*>(pTrajectoryTask->getMethod()); pMethod->getParameter("Absolute Tolerance")->setValue(1.0e-12); CCopasiVectorN< CCopasiTask > & TaskList = * pCOPASIDATAMODEL->getTaskList(); TaskList.remove("Time-Course"); TaskList.add(pTrajectoryTask, true); try { pTrajectoryTask->initialize(CCopasiTask::OUTPUT_UI, pCOPASIDATAMODEL, &result); pTrajectoryTask->process(true); pTrajectoryTask->restore(); } catch (...) { // there should be no exception CPPUNIT_ASSERT(false); } // analyse the result CPPUNIT_ASSERT(!result.str().empty()); std::string result_string = result.str(); std::string delimiter = "\n"; std::string delimiter2 = ","; std::size_t lastPos = result_string.find_first_not_of(delimiter); std::size_t pos; std::string line, number_string; unsigned int index = 0; unsigned int index2; std::size_t lastPos2; std::size_t pos2; double last = std::numeric_limits<double>::max(), current = std::numeric_limits<double>::max(); while (lastPos != std::string::npos) { pos = result_string.find_first_of(delimiter, lastPos); line = result_string.substr(lastPos, pos - lastPos); lastPos = result_string.find_first_not_of(delimiter, pos); lastPos2 = line.find_first_not_of(delimiter2); // skip the header line if (index != 0) { index2 = 0; while (lastPos2 != std::string::npos) { pos2 = line.find_first_of(delimiter2, lastPos2); number_string = line.substr(lastPos2, pos2 - lastPos2); lastPos2 = line.find_first_not_of(delimiter2, pos2); // skip the time column if (index2 != 0) { //check that all values in the row (besides the time) // are always the same if (index2 == 1) { last = strToDouble(number_string.c_str(), NULL); if (index == 1) { // just make sure that we don't compare all zeros // The initial value of the substrate hould be higher than 1 CPPUNIT_ASSERT(fabs(pSubstrate->getInitialValue()) > 1); // the first rwo should correspond the the initial value of the substrate // We check this to make sure that the whole timeseries does not consist of zeros CPPUNIT_ASSERT(fabs((last - pSubstrate->getInitialConcentration()) / pSubstrate->getInitialConcentration()) < 1e-20); } } else { current = strToDouble(number_string.c_str(), NULL); CPPUNIT_ASSERT(fabs((current - last) / last) < 1e-20); last = current; } } ++index2; } } ++index; } // make sure there actually were datapoints CPPUNIT_ASSERT(index > 1); // the simulation is set to run until all substrate is depleted, so in the end // last should be below the absolute tolerance for the simulation CPPUNIT_ASSERT(last < *pMethod->getParameter("Absolute Tolerance")->getValue().pDOUBLE); }
void CQExpressionWidget::setExpression(const std::string & expression) { if (mpValidatorExpression == NULL) { mpValidatorExpression = new CQValidatorExpression(this, ""); mpValidatorExpression->revalidate(); } // Reset the parse list. mParseList.clear(); mCursor = textCursor(); CFunctionDB* pFunDB = CCopasiRootContainer::getFunctionList(); assert(CCopasiRootContainer::getDatamodelList()->size() > 0); CCopasiDataModel* pDataModel = &CCopasiRootContainer::getDatamodelList()->operator[](0); assert(pDataModel != NULL); CObjectInterface::ContainerList containers; containers.push_back(pDataModel); containers.push_back(pFunDB); const QString Infix(FROM_UTF8(expression)); QString Display; QRegExp InfixObjectPattern(CQExpressionWidget::InfixPattern); int Index = 0; QString::const_iterator it = Infix.begin(); QString::const_iterator end; while (true) { Index = InfixObjectPattern.indexIn(Infix, Index); if (Index < 0) { end = Infix.end(); } else { end = Infix.begin() + Index; } // Copy the non-object part for (; it != end; ++it) { Display.append(*it); } if (InfixObjectPattern.matchedLength() < 0) break; Index += InfixObjectPattern.matchedLength(); it += InfixObjectPattern.matchedLength(); CCopasiObjectName InfixName(TO_UTF8(InfixObjectPattern.cap(1))); const CCopasiObject * pObject = CObjectInterface::DataObject(CObjectInterface::GetObjectFromCN(containers, InfixName)); if (pObject != NULL) { std::string DisplayName = pObject->getObjectDisplayName(); // We need to escape '\' and '}' std::string::size_type pos = DisplayName.find_first_of("\\}"); while (pos != std::string::npos) { DisplayName.insert(pos, "\\"); pos += 2; pos = DisplayName.find_first_of("\\}", pos); } mParseList[DisplayName] = pObject; Display += '{' + FROM_UTF8(DisplayName) + '}'; } else { std::string DisplayName = InfixName; // We need to escape '\' and '}' std::string::size_type pos = DisplayName.find_first_of("\\}"); while (pos != std::string::npos) { DisplayName.insert(pos, "\\"); pos += 2; pos = DisplayName.find_first_of("\\}", pos); } Display += '{' + FROM_UTF8(DisplayName) + '}'; } } setText(Display); mpValidatorExpression->saved(); return; }
void SliderDialog::createNewSlider() { // allow the user to create more than one slider std::vector<const CCopasiObject*> objects = CCopasiSelectionDialog::getObjectVector(this, CQSimpleSelectionTree::InitialTime | CQSimpleSelectionTree::Parameters); std::vector<CSlider*>* pVector = getCSlidersForCurrentFolderId(); std::vector<const CCopasiObject*>::const_iterator it = objects.begin(), endit = objects.end(); bool yesToAll = false; bool noToAll = false; // create the sliders for all the selected objects // first we need the task object because we need it later to associate the // later with the correct task CCopasiObject* object = (CCopasiObject*)getTaskForFolderId(mCurrentFolderId); if (!object) return; CCopasiObject* pTmpObject = NULL; while (it != endit) { // create a new slider assert((*it) != NULL); pTmpObject = const_cast<CCopasiObject*>(determineCorrectObjectForSlider(*it)); CCopasiDataModel * pDataModel = pTmpObject->getObjectDataModel(); assert(pDataModel != NULL); CSlider* pCSlider = new CSlider("slider", pDataModel); if (pCSlider) { pCSlider->setSliderObject(pTmpObject); pCSlider->setAssociatedEntityKey(object->getKey()); // check if a slider for that object already exists and if so, prompt // the user what to do CSlider* pEquivalentSlider = equivalentSliderExists(pCSlider); if (pEquivalentSlider != NULL) { CopasiSlider* pCopasiSlider = NULL; // if the user has specified yesToAll, we reset the ranges of all // duplicate sliders if (yesToAll) { pEquivalentSlider->resetRange(); // update the slider widget pCopasiSlider = findCopasiSliderForCSlider(pEquivalentSlider); assert(pCopasiSlider != NULL); if (pCopasiSlider != NULL) { pCopasiSlider->updateSliderData(); } } // if the user has not specified noToAll, we need to prompt else if (!noToAll) { QMessageBox::StandardButton result = CQMessageBox::information(NULL, "Slider Exists", "A slider for this object already exists.\n\nDo you want to reset the range of the slider?", QMessageBox::Yes | QMessageBox::No | QMessageBox::YesToAll | QMessageBox::NoToAll, QMessageBox::No); // check the answer and maybe set some flags switch (result) { case QMessageBox::YesToAll: // set the flag yesToAll = true; case QMessageBox::Yes: // reset the range pEquivalentSlider->resetRange(); // update the slider widget pCopasiSlider = findCopasiSliderForCSlider(pEquivalentSlider); assert(pCopasiSlider != NULL); if (pCopasiSlider != NULL) { pCopasiSlider->updateSliderData(); } break; case QMessageBox::NoToAll: // set the flag noToAll = true; break; case QMessageBox::No: // do nothing else break; default: // do nothing break; } } delete pCSlider; } else { CObjectInterface::ContainerList listOfContainers; assert(CCopasiRootContainer::getDatamodelList()->size() > 0); listOfContainers.push_back(pDataModel->getModel()); pCSlider->compile(listOfContainers); pCSlider->resetRange(); addSlider(pCSlider); mChanged = true; } } ++it; } delete pVector; }
bool CCopasiTask::initialize(const OutputFlag & of, COutputHandler * pOutputHandler, std::ostream * pOstream) { bool success = true; if (mpProblem == NULL) { CCopasiMessage(CCopasiMessage::ERROR, MCCopasiTask + 1, getObjectName().c_str()); return false; } if (mpContainer == NULL) { CCopasiMessage(CCopasiMessage::ERROR, MCCopasiTask + 2, getObjectName().c_str()); return false; } if (mpMethod == NULL) { CCopasiMessage(CCopasiMessage::ERROR, MCCopasiTask + 3, getObjectName().c_str()); return false; } if (mpContainer != NULL) { mInitialState = mpContainer->getInitialState(); } else { mInitialState.resize(0); } mDoOutput = of; mpOutputHandler = pOutputHandler; if (mDoOutput == NO_OUTPUT || mpOutputHandler == NULL) return true; mOutputCounter = 0; if (mDoOutput & REPORT) { if (mReport.open(getObjectDataModel(), pOstream) && mReport.getTarget() != "") mpOutputHandler->addInterface(&mReport); else if (pOstream == NULL) CCopasiMessage(CCopasiMessage::COMMANDLINE, MCCopasiTask + 5, getObjectName().c_str()); } CObjectInterface::ContainerList ListOfContainer; ListOfContainer.push_back(this); if (mpContainer != NULL) { ListOfContainer.push_back(mpContainer); } if (!mpOutputHandler->compile(ListOfContainer)) { // Warning CCopasiMessage(CCopasiMessage::WARNING, MCCopasiTask + 7); success = false; } return success; }
bool CMetab::compile() { bool success = true; // We first clear all dependencies and refreshes // Particle Number mpValueReference->clearDirectDependencies(); // Rate (particle number rate) mRateVector.clear(); mpRateReference->clearDirectDependencies(); // Concentration mpConcReference->clearDirectDependencies(); // Concentration Rate mpConcRateReference->clearDirectDependencies(); // Noise mpNoiseReference->clearDirectDependencies(); mpIntensiveNoiseReference->clearDirectDependencies(); // Transition Time mpTTReference->clearDirectDependencies(); // Prepare the compilation std::set<const CCopasiObject *> Dependencies; CObjectInterface::ContainerList listOfContainer; listOfContainer.push_back(getObjectAncestor("Model")); CCopasiDataModel* pDataModel = NULL; const CCopasiObject * pVolumeReference = NULL; if (mpCompartment) pVolumeReference = mpCompartment->getValueReference(); // Compile the value (particle number) Dependencies.insert(mpConcReference); if (pVolumeReference) Dependencies.insert(pVolumeReference); // We no longer need to distinguish the cases since the reference are now context sensitive mpValueReference->setDirectDependencies(Dependencies); Dependencies.clear(); // Compiling of the rest. switch (getStatus()) { case FIXED: // Concentration Dependencies.insert(mpValueReference); if (pVolumeReference) Dependencies.insert(pVolumeReference); mpConcReference->setDirectDependencies(Dependencies); // Fixed values mRate = 0.0; mConcRate = 0.0; mIntensiveNoise = std::numeric_limits<C_FLOAT64>::quiet_NaN(); mTT = std::numeric_limits<C_FLOAT64>::infinity(); break; case ASSIGNMENT: // Concentration success = mpExpression->compile(listOfContainer); mpConcReference->setDirectDependencies(mpExpression->getDirectDependencies()); // Implicit initial expression pdelete(mpInitialExpression); pDataModel = getObjectDataModel(); mpInitialExpression = CExpression::createInitialExpression(*mpExpression, pDataModel); mpInitialExpression->setObjectName("InitialExpression"); // Fixed values mRate = std::numeric_limits< C_FLOAT64 >::quiet_NaN(); mConcRate = std::numeric_limits< C_FLOAT64 >::quiet_NaN(); mIntensiveNoise = std::numeric_limits<C_FLOAT64>::quiet_NaN(); mTT = std::numeric_limits< C_FLOAT64 >::quiet_NaN(); break; case ODE: // Concentration Dependencies.insert(mpValueReference); if (pVolumeReference) Dependencies.insert(pVolumeReference); mpConcReference->setDirectDependencies(Dependencies); // Rate (particle number rate) success = mpExpression->compile(listOfContainer); Dependencies = mpExpression->getDirectDependencies(); if (pVolumeReference) Dependencies.insert(pVolumeReference); mpRateReference->setDirectDependencies(Dependencies); Dependencies.clear(); // Concentration Rate Dependencies.insert(mpRateReference); Dependencies.insert(mpConcReference); if (pVolumeReference) Dependencies.insert(pVolumeReference); if (mpCompartment) Dependencies.insert(mpCompartment->getRateReference()); mpConcRateReference->setDirectDependencies(Dependencies); if (mpNoiseExpression != NULL) { // Noise (particle number rate) success = mpNoiseExpression->compile(listOfContainer); Dependencies = mpNoiseExpression->getDirectDependencies(); if (pVolumeReference) Dependencies.insert(pVolumeReference); mpNoiseReference->setDirectDependencies(Dependencies); Dependencies.clear(); // Intensive Noise Dependencies.insert(mpNoiseReference); if (pVolumeReference) Dependencies.insert(pVolumeReference); mpIntensiveNoiseReference->setDirectDependencies(Dependencies); Dependencies.clear(); } // Transition Time Dependencies.insert(mpValueReference); Dependencies.insert(mpRateReference); mpTTReference->setDirectDependencies(Dependencies); Dependencies.clear(); break; case REACTIONS: { // Concentration Dependencies.insert(mpValueReference); if (pVolumeReference) Dependencies.insert(pVolumeReference); mpConcReference->setDirectDependencies(Dependencies); Dependencies.clear(); std::set<const CCopasiObject *> NoiseDependencies; // Create the rate vector CCopasiVectorN< CReaction >::const_iterator it = mpModel->getReactions().begin(); CCopasiVectorN< CReaction >::const_iterator end = mpModel->getReactions().end(); for (; it != end; ++it) { const CCopasiVector< CChemEqElement > &Balances = it->getChemEq().getBalances(); CCopasiVector< CChemEqElement >::const_iterator itChem = Balances.begin(); CCopasiVector< CChemEqElement >::const_iterator endChem = Balances.end(); for (; itChem != endChem; ++itChem) if (itChem->getMetaboliteKey() == mKey) break; if (itChem != endChem) { Dependencies.insert(it->getParticleFluxReference()); NoiseDependencies.insert(it->getParticleNoiseReference()); std::pair< C_FLOAT64, const C_FLOAT64 * > Insert; Insert.first = itChem->getMultiplicity(); Insert.second = &it->getParticleFlux(); mRateVector.push_back(Insert); } } // Rate (particle number rate) mpRateReference->setDirectDependencies(Dependencies); // Transition Time mpTTReference->setDirectDependencies(Dependencies); Dependencies.clear(); // Concentration Rate Dependencies.insert(mpRateReference); Dependencies.insert(mpConcReference); if (pVolumeReference) Dependencies.insert(pVolumeReference); if (mpCompartment) Dependencies.insert(mpCompartment->getRateReference()); mpConcRateReference->setDirectDependencies(Dependencies); Dependencies.clear(); mpNoiseReference->setDirectDependencies(NoiseDependencies); if (pVolumeReference) NoiseDependencies.insert(pVolumeReference); mpIntensiveNoiseReference->setDirectDependencies(NoiseDependencies); } break; default: break; } // The initial values success &= compileInitialValueDependencies(); return success; }