COPASI API  4.16.103
Public Member Functions | Static Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
CChemEqInterface Class Reference

#include <CChemEqInterface.h>

Collaboration diagram for CChemEqInterface:
Collaboration graph
[legend]

Public Member Functions

void addModifier (const std::string &name)
 
 CChemEqInterface (CModel *pModel)
 
void clearModifiers ()
 
bool createNonExistingMetabs ()
 
std::string getChemEqString (bool expanded) const
 
const CCompartmentgetCompartment () const
 
const std::vector< std::string > & getListOfDisplayNames (CFunctionParameter::Role role) const
 
const std::vector< C_FLOAT64 > & getListOfMultiplicities (CFunctionParameter::Role role) const
 
size_t getMolecularity (CFunctionParameter::Role role) const
 
bool getReversibility () const
 
bool isMulticompartment () const
 
std::set< std::pair
< std::string, std::string > > 
listOfNonExistingMetabNames () const
 
std::set< std::string > listOfNonUniqueMetabNames () const
 
bool loadFromChemEq (const CChemEq &ce)
 
void reverse ()
 
bool setChemEqString (const std::string &ces)
 
void setReversibility (bool rev)
 
bool writeToChemEq (CChemEq &ce) const
 
 ~CChemEqInterface ()
 

Static Public Member Functions

static std::string getChemEqString (CModel *model, const CReaction &rea, bool expanded)
 
static bool isValidEq (const std::string &eq)
 
static void setChemEqFromString (CModel *model, CReaction &rea, const std::string &ces)
 

Private Member Functions

void buildDisplayNames ()
 
 CChemEqInterface ()
 
void completeCompartments ()
 

Static Private Member Functions

static std::string writeElement (const std::string &name, C_FLOAT64 mult, bool expanded)
 

Private Attributes

std::vector< std::string > mModifierCompartments
 
std::vector< std::string > mModifierDisplayNames
 
std::vector< C_FLOAT64mModifierMult
 
std::vector< std::string > mModifierNames
 
CModelmpModel
 
std::vector< std::string > mProductCompartments
 
std::vector< std::string > mProductDisplayNames
 
std::vector< C_FLOAT64mProductMult
 
std::vector< std::string > mProductNames
 
bool mReversibility
 
std::vector< std::string > mSubstrateCompartments
 
std::vector< std::string > mSubstrateDisplayNames
 
std::vector< C_FLOAT64mSubstrateMult
 
std::vector< std::string > mSubstrateNames
 

Detailed Description

This class describes a chemical equation based on metabolite names It supports parsing and generating string representations. Note that this class handles only metab names without caring about whether these metabs exist in the model. There is however a method to create the missing metabs.

Definition at line 44 of file CChemEqInterface.h.

Constructor & Destructor Documentation

CChemEqInterface::CChemEqInterface ( )
private

Definition at line 28 of file CChemEqInterface.cpp.

28  :
29  mpModel(NULL),
31  mProductNames(),
34  mProductMult(),
35  mModifierMult(),
42  mReversibility(false)
43 {}
std::vector< std::string > mModifierCompartments
std::vector< C_FLOAT64 > mSubstrateMult
std::vector< std::string > mModifierNames
std::vector< C_FLOAT64 > mModifierMult
std::vector< std::string > mSubstrateDisplayNames
std::vector< C_FLOAT64 > mProductMult
std::vector< std::string > mProductNames
std::vector< std::string > mModifierDisplayNames
std::vector< std::string > mProductDisplayNames
std::vector< std::string > mSubstrateCompartments
std::vector< std::string > mSubstrateNames
std::vector< std::string > mProductCompartments
CChemEqInterface::CChemEqInterface ( CModel pModel)

Definition at line 45 of file CChemEqInterface.cpp.

45  :
46  mpModel(pModel),
48  mProductNames(),
51  mProductMult(),
52  mModifierMult(),
59  mReversibility(false)
60 {}
std::vector< std::string > mModifierCompartments
std::vector< C_FLOAT64 > mSubstrateMult
std::vector< std::string > mModifierNames
std::vector< C_FLOAT64 > mModifierMult
std::vector< std::string > mSubstrateDisplayNames
std::vector< C_FLOAT64 > mProductMult
std::vector< std::string > mProductNames
std::vector< std::string > mModifierDisplayNames
std::vector< std::string > mProductDisplayNames
std::vector< std::string > mSubstrateCompartments
std::vector< std::string > mSubstrateNames
std::vector< std::string > mProductCompartments
CChemEqInterface::~CChemEqInterface ( )

Definition at line 62 of file CChemEqInterface.cpp.

63 {}

Member Function Documentation

void CChemEqInterface::addModifier ( const std::string &  name)

add a modifier to the chemical equation. It is only added if it is not alreay in there.

Definition at line 466 of file CChemEqInterface.cpp.

References mModifierCompartments, mModifierDisplayNames, mModifierMult, mModifierNames, quote(), and CMetabNameInterface::splitDisplayName().

Referenced by CReactionInterface::updateModifiersInChemEq().

