@@ -1621,55 +1621,104 @@ def __generateReactions(self, reactants, products=None, forward=True, **options)
16211621 # other than the ones specified (if given); these should be removed
16221622 rxnList0 = rxnList [:]
16231623 rxnList = []
1624- for index0 , reaction0 in enumerate (rxnList0 ):
1624+ index0 = 0
1625+ while index0 < len (rxnList0 ):
1626+ reaction0 = rxnList0 [index0 ]
16251627
16261628 # Generate resonance isomers for products of the current reaction
1627- products0 = [product .generateResonanceIsomers () for product in reaction0 .products ]
1628-
1629- # If products is given, skip reactions that don't match the given products
1630- if products is not None :
1631- match = False
1632- if len (products ) == len (products0 ) == 1 :
1633- for product in products0 [0 ]:
1634- if products [0 ].isIsomorphic (product ):
1635- match = True
1636- break
1637- elif len (products ) == len (products0 ) == 2 :
1638- for productA in products0 [0 ]:
1639- for productB in products0 [1 ]:
1640- if products [0 ].isIsomorphic (productA ) and products [1 ].isIsomorphic (productB ):
1629+ if forward :
1630+ reactants0 = None
1631+ products0 = [product .generateResonanceIsomers () for product in reaction0 .products ]
1632+
1633+ # If products is given, skip reactions that don't match the given products
1634+ if products is not None :
1635+ match = False
1636+ if len (products ) == len (products0 ) == 1 :
1637+ for product in products0 [0 ]:
1638+ if products [0 ].isIsomorphic (product ):
16411639 match = True
16421640 break
1643- elif products [0 ].isIsomorphic (productB ) and products [1 ].isIsomorphic (productA ):
1641+ elif len (products ) == len (products0 ) == 2 :
1642+ for productA in products0 [0 ]:
1643+ for productB in products0 [1 ]:
1644+ if products [0 ].isIsomorphic (productA ) and products [1 ].isIsomorphic (productB ):
1645+ match = True
1646+ break
1647+ elif products [0 ].isIsomorphic (productB ) and products [1 ].isIsomorphic (productA ):
1648+ match = True
1649+ break
1650+ else :
1651+ match = True
1652+
1653+ else :
1654+ reactants0 = [reactant .generateResonanceIsomers () for reactant in reaction0 .reactants ]
1655+ products0 = None
1656+
1657+ # If products is given, skip reactions that don't match the given products
1658+ if products is not None :
1659+ match = False
1660+ if len (products ) == len (reactants0 ) == 1 :
1661+ for reactant in reactants0 [0 ]:
1662+ if products [0 ].isIsomorphic (reactant ):
16441663 match = True
16451664 break
1646- else :
1647- match = True
1648- if not match : continue
1665+ elif len (products ) == len (reactants0 ) == 2 :
1666+ for reactantA in reactants0 [0 ]:
1667+ for reactantB in reactants0 [1 ]:
1668+ if products [0 ].isIsomorphic (reactantA ) and reactants [1 ].isIsomorphic (reactantB ):
1669+ match = True
1670+ break
1671+ elif products [0 ].isIsomorphic (reactantB ) and reactants [1 ].isIsomorphic (reactantA ):
1672+ match = True
1673+ break
1674+ else :
1675+ match = True
1676+
1677+ if not match :
1678+ index0 += 1
1679+ continue
16491680
16501681 rxnList .append (reaction0 )
16511682
16521683 # Remove duplicates from the reaction list
16531684 index = index0 + 1
16541685 while index < len (rxnList0 ):
16551686 reaction = rxnList0 [index ]
1656- # We know the reactants are the same, so we only need to compare the products
1687+
16571688 match = False
1658- if len (reaction .products ) == len (products0 ) == 1 :
1659- for product in products0 [0 ]:
1660- if rxnList0 [index ].products [0 ].isIsomorphic (product ):
1661- match = True
1662- break
1663- elif len (reaction .products ) == len (products0 ) == 2 :
1664- for productA in products0 [0 ]:
1665- for productB in products0 [1 ]:
1666- if reaction .products [0 ].isIsomorphic (productA ) and reaction .products [1 ].isIsomorphic (productB ):
1689+ if forward :
1690+ # We know the reactants are the same, so we only need to compare the products
1691+ if len (reaction .products ) == len (products0 ) == 1 :
1692+ for product in products0 [0 ]:
1693+ if reaction .products [0 ].isIsomorphic (product ):
16671694 match = True
16681695 break
1669- elif reaction .products [0 ].isIsomorphic (productB ) and reaction .products [1 ].isIsomorphic (productA ):
1696+ elif len (reaction .products ) == len (products0 ) == 2 :
1697+ for productA in products0 [0 ]:
1698+ for productB in products0 [1 ]:
1699+ if reaction .products [0 ].isIsomorphic (productA ) and reaction .products [1 ].isIsomorphic (productB ):
1700+ match = True
1701+ break
1702+ elif reaction .products [0 ].isIsomorphic (productB ) and reaction .products [1 ].isIsomorphic (productA ):
1703+ match = True
1704+ break
1705+ else :
1706+ # We know the products are the same, so we only need to compare the reactants
1707+ if len (reaction .reactants ) == len (reactants0 ) == 1 :
1708+ for reactant in reactants0 [0 ]:
1709+ if reaction .reactants [0 ].isIsomorphic (reactant ):
16701710 match = True
16711711 break
1672-
1712+ elif len (reaction .reactants ) == len (reactants0 ) == 2 :
1713+ for reactantA in reactants0 [0 ]:
1714+ for reactantB in reactants0 [1 ]:
1715+ if reaction .reactants [0 ].isIsomorphic (reactantA ) and reaction .reactants [1 ].isIsomorphic (reactantB ):
1716+ match = True
1717+ break
1718+ elif reaction .reactants [0 ].isIsomorphic (reactantB ) and reaction .reactants [1 ].isIsomorphic (reactantA ):
1719+ match = True
1720+ break
1721+
16731722 # If we found a match, remove it from the list
16741723 # Also increment the reaction path degeneracy of the remaining reaction
16751724 if match :
@@ -1678,6 +1727,8 @@ def __generateReactions(self, reactants, products=None, forward=True, **options)
16781727 else :
16791728 index += 1
16801729
1730+ index0 += 1
1731+
16811732 # For R_Recombination reactions, the degeneracy is twice what it should
16821733 # be, so divide those by two
16831734 # This is hardcoding of reaction families!
0 commit comments