diff --git a/.gitignore b/.gitignore index aec89043f..e4f4a7226 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ /cmake-build* /build* /.idea/ +/nfsim/ diff --git a/NFsim_v1.11/src/NFcore/reactionClass.cpp b/NFsim_v1.11/src/NFcore/reactionClass.cpp index 5d6c3689e..f0ea74764 100644 --- a/NFsim_v1.11/src/NFcore/reactionClass.cpp +++ b/NFsim_v1.11/src/NFcore/reactionClass.cpp @@ -455,7 +455,46 @@ void ReactionClass::fire(double random_A_number) { } } - // If we're handling observables on the fly, tell each molecule to add itself to observables. + for ( complexIter = productComplexes.begin(); complexIter != productComplexes.end(); ++complexIter ) { + // update all species observables for this complex + Complex* c = *complexIter; + set complexMoleculeNames; + list ::iterator itm; + for( itm = c->complexMembers.begin(); itm != c->complexMembers.end(); itm++ ) + { + string moleculeName = (*itm)->getMoleculeTypeName(); + complexMoleculeNames.insert(moleculeName); + } + + // see if any product pattern is satisfied by this complex + list> listOfProductSets = this->transformationSet->getProductSets(); + list>::iterator it; + bool matchingSetFound = false; + for (it=listOfProductSets.begin(); it != listOfProductSets.end(); it++) { + set productMoleculeNames = *it; + set::iterator it; + bool setNamesFound = true; + for (it=productMoleculeNames.begin(); it != productMoleculeNames.end(); it++) { + string moleculeName = *it; + if ( complexMoleculeNames.find(moleculeName) == complexMoleculeNames.end() ) { + setNamesFound = false; + break; // a molecule in this product pattern is not in the complex + } + } + if(setNamesFound == true) { + matchingSetFound = true; // all molecules in the product pattern found in the complex + break; // look no more + } + } + complexMoleculeNames.clear(); +// cout< addmol_templates; - // Read in the Reactant Patterns for this rule TiXmlElement *pListOfReactantPatterns = pRxnRule->FirstChildElement("ListOfReactantPatterns"); if(!pListOfReactantPatterns) { @@ -1149,7 +1148,51 @@ bool NFinput::initReactionRules( // cout << (*it).first << " => " << (*it).second->getMoleculeType()->getName() << endl; - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // Read in the Product Patterns for this rule + list > listOfProductSets; + TiXmlElement *pListOfProductPatterns = pRxnRule->FirstChildElement("ListOfProductPatterns"); + if(pListOfProductPatterns != nullptr) { + TiXmlElement *pProduct; + for ( pProduct = pListOfProductPatterns->FirstChildElement("ProductPattern"); pProduct != 0; pProduct = pProduct->NextSiblingElement("ProductPattern")) + { + const char *productName = pProduct->Attribute("id"); + if(!productName) { + continue; + } + TiXmlElement *pListOfMols = pProduct->FirstChildElement("ListOfMolecules"); + if(!pListOfMols) { + continue; + } + TiXmlElement *pMol; + set moleculeNames; + for ( pMol = pListOfMols->FirstChildElement("Molecule"); pMol != 0; pMol = pMol->NextSiblingElement("Molecule")) + { + string moleculeName; + if(!pMol->Attribute("name")) { + continue; + } + moleculeName = pMol->Attribute("name"); + if(moleculeName=="Trash" || moleculeName=="TRASH" || moleculeName=="trash") { + continue; // we ignore this, may be dealt with elsewhere + } + moleculeNames.insert(moleculeName); + } + listOfProductSets.push_back(moleculeNames); + } + } + +// list >::iterator it; +// for (it=listOfProductSets.begin(); it != listOfProductSets.end(); it++) { +// set moleculeNames = *it; +// set::iterator it; +// for (it=moleculeNames.begin(); it != moleculeNames.end(); it++) { +// string moleculeName = *it; +// cout<FirstChildElement("ListOfOperations"); if ( !pListOfOperations ) @@ -1364,6 +1407,8 @@ bool NFinput::initReactionRules( ts->setSymmetryFactor(symmetryFactor); } + ts->addProductSets(listOfProductSets); + //Next extract out the state changes TiXmlElement *pStateChange; diff --git a/NFsim_v1.11/src/NFreactions/transformations/transformationSet.cpp b/NFsim_v1.11/src/NFreactions/transformations/transformationSet.cpp index fe2b4bdd5..ee6de8db7 100644 --- a/NFsim_v1.11/src/NFreactions/transformations/transformationSet.cpp +++ b/NFsim_v1.11/src/NFreactions/transformations/transformationSet.cpp @@ -174,6 +174,11 @@ bool TransformationSet::addLocalFunctionReference(TemplateMolecule *t, string Po return true; } +bool TransformationSet::addProductSets(list> &productSets) { + this->productSets = productSets; + return true; +} + bool TransformationSet::addIncrementStateTransform(TemplateMolecule *t, string cName) { diff --git a/NFsim_v1.11/src/NFreactions/transformations/transformationSet.hh b/NFsim_v1.11/src/NFreactions/transformations/transformationSet.hh index 4bad0022a..5845de9da 100644 --- a/NFsim_v1.11/src/NFreactions/transformations/transformationSet.hh +++ b/NFsim_v1.11/src/NFreactions/transformations/transformationSet.hh @@ -161,7 +161,13 @@ namespace NFcore */ bool addLocalFunctionReference(TemplateMolecule *t, string PointerName, int scope); - + /*! + Adds lists of molecule names for each product pattern + Used to crudely verify that a generated complex matches a product pattern + @author Dan Vasilescu + */ + bool addProductSets(list> &productSets); + list> getProductSets() const { return this->productSets; }; /*! Call this (in a ReactionClass) to transform the array of MappingSets (one MappingSet per reactant in the correct position in the array, please!). @@ -323,6 +329,9 @@ namespace NFcore /*! The array of TemplateMolecules that represent the reactants */ TemplateMolecule ** reactants; + /*! names of the molecules in every product pattern of the reaction */ + list> productSets; + /*! The array of TemplateMolecules that represent the added molecules. * Not sure if this will be used. --Justin */ TemplateMolecule ** addmol;