467 {
468  std::pair< std::string, std::string > Modifier =
470 
471  //is the name already in the list
472  std::vector< std::string >::const_iterator it, itEnd = mModifierNames.end();
473  std::vector< std::string >::const_iterator itComp = mModifierCompartments.begin();
474 
475  for (it = mModifierNames.begin(); it != itEnd; ++it, ++itComp)
476  if (Modifier.first == *it &&
477  Modifier.second == *itComp) break;
478 
479  if (it == itEnd)
480  {
481  mModifierNames.push_back(Modifier.first);
482  mModifierMult.push_back(1.0);
483  mModifierCompartments.push_back(Modifier.second);
484  mModifierDisplayNames.push_back(quote(name));
485  }
486 }
std::vector< std::string > mModifierCompartments
std::vector< std::string > mModifierNames
std::vector< C_FLOAT64 > mModifierMult
std::string quote(const std::string &name, const std::string &additionalEscapes)
Definition: utility.cpp:144
static std::pair< std::string, std::string > splitDisplayName(const std::string &name)
char name[1]
Definition: stdsoap2.h:1342
std::vector< std::string > mModifierDisplayNames
void CChemEqInterface::buildDisplayNames ( )
private

Definition at line 356 of file CChemEqInterface.cpp.

References CMetabNameInterface::getDisplayName(), mModifierCompartments, mModifierDisplayNames, mModifierNames, mpModel, mProductCompartments, mProductDisplayNames, mProductNames, mSubstrateCompartments, mSubstrateDisplayNames, and mSubstrateNames.

Referenced by createNonExistingMetabs(), loadFromChemEq(), and setChemEqString().

357 {
358  std::vector< std::string >::const_iterator itName, itCompartment;
359  std::vector< std::string >::iterator it, end;
360 
361  // We need to build the list of display names for the substrates;
363 
364  for (itName = mSubstrateNames.begin(),
365  itCompartment = mSubstrateCompartments.begin(),
366  it = mSubstrateDisplayNames.begin(),
367  end = mSubstrateDisplayNames.end();
368  it != end;
369  ++itName, ++itCompartment, ++it)
370  *it = CMetabNameInterface::getDisplayName(mpModel, *itName, *itCompartment, true);
371 
372  // We need to build the list of display names for the products;
373  mProductDisplayNames.resize(mProductNames.size());
374 
375  for (itName = mProductNames.begin(),
376  itCompartment = mProductCompartments.begin(),
377  it = mProductDisplayNames.begin(),
378  end = mProductDisplayNames.end();
379  it != end;
380  ++itName, ++itCompartment, ++it)
381  *it = CMetabNameInterface::getDisplayName(mpModel, *itName, *itCompartment, true);
382 
383  // We need to build the list of display names for the modifiers;
384  mModifierDisplayNames.resize(mModifierNames.size());
385 
386  for (itName = mModifierNames.begin(),
387  itCompartment = mModifierCompartments.begin(),
388  it = mModifierDisplayNames.begin(),
389  end = mModifierDisplayNames.end();
390  it != end;
391  ++itName, ++itCompartment, ++it)
392  *it = CMetabNameInterface::getDisplayName(mpModel, *itName, *itCompartment, true);
393 
394  return;
395 }
std::vector< std::string > mModifierCompartments
std::vector< std::string > mModifierNames
static std::string getDisplayName(const CModel *model, const std::string &key, const bool &quoted)
std::vector< std::string > mSubstrateDisplayNames
std::vector< std::string > mProductNames
std::vector< std::string > mModifierDisplayNames
std::vector< std::string > mProductDisplayNames
std::vector< std::string > mSubstrateCompartments
std::vector< std::string > mSubstrateNames
std::vector< std::string > mProductCompartments
void CChemEqInterface::clearModifiers ( )

Definition at line 488 of file CChemEqInterface.cpp.

References mModifierCompartments, mModifierDisplayNames, mModifierMult, and mModifierNames.

Referenced by CReactionInterface::updateModifiersInChemEq().

489 {
490  mModifierNames.clear();
491  mModifierMult.clear();
492  mModifierCompartments.clear();
493  mModifierDisplayNames.clear();
494 }
std::vector< std::string > mModifierCompartments
std::vector< std::string > mModifierNames
std::vector< C_FLOAT64 > mModifierMult
std::vector< std::string > mModifierDisplayNames
void CChemEqInterface::completeCompartments ( )
private

Definition at line 141 of file CChemEqInterface.cpp.

References CMetab::getCompartment(), CModel::getCompartments(), CMetabNameInterface::getMetabolite(), CCopasiObject::getObjectName(), CMetabNameInterface::isUnique(), mModifierCompartments, mModifierNames, mpModel, mProductCompartments, mProductNames, mSubstrateCompartments, mSubstrateNames, and CCopasiVector< T >::size().

Referenced by setChemEqString().

