void BasicRxnClass::remove(Molecule *m, unsigned int reactantPos) { //First a bit of error checking... if(reactantPos<0 || reactantPos>=n_reactants || m==NULL) { cout<<"Error removing molecule from a reaction!! Invalid molecule or reactant position given. Quitting."<<endl; exit(1); } //Get the specified reactantList ReactantList *rl = reactantLists[reactantPos]; //Check if the molecule is in this list int rxnIndex = m->getMoleculeType()->getRxnIndex(this,reactantPos); bool isInRxn = (m->getRxnListMappingId(rxnIndex)>=0); if(isInRxn) { rl->removeMappingSet(m->getRxnListMappingId(rxnIndex)); m->setRxnListMappingId(rxnIndex,Molecule::NOT_IN_RXN); } }
void DOR2RxnClass::remove(Molecule *m, unsigned int reactantPos) { // removing molecule from a DOR!! if(reactantPos==(unsigned)this->DORreactantIndex1){ // handle the DOR reactant1 int rxnIndex = m->getMoleculeType()->getRxnIndex(this,reactantPos); if(m->getRxnListMappingId(rxnIndex)>=0) { //cout<<"was in the tree, so we should remove"<<endl; reactantTree1->removeMappingSet(m->getRxnListMappingId(rxnIndex)); m->setRxnListMappingId(rxnIndex,Molecule::NOT_IN_RXN); } } else if (reactantPos==(unsigned)this->DORreactantIndex2){ // handle the DOR reactant2 int rxnIndex = m->getMoleculeType()->getRxnIndex(this,reactantPos); if(m->getRxnListMappingId(rxnIndex)>=0) { //cout<<"was in the tree, so we should remove"<<endl; reactantTree2->removeMappingSet(m->getRxnListMappingId(rxnIndex)); m->setRxnListMappingId(rxnIndex,Molecule::NOT_IN_RXN); } } else { // handle it normally... ReactantList *rl = reactantLists[reactantPos]; int rxnIndex = m->getMoleculeType()->getRxnIndex(this,reactantPos); if(m->getRxnListMappingId(rxnIndex)>=0) { rl->removeMappingSet(m->getRxnListMappingId(rxnIndex)); m->setRxnListMappingId(rxnIndex,Molecule::NOT_IN_RXN); } } }
void DORRxnClass::remove(Molecule *m, unsigned int reactantPos) { //cout<<"removing from a DOR!!"<<endl; if(reactantPos==(unsigned)this->DORreactantIndex) { //if(DEBUG_MESSAGE)cout<<" ... as a DOR"<<endl; // handle the DOR reactant int rxnIndex = m->getMoleculeType()->getRxnIndex(this,reactantPos); if(m->getRxnListMappingId(rxnIndex)>=0) { //cout<<"was in the tree, so we should remove"<<endl; reactantTree->removeMappingSet(m->getRxnListMappingId(rxnIndex)); m->setRxnListMappingId(rxnIndex,Molecule::NOT_IN_RXN); } } else { // handle it normally... //if(DEBUG_MESSAGE)cout<<" ... as a normal reactant"<<endl; ReactantList *rl = reactantLists[reactantPos]; int rxnIndex = m->getMoleculeType()->getRxnIndex(this,reactantPos); if(m->getRxnListMappingId(rxnIndex)>=0) { rl->removeMappingSet(m->getRxnListMappingId(rxnIndex)); m->setRxnListMappingId(rxnIndex,Molecule::NOT_IN_RXN); } } //if(DEBUG_MESSAGE)cout<<"finished removing"<<endl; }
bool DOR2RxnClass::tryToAdd(Molecule *m, unsigned int reactantPos) { // adding molecule to DOR2RxnClass //if(DEBUG_MESSAGE)m->printDetails(); if (reactantPos==(unsigned)this->DORreactantIndex1) { // handle the DOR reactant int rxnIndex = m->getMoleculeType()->getRxnIndex(this,reactantPos); if(reactantTree1->getHasClonedMappings()) { if(m->getRxnListMappingId(rxnIndex)>=0) { reactantTree1->removeMappingSet(m->getRxnListMappingId(rxnIndex)); m->setRxnListMappingId(rxnIndex,Molecule::NOT_IN_RXN); } } if(m->getRxnListMappingId(rxnIndex)>=0) { // was in the tree, so checking if we should remove if(!reactantTemplates[reactantPos]->compare(m)) { // removing reactantTree1->removeMappingSet(m->getRxnListMappingId(rxnIndex)); m->setRxnListMappingId(rxnIndex,Molecule::NOT_IN_RXN); } else {} } else { // wasn't in the tree, so trying to push and compare ms=reactantTree1->pushNextAvailableMappingSet(); if(!reactantTemplates[reactantPos]->compare(m,reactantTree1,ms)) { //cout<<"shouldn't be in the tree, so we pop"<<endl; reactantTree1->removeMappingSet(ms->getId()); } else { //we are keeping it, so evaluate the function and confirm the push double localFunctionValue = evaluateLocalFunctions1(ms); //if(DEBUG_MESSAGE)cout<<"local function value is: "<<localFunctionValue<<endl; reactantTree1->confirmPush(ms->getId(),localFunctionValue); m->setRxnListMappingId(rxnIndex,ms->getId()); } } } else if (reactantPos==(unsigned)this->DORreactantIndex2) { // handle the DOR reactant int rxnIndex = m->getMoleculeType()->getRxnIndex(this,reactantPos); if(reactantTree2->getHasClonedMappings()) { if(m->getRxnListMappingId(rxnIndex)>=0) { reactantTree2->removeMappingSet(m->getRxnListMappingId(rxnIndex)); m->setRxnListMappingId(rxnIndex,Molecule::NOT_IN_RXN); } } if(m->getRxnListMappingId(rxnIndex)>=0) { // was in the tree, so checking if we should remove if(!reactantTemplates[reactantPos]->compare(m)) { // removing reactantTree2->removeMappingSet(m->getRxnListMappingId(rxnIndex)); m->setRxnListMappingId(rxnIndex,Molecule::NOT_IN_RXN); } else {} } else { // wasn't in the tree, so trying to push and compare ms=reactantTree2->pushNextAvailableMappingSet(); if(!reactantTemplates[reactantPos]->compare(m,reactantTree2,ms)) { //cout<<"shouldn't be in the tree, so we pop"<<endl; reactantTree2->removeMappingSet(ms->getId()); } else { //we are keeping it, so evaluate the function and confirm the push double localFunctionValue = this->evaluateLocalFunctions2(ms); //if(DEBUG_MESSAGE)cout<<"local function value is: "<<localFunctionValue<<endl; reactantTree2->confirmPush(ms->getId(),localFunctionValue); m->setRxnListMappingId(rxnIndex,ms->getId()); } } } else { //Get the specified reactantList ReactantList *rl = reactantLists[reactantPos]; int rxnIndex = m->getMoleculeType()->getRxnIndex(this,reactantPos); if(rl->getHasClonedMappings()) { if(m->getRxnListMappingId(rxnIndex)>=0) { rl->removeMappingSet(m->getRxnListMappingId(rxnIndex)); m->setRxnListMappingId(rxnIndex,Molecule::NOT_IN_RXN); } } //Here we get the standard update... if(m->getRxnListMappingId(rxnIndex)>=0) //If we are in this reaction... { if(!reactantTemplates[reactantPos]->compare(m)) { //cout<<"Removing molecule "<<m->getUniqueID()<<" which was at mappingSet: "<<m->getRxnListMappingId(rxnIndex)<<endl; rl->removeMappingSet(m->getRxnListMappingId(rxnIndex)); m->setRxnListMappingId(rxnIndex,Molecule::NOT_IN_RXN); } } else { //Try to map it! ms = rl->pushNextAvailableMappingSet(); if(!reactantTemplates[reactantPos]->compare(m,rl,ms)) { //we must remove, if we did not match. This will also remove //everything that was cloned off of the mapping set rl->removeMappingSet(ms->getId()); } else { m->setRxnListMappingId(rxnIndex,ms->getId()); } } } return true; }
bool DORRxnClass::tryToAdd(Molecule *m, unsigned int reactantPos) { //if(DEBUG_MESSAGE)cout<<endl<<endl<<"adding molecule to DORRxnClass"<<endl; //if(DEBUG_MESSAGE)m->printDetails(); if(reactantPos==(unsigned)this->DORreactantIndex) { // if(DEBUG_MESSAGE)cout<<" ... as a DOR"<<endl; //cout<<"RxnListMappingId: "<<m->getRxnListMappingId(m->getMoleculeType()->getRxnIndex(this,reactantPos))<<endl; // handle the DOR reactant int rxnIndex = m->getMoleculeType()->getRxnIndex(this,reactantPos); //cout<<"trying to add to the tree:"<<endl; //m->printDetails(); if(reactantTree->getHasClonedMappings()) { if(m->getRxnListMappingId(rxnIndex)>=0) { //cout<<"removing"<<endl; reactantTree->removeMappingSet(m->getRxnListMappingId(rxnIndex)); m->setRxnListMappingId(rxnIndex,Molecule::NOT_IN_RXN); } } if(m->getRxnListMappingId(rxnIndex)>=0) { //if(DEBUG_MESSAGE)cout<<"was in the tree, so checking if we should remove"<<endl; if(!reactantTemplates[reactantPos]->compare(m)) { //if(DEBUG_MESSAGE)cout<<"removing..."<<endl; reactantTree->removeMappingSet(m->getRxnListMappingId(rxnIndex)); m->setRxnListMappingId(rxnIndex,Molecule::NOT_IN_RXN); } else {} } else { //if(DEBUG_MESSAGE)cout<<"wasn't in the tree, so trying to push and compare"<<endl; ms=reactantTree->pushNextAvailableMappingSet(); if(!reactantTemplates[reactantPos]->compare(m,reactantTree,ms)) { //cout<<"shouldn't be in the tree, so we pop"<<endl; reactantTree->removeMappingSet(ms->getId()); } else { //cout<<"should be in the tree, so confirm push."<<endl; //m->printDetails(); //ms->printDetails(); //we are keeping it, so evaluate the function and confirm the push double localFunctionValue = this->evaluateLocalFunctions(ms); //if(DEBUG_MESSAGE)cout<<"local function value is: "<<localFunctionValue<<endl; reactantTree->confirmPush(ms->getId(),localFunctionValue); m->setRxnListMappingId(rxnIndex,ms->getId()); } } } else { //Get the specified reactantList ReactantList *rl = reactantLists[reactantPos]; int rxnIndex = m->getMoleculeType()->getRxnIndex(this,reactantPos); if(rl->getHasClonedMappings()) { if(m->getRxnListMappingId(rxnIndex)>=0) { rl->removeMappingSet(m->getRxnListMappingId(rxnIndex)); m->setRxnListMappingId(rxnIndex,Molecule::NOT_IN_RXN); } } //Here we get the standard update... if(m->getRxnListMappingId(rxnIndex)>=0) //If we are in this reaction... { if(!reactantTemplates[reactantPos]->compare(m)) { //cout<<"Removing molecule "<<m->getUniqueID()<<" which was at mappingSet: "<<m->getRxnListMappingId(rxnIndex)<<endl; rl->removeMappingSet(m->getRxnListMappingId(rxnIndex)); m->setRxnListMappingId(rxnIndex,Molecule::NOT_IN_RXN); } } else { //Try to map it! ms = rl->pushNextAvailableMappingSet(); if(!reactantTemplates[reactantPos]->compare(m,rl,ms)) { //we must remove, if we did not match. This will also remove //everything that was cloned off of the mapping set rl->removeMappingSet(ms->getId()); } else { m->setRxnListMappingId(rxnIndex,ms->getId()); } } // // handle it normally... // //if(DEBUG_MESSAGE)cout<<" ... as a normal reactant"<<endl; // ReactantList *rl = reactantLists[reactantPos]; // int rxnIndex = m->getMoleculeType()->getRxnIndex(this,reactantPos); // if(m->getRxnListMappingId(rxnIndex)>=0) { // if(!reactantTemplates[reactantPos]->compare(m)) { // rl->removeMappingSet(m->getRxnListMappingId(rxnIndex)); // m->setRxnListMappingId(rxnIndex,Molecule::NOT_IN_RXN); // } // } else { // //try to map it. // ms = rl->pushNextAvailableMappingSet(); // if(!reactantTemplates[reactantPos]->compare(m,rl,ms)) { // rl->popLastMappingSet(); // //we just pushed, then popped, so molecule has not changed... // } else { // m->setRxnListMappingId(rxnIndex,ms->getId()); // } // } } //if(DEBUG_MESSAGE)cout<<"finished adding"<<endl; return true; }