Skip to content

Commit 4e17060

Browse files
committed
Added N and S atoms to reaction.pairs determination by similarity
1 parent 2a27920 commit 4e17060

1 file changed

Lines changed: 19 additions & 14 deletions

File tree

rmgpy/reaction.py

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -894,41 +894,46 @@ def generatePairs(self):
894894
895895
There are a number of ways of determining the correct pairing for
896896
bimolecular reactions. Here we try a simple similarity analysis by comparing
897-
the number of heavy atoms (carbons and oxygens at the moment). This should
897+
the number of heavy atoms (C/O/N/S at the moment). This should
898898
work most of the time, but a more rigorous algorithm may be needed for
899899
some cases.
900900
"""
901901
self.pairs = []
902-
902+
903903
if len(self.reactants) == 1 or len(self.products) == 1:
904904
# Pair each reactant with each product
905905
for reactant in self.reactants:
906906
for product in self.products:
907907
self.pairs.append((reactant, product))
908908

909-
else:
910-
909+
else: # this is the bimolecular case
911910
reactants = self.reactants[:]
912911
products = self.products[:]
912+
913+
reactantCarbons = [sum([1 for atom in reactant.molecule[0].atoms if atom.isCarbon()]) for reactant in reactants]
914+
productCarbons = [sum([1 for atom in product.molecule[0].atoms if atom.isCarbon()]) for product in products ]
915+
reactantOxygens = [sum([1 for atom in reactant.molecule[0].atoms if atom.isOxygen()]) for reactant in reactants]
916+
productOxygens = [sum([1 for atom in product.molecule[0].atoms if atom.isOxygen()]) for product in products ]
917+
reactantNitrogens = [sum([1 for atom in reactant.molecule[0].atoms if atom.isNitrogen()]) for reactant in reactants]
918+
productNitrogens = [sum([1 for atom in product.molecule[0].atoms if atom.isNitrogen()]) for product in products ]
919+
reactantSulfurs = [sum([1 for atom in reactant.molecule[0].atoms if atom.isSulfur()]) for reactant in reactants]
920+
productSulfurs = [sum([1 for atom in product.molecule[0].atoms if atom.isSulfur()]) for product in products ]
913921

914-
reactantCarbons = [sum([1 for atom in reactant.molecule[0].atoms if atom.isCarbon()]) for reactant in reactants]
915-
productCarbons = [sum([1 for atom in product.molecule[0].atoms if atom.isCarbon()]) for product in products ]
916-
reactantOxygens = [sum([1 for atom in reactant.molecule[0].atoms if atom.isOxygen()]) for reactant in reactants]
917-
productOxygens = [sum([1 for atom in product.molecule[0].atoms if atom.isOxygen()]) for product in products ]
918-
919-
# Sort the reactants and products by carbon number, then by oxygen number
920-
reactants = [(carbon, oxygen, reactant) for carbon, oxygen, reactant in zip(reactantCarbons,reactantOxygens,reactants)]
922+
# Sort the reactants and products by C/O/N/S numbers
923+
reactants = [(carbon, oxygen, nitrogen, sulfur, reactant) for carbon, oxygen, nitrogen, sulfur, reactant
924+
in zip(reactantCarbons,reactantOxygens,reactantNitrogens,reactantSulfurs,reactants)]
921925
reactants.sort()
922-
products = [(carbon, oxygen, product) for carbon, oxygen, product in zip(productCarbons,productOxygens,products)]
926+
products = [(carbon, oxygen, nitrogen, sulfur, product) for carbon, oxygen, nitrogen, sulfur, product
927+
in zip(productCarbons,productOxygens,productNitrogens,productSulfurs,products)]
923928
products.sort()
924929

925930
while len(reactants) > 1 and len(products) > 1:
926-
self.pairs.append((reactants[-1][2], products[-1][2]))
931+
self.pairs.append((reactants[-1][4], products[-1][4]))
927932
reactants.pop()
928933
products.pop()
929934
for reactant in reactants:
930935
for product in products:
931-
self.pairs.append((reactant[2], product[2]))
936+
self.pairs.append((reactant[4], product[4]))
932937

933938
def draw(self, path):
934939
"""

0 commit comments

Comments
 (0)