142 {
143  std::string DefaultCompartment;
144 
145  if (mpModel->getCompartments().size() == 0)
146  DefaultCompartment = "compartment";
147  else
148  DefaultCompartment = mpModel->getCompartments()[0]->getObjectName();
149 
150  // We try to find a reaction compartment. Note, it is not possible to use
151  // getCompartment as writeToChemEq may fail;
152  std::string ReactionCompartment = "";
153  bool first = true;
154  bool HaveReactionCompartment = true;
155 
156  std::vector< std::string >::iterator itCompartment, endCompartment;
157 
158  itCompartment = mSubstrateCompartments.begin();
159  endCompartment = mSubstrateCompartments.end();
160 
161  for (; itCompartment != endCompartment && HaveReactionCompartment; ++itCompartment)
162  {
163  if (*itCompartment == "") continue;
164 
165  if (first)
166  {
167  ReactionCompartment = *itCompartment;
168  first = false;
169  }
170  else if (ReactionCompartment != *itCompartment)
171  HaveReactionCompartment = false;
172  }
173 
174  itCompartment = mProductCompartments.begin();
175  endCompartment = mProductCompartments.end();
176 
177  for (; itCompartment != endCompartment && HaveReactionCompartment; ++itCompartment)
178  {
179  if (*itCompartment == "") continue;
180 
181  if (first)
182  {
183  ReactionCompartment = *itCompartment;
184  first = false;
185  }
186  else if (ReactionCompartment != *itCompartment)
187  HaveReactionCompartment = false;
188  }
189 
190  itCompartment = mModifierCompartments.begin();
191  endCompartment = mModifierCompartments.end();
192 
193  for (; itCompartment != endCompartment && HaveReactionCompartment; ++itCompartment)
194  {
195  if (*itCompartment == "") continue;
196 
197  if (first)
198  {
199  ReactionCompartment = *itCompartment;
200  first = false;
201  }
202  else if (ReactionCompartment != *itCompartment)
203  HaveReactionCompartment = false;
204  }
205 
206  if (first)
207  ReactionCompartment = DefaultCompartment;
208 
209  CMetab * pMetab;
210 
211  std::vector< std::string >::iterator itMetab;
212 
213  itMetab = mSubstrateNames.begin();
214  itCompartment = mSubstrateCompartments.begin();
215  endCompartment = mSubstrateCompartments.end();
216 
217  for (; itCompartment != endCompartment; ++itCompartment, ++itMetab)
218  if (*itCompartment == "")
219  {
220  pMetab = CMetabNameInterface::getMetabolite(mpModel, *itMetab, "");
221 
222  if (pMetab == NULL)
223  *itCompartment = ReactionCompartment;
224  else if (CMetabNameInterface::isUnique(mpModel, *itMetab))
225  *itCompartment = pMetab->getCompartment()->getObjectName();
226  else // Multiple metabolites with the given name exist.
227  {
228  // 1. Metabolite in the reaction compartment
229  pMetab = CMetabNameInterface::getMetabolite(mpModel, *itMetab, ReactionCompartment);
230 
231  // 2. Metabolite in the default compartment if different from reaction compartment
232  if (pMetab == NULL && ReactionCompartment != DefaultCompartment)
233  pMetab = CMetabNameInterface::getMetabolite(mpModel, *itMetab, DefaultCompartment);
234 
235  // 3. The first metabolite found
236  if (pMetab == NULL)
237  pMetab = CMetabNameInterface::getMetabolite(mpModel, *itMetab, "");
238 
239  *itCompartment = pMetab->getCompartment()->getObjectName();
240  }
241  }
242 
243  itMetab = mProductNames.begin();
244  itCompartment = mProductCompartments.begin();
245  endCompartment = mProductCompartments.end();
246 
247  for (; itCompartment != endCompartment; ++itCompartment, ++itMetab)
248  if (*itCompartment == "")
249  {
250  pMetab = CMetabNameInterface::getMetabolite(mpModel, *itMetab, "");
251 
252  if (pMetab == NULL)
253  *itCompartment = ReactionCompartment;
254  else if (CMetabNameInterface::isUnique(mpModel, *itMetab))
255  *itCompartment = pMetab->getCompartment()->getObjectName();
256  else // Multiple metabolites with the given name exist.
257  {
258  // 1. Metabolite in the reaction compartment
259  pMetab = CMetabNameInterface::getMetabolite(mpModel, *itMetab, ReactionCompartment);
260 
261  // 2. Metabolite in the default compartment if different from reaction compartment
262  if (pMetab == NULL && ReactionCompartment != DefaultCompartment)
263  pMetab = CMetabNameInterface::getMetabolite(mpModel, *itMetab, DefaultCompartment);
264 
265  // 3. The first metabolite found
266  if (pMetab == NULL)
267  pMetab = CMetabNameInterface::getMetabolite(mpModel, *itMetab, "");
268 
269  *itCompartment = pMetab->getCompartment()->getObjectName();
270  }
271  }
272 
273  itMetab = mModifierNames.begin();
274  itCompartment = mModifierCompartments.begin();
275  endCompartment = mModifierCompartments.end();
276 
277  for (; itCompartment != endCompartment; ++itCompartment, ++itMetab)
278  if (*itCompartment == "")
279  {
280  pMetab = CMetabNameInterface::getMetabolite(mpModel, *itMetab, "");
281 
282  if (pMetab == NULL)
283  *itCompartment = ReactionCompartment;
284  else if (CMetabNameInterface::isUnique(mpModel, *itMetab))
285  *itCompartment = pMetab->getCompartment()->getObjectName();
286  else // Multiple metabolites with the given name exist.
287  {
288  // 1. Metabolite in the reaction compartment
289  pMetab = CMetabNameInterface::getMetabolite(mpModel, *itMetab, ReactionCompartment);
290 
291  // 2. Metabolite in the default compartment if different from reaction compartment
292  if (pMetab == NULL && ReactionCompartment != DefaultCompartment)
293  pMetab = CMetabNameInterface::getMetabolite(mpModel, *itMetab, DefaultCompartment);
294 
295  // 3. The first metabolite found
296  if (pMetab == NULL)
297  pMetab = CMetabNameInterface::getMetabolite(mpModel, *itMetab, "");
298 
299  *itCompartment = pMetab->getCompartment()->getObjectName();
300  }
301  }
302 }
std::vector< std::string > mModifierCompartments
const std::string & getObjectName() const
static CMetab * getMetabolite(const CModel *model, const std::string &metabolite, const std::string &compartment)
virtual size_t size() const
std::vector< std::string > mModifierNames
Definition: CMetab.h:178
std::vector< std::string > mProductNames
CCopasiVectorNS< CCompartment > & getCompartments()
Definition: CModel.cpp:1145
static bool isUnique(const CModel *model, const std::string &name)
const CCompartment * getCompartment() const
Definition: CMetab.cpp:222
std::vector< std::string > mSubstrateCompartments
std::vector< std::string > mSubstrateNames
std::vector< std::string > mProductCompartments
bool CChemEqInterface::createNonExistingMetabs ( )

