From fbd9499c21187844422babb94c488b42199e8caf Mon Sep 17 00:00:00 2001 From: Arthur Goldberg Date: Mon, 20 Nov 2017 12:50:04 -0500 Subject: [PATCH] make get_species() calls deterministic --- wc_lang/core.py | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/wc_lang/core.py b/wc_lang/core.py index 0af7abd..139ea28 100644 --- a/wc_lang/core.py +++ b/wc_lang/core.py @@ -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 @@ -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`. @@ -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() @@ -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.