def test_generate_sbml_model(): # Test a non-reversible reaction s1 = Species("S1") s2 = Species("S2") rx0 = Reaction.from_massaction(inputs=[s1], outputs=[s2], k_forward=0.1) crn = ChemicalReactionNetwork(species=[s1, s2], reactions=[rx0]) # generate an sbml model document, model = crn.generate_sbml_model() # all species from the CRN are accounted for assert len(model.getListOfSpecies()) == len(crn.species) # all reactions from the CRN are accounted for assert len(model.getListOfReactions()) == len(crn.reactions) document2, model2 = crn.generate_sbml_model(check_validity=False) assert len(model2.getListOfSpecies()) == len( crn.species) #the same model is made if you dont check validity assert len(model2.getListOfReactions()) == len( crn.reactions) #the same model is made if you dont check validity # reversible needs to be off! # assert not model.getListOfReactions()[0].isSetReversible() # test a reversible reaction rx1 = Reaction.from_massaction(inputs=[s1], outputs=[s2], k_forward=0.1, k_reverse=0.1) rxn_list = [rx1] crn = ChemicalReactionNetwork(species=[s1, s2], reactions=rxn_list) # generate an sbml model document, model = crn.generate_sbml_model() # all species from the CRN are accounted for assert len(model.getListOfSpecies()) == len(crn.species) # all reactions from the CRN are accounted for assert len(model.getListOfReactions()) == 2 # although sbml represents a reverisble reaction with reversible flag # BioCRNpyler always creates two reactions, because this is correct # for stochastic simulation with SBML. sbml_rxn = model.getListOfReactions() # assert not sbml_rxn[0].isSetReversible() # assert not sbml_rxn[1].isSetReversible() # Test propagation for for_bioscrape keyword # generate an sbml model with for_bioscrape = True document, model = crn.generate_sbml_model(for_bioscrape=True) for r in model.getListOfReactions(): assert r.getAnnotation() is not None assert validate_sbml(document) == 0 # generate an sbml model with for_bioscrape = False document, model = crn.generate_sbml_model(for_bioscrape=False) for r in model.getListOfReactions(): assert r.getAnnotation() is None assert validate_sbml(document) == 0
def test_generate_sbml_model_parameter_names(): s1 = Species("S1") s2 = Species("S2") # The correct parameter formating should be: "name_partid_mechanism" key0 = ParameterKey(mechanism="m", part_id="p", name="n") k0 = ParameterEntry("n", 1.0, parameter_key=key0) # Tests 3 Parameter entries with seemingly redundant keys. # In SBML parameter id, None will be kept blank, resulting in # different numbers of underscores between the V's k1 = ParameterEntry("v", 1.0, parameter_key=None) key2 = ParameterKey(mechanism=None, part_id="v", name="v") k2 = ParameterEntry("v", 2.0, parameter_key=key2) key3 = ParameterKey(mechanism="v", part_id=None, name="v") k3 = ParameterEntry("v", 2.0, parameter_key=key3) key4 = ParameterKey(mechanism="v", part_id="v", name="v") k4 = ParameterEntry("v", 2.0, parameter_key=key4) # Throw a duplicate key for good measure! rx0 = Reaction.from_massaction(inputs=[], outputs=[s1], k_forward=k0, k_reverse=k1) rx1 = Reaction.from_massaction(inputs=[s1], outputs=[s2], k_forward=k1, k_reverse=k2) rx2 = Reaction.from_massaction(inputs=2 * [s1], outputs=2 * [s2], k_forward=k3, k_reverse=k4) rxn_list = [rx0, rx1, rx2] crn = ChemicalReactionNetwork(species=[s1, s2], reactions=rxn_list) document, model = crn.generate_sbml_model() assert validate_sbml(document) == 0 correct_ids = set(["v_v_", "v__v", "v_v_v", "v__", "n_p_m"]) ids = set([p.getId() for p in model.getListOfParameters()]) assert ids == correct_ids
# Names of different supported propensities for prop in Propensity.get_available_propensities(): print(prop) kb = 100 ku = 10 kex = 1. kd = .1 G = Species(name="G", material_type="dna") #DNA A = Species(name="A", material_type="protein") #Activator GA = ComplexSpecies([G, A, A]) #Activated Gene X = Species(name="X", material_type="protein") rxnd = Reaction.from_massaction(inputs=[X], outputs=[], k_forward=kd) # Massaction Unregulated species1 = [G, A, GA, X] rxn0_1 = Reaction.from_massaction(inputs=[G, A, A], outputs=[GA], k_forward=kb, k_reverse=ku) rxn0_2 = Reaction.from_massaction(inputs=[GA], outputs=[GA, X], k_forward=kex) CRN0 = ChemicalReactionNetwork(species1, [rxn0_1, rxn0_2, rxnd]) mak1 = MassAction(k_forward=kb, k_reverse=ku) mak2 = MassAction(k_forward=kex) rxn1_1 = Reaction([G, A, A], [GA], propensity_type=mak1) rxn1_2 = Reaction([G], [G, X], propensity_type=mak2)