Definition at line 649 of file CChemEqInterface.cpp.

References buildDisplayNames(), C_INVALID_INDEX, CModel::createCompartment(), CModel::createMetabolite(), CModel::getCompartments(), CCopasiVectorN< CType >::getIndex(), listOfNonExistingMetabNames(), mpModel, and CModelEntity::REACTIONS.

Referenced by CReactionInterface::createMetabolites().

650 {
651  std::set< std::pair< std::string, std::string > > metabs = listOfNonExistingMetabNames();
652  bool ret;
653  if (metabs.size() == 0) ret = false; else ret = true;
654 
655  std::set< std::pair< std::string, std::string > >::const_iterator it, itEnd;
656 
657  itEnd = metabs.end();
658 
659  for (it = metabs.begin(); it != itEnd; ++it)
660  {
661  if (mpModel->getCompartments().getIndex(it->second) == C_INVALID_INDEX)
662  mpModel->createCompartment(it->second, 1);
663 
664  mpModel->createMetabolite(it->first,
665  it->second,
667  }
668 
669  // Due to the creation of metabolites the display names may have changed.
671 
672  return ret;
673 }
#define C_INVALID_INDEX
Definition: copasi.h:222
virtual size_t getIndex(const std::string &name) const
CCopasiVectorNS< CCompartment > & getCompartments()
Definition: CModel.cpp:1145
std::set< std::pair< std::string, std::string > > listOfNonExistingMetabNames() const
CCompartment * createCompartment(const std::string &name, const C_FLOAT64 &volume=1.0)
Definition: CModel.cpp:2698
CMetab * createMetabolite(const std::string &name, const std::string &compartment, const C_FLOAT64 &iconc=1.0, const CModelEntity::Status &status=CModelEntity::REACTIONS)
Definition: CModel.cpp:2622
std::string CChemEqInterface::getChemEqString ( bool  expanded) const

Definition at line 65 of file CChemEqInterface.cpp.

References mModifierDisplayNames, mModifierNames, mProductDisplayNames, mProductMult, mProductNames, mReversibility, mSubstrateDisplayNames, mSubstrateMult, mSubstrateNames, and writeElement().

Referenced by CQReactionDM::data(), CQMergingData::fillTree(), CReactionInterface::getChemEqString(), getChemEqString(), CEFMTask::getReactionEquation(), StateSubwidget::loadReactions(), and CQSpeciesDetail::loadReactionTable().

66 {
67  std::string ChemicalEquation;
68  size_t j;
69 
70  if ((mSubstrateNames.size() == 0) && (mProductNames.size() == 0) && (mModifierNames.size() == 0))
71  return "";
72 
73  for (j = 0; j < mSubstrateNames.size(); j++)
74  {
75  if (j)
76  ChemicalEquation += " + ";
77 
78  ChemicalEquation += writeElement(mSubstrateDisplayNames[j], mSubstrateMult[j], expanded);
79  }
80 
81  if (mReversibility)
82  ChemicalEquation += " = ";
83  else
84  ChemicalEquation += " -> ";
85 
86  for (j = 0; j < mProductNames.size(); j++)
87  {
88  if (j)
89  ChemicalEquation += " + ";
90 
91  ChemicalEquation += writeElement(mProductDisplayNames[j], mProductMult[j], expanded);
92  }
93 
94  if (mModifierNames.size())
95  {
96  ChemicalEquation += "; ";
97 
98  for (j = 0; j < mModifierNames.size(); j++)
99  {
100  ChemicalEquation += " ";
101 
102  ChemicalEquation += mModifierDisplayNames[j];
103  }
104  }
105 
106  return ChemicalEquation;
107 }
std::vector< C_FLOAT64 > mSubstrateMult
std::vector< std::string > mModifierNames
std::vector< std::string > mSubstrateDisplayNames
std::vector< C_FLOAT64 > mProductMult
std::vector< std::string > mProductNames
static std::string writeElement(const std::string &name, C_FLOAT64 mult, bool expanded)
std::vector< std::string > mModifierDisplayNames
std::vector< std::string > mProductDisplayNames
std::vector< std::string > mSubstrateNames
std::string CChemEqInterface::getChemEqString ( CModel model,
const CReaction rea,
bool  expanded 
)
static

Definition at line 740 of file CChemEqInterface.cpp.

References CReaction::getChemEq(), getChemEqString(), and loadFromChemEq().

741 {
742  CChemEqInterface cei(model);
743  cei.loadFromChemEq(rea.getChemEq());
744  return cei.getChemEqString(expanded);
745 }
const CChemEq & getChemEq() const
Definition: CReaction.cpp:223
const CCompartment * CChemEqInterface::getCompartment ( ) const

convenience method. If the reaction is single compartment the compartment is returned, else NULL.

Definition at line 716 of file CChemEqInterface.cpp.

References CMetab::getCompartment(), CChemEq::getCompartmentNumber(), CChemEq::getProducts(), CChemEq::getSubstrates(), CCopasiVector< T >::size(), and writeToChemEq().

Referenced by CReactionInterface::connectNonMetabolites(), and CQCompartment::copy().

717 {
718  CChemEq ce;
719  writeToChemEq(ce);
720 
721  if (ce.getCompartmentNumber() > 1)
722  return NULL;
723  else
724  {
725  const CMetab * metab = NULL;
726 
727  if (ce.getSubstrates().size())
728  metab = ce.getSubstrates()[0]->getMetabolite();
729  else if (ce.getProducts().size())
730  metab = ce.getProducts()[0]->getMetabolite();
731 
732  if (metab)
733  return metab->getCompartment();
734  else
735  return NULL;
736  }
737 }
size_t getCompartmentNumber() const
Definition: CChemEq.cpp:110
virtual size_t size() const
Definition: CMetab.h:178
const CCopasiVector< CChemEqElement > & getProducts() const
Definition: CChemEq.cpp:63
const CCopasiVector< CChemEqElement > & getSubstrates() const
Definition: CChemEq.cpp:60
bool writeToChemEq(CChemEq &ce) const
const CCompartment * getCompartment() const
Definition: CMetab.cpp:222
const std::vector< std::string > & CChemEqInterface::getListOfDisplayNames ( CFunctionParameter::Role  role) const
const std::vector< C_FLOAT64 > & CChemEqInterface::getListOfMultiplicities ( CFunctionParameter::Role  role) const

Definition at line 446 of file CChemEqInterface.cpp.

References fatalError, mModifierMult, CFunctionParameter::MODIFIER, mProductMult, mSubstrateMult, CFunctionParameter::PRODUCT, and CFunctionParameter::SUBSTRATE.

Referenced by CReactionInterface::getExpandedMetabList().

447 {
448  if (role == CFunctionParameter::SUBSTRATE) return mSubstrateMult;
449  else if (role == CFunctionParameter::PRODUCT) return mProductMult;
450  else if (role == CFunctionParameter::MODIFIER) return mModifierMult;
451  else fatalError();
452 
453  return mSubstrateMult; //never reached
454 }
std::vector< C_FLOAT64 > mSubstrateMult
#define fatalError()
std::vector< C_FLOAT64 > mModifierMult
std::vector< C_FLOAT64 > mProductMult
size_t CChemEqInterface::getMolecularity ( CFunctionParameter::Role  role) const

Definition at line 537 of file CChemEqInterface.cpp.

References C_INVALID_INDEX, fatalError, mModifierMult, CFunctionParameter::MODIFIER, mProductMult, mSubstrateMult, CFunctionParameter::PRODUCT, and CFunctionParameter::SUBSTRATE.

Referenced by CReactionInterface::getListOfPossibleFunctions(), and ParameterTable::updateTable().

538 {
539  const std::vector<C_FLOAT64> * tmpVector = NULL;
540 
541  if (role == CFunctionParameter::SUBSTRATE)
542  tmpVector = &mSubstrateMult;
543  else if (role == CFunctionParameter::PRODUCT)
544  tmpVector = &mProductMult;
545  else if (role == CFunctionParameter::MODIFIER)
546  tmpVector = &mModifierMult;
547  else fatalError();
548 
549  size_t ccc, i, imax = tmpVector->size();
550  ccc = 0;
551 
552  for (i = 0; i < imax; ++i)
553  {
554  if ((*tmpVector)[i] != floor((*tmpVector)[i] + 0.5))
555  return C_INVALID_INDEX;
556 
557  ccc += (size_t) floor((*tmpVector)[i]);
558  }
559 
560  return ccc;
561 }
std::vector< C_FLOAT64 > mSubstrateMult
#define fatalError()
#define C_INVALID_INDEX
Definition: copasi.h:222
std::vector< C_FLOAT64 > mModifierMult
std::vector< C_FLOAT64 > mProductMult
bool CChemEqInterface::getReversibility ( ) const
inline
bool CChemEqInterface::isMulticompartment ( ) const

this method tries to find out if the chemical equation involves several compartments in a given model. It only takes into account the metabs that actually exist in the model. A non existing metabolite is assumed not to be in a different compartment

Definition at line 675 of file CChemEqInterface.cpp.

References mModifierCompartments, mProductCompartments, and mSubstrateCompartments.

Referenced by CReactionInterface::isMulticompartment().

676 {
677  bool Initialize = true;
678  std::string Compartment = "";
679 
680  std::vector< std::string >::const_iterator it;
681  std::vector< std::string >::const_iterator end;
682 
683  for (it = mSubstrateCompartments.begin(), end = mSubstrateCompartments.end();
684  it != end; ++it)
685  if (Initialize)
686  {
687  Compartment = *it;
688  Initialize = false;
689  }
690  else if (Compartment != *it)
691  return true;
692 
693  for (it = mProductCompartments.begin(), end = mProductCompartments.end();
694  it != end; ++it)
695  if (Initialize)
696  {
697  Compartment = *it;
698  Initialize = false;
699  }
700  else if (Compartment != *it)
701  return true;
702 
703  for (it = mModifierCompartments.begin(), end = mModifierCompartments.end();
704  it != end; ++it)
705  if (Initialize)
706  {
707  Compartment = *it;
708  Initialize = false;
709  }
710  else if (Compartment != *it)
711  return true;
712 
713  return false;
714 }
std::vector< std::string > mModifierCompartments
std::vector< std::string > mSubstrateCompartments
std::vector< std::string > mProductCompartments
bool CChemEqInterface::isValidEq ( const std::string &  eq)
static

Definition at line 756 of file CChemEqInterface.cpp.

References CChemEqParserBase::yyparse().

Referenced by CQReactionDM::setEquation(), ReactionsWidget1::slotLineEditChanged(), and ChemEqValidator::validate().

757 {
758  if (eq.empty()) return false;
759 
760  // parse the description into a linked node tree
761  std::istringstream buffer(eq);
762  CChemEqParser Parser(&buffer);
763 
764  return (Parser.yyparse() == 0);
765 }
std::set< std::pair< std::string, std::string > > CChemEqInterface::listOfNonExistingMetabNames ( ) const

Definition at line 609 of file CChemEqInterface.cpp.

References CMetabNameInterface::doesExist(), mModifierCompartments, mModifierNames, mpModel, mProductCompartments, mProductNames, mSubstrateCompartments, and mSubstrateNames.

Referenced by createNonExistingMetabs().

610 {
611  std::set< std::pair< std::string, std::string > > ret;
612  std::pair< std::string, std::string > Insert;
613 
614  std::vector<std::string>::const_iterator it, itComp, itEnd;
615 
616  itEnd = mSubstrateNames.end();
617 
618  for (it = mSubstrateNames.begin(), itComp = mSubstrateCompartments.begin(); it != itEnd; ++it, ++itComp)
619  if (!CMetabNameInterface::doesExist(mpModel, *it, *itComp))
620  {
621  Insert.first = *it;
622  Insert.second = *itComp;
623  ret.insert(Insert);
624  }
625 
626  itEnd = mProductNames.end();
627 
628  for (it = mProductNames.begin(), itComp = mProductCompartments.begin(); it != itEnd; ++it, ++itComp)
629  if (!CMetabNameInterface::doesExist(mpModel, *it, *itComp))
630  {
631  Insert.first = *it;
632  Insert.second = *itComp;
633  ret.insert(Insert);
634  }
635 
636  itEnd = mModifierNames.end();
637 
638  for (it = mModifierNames.begin(), itComp = mModifierCompartments.begin(); it != itEnd; ++it, ++itComp)
639  if (!CMetabNameInterface::doesExist(mpModel, *it, *itComp))
640  {
641  Insert.first = *it;
642  Insert.second = *itComp;
643  ret.insert(Insert);
644  }
645 
646  return ret;
647 }
std::vector< std::string > mModifierCompartments
std::vector< std::string > mModifierNames
std::vector< std::string > mProductNames
static bool doesExist(const CModel *model, const std::string &metabolite, const std::string &compartment)
std::vector< std::string > mSubstrateCompartments
std::vector< std::string > mSubstrateNames
std::vector< std::string > mProductCompartments
std::set< std::string > CChemEqInterface::listOfNonUniqueMetabNames ( ) const

Definition at line 582 of file CChemEqInterface.cpp.

References CMetabNameInterface::isUnique(), mModifierNames, mpModel, mProductNames, and mSubstrateNames.

583 {
584  std::set<std::string> ret;
585 
586  std::vector<std::string>::const_iterator it, itEnd;
587 
588  itEnd = mSubstrateNames.end();
589 
590  for (it = mSubstrateNames.begin(); it != itEnd; ++it)
592  ret.insert(*it);
593 
594  itEnd = mProductNames.end();
595 
596  for (it = mProductNames.begin(); it != itEnd; ++it)
598  ret.insert(*it);
599 
600  itEnd = mModifierNames.end();
601 
602  for (it = mModifierNames.begin(); it != itEnd; ++it)
604  ret.insert(*it);
605 
606  return ret;
607 }
std::vector< std::string > mModifierNames
std::vector< std::string > mProductNames
static bool isUnique(const CModel *model, const std::string &name)
std::vector< std::string > mSubstrateNames
bool CChemEqInterface::loadFromChemEq ( const CChemEq ce)

Definition at line 304 of file CChemEqInterface.cpp.

References buildDisplayNames(), CChemEq::getModifiers(), CChemEq::getProducts(), CChemEq::getReversibility(), CChemEq::getSubstrates(), mModifierCompartments, mModifierMult, mModifierNames, mProductCompartments, mProductMult, mProductNames, mReversibility, mSubstrateCompartments, mSubstrateMult, mSubstrateNames, and CCopasiVector< T >::size().

Referenced by getChemEqString(), and CReactionInterface::initFromReaction().

305 {
306  bool ret = true;
307  const CCopasiVector<CChemEqElement> * elements;
308  size_t i, imax;
309 
310  elements = &ce.getSubstrates();
311  imax = elements->size();
312  mSubstrateNames.resize(imax);
313  mSubstrateMult.resize(imax);
314  mSubstrateCompartments.resize(imax);
315 
316  for (i = 0; i < imax; ++i)
317  {
318  mSubstrateNames[i] = (*elements)[i]->getMetabolite()->getObjectName();
319  mSubstrateMult[i] = (*elements)[i]->getMultiplicity();
320  mSubstrateCompartments[i] = (*elements)[i]->getMetabolite()->getCompartment()->getObjectName();
321  }
322 
323  elements = &ce.getProducts();
324  imax = elements->size();
325  mProductNames.resize(imax);
326  mProductMult.resize(imax);
327  mProductCompartments.resize(imax);
328 
329  for (i = 0; i < imax; ++i)
330  {
331  mProductNames[i] = (*elements)[i]->getMetabolite()->getObjectName();
332  mProductMult[i] = (*elements)[i]->getMultiplicity();
333  mProductCompartments[i] = (*elements)[i]->getMetabolite()->getCompartment()->getObjectName();
334  }
335 
336  elements = &ce.getModifiers();
337  imax = elements->size();
338  mModifierNames.resize(imax);
339  mModifierMult.resize(imax);
340  mModifierCompartments.resize(imax);
341 
342  for (i = 0; i < imax; ++i)
343  {
344  mModifierNames[i] = (*elements)[i]->getMetabolite()->getObjectName();
345  mModifierMult[i] = (*elements)[i]->getMultiplicity();
346  mModifierCompartments[i] = (*elements)[i]->getMetabolite()->getCompartment()->getObjectName();
347  }
348 
350 
352 
353  return ret;
354 }
std::vector< std::string > mModifierCompartments
virtual size_t size() const
std::vector< C_FLOAT64 > mSubstrateMult
std::vector< std::string > mModifierNames
std::vector< C_FLOAT64 > mModifierMult
const CCopasiVector< CChemEqElement > & getProducts() const
Definition: CChemEq.cpp:63
std::vector< C_FLOAT64 > mProductMult
std::vector< std::string > mProductNames
const bool & getReversibility() const
Definition: CChemEq.cpp:77
const CCopasiVector< CChemEqElement > & getSubstrates() const
Definition: CChemEq.cpp:60
const CCopasiVector< CChemEqElement > & getModifiers() const
Definition: CChemEq.cpp:66
std::vector< std::string > mSubstrateCompartments
std::vector< std::string > mSubstrateNames
std::vector< std::string > mProductCompartments
void CChemEqInterface::reverse ( )

Definition at line 563 of file CChemEqInterface.cpp.

References mProductCompartments, mProductMult, mProductNames, mSubstrateCompartments, mSubstrateMult, and mSubstrateNames.

Referenced by CReactionInterface::reverse().

564 {
565  std::vector<std::string> dummyNames;
566  std::vector<C_FLOAT64> dummyMults;
567  std::vector<std::string> dummyCompartments;
568 
569  dummyNames = mSubstrateNames;
570  dummyMults = mSubstrateMult;
571  dummyCompartments = mSubstrateCompartments;
572 
576 
577  mProductNames = dummyNames;
578  mProductMult = dummyMults;
579  mProductCompartments = dummyCompartments;
580 }
std::vector< C_FLOAT64 > mSubstrateMult
std::vector< C_FLOAT64 > mProductMult
std::vector< std::string > mProductNames
std::vector< std::string > mSubstrateCompartments
std::vector< std::string > mSubstrateNames
std::vector< std::string > mProductCompartments
void CChemEqInterface::setChemEqFromString ( CModel model,
CReaction rea,
const std::string &  ces 
)
static

Definition at line 748 of file CChemEqInterface.cpp.

References CReaction::getChemEq(), setChemEqString(), and writeToChemEq().

Referenced by CReaction::load().

749 {
750  CChemEqInterface cei(model);
751  cei.setChemEqString(ces);
752  cei.writeToChemEq(rea.getChemEq());
753 }
const CChemEq & getChemEq() const
Definition: CReaction.cpp:223
bool CChemEqInterface::setChemEqString ( const std::string &  ces)

Definition at line 109 of file CChemEqInterface.cpp.

References buildDisplayNames(), completeCompartments(), CChemEqParserBase::getModifierCompartments(), CChemEqParserBase::getModifierMulitplicities(), CChemEqParserBase::getModifierNames(), CChemEqParserBase::getProductCompartments(), CChemEqParserBase::getProductMulitplicities(), CChemEqParserBase::getProductNames(), CChemEqParserBase::getSubstrateCompartments(), CChemEqParserBase::getSubstrateMulitplicities(), CChemEqParserBase::getSubstrateNames(), CChemEqParserBase::isReversible(), mModifierCompartments, mModifierMult, mModifierNames, mProductCompartments, mProductMult, mProductNames, mReversibility, mSubstrateCompartments, mSubstrateMult, mSubstrateNames, and CChemEqParserBase::yyparse().

Referenced by setChemEqFromString(), and CReactionInterface::setChemEqString().

110 {
111  // parse the description into a linked node tree
112  std::istringstream buffer(ces);
113  CChemEqParser Parser(&buffer);
114 
115  bool success = (Parser.yyparse() == 0);
116 
117  if (success)
118  {
119  mReversibility = Parser.isReversible();
120 
121  mSubstrateNames = Parser.getSubstrateNames();
122  mSubstrateMult = Parser.getSubstrateMulitplicities();
123  mSubstrateCompartments = Parser.getSubstrateCompartments();
124 
125  mProductNames = Parser.getProductNames();
126  mProductMult = Parser.getProductMulitplicities();
127  mProductCompartments = Parser.getProductCompartments();
128 
129  mModifierNames = Parser.getModifierNames();
130  mModifierMult = Parser.getModifierMulitplicities();
131  mModifierCompartments = Parser.getModifierCompartments();
132  }
133 
135 
137 
138  return success;
139 }
std::vector< std::string > mModifierCompartments
std::vector< C_FLOAT64 > mSubstrateMult
std::vector< std::string > mModifierNames
std::vector< C_FLOAT64 > mModifierMult
std::vector< C_FLOAT64 > mProductMult
std::vector< std::string > mProductNames
std::vector< std::string > mSubstrateCompartments
std::vector< std::string > mSubstrateNames
std::vector< std::string > mProductCompartments
void CChemEqInterface::setReversibility ( bool  rev)
inline

Definition at line 91 of file CChemEqInterface.h.

References mReversibility.

Referenced by CReactionInterface::reverse(), and CReactionInterface::setReversibility().

91 {mReversibility = rev;};
std::string CChemEqInterface::writeElement ( const std::string &  name,
C_FLOAT64  mult,
bool  expanded 
)
staticprivate

Definition at line 496 of file CChemEqInterface.cpp.

References C_INT32, and isNumber().

Referenced by getChemEqString().

497 {
498  std::ostringstream Element;
499  Element.imbue(std::locale::classic());
500  Element.precision(6);
501 
502  std::string Metabolite = name;
503 
504  // The last character must not be a ';' in a reaction.
505  if (Metabolite[Metabolite.length() - 1] == ';')
506  Metabolite = "\"" + Metabolite + "\"";
507 
508  if (isNumber(Metabolite))
509  Metabolite = "\"" + Metabolite + "\"";
510 
511  if (expanded)
512  {
513  C_INT32 i, imax = (C_INT32) mult;
514 
515  for (i = 0; i < imax; ++i)
516  {
517  if (i) Element << " + ";
518 
519  Element << Metabolite;
520  }
521  }
522  else
523  {
524  if (mult == 1.0)
525  {
526  Element << Metabolite;
527  }
528  else
529  {
530  Element << mult << " * " << Metabolite;
531  }
532  }
533 
534  return Element.str();
535 }
bool isNumber(const std::string &str)
Definition: utility.cpp:75
#define C_INT32
Definition: copasi.h:90
char name[1]
Definition: stdsoap2.h:1342
bool CChemEqInterface::writeToChemEq ( CChemEq ce) const

Definition at line 397 of file CChemEqInterface.cpp.

References CChemEq::addMetabolite(), CChemEq::cleanup(), CMetabNameInterface::getMetaboliteKey(), mModifierCompartments, mModifierMult, mModifierNames, CChemEq::MODIFIER, mpModel, mProductCompartments, mProductMult, mProductNames, mReversibility, mSubstrateCompartments, mSubstrateMult, mSubstrateNames, CChemEq::PRODUCT, CChemEq::setReversibility(), and CChemEq::SUBSTRATE.

Referenced by getCompartment(), setChemEqFromString(), and CReactionInterface::writeBackToReaction().

398 {
399  bool ret = true;
400  std::string metabkey;
401  size_t i, imax;
402 
403  ce.cleanup();
404 
405  imax = mSubstrateNames.size();
406 
407  for (i = 0; i < imax; ++i)
408  {
410 
411  if (metabkey.empty())
412  ret = false;
413  else
415  }
416 
417  imax = mProductNames.size();
418 
419  for (i = 0; i < imax; ++i)
420  {
422 
423  if (metabkey.empty())
424  ret = false;
425  else
426  ce.addMetabolite(metabkey, mProductMult[i], CChemEq::PRODUCT);
427  }
428 
429  imax = mModifierNames.size();
430 
431  for (i = 0; i < imax; ++i)
432  {
434 
435  if (metabkey.empty())
436  ret = false;
437  else
439  }
440 
442 
443  return ret; //TODO: really check
444 }
static std::string getMetaboliteKey(const CModel *model, const std::string &metabolite, const std::string &compartment)
std::vector< std::string > mModifierCompartments
std::vector< C_FLOAT64 > mSubstrateMult
std::vector< std::string > mModifierNames
std::vector< C_FLOAT64 > mModifierMult
std::vector< C_FLOAT64 > mProductMult
std::vector< std::string > mProductNames
void cleanup()
Definition: CChemEq.cpp:52
bool addMetabolite(const std::string &key, const C_FLOAT64 multiplicity, const MetaboliteRole &role)
Definition: CChemEq.cpp:80
void setReversibility(const bool &reversible)
Definition: CChemEq.cpp:72
std::vector< std::string > mSubstrateCompartments
std::vector< std::string > mSubstrateNames
std::vector< std::string > mProductCompartments

Member Data Documentation

std::vector< std::string > CChemEqInterface::mModifierCompartments
private
std::vector< std::string > CChemEqInterface::mModifierDisplayNames
private
std::vector< C_FLOAT64 > CChemEqInterface::mModifierMult
private
std::vector< std::string > CChemEqInterface::mModifierNames
private
CModel* CChemEqInterface::mpModel
private
std::vector< std::string > CChemEqInterface::mProductCompartments
private
std::vector< std::string > CChemEqInterface::mProductDisplayNames
private

Definition at line 62 of file CChemEqInterface.h.

Referenced by buildDisplayNames(), getChemEqString(), and getListOfDisplayNames().

std::vector< C_FLOAT64 > CChemEqInterface::mProductMult
private
std::vector< std::string > CChemEqInterface::mProductNames
private
bool CChemEqInterface::mReversibility
private
std::vector< std::string > CChemEqInterface::mSubstrateCompartments
private
std::vector< std::string > CChemEqInterface::mSubstrateDisplayNames
private

Definition at line 61 of file CChemEqInterface.h.

Referenced by buildDisplayNames(), getChemEqString(), and getListOfDisplayNames().

std::vector< C_FLOAT64 > CChemEqInterface::mSubstrateMult
private
std::vector< std::string > CChemEqInterface::mSubstrateNames
private

The documentation for this class was generated from the following files: