private static int Main(string[] args) { var retval = 0; var sbmlns = new SBMLNamespaces(3, 1, "comp", 1); // create the document var document = new SBMLDocument(sbmlns); var compdoc = (CompSBMLDocumentPlugin)(document.getPlugin("comp")); compdoc.setRequired(true); var mod1 = compdoc.createModelDefinition(); mod1.setId("enzyme"); mod1.setName("enzyme"); var comp = mod1.createCompartment(); comp.setSpatialDimensions(3); comp.setConstant(true); comp.setId("comp"); comp.setSize(1L); var spec = new Species(sbmlns); //We have to construct it this way because we get the comp plugin from it later. spec.setCompartment("comp"); spec.setHasOnlySubstanceUnits(false); spec.setConstant(false); spec.setBoundaryCondition(false); spec.setId("S"); mod1.addSpecies(spec); spec.setId("E"); mod1.addSpecies(spec); spec.setId("D"); mod1.addSpecies(spec); spec.setId("ES"); mod1.addSpecies(spec); var rxn = new Reaction(sbmlns); rxn.setReversible(true); rxn.setFast(false); var rxn2 = new Reaction(sbmlns); rxn2.setReversible(true); rxn2.setFast(false); rxn.setId("J0"); rxn2.setId("J1"); var sr = new SpeciesReference(3, 1); sr.setConstant(true); sr.setStoichiometry(1); sr.setSpecies("S"); rxn.addReactant(sr); sr.setSpecies("E"); rxn.addReactant(sr); rxn2.addProduct(sr); sr.setSpecies("ES"); rxn.addProduct(sr); rxn2.addReactant(sr); sr.setSpecies("D"); rxn2.addProduct(sr); mod1.addReaction(rxn); mod1.addReaction(rxn2); var mod1plug = (CompModelPlugin)(mod1.getPlugin("comp")); var m1port = new Port(); m1port.setIdRef("comp"); m1port.setId("comp_port"); mod1plug.addPort(m1port); m1port.setIdRef("S"); m1port.setId("S_port"); mod1plug.addPort(m1port); m1port.setIdRef("E"); m1port.setId("E_port"); mod1plug.addPort(m1port); m1port.setIdRef("D"); m1port.setId("D_port"); mod1plug.addPort(m1port); m1port.setIdRef("ES"); m1port.setId("ES_port"); mod1plug.addPort(m1port); m1port.setIdRef("J0"); m1port.setId("J0_port"); mod1plug.addPort(m1port); m1port.setIdRef("J1"); m1port.setId("J1_port"); mod1plug.addPort(m1port); //Define the 'simple' model var mod2 = compdoc.createModelDefinition(); mod2.setId("simple"); var comp2 = mod2.createCompartment(); comp2.setSpatialDimensions(3); comp2.setConstant(true); comp2.setId("comp"); comp2.setSize(1L); spec.setCompartment("comp"); spec.setHasOnlySubstanceUnits(false); spec.setConstant(false); spec.setBoundaryCondition(false); spec.setId("S"); spec.setInitialConcentration(5); mod2.addSpecies(spec); spec.setId("D"); spec.setInitialConcentration(10); mod2.addSpecies(spec); var rxn3 = new Reaction(sbmlns); //We have to construct it this way because we get the comp plugin from it later. rxn3.setReversible(true); rxn3.setFast(false); rxn3.setId("J0"); var sr2 = new SpeciesReference(3, 1); //These will not need plugins. sr2.setConstant(true); sr2.setStoichiometry(1); sr2.setSpecies("S"); rxn3.addReactant(sr2); sr2.setSpecies("D"); rxn3.addProduct(sr2); mod2.addReaction(rxn3); var mod2plug = (CompModelPlugin)(mod2.getPlugin("comp")); var port = new Port(); port.setId("S_port"); port.setIdRef("S"); mod2plug.addPort(port); var port2 = mod2plug.createPort(); port2.setId("D_port"); port2.setIdRef("D"); port.setId("comp_port"); port.setIdRef("comp"); mod2plug.addPort(port); port.setId("J0_port"); port.setIdRef("J0"); mod2plug.addPort(port); // create the Model var model = document.createModel(); model.setId("complexified"); // Set the submodels var mplugin = (CompModelPlugin)(model.getPlugin("comp")); var submod1 = mplugin.createSubmodel(); submod1.setId("A"); submod1.setModelRef("enzyme"); var submod2 = mplugin.createSubmodel(); submod2.setId("B"); submod2.setModelRef("simple"); var del = submod2.createDeletion(); del.setPortRef("J0_port"); del.setId("oldrxn"); // Synchronize the compartments var mcomp = model.createCompartment(); mcomp.setSpatialDimensions(3); mcomp.setConstant(true); mcomp.setId("comp"); mcomp.setSize(1L); var compartplug = (CompSBasePlugin)(mcomp.getPlugin("comp")); var re = new ReplacedElement(); re.setIdRef("comp"); re.setSubmodelRef("A"); compartplug.addReplacedElement(re); re.setSubmodelRef("B"); re.unsetIdRef(); re.setPortRef("comp_port"); compartplug.addReplacedElement(re); //Synchronize the species spec.setId("S"); spec.setInitialConcentration(5); var specplug = (CompSBasePlugin)(spec.getPlugin("comp")); var sre = specplug.createReplacedElement(); sre.setSubmodelRef("A"); sre.setIdRef("S"); var sre2 = specplug.createReplacedElement(); sre2.setSubmodelRef("B"); sre2.setPortRef("S_port"); model.addSpecies(spec); spec.setId("D"); spec.setInitialConcentration(10); sre.setIdRef("D"); sre2.setPortRef("D_port"); model.addSpecies(spec); spec.setId("E"); spec.unsetInitialConcentration(); sre.unsetIdRef(); sre2.unsetIdRef(); sre.setPortRef("E_port"); sre2.setDeletion("oldrxn"); model.addSpecies(spec); spec.setId("ES"); spec.unsetInitialConcentration(); sre.setPortRef("ES_port"); sre2.setDeletion("oldrxn"); model.addSpecies(spec); //Synchronize the reactions var rxn1plug = (CompSBasePlugin)(rxn.getPlugin("comp")); var rxn2plug = (CompSBasePlugin)(rxn2.getPlugin("comp")); var deletion = new ReplacedElement(); deletion.setDeletion("oldrxn"); deletion.setSubmodelRef("B"); rxn1plug.addReplacedElement(deletion); rxn2plug.addReplacedElement(deletion); var re2 = new ReplacedElement(); re2.setSubmodelRef("A"); re2.setPortRef("J0_port"); rxn1plug.addReplacedElement(re2); re2.setPortRef("J1_port"); rxn2plug.addReplacedElement(re2); model.addReaction(rxn); model.addReaction(rxn2); libsbml.writeSBMLToFile(document, "spec_example4.xml"); document = libsbml.readSBMLFromFile("spec_example4.xml"); if (document == null) { Console.WriteLine("Error reading back in file."); retval = -1; } else { document.setConsistencyChecks(libsbml.LIBSBML_CAT_UNITS_CONSISTENCY, false); document.checkConsistency(); if (document.getErrorLog().getNumFailsWithSeverity(2) > 0 || document.getErrorLog().getNumFailsWithSeverity(3) > 0) { var stream = new OStringStream(); document.printErrors(stream); Console.WriteLine("Errors encoutered when round-tripping SBML file: \n" + stream.str()); retval = -1; } libsbml.writeSBMLToFile(document, "spec_example4_rt.xml"); } return(retval); }
static void Main(string[] args) { SBMLNamespaces sbmlns = new SBMLNamespaces(3, 1, "fbc", 1); SBMLDocument document = new SBMLDocument(sbmlns); // create the Model Model model = document.createModel(); // create the Compartment Compartment compartment = model.createCompartment(); compartment.setId("compartment"); compartment.setConstant(true); compartment.setSize(1); // create the Species Species species = model.createSpecies(); species.setId("Node1"); species.setCompartment("compartment"); species.setConstant(false); species.setHasOnlySubstanceUnits(false); species.setBoundaryCondition(false); species = model.createSpecies(); species.setId("Node2"); species.setCompartment("compartment"); species.setConstant(false); species.setHasOnlySubstanceUnits(false); species.setConstant(false); species.setHasOnlySubstanceUnits(false); species.setBoundaryCondition(false); species = model.createSpecies(); species.setId("Node3"); species.setCompartment("compartment"); species.setConstant(false); species.setHasOnlySubstanceUnits(false); species.setBoundaryCondition(false); species = model.createSpecies(); species.setId("Node4"); species.setCompartment("compartment"); species.setConstant(false); species.setHasOnlySubstanceUnits(false); species.setBoundaryCondition(false); species = model.createSpecies(); species.setId("Node5"); species.setCompartment("compartment"); species.setConstant(false); species.setHasOnlySubstanceUnits(false); species.setBoundaryCondition(false); species = model.createSpecies(); species.setId("Node6"); species.setCompartment("compartment"); species.setConstant(false); species.setHasOnlySubstanceUnits(false); species.setBoundaryCondition(false); species = model.createSpecies(); species.setId("Node7"); species.setCompartment("compartment"); species.setConstant(false); species.setHasOnlySubstanceUnits(false); species.setBoundaryCondition(false); species = model.createSpecies(); species.setId("Node8"); species.setCompartment("compartment"); species.setConstant(false); species.setHasOnlySubstanceUnits(false); species.setBoundaryCondition(false); species = model.createSpecies(); species.setId("Node0"); species.setCompartment("compartment"); species.setConstant(false); species.setHasOnlySubstanceUnits(false); species.setBoundaryCondition(true); species = model.createSpecies(); species.setId("Node9"); species.setCompartment("compartment"); species.setConstant(false); species.setHasOnlySubstanceUnits(false); species.setBoundaryCondition(true); Reaction reaction = model.createReaction(); reaction.setId("J0"); reaction.setReversible(false); reaction.setFast(false); SpeciesReference reactant = reaction.createReactant(); reactant.setSpecies("Node0"); reactant.setStoichiometry(1); reactant.setConstant(true); SpeciesReference product = reaction.createProduct(); product.setSpecies("Node1"); product.setStoichiometry(1); product.setConstant(true); reaction = model.createReaction(); reaction.setId("J1"); reaction.setReversible(false); reaction.setFast(false); reactant = reaction.createReactant(); reactant.setSpecies("Node1"); reactant.setStoichiometry(1); reactant.setConstant(true); product = reaction.createProduct(); product.setSpecies("Node2"); product.setStoichiometry(1); product.setConstant(true); reaction = model.createReaction(); reaction.setId("J2"); reaction.setReversible(false); reaction.setFast(false); reactant = reaction.createReactant(); reactant.setSpecies("Node2"); reactant.setStoichiometry(1); reactant.setConstant(true); product = reaction.createProduct(); product.setSpecies("Node3"); product.setStoichiometry(1); product.setConstant(true); reaction = model.createReaction(); reaction.setId("J3"); reaction.setReversible(false); reaction.setFast(false); reactant = reaction.createReactant(); reactant.setSpecies("Node1"); reactant.setStoichiometry(1); reactant.setConstant(true); product = reaction.createProduct(); product.setSpecies("Node4"); product.setStoichiometry(1); product.setConstant(true); reaction = model.createReaction(); reaction.setId("J4"); reaction.setReversible(false); reaction.setFast(false); reactant = reaction.createReactant(); reactant.setSpecies("Node4"); reactant.setStoichiometry(1); reactant.setConstant(true); product = reaction.createProduct(); product.setSpecies("Node3"); product.setStoichiometry(1); product.setConstant(true); reaction = model.createReaction(); reaction.setId("J5"); reaction.setReversible(false); reaction.setFast(false); reactant = reaction.createReactant(); reactant.setSpecies("Node3"); reactant.setStoichiometry(1); reactant.setConstant(true); product = reaction.createProduct(); product.setSpecies("Node5"); product.setStoichiometry(1); product.setConstant(true); reaction = model.createReaction(); reaction.setId("J6"); reaction.setReversible(false); reaction.setFast(false); reactant = reaction.createReactant(); reactant.setSpecies("Node5"); reactant.setStoichiometry(1); reactant.setConstant(true); product = reaction.createProduct(); product.setSpecies("Node6"); product.setStoichiometry(1); product.setConstant(true); reaction = model.createReaction(); reaction.setId("J7"); reaction.setReversible(false); reaction.setFast(false); reactant = reaction.createReactant(); reactant.setSpecies("Node6"); reactant.setStoichiometry(1); reactant.setConstant(true); product = reaction.createProduct(); product.setSpecies("Node7"); product.setStoichiometry(1); product.setConstant(true); reaction = model.createReaction(); reaction.setId("J8"); reaction.setReversible(false); reaction.setFast(false); reactant = reaction.createReactant(); reactant.setSpecies("Node5"); reactant.setStoichiometry(1); reactant.setConstant(true); product = reaction.createProduct(); product.setSpecies("Node8"); product.setStoichiometry(1); product.setConstant(true); reaction = model.createReaction(); reaction.setId("J9"); reaction.setReversible(false); reaction.setFast(false); reactant = reaction.createReactant(); reactant.setSpecies("Node8"); reactant.setStoichiometry(1); reactant.setConstant(true); product = reaction.createProduct(); product.setSpecies("Node7"); product.setStoichiometry(1); product.setConstant(true); reaction = model.createReaction(); reaction.setId("J10"); reaction.setReversible(false); reaction.setFast(false); reactant = reaction.createReactant(); reactant.setSpecies("Node7"); reactant.setStoichiometry(1); reactant.setConstant(true); product = reaction.createProduct(); product.setSpecies("Node9"); product.setStoichiometry(1); product.setConstant(true); // // Get a FbcModelPlugin object plugged in the model object. // // The type of the returned value of SBase::getPlugin() function is SBasePlugin, and // thus the value needs to be casted for the corresponding derived class. // FbcModelPlugin mplugin = (FbcModelPlugin)(model.getPlugin("fbc")); FluxBound bound = mplugin.createFluxBound(); bound.setId("bound1"); bound.setReaction("J0"); bound.setOperation("equal"); bound.setValue(10); Objective objective = mplugin.createObjective(); objective.setId("obj1"); objective.setType("maximize"); // mark obj1 as active objective mplugin.setActiveObjectiveId("obj1"); FluxObjective fluxObjective = objective.createFluxObjective(); fluxObjective.setReaction("J8"); fluxObjective.setCoefficient(1); libsbml.writeSBMLToFile(document, "fbc_example1.xml"); }
private static int Main(string[] args) { var sbmlns = new SBMLNamespaces(3, 1, "comp", 1); // create the document var document = new SBMLDocument(sbmlns); //Define the external model definitions var compdoc = (CompSBMLDocumentPlugin)(document.getPlugin("comp")); compdoc.setRequired(true); var extmod = compdoc.createExternalModelDefinition(); extmod.setId("ExtMod1"); extmod.setSource("enzyme_model.xml"); extmod.setModelRef("enzyme"); // create the main Model var model = document.createModel(); // Set the submodels var mplugin = (CompModelPlugin)(model.getPlugin("comp")); var submod1 = mplugin.createSubmodel(); submod1.setId("A"); submod1.setModelRef("ExtMod1"); var submod2 = mplugin.createSubmodel(); submod2.setId("B"); submod2.setModelRef("ExtMod1"); // create a replacement compartment var comp = model.createCompartment(); comp.setSpatialDimensions(3); comp.setConstant(true); comp.setId("comp"); comp.setSize(1L); //Tell the model that this compartment replaces both of the inside ones. var compartplug = (CompSBasePlugin)(comp.getPlugin("comp")); var re = new ReplacedElement(); re.setIdRef("comp"); re.setSubmodelRef("A"); compartplug.addReplacedElement(re); re.setSubmodelRef("B"); compartplug.addReplacedElement(re); // create a replacement species var spec = model.createSpecies(); spec.setCompartment("comp"); spec.setHasOnlySubstanceUnits(false); spec.setConstant(false); spec.setBoundaryCondition(false); spec.setId("S"); //Tell the model that this species replaces both of the inside ones. var spp = (CompSBasePlugin)(spec.getPlugin("comp")); re.setIdRef("S"); re.setSubmodelRef("A"); spp.addReplacedElement(re); re.setSubmodelRef("B"); spp.addReplacedElement(re); libsbml.writeSBMLToFile(document, "spec_example2.xml"); document = libsbml.readSBMLFromFile("spec_example2.xml"); if (document == null) { Console.WriteLine("Error reading back in file."); return(-1); } else { document.setConsistencyChecks(libsbml.LIBSBML_CAT_UNITS_CONSISTENCY, false); document.checkConsistency(); if (document.getErrorLog().getNumFailsWithSeverity(2) > 0 || document.getErrorLog().getNumFailsWithSeverity(3) > 0) { var stream = new OStringStream(); document.printErrors(stream); Console.WriteLine("Errors encoutered when round-tripping SBML file: \n" + stream.str()); return(-1); } libsbml.writeSBMLToFile(document, "spec_example2_rt.xml"); } return(0); }
private static int Main(string[] args) { var retval = 0; var sbmlns = new SBMLNamespaces(3, 1, "comp", 1); // create the document var document = new SBMLDocument(sbmlns); //Create our submodel var compdoc = (CompSBMLDocumentPlugin)(document.getPlugin("comp")); compdoc.setRequired(true); var mod1 = compdoc.createModelDefinition(); mod1.setId("enzyme"); mod1.setName("enzyme"); var comp = mod1.createCompartment(); comp.setSpatialDimensions(3); comp.setConstant(true); comp.setId("comp"); comp.setSize(1L); var spec = new Species(3, 1); spec.setCompartment("comp"); spec.setHasOnlySubstanceUnits(false); spec.setConstant(false); spec.setBoundaryCondition(false); spec.setId("S"); mod1.addSpecies(spec); spec.setId("E"); mod1.addSpecies(spec); spec.setId("D"); mod1.addSpecies(spec); spec.setId("ES"); mod1.addSpecies(spec); var rxn = new Reaction(3, 1); rxn.setReversible(true); rxn.setFast(false); var rxn2 = new Reaction(rxn); rxn.setId("J0"); rxn2.setId("J1"); var sr = new SpeciesReference(3, 1); sr.setConstant(true); sr.setStoichiometry(1); sr.setSpecies("S"); rxn.addReactant(sr); sr.setSpecies("E"); rxn.addReactant(sr); rxn2.addProduct(sr); sr.setSpecies("ES"); rxn.addProduct(sr); rxn2.addReactant(sr); sr.setSpecies("D"); rxn2.addProduct(sr); mod1.addReaction(rxn); mod1.addReaction(rxn2); // create the Model var model = document.createModel(); model.setId("aggregate"); // Create a submodel var mplugin = (CompModelPlugin)(model.getPlugin("comp")); var submod1 = mplugin.createSubmodel(); submod1.setId("submod1"); submod1.setModelRef("enzyme"); var submod2 = new Submodel(); submod2.setId("submod2"); submod2.setModelRef("enzyme"); mplugin.addSubmodel(submod2); libsbml.writeSBMLToFile(document, "enzyme_model.xml"); document = libsbml.readSBMLFromFile("enzyme_model.xml"); if (document == null) { Console.WriteLine("Error reading back in file."); retval = -1; } else { document.setConsistencyChecks(libsbml.LIBSBML_CAT_UNITS_CONSISTENCY, false); document.checkConsistency(); if (document.getErrorLog().getNumFailsWithSeverity(2) > 0 || document.getErrorLog().getNumFailsWithSeverity(3) > 0) { var stream = new OStringStream(); document.printErrors(stream); Console.WriteLine("Errors encoutered when round-tripping SBML file: \n" + stream.str()); retval = -1; } libsbml.writeSBMLToFile(document, "enzyme_model_rt.xml"); } return(retval); }
public static int Main(string[] args) { int retval = 0; SBMLNamespaces sbmlns = new SBMLNamespaces(3, 1, "comp", 1); // create the document SBMLDocument document = new SBMLDocument(sbmlns); // create the Model Model model = document.createModel(); // create a replacement parameter Parameter parameter = model.createParameter(); parameter.setId("x"); parameter.setConstant(true); // create a parameter to be a conversion factor Parameter param2 = model.createParameter(); param2.setId("x_conv"); param2.setMetaId("_110013"); param2.setConstant(true); // create a parameter to be a conversion factor Parameter param3 = model.createParameter(); param3.setId("lcf"); param3.setConstant(true); // Convert parameter to the plugin version so we can add the new attributes and replacements to it. CompSBasePlugin splugin = (CompSBasePlugin)(parameter.getPlugin("comp")); // Add a replaced element. ReplacedElement rep1 = splugin.createReplacedElement(); int rv = rep1.setSubmodelRef("submod1"); rv = rep1.setConversionFactor("x_conv"); rv = rep1.setIdRef("param1"); // Add a second replaced element in a different way. ReplacedElement rep2 = new ReplacedElement(); rv = rep2.setSubmodelRef("submod2"); rv = rep2.setDeletion("del1"); rv = splugin.addReplacedElement(rep2); //Now create a replaced element that points into a submodel. rep2.unsetDeletion(); rep2.setIdRef("submod2"); SBaseRef sbr5 = rep2.createSBaseRef(); sbr5.setIdRef("submodelG"); SBaseRef sbr6 = sbr5.createSBaseRef(); sbr6.setIdRef("buriedElement"); splugin.addReplacedElement(rep2); // Create a submodel CompModelPlugin mplugin = (CompModelPlugin)(model.getPlugin("comp")); CompSBMLDocumentPlugin compdoc = (CompSBMLDocumentPlugin)(document.getPlugin("comp")); compdoc.setRequired(true); ModelDefinition moddef1 = compdoc.createModelDefinition(); moddef1.setId("Mod1"); Parameter m1param1 = moddef1.createParameter(); m1param1.setId("param1"); m1param1.setConstant(true); Parameter m1param2 = moddef1.createParameter(); m1param2.setId("param2"); m1param2.setConstant(false); m1param2.setValue(3.2); ModelDefinition moddef2 = new ModelDefinition(); moddef2.setId("Mod2"); Parameter subparam2 = moddef2.createParameter(); subparam2.setId("subparam2"); subparam2.setConstant(false); compdoc.addModelDefinition(moddef2); ExternalModelDefinition extmod1 = compdoc.createExternalModelDefinition(); extmod1.setId("ExtMod1"); extmod1.setSource("urn:miriam:biomodels.db:BIOMD0000000127"); ExternalModelDefinition extmod2 = new ExternalModelDefinition(); extmod2.setId("ExtMod2"); extmod2.setSource("otherfile.xml"); extmod2.setModelRef("modelnamethere"); extmod2.setMd5("406022s908ge74sklj"); compdoc.addExternalModelDefinition(extmod2); Submodel submod1 = mplugin.createSubmodel(); submod1.setId("submod1"); submod1.setModelRef("Mod1"); Deletion del1 = submod1.createDeletion(); del1.setId("deletionA"); del1.setIdRef("param2"); Submodel submod2 = new Submodel(); submod2.setId("submod2"); submod2.setModelRef("ExtMod1"); submod2.setSubstanceConversionFactor("subcf"); submod2.setTimeConversionFactor("tcf"); submod2.setExtentConversionFactor("xtf"); Deletion del2 = new Deletion(); del2.setId("deletionB"); del2.setMetaIdRef("_0010110"); rv = submod2.addDeletion(del2); del2.setId("deletionC"); del2.unsetMetaIdRef(); del2.setPortRef("port2"); rv = submod2.addDeletion(del2); del2.unsetId(); del2.unsetPortRef(); del2.setUnitRef("mph"); rv = submod2.addDeletion(del2); del2.unsetUnitRef(); del2.setIdRef("submodG"); SBaseRef sbr = del2.createSBaseRef(); sbr.setIdRef("element5"); rv = submod2.addDeletion(del2); Deletion del3 = new Deletion(); del3.setIdRef("submodG"); SBaseRef sbr2 = new SBaseRef(); sbr2.setIdRef("subsubmodQ"); SBaseRef subsbr = sbr2.createSBaseRef(); subsbr.setPortRef("toBdel"); del3.setSBaseRef(sbr2); submod2.addDeletion(del3); mplugin.addSubmodel(submod2); Port port1 = mplugin.createPort(); port1.setId("port1"); port1.setMetaIdRef("_110013"); Port port2 = new Port(); port2.setId("port2"); port2.setIdRef("x"); mplugin.addPort(port2); port2.setId("port3"); port2.setIdRef("submod2"); port2.setSBaseRef(sbr2); mplugin.addPort(port2); libsbml.writeSBMLToFile(document, "comp_example1.xml"); document = libsbml.readSBMLFromFile("comp_example1.xml"); if (document == null) { Console.WriteLine("Error reading back in file."); retval = -1; } else { document.setConsistencyChecks(libsbml.LIBSBML_CAT_UNITS_CONSISTENCY, false); document.checkConsistency(); if (document.getErrorLog().getNumFailsWithSeverity(2) > 0 || document.getErrorLog().getNumFailsWithSeverity(3) > 0) { OStringStream stream = new OStringStream(); document.printErrors(stream); Console.WriteLine("Errors encoutered when round-tripping SBML file: \n" + stream.str()); retval = -1; } libsbml.writeSBMLToFile(document, "comp_example1_rt.xml"); } return(retval); }
static void Main(string[] args) { SBMLNamespaces sbmlns = new SBMLNamespaces(3, 1, "multi", 1); // create the document SBMLDocument document = new SBMLDocument(sbmlns); // set the required attribute to true SBMLDocumentPlugin docPlug = (SBMLDocumentPlugin)(document.getPlugin("multi")); docPlug.setRequired(true); // create the Model Model model = document.createModel(); // create the compartments Compartment c = model.createCompartment(); c.setId("membrane"); c.setConstant(true); // set the multi attribute isType via the compartmentPlugin MultiCompartmentPlugin compPlug = (MultiCompartmentPlugin)(c.getPlugin("multi")); compPlug.setIsType(true); // create the speciesTypes MultiModelPlugin modelPlug = (MultiModelPlugin)(model.getPlugin("multi")); MultiSpeciesType st = modelPlug.createMultiSpeciesType(); st.setId("stX"); st.setCompartment("membrane"); // create species Species s = model.createSpecies(); s.setId("s1"); s.setCompartment("membrane"); s.setBoundaryCondition(false); s.setHasOnlySubstanceUnits(false); s.setConstant(false); // set the multi attribute speciesType via the compartmentPlugin MultiSpeciesPlugin spPlug = (MultiSpeciesPlugin)(s.getPlugin("multi")); spPlug.setSpeciesType("stX"); // create species feature SpeciesFeature sf = spPlug.createSpeciesFeature(); sf.setSpeciesFeatureType("a"); sf.setOccur(1); sf.setComponent("b"); SpeciesFeatureValue sfv = sf.createSpeciesFeatureValue(); sfv.setValue("c"); // create a subListOfSpeciesFeatures SubListOfSpeciesFeatures subloSF = spPlug.createSubListOfSpeciesFeatures(); subloSF.setRelation(libsbml.Relation_fromString("and")); // add speciesFeatures to the subList SpeciesFeature sf1 = new SpeciesFeature(3, 1, 1); sf1.setSpeciesFeatureType("a1"); sf1.setOccur(1); sf1.setComponent("b1"); SpeciesFeatureValue sfv1 = sf1.createSpeciesFeatureValue(); sfv1.setValue("c1"); subloSF.appendAndOwn(sf1); sf1 = new SpeciesFeature(3, 1, 1); sf1.setSpeciesFeatureType("a2"); sf1.setOccur(1); sf1.setComponent("b2"); sfv1 = sf1.createSpeciesFeatureValue(); sfv1.setValue("c2"); subloSF.appendAndOwn(sf1); // create a second subListOfSpeciesfeatures subloSF = spPlug.createSubListOfSpeciesFeatures(); subloSF.setRelation(libsbml.Relation_fromString("or")); sf1 = new SpeciesFeature(3, 1, 1); sf1.setSpeciesFeatureType("a3"); sf1.setOccur(1); sf1.setComponent("b3"); sfv1 = sf1.createSpeciesFeatureValue(); sfv1.setValue("c3"); subloSF.appendAndOwn(sf1); sf1 = new SpeciesFeature(3, 1, 1); sf1.setSpeciesFeatureType("a4"); sf1.setOccur(1); sf1.setComponent("b4"); sfv1 = sf1.createSpeciesFeatureValue(); sfv1.setValue("c4"); subloSF.appendAndOwn(sf1); libsbml.writeSBML(document, "multi_example3.xml"); }
public static void Main(string[] args) { // // Creates an SBMLNamespaces object with the given SBML level, version // package name, package version. // // (NOTE) By defualt, the name of package (i.e. "groups") will be used // if the arugment for the prefix is missing or empty. Thus the argument // for the prefix can be added as follows: // // SBMLNamespaces sbmlns(3,1,"groups",1,"GROUP"); // SBMLNamespaces sbmlns = new SBMLNamespaces(3, 1, "groups", 1); // // (NOTES) The above code creating an SBMLNamespaces object can be replaced // with one of the following other styles. // // (1) Creates an SBMLNamespace object with a SBML core namespace and then // adds a groups package namespace to the object. // // SBMLNamespaces sbmlns(3,1); // sbmlns.addPkgNamespace("groups",1); // // OR // // SBMLNamespaces sbmlns(3,1); // sbmlns.addNamespace(GroupsExtension::XmlnsL3V1V1,"groups"); // // (2) Creates a GroupsPkgNamespaces object (SBMLNamespace derived class for // groups package. The class is basically used for createing an SBase derived // objects defined in the groups package) with the given SBML level, version, // and package version // // GroupsPkgNamespaces sbmlns(3,1,1); // // create the document SBMLDocument document = new SBMLDocument(sbmlns); // create the Model Model model = document.createModel(); // create the Compartment Compartment compartment = model.createCompartment(); compartment.setId("cytosol"); compartment.setConstant(true); compartment = model.createCompartment(); compartment.setId("mitochon"); compartment.setConstant(true); // create the Species Species species = model.createSpecies(); species.setId("ATPc"); species.setCompartment("cytosol"); species.setInitialConcentration(1); species.setHasOnlySubstanceUnits(false); species.setBoundaryCondition(false); species.setConstant(false); species = model.createSpecies(); species.setId("ATPm"); species.setCompartment("mitochon"); species.setInitialConcentration(2); species.setHasOnlySubstanceUnits(false); species.setBoundaryCondition(false); species.setConstant(false); // create the Groups // // Get a GroupsModelPlugin object plugged in the model object. // // The type of the returned value of SBase::getPlugin() function is SBasePlugin, and // thus the value needs to be casted for the corresponding derived class. // GroupsModelPlugin mplugin = (GroupsModelPlugin)(model.getPlugin("groups")); // // Creates a Group object via GroupsModelPlugin object. // Group group = mplugin.createGroup(); group.setId("ATP"); group.setKind(libsbml.GROUP_KIND_CLASSIFICATION); group.setSBOTerm("SBO:0000252"); Member member = group.createMember(); member.setIdRef("ATPc"); member = group.createMember(); member.setIdRef("ATPm"); libsbml.writeSBML(document, "groups_example1-cs.xml"); }
public static void Main(string[] args) { ArraysPkgNamespaces arraysNs = new ArraysPkgNamespaces(); SBMLDocument doc = new SBMLDocument(arraysNs); doc.setPackageRequired("arrays", true); Model model = doc.createModel(); // create compartment Compartment comp = model.createCompartment(); comp.setMetaId("dd"); comp.setId("s"); comp.setConstant(true); // set dimensions ArraysSBasePlugin compPlugin = (ArraysSBasePlugin)comp.getPlugin("arrays"); Dimension dim = compPlugin.createDimension(); dim.setId("i"); dim.setSize("n"); // create species Species species = model.createSpecies(); species.setId("A"); species.setCompartment("s"); species.setHasOnlySubstanceUnits(false); species.setBoundaryCondition(false); species.setConstant(false); ArraysSBasePlugin splugin = (ArraysSBasePlugin)species.getPlugin("arrays"); dim = splugin.createDimension(); dim.setId("i"); dim.setSize("n"); species = model.createSpecies(); species.setId("B"); species.setCompartment("s"); species.setHasOnlySubstanceUnits(false); species.setBoundaryCondition(false); species.setConstant(false); splugin = (ArraysSBasePlugin)species.getPlugin("arrays"); dim = splugin.createDimension(); dim.setId("i"); dim.setSize("n"); species = model.createSpecies(); species.setId("C"); species.setCompartment("s"); species.setHasOnlySubstanceUnits(false); species.setBoundaryCondition(false); species.setConstant(false); splugin = (ArraysSBasePlugin)species.getPlugin("arrays"); dim = splugin.createDimension(); dim.setId("i"); dim.setSize("n"); // create parameter Parameter param = model.createParameter(); param.setId("n"); param.setValue(100); param.setConstant(true); // create reaction Reaction reaction = model.createReaction(); reaction.setId("reaction1"); reaction.setReversible(false); reaction.setFast(false); ArraysSBasePlugin reactionPlugin = (ArraysSBasePlugin)reaction.getPlugin("arrays"); dim = reactionPlugin.createDimension(); dim.setId("i"); dim.setSize("n"); SpeciesReference speciesRef = reaction.createReactant(); speciesRef.setSpecies("A"); speciesRef.setConstant(false); ArraysSBasePlugin refPlugin = (ArraysSBasePlugin)speciesRef.getPlugin("arrays"); Index index = refPlugin.createIndex(); ASTNode ast = new ASTNode(libsbml.AST_LINEAR_ALGEBRA_SELECTOR); ASTNode ci = new ASTNode(libsbml.AST_NAME); ci.setName("A"); ast.addChild(ci); ci = new ASTNode(libsbml.AST_NAME); ci.setName("i"); ast.addChild(ci); index.setMath(ast); speciesRef = reaction.createProduct(); speciesRef.setSpecies("C"); speciesRef.setConstant(false); refPlugin = (ArraysSBasePlugin)speciesRef.getPlugin("arrays"); index = refPlugin.createIndex(); ast = new ASTNode(libsbml.AST_LINEAR_ALGEBRA_SELECTOR); ci = new ASTNode(libsbml.AST_NAME); ci.setName("C"); ast.addChild(ci); ci = new ASTNode(libsbml.AST_NAME); ci.setName("i"); ast.addChild(ci); index.setMath(ast); libsbml.writeSBMLToFile(doc, "arrays1.xml"); }
public static int Main(string[] args) { // Creates an SBMLNamespaces object with the given SBML level, version // package name, package version. SBMLNamespaces sbmlns = new SBMLNamespaces(3, 1, "qual", 1); // create the document SBMLDocument document = new SBMLDocument(sbmlns); // mark qual as required document.setPackageRequired("qual", true); // create the Model Model model = document.createModel(); // create the Compartment Compartment compartment = model.createCompartment(); compartment.setId("c"); compartment.setConstant(true); // Get a QualModelPlugin object plugged in the model object. QualModelPlugin mplugin = (QualModelPlugin)(model.getPlugin("qual")); // create the QualitativeSpecies QualitativeSpecies qs = mplugin.createQualitativeSpecies(); qs.setId("s1"); qs.setCompartment("c"); qs.setConstant(false); qs.setInitialLevel(1); qs.setMaxLevel(4); qs.setName("sss"); // create the Transition Transition t = mplugin.createTransition(); t.setId("d"); t.setSBOTerm(1); Input i = t.createInput(); i.setId("RD"); i.setQualitativeSpecies("s1"); i.setTransitionEffect(libsbml.INPUT_TRANSITION_EFFECT_NONE); i.setSign(libsbml.INPUT_SIGN_NEGATIVE); i.setThresholdLevel(2); i.setName("aa"); Output o = t.createOutput(); o.setId("wd"); o.setQualitativeSpecies("s1"); o.setTransitionEffect(libsbml.OUTPUT_TRANSITION_EFFECT_PRODUCTION); o.setOutputLevel(2); o.setName("aa"); FunctionTerm ft = t.createFunctionTerm(); ASTNode math = libsbml.parseL3Formula("geq(s1, 2)"); ft.setResultLevel(1); ft.setMath(math); DefaultTerm dt = t.createDefaultTerm(); dt.setResultLevel(2); int result = libsbml.writeSBML(document, "qual_example1.xml"); if (result == 1) { Console.WriteLine("Wrote file"); return(0); } else { Console.WriteLine("Failed to write"); return(1); } }