Skip to content

Commit

Permalink
Don't modify the list you're iterating through!!
Browse files Browse the repository at this point in the history
I've seen bugs like this before. *sigh*  :-(
In this case it was skipping alternate reactions.
  • Loading branch information
rwest committed Aug 18, 2015
1 parent 2802c30 commit 6e94e91
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions importChemkin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1363,7 +1363,7 @@ def checkReactionsForMatches(self, reactionsToCheck):
reactionsToPrune = set()
for edgeReaction in reactionsToCheck:
edgeReactionMatchesSomething = False
for chemkinReaction in chemkinReactionsUnmatched:
for chemkinReaction in chemkinReactionsUnmatched[:]: # iterate over a copy of the list
self.suggestedMatches = {}
if reactionsMatch(edgeReaction, chemkinReaction):
edgeReactionMatchesSomething = True
Expand Down Expand Up @@ -1509,7 +1509,7 @@ def addReactionToKineticsLibrary(self, chemkinReaction):
entry = kinEntry()
#source = self.args.reactions
#entry.index = len(self.chemkinReactions) - len(self.chemkinReactionsUnmatched)
entry.index = self.chemkinReactions.index(chemkinReaction)
entry.index = self.chemkinReactions.index(chemkinReaction) + 1
entry.item = chemkinReaction
entry.label = str(chemkinReaction)
entry.data = chemkinReaction.kinetics
Expand Down Expand Up @@ -1893,7 +1893,7 @@ def main(self):

# Now would be a good time to print identified reactions to the .kinetics.py file?
# All the species in self.identified_labels should have been through generateResonanceIsomers and generateThermoData
for chemkinReaction in chemkinReactionsUnmatched:
for chemkinReaction in chemkinReactionsUnmatched[:]: # iterate over a copy of the list, so you can modify the list itself
for reagents in (chemkinReaction.reactants, chemkinReaction.products):
for reagent in reagents:
if reagent.label not in self.identified_labels:
Expand Down

0 comments on commit 6e94e91

Please sign in to comment.