void ReactantList::removeMappingSet(unsigned int mappingSetId) { //Make sure this mappingSet is not empty if(n_mappingSets==0) { printDetails(); cout.flush(); cerr<<"Trying to remove from an empty ReactantList!!"<<endl; exit(1); } //First, get the position of the mappingSet we need to remove int pos = msPositionMap[mappingSetId]; //Make sure the position is valid (not out of bounds of the List) if(pos+1>(n_mappingSets)) { cout<<"Error in ReactantList: you can't remove a mappingSet that has been cleared! (trying to remove: "<< mappingSetId << " in pos " << pos <<" but size is: "<<size()<<endl; printDetails(); return; } //If the array has only one element, or we just happened to select the last element, //then just remove the last element without a swap if( pos+1 == (n_mappingSets) ) { popLastMappingSet(); return; } //Otherwise, we have to swap with the last element in the list MappingSet *tempMappingSet = mappingSets[pos]; mappingSets[pos] = mappingSets[n_mappingSets-1]; mappingSets[n_mappingSets-1] = tempMappingSet; //Careful here! We have to swap values in the msPositionMap //so that msPositionMap[mappingId] points correctly to where //that MappingSet now lives. Notice that this is a different //swap than above in the MappingSets array! msPositionMap[mappingSetId] = n_mappingSets-1; msPositionMap[mappingSets[pos]->getId()] = pos; //Remember to remove n_mappingSets--; //Make sure we clear what we don't need unsigned int clone = tempMappingSet->getClonedMapping(); tempMappingSet->clear(); //Now, IF this mapping set had a clone, we have to remove it as well if(clone!=MappingSet::NO_CLONE) { this->removeMappingSet(clone); } }
bool TransformationSet::transform(MappingSet **mappingSets) { if(!finalized) { cerr<<"TransformationSet cannot apply a transform if it is not finalized!"<<endl; exit(1); } //cout<<"transforming!"<<endl; //list <Molecule *> deleteList; for(unsigned int r=0; r<n_reactants; r++) { MappingSet *ms = mappingSets[r]; for(unsigned int t=0; t<transformations[r].size(); t++) { if(transformations[r].at(t)->getType()==(int)TransformationFactory::REMOVE) { Mapping *m1 = ms->get(t); if(transformations[r].at(t)->getRemovalType()==TransformationFactory::COMPLETE_SPECIES_REMOVAL) { m1->getMolecule()->traverseBondedNeighborhood(deleteList,ReactionClass::NO_LIMIT); } else if (transformations[r].at(t)->getRemovalType()==TransformationFactory::DELETE_MOLECULES) { deleteList.push_back(m1->getMolecule()); } } else { //cout<<"applying!"<<endl; //cout<<transformations[r].at(t)->getType()<<endl; transformations[r].at(t)->apply(ms->get(t),mappingSets); } } } if(deleteList.size()>0) { list <Molecule *>::iterator it; //Each molecule that is on the list must be dealt with for(it = deleteList.begin(); it!=deleteList.end(); it++) { (*it)->getMoleculeType()->removeMoleculeFromRunningSystem((*it)); } deleteList.clear(); } int size = addMoleculeTransformations.size(); if(size>0) { for(int i=0; i<size; i++) { addMoleculeTransformations.at(i)->apply(NULL,NULL); } } return true; }
void ReactantTree::removeMappingSet(unsigned int mappingSetId) { if(n_mappingSets==0) { cerr<<"Trying to remove from an empty ReactantTree!!"<<endl; exit(1); } //first get the position of this mappingSet in the tree int msTreeArrayPosition = msTreePositionMap[mappingSetId]; //If we have already confirmed this push on the tree, we must take it out of //the tree. IF we didn't find this on the tree, then perhaps it just wasn't //pushed on yet. if(msTreeArrayPosition>=0) { removeFromTreeOnly(msTreeArrayPosition,mappingSetId); } //At this point, the tree is up to date, but we still have to get rid of the empty mappingSet //by swapping it with the end of the list... This will allow us to reuse the mappingSet without //destroying it and creating it again later... //So first, get the position of the mappingSet we need to remove int pos = msPositionMap[mappingSetId]; //Make sure the position is valid (not out of bounds of the List) if(pos+1>(n_mappingSets)) { cout<<"Error in ReactantTree: you can't remove a mappingSet that has been cleared! (trying to remove: "; cout<< mappingSetId << " in pos " << pos <<" but size is: "<<size()<<endl; exit(1); } //If the array has only one element, or we just happened to select the last element, //then just remove the last element without a swap - we can do this by popping the //last mapping set. This will work, because we already cleared the tree at this location if( pos+1 == (n_mappingSets) ) { popLastMappingSet(); return; } //Otherwise, we have to swap with the last element in the list MappingSet *tempMappingSet = mappingSets[pos]; mappingSets[pos] = mappingSets[n_mappingSets-1]; mappingSets[n_mappingSets-1] = tempMappingSet; //Careful here! We have to swap values in the msPositionMap //so that msPositionMap[mappingId] points correctly to where //that MappingSet now lives. msPositionMap[mappingSetId] = n_mappingSets-1; msPositionMap[mappingSets[pos]->getId()] = pos; //Make sure we clear what we don't need unsigned int clone = mappingSets[n_mappingSets-1]->getClonedMapping(); tempMappingSet->clear(); //Remember to mark the removal on our counter... n_mappingSets--; //Remove all the clones as well if(clone!=MappingSet::NO_CLONE) { this->removeMappingSet(clone); } }