Skip to content

Commit

Permalink
make get_species() calls deterministic
Browse files Browse the repository at this point in the history
  • Loading branch information
artgoldberg committed Nov 20, 2017
1 parent 80ec339 commit fbd9499
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions wc_lang/core.py
Expand Up @@ -497,14 +497,20 @@ def get_species(self):
:obj:`list` of `Species`: species
"""
species = []
species_set = set()

for submodel in self.submodels:
species.extend(submodel.get_species())
for specie in submodel.get_species():
if not specie in species_set:
species.append(specie)
species_set.add(specie)

for concentation in self.get_concentrations():
species.append(concentation.species)
if not concentation.species in species_set:
species.append(concentation.species)
species_set.add(concentation.species)

return list(set(species))
return species

def get_concentrations(self):
""" Get all concentrations from species types
Expand Down Expand Up @@ -690,11 +696,15 @@ def get_species(self):
:obj:`list` of `Species`: species in reactions
"""
species = []
species_set = set()

for rxn in self.reactions:
species.extend(rxn.get_species())
for specie in rxn.get_species():
if not specie in species_set:
species.append(specie)
species_set.add(specie)

return list(set(species))
return species

def add_to_sbml_doc(self, sbml_document):
""" Add this Submodel to a libsbml SBML document as a `libsbml.model`.
Expand Down Expand Up @@ -928,7 +938,7 @@ class Compartment(BaseModel):
cross_references (:obj:`list` of `CrossReference`): cross references
concentrations (:obj:`list` of `Concentration`): concentrations
reaction_participants (:obj:`list` of `ReactionParticipant`): reaction participants
biomass_reactions (:obj:`list` of `BiomassReaction`): biomas reactions defined for this
biomass_reactions (:obj:`list` of `BiomassReaction`): biomass reactions defined for this
compartment
"""
id = SlugAttribute()
Expand Down Expand Up @@ -1263,10 +1273,14 @@ def get_species(self):
for part in self.participants:
species.append(part.species)

species_set = set()
for rate_law in self.rate_laws:
species.extend(rate_law.equation.modifiers)
for specie in rate_law.equation.modifiers:
if not specie in species_set:
species.append(specie)
species_set.add(specie)

return list(set(species))
return species

def add_to_sbml_doc(self, sbml_document):
""" Add this Reaction to a libsbml SBML document.
Expand Down

0 comments on commit fbd9499

Please sign in to comment.