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); }
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, "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"); }
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); }