コード例 #1
0
ファイル: CMathObject.cpp プロジェクト: jonasfoe/COPASI
bool CMathObject::createExtensiveODERateExpression(const CMetab * pSpecies,
    CMathContainer & container)
{
  bool success = true;

  std::ostringstream Infix;
  Infix.imbue(std::locale::classic());
  Infix.precision(16);

  /*
    mRate = mpModel->getQuantity2NumberFactor() *
      mpCompartment->getValue() * mpExpression->calcValue();
   */

  if (!pSpecies->getExpression().empty())
    {
      Infix << container.getModel().getQuantity2NumberFactor();
      Infix << "*";
      Infix << pointerToString(container.getMathObject(pSpecies->getCompartment()->getValueReference())->getValuePointer());
      Infix << "*(";
      Infix << pSpecies->getExpression();
      Infix << ")";
    }

  CExpression E("ExtensiveODERateExpression", &container);

  success &= E.setInfix(Infix.str());

  pdelete(mpExpression);
  mpExpression = new CMathExpression(E, container, !mIsInitialValue);
  compileExpression();

  return success;
}
コード例 #2
0
ファイル: CMathObject.cpp プロジェクト: jonasfoe/COPASI
bool CMathObject::compileParticleFlux(CMathContainer & container)
{
  bool success = true;

  // The default value is NaN
  *mpValue = InvalidValue;

  // Reset the prerequisites
  mPrerequisites.clear();

  const CReaction * pReaction = static_cast< const CReaction * >(mpDataObject->getObjectParent());

  // We need to check whether this reaction is a single compartment reaction and scale
  // it if true.
  //   mParticleFlux = *mUnitScalingFactor * mFlux;
  //   mUnitScalingFactor = & pModel->getQuantity2NumberFactor();

  std::ostringstream Infix;
  Infix.imbue(std::locale::classic());
  Infix.precision(16);

  Infix << container.getModel().getQuantity2NumberFactor();
  Infix << "*";
  Infix << pointerToString(container.getMathObject(pReaction->getFluxReference())->getValuePointer());

  CExpression E("ParticleFluxExpression", &container);

  success &= E.setInfix(Infix.str());

  pdelete(mpExpression);
  mpExpression = new CMathExpression(E, container, !mIsInitialValue);
  compileExpression();

  return success;
}
コード例 #3
0
// virtual
CValidatedUnit CEvaluationNodeDelay::setUnit(const CMathContainer & container,
    const std::map < CEvaluationNode * , CValidatedUnit > & currentUnits,
    std::map < CEvaluationNode * , CValidatedUnit > & targetUnits) const
{
  CValidatedUnit Delay(CEvaluationNode::setUnit(container, currentUnits, targetUnits));

  targetUnits[mpDelayValueNode] = Delay;
  targetUnits[mpDelayLagNode] = CValidatedUnit(container.getModel().getTimeUnit(), false);

  return Delay;
}
コード例 #4
0
// virtual
CValidatedUnit CEvaluationNodeDelay::getUnit(const CMathContainer & container,
    const std::vector< CValidatedUnit > & units) const
{
  // The units of the delay functions are the units of the delay value which is the first child
  CValidatedUnit Delay = units[0];
  CValidatedUnit Lag = CValidatedUnit::merge(CValidatedUnit(container.getModel().getTimeUnit(), false), units[1]);

  Delay.setConflict(Delay.conflict() || Lag.conflict());

  return Delay;
}
コード例 #5
0
ファイル: TaskWidget.cpp プロジェクト: copasi/COPASI
bool TaskWidget::commonAfterRunTask()
{
  if (!mpTask) return false;

  if (CRootContainer::getConfiguration()->displayPopulations())
    {

      if (dynamic_cast<COptTask*>(mpTask) != NULL || dynamic_cast<CFitTask*>(mpTask) != NULL)
        {
          CopasiUI3Window* pWindow = CopasiUI3Window::getMainWindow();
          CQOptPopulation* pPopWidget = pWindow->getPopulationDisplay();
          COptPopulationMethod* pMethod = dynamic_cast<COptPopulationMethod*>(mpTask->getMethod());
          pPopWidget->setMethod(NULL);

          if (pMethod != NULL)
            {
              mpDataModel->removeInterface(pPopWidget);
            }
        }
    }

  if (mProgressBar != NULL)
    {
      mProgressBar->finish();
      mProgressBar->deleteLater();
      mProgressBar = NULL;
    }

  mpTask->setCallBack(NULL);

  CCopasiMessage::clearDeque();

  assert(mpDataModel != NULL);
  mpDataModel->finish();

  CMathContainer * pContainer = mpTask->getMathContainer();
  protectedNotify(ListViews::ObjectType::STATE, ListViews::CHANGE, pContainer->getModel().getKey());

  unsetCursor();
  CopasiUI3Window::getMainWindow()->suspendAutoSave(false);

  return loadTask();
}
コード例 #6
0
ファイル: CMathObject.cpp プロジェクト: jonasfoe/COPASI
bool CMathObject::createExtensiveValueExpression(const CMetab * pSpecies,
    CMathContainer & container)
{
  bool success = true;

  // mConc * mpCompartment->getValue() * mpModel->getQuantity2NumberFactor();

  CObjectInterface * pDensity = NULL;
  CObjectInterface * pCompartment = NULL;

  if (mIsInitialValue)
    {
      pDensity = pSpecies->getInitialConcentrationReference();
      pCompartment = pSpecies->getCompartment()->getInitialValueReference();
    }
  else
    {
      pDensity = pSpecies->getConcentrationReference();
      pCompartment = pSpecies->getCompartment()->getValueReference();
    }

  std::ostringstream Infix;
  Infix.imbue(std::locale::classic());
  Infix.precision(16);

  Infix << container.getModel().getQuantity2NumberFactor();
  Infix << "*";
  Infix << pointerToString(container.getMathObject(pDensity)->getValuePointer());
  Infix << "*";
  Infix << pointerToString(container.getMathObject(pCompartment)->getValuePointer());

  CExpression E("ExtensiveValueExpression", &container);

  success &= E.setInfix(Infix.str());

  pdelete(mpExpression);
  mpExpression = new CMathExpression(E, container, !mIsInitialValue);
  compileExpression();

  return success;
}
コード例 #7
0
ファイル: CMathObject.cpp プロジェクト: sachiinb/COPASI
bool CMathObject::createIntensiveValueExpression(const CMetab * pSpecies,
    CMathContainer & container)
{
  bool success = true;

  // mConc = *mpValue / mpCompartment->getValue() * mpModel->getNumber2QuantityFactor();
  CObjectInterface * pNumber = NULL;
  CObjectInterface * pCompartment = NULL;

  if (mIsInitialValue)
    {
      pNumber = pSpecies->getInitialValueReference();
      pCompartment = pSpecies->getCompartment()->getInitialValueReference();
    }
  else
    {
      pNumber = pSpecies->getValueReference();
      pCompartment = pSpecies->getCompartment()->getValueReference();
    }

  std::ostringstream Infix;
  Infix.imbue(std::locale::classic());
  Infix.precision(16);

  Infix << container.getModel().getNumber2QuantityFactor();
  Infix << "*<";
  Infix << pNumber->getCN();
  Infix << ">/<";
  Infix << pCompartment->getCN();
  Infix << ">";

  CExpression E("IntensiveValueExpression", &container);

  success &= E.setInfix(Infix.str());

  mpExpression = new CMathExpression(E, container, !mIsInitialValue);
  compileExpression();

  return success;
}
コード例 #8
0
ファイル: CMathObject.cpp プロジェクト: jonasfoe/COPASI
bool CMathObject::createIntensiveRateExpression(const CMetab * pSpecies,
    CMathContainer & container)
{
  bool success = true;

  /*
    mConcRate =
      (mRate * mpModel->getNumber2QuantityFactor() - mConc * mpCompartment->getRate())
      / mpCompartment->getValue();
   */

  std::ostringstream Infix;
  Infix.imbue(std::locale::classic());
  Infix.precision(16);

  Infix << "(";
  Infix << pointerToString(container.getMathObject(pSpecies->getRateReference())->getValuePointer());
  Infix << "*";
  Infix << container.getModel().getNumber2QuantityFactor();
  Infix << "-";
  Infix << pointerToString(container.getMathObject(pSpecies->getCompartment()->getValueReference())->getValuePointer());
  Infix << "*";
  Infix << pointerToString(container.getMathObject(pSpecies->getCompartment()->getRateReference())->getValuePointer());
  Infix << ")/";
  Infix << pointerToString(container.getMathObject(pSpecies->getCompartment()->getValueReference())->getValuePointer());

  CExpression E("IntensiveRateExpression", &container);

  success &= E.setInfix(Infix.str());

  pdelete(mpExpression);
  mpExpression = new CMathExpression(E, container, !mIsInitialValue);
  compileExpression();

  return success;
}
コード例 #9
0
ファイル: CMathObject.cpp プロジェクト: jonasfoe/COPASI
bool CMathObject::compilePropensity(CMathContainer & container)
{
  bool success = true;

  // The default value is NaN
  *mpValue = InvalidValue;

  // Reset the prerequisites
  mPrerequisites.clear();

  const CReaction * pReaction = static_cast< const CReaction * >(mpDataObject->getObjectParent());

  std::ostringstream Infix;
  Infix.imbue(std::locale::classic());
  Infix.precision(16);

  // Propensity for reversible reactions must be NaN
  if (pReaction->isReversible())
    {
      Infix << "NAN";
    }
  else
    {
      // Propensity is the same as the flux, but it must now be negative.
      Infix << "max(0," << pointerToString(container.getMathObject(pReaction->getParticleFluxReference())->getValuePointer());

      // Apply correction for deterministic models
      if (container.getModel().getModelType() == CModel::deterministic)
        {
          std::ostringstream Divisor;
          Divisor.imbue(std::locale::classic());
          Divisor.precision(16);

          const CCopasiVector<CChemEqElement> & Substrates = pReaction->getChemEq().getSubstrates();
          CCopasiVector< CChemEqElement >::const_iterator itSubstrate = Substrates.begin();
          CCopasiVector< CChemEqElement >::const_iterator endSubstrate = Substrates.end();
          bool first = true;

          for (; itSubstrate != endSubstrate; ++itSubstrate)
            {
              const std::string NumberPointer = pointerToString(container.getMathObject(itSubstrate->getMetabolite()->getValueReference())->getValuePointer());

              C_FLOAT64 Multiplicity = itSubstrate->getMultiplicity();

              Multiplicity -= 1.0; // Nothing to correct if the multiplicity is 1.

              if (Multiplicity > 2.0 - 100.0 * std::numeric_limits< C_FLOAT64 >::epsilon())
                {
                  if (!first)
                    {
                      Divisor << "*";
                    }

                  first = false;
                  Divisor << NumberPointer << "^" << Multiplicity;
                }
              else if (Multiplicity > 1.0 - 100.0 * std::numeric_limits< C_FLOAT64 >::epsilon())
                {
                  if (!first)
                    {
                      Divisor << "*";
                    }

                  first = false;
                  Divisor << NumberPointer;
                }

              while (Multiplicity > 1.0 - 100.0 * std::numeric_limits< C_FLOAT64 >::epsilon())
                {
                  Infix << "*(" << NumberPointer << "-" << Multiplicity << ")";
                  Multiplicity -= 1.0;
                }
            }

          if (Divisor.str() != "")
            {
              Infix << "/(" << Divisor.str() << ")";
            }
        }

      Infix << ")";
    }

  CExpression E("PropensityExpression", &container);

  success &= E.setInfix(Infix.str());

  pdelete(mpExpression);
  mpExpression = new CMathExpression(E, container, !mIsInitialValue);
  compileExpression();

  return success;
}
コード例 #10
0
ファイル: CMathObject.cpp プロジェクト: jonasfoe/COPASI
bool CMathObject::createExtensiveReactionRateExpression(const CMetab * pSpecies,
    CMathContainer & container)
{
  bool success = true;

  std::ostringstream Infix;
  Infix.imbue(std::locale::classic());
  Infix.precision(16);

  std::string Key = pSpecies->getKey();
  bool First = true;

  CCopasiVectorN< CReaction >::const_iterator it = container.getModel().getReactions().begin();
  CCopasiVectorN< CReaction >::const_iterator end = container.getModel().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() == Key)
          break;

      if (itChem != endChem)
        {
          const C_FLOAT64 & Multiplicity = itChem->getMultiplicity();

          if (First || Multiplicity < 0.0)
            {
              if (Multiplicity == std::numeric_limits< C_FLOAT64 >::infinity())
                {
                  Infix << "infinity";
                }
              else if (Multiplicity == -std::numeric_limits< C_FLOAT64 >::infinity())
                {
                  Infix << "-infinity";
                }
              else
                {
                  Infix << Multiplicity;
                }
            }
          else
            {
              if (Multiplicity == std::numeric_limits< C_FLOAT64 >::infinity())
                {
                  Infix << "+infinity";
                }
              else
                {
                  Infix << "+" << Multiplicity;
                }
            }

          First = false;

          Infix << "*";
          Infix << pointerToString(container.getMathObject(it->getParticleFluxReference())->getValuePointer());
        }
    }

  CExpression E("ExtensiveReactionExpression", &container);

  success &= E.setInfix(Infix.str());

  pdelete(mpExpression);
  mpExpression = new CMathExpression(E, container, !mIsInitialValue);
  compileExpression();

  return success;
}
コード例 #11
0
ファイル: CMathObject.cpp プロジェクト: jonasfoe/COPASI
bool CMathObject::compileTransitionTime(CMathContainer & container)
{
  bool success = true;

  // The default value is NaN
  *mpValue = InvalidValue;

  // Reset the prerequisites
  mPrerequisites.clear();

  const CMetab * pSpecies = static_cast< const CMetab *>(mpDataObject->getObjectParent());

  std::ostringstream Infix;
  Infix.imbue(std::locale::classic());
  Infix.precision(16);

  switch (pSpecies->getStatus())
    {
      case CModelEntity::ODE:
        // mTT = *mpValue / fabs(mRate);
        Infix << "abs(";
        Infix << pointerToString(container.getMathObject(pSpecies->getValueReference())->getValuePointer());
        Infix << "/";
        Infix << pointerToString(container.getMathObject(pSpecies->getRateReference())->getValuePointer());
        Infix << ")";
        break;

      case CModelEntity::REACTIONS:
      {
        std::ostringstream PositiveFlux;
        PositiveFlux.imbue(std::locale::classic());
        PositiveFlux.precision(16);

        std::ostringstream NegativeFlux;
        NegativeFlux.imbue(std::locale::classic());
        NegativeFlux.precision(16);

        std::string Key = pSpecies->getKey();
        bool First = true;

        CCopasiVectorN< CReaction >::const_iterator it = container.getModel().getReactions().begin();
        CCopasiVectorN< CReaction >::const_iterator end = container.getModel().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() == Key)
                break;

            if (itChem != endChem)
              {
                const C_FLOAT64 & Multiplicity = itChem->getMultiplicity();

                if (!First)
                  {
                    PositiveFlux << "+";
                    NegativeFlux << "+";
                  }

                PositiveFlux << "max(";
                NegativeFlux << "min(";

                if (Multiplicity == std::numeric_limits< C_FLOAT64 >::infinity())
                  {
                    PositiveFlux << "infinity";
                    NegativeFlux << "infinity";
                  }
                else if (Multiplicity == -std::numeric_limits< C_FLOAT64 >::infinity())
                  {
                    PositiveFlux << "-infinity";
                    NegativeFlux << "-infinity";
                  }
                else
                  {
                    PositiveFlux << Multiplicity;
                    NegativeFlux << Multiplicity;
                  }

                PositiveFlux << "*";
                NegativeFlux << "*";
                PositiveFlux << pointerToString(container.getMathObject(it->getParticleFluxReference())->getValuePointer());
                NegativeFlux << pointerToString(container.getMathObject(it->getParticleFluxReference())->getValuePointer());

                PositiveFlux << ",0)";
                NegativeFlux << ",0)";

                First = false;
              }
          }

        if (!First)
          {
            Infix << "abs(";
            Infix << pointerToString(container.getMathObject(pSpecies->getValueReference())->getValuePointer());
            Infix << ")/if(";
            Infix << pointerToString(container.getMathObject(pSpecies->getRateReference())->getValuePointer());
            Infix << "<0,-(" << NegativeFlux.str() << ")," << PositiveFlux.str() << ")";
          }
      }
      break;

      default:
        break;
    }

  CExpression E("TransitionTimeExpression", &container);

  success &= E.setInfix(Infix.str());

  pdelete(mpExpression);
  mpExpression = new CMathExpression(E, container, false);
  compileExpression();

  return success;
}