Skip to content

Commit 0dfce7b

Browse files
committed
Added getAllSpecies() method to Network class.
This method provides an easy way to get a list containing all of the species that participate in the pressure-dependent reaction network, including all isomers, reactant and product channels, and even bath gas species. This is already useful in output file writing; I expect it to be useful in other situations as well.
1 parent c776418 commit 0dfce7b

2 files changed

Lines changed: 19 additions & 15 deletions

File tree

rmgpy/measure/network.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,24 @@ def containsSpecies(self, species):
126126
if rxn.products[0] == species and species in self.explored: return True
127127
return False
128128

129+
def getAllSpecies(self):
130+
"""
131+
Return a list of all unique species in the network, including all
132+
isomers, reactant and product channels, and bath gas species.
133+
"""
134+
speciesList = []
135+
for isomer in self.isomers:
136+
if isomer not in speciesList: speciesList.append(isomer)
137+
for reactants in self.reactants:
138+
for spec in reactants:
139+
if spec not in speciesList: speciesList.append(spec)
140+
for products in self.products:
141+
for spec in products:
142+
if spec not in speciesList: speciesList.append(spec)
143+
for spec in self.bathGas:
144+
if spec not in speciesList: speciesList.append(spec)
145+
return speciesList
146+
129147
def getEnergyGrains(self, Emin, Emax, dE=0.0, Ngrains=0):
130148
"""
131149
Return an array of energy grains that have a minimum of `Emin`, a

rmgpy/measure/output.py

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -132,21 +132,7 @@ def writeNetworkSpecies(f, network):
132132
object`f`. All isomer, reactant, product, and bath gas species are
133133
automatically written one time each.
134134
"""
135-
136-
# Get list of all species in network
137-
speciesList = []
138-
for isomer in network.isomers:
139-
if isomer not in speciesList: speciesList.append(isomer)
140-
for reactants in network.reactants:
141-
for spec in reactants:
142-
if spec not in speciesList: speciesList.append(spec)
143-
for products in network.products:
144-
for spec in products:
145-
if spec not in speciesList: speciesList.append(spec)
146-
for spec in network.bathGas:
147-
if spec not in speciesList: speciesList.append(spec)
148-
149-
for spec in speciesList:
135+
for spec in network.getAllSpecies():
150136
writeSpecies(f, spec)
151137

152138
def writeSpecies(f, spec):

0 commit comments

Comments
 (0)