Package org.sbml.jsbml

Examples of org.sbml.jsbml.Model


  // TODO : transform this file into a proper junit test class that is included in the jsbml standard tests.
  // The junit test file would test uniqueness of metaids and ids in the model. 
   
  // Setup : creating some simple objects
    SBMLDocument doc=new SBMLDocument(2,4);
    Model m=doc.createModel("model1");
    Reaction r = m.createReaction("id1");
    SpeciesReference s = new SpeciesReference();
    s.setMetaId("meta2");
    r.addReactant(s);
    r.setMetaId("meta");

    System.out.println("Reaction parent and model                    : " + r.getParent() + " " + r.getModel() + "\n");

    Reaction clonedReaction = r.clone();
   
    // Here everything is fine, the cloned reaction get created with all
    // the appropriate fields but the parent that is set to null for all cloned JSBML objects
    // (any objects that inherit from AbstracTreeNode)
    // That is why the getParent() and getModel() are returning null as they should
    System.out.println("Cloned reaction metaid and id                : " + clonedReaction.getMetaId() + " " + clonedReaction.getId());
    System.out.println("Cloned reaction metaid of the first reactant : " + clonedReaction.getReactant(0).getMetaId());
    System.out.println("Cloned reaction parent and model             : " + clonedReaction.getParent() + " " + clonedReaction.getModel() + "\n");
   
    System.out.println("Trying to add the cloned reaction to the model, which should not be possible");
    // Trying to add the
    boolean operationSuccessful = m.addReaction(clonedReaction);

    if (operationSuccessful != false) {
      throw new SBMLException("It should not be possible to add two elements with the same id in a ListOf class !!");
    }
    // Here the parent is still null as it should as the cloned reaction
    // was not added to the model as her id is the same as the reaction 'r'
    System.out.println("Cloned reaction parent and model still null  : " + clonedReaction.getParent() + " " + clonedReaction.getModel() + "\n");

    // setting a new unit id the the cloned reaction
    clonedReaction.setId("id2");
   
    System.out.println("Trying to add the cloned reaction to the model, with a new unique id. It is still not possible as the metaids are not unique.");
    try {
      m.addReaction(clonedReaction);
      throw new SBMLException("It should not be possible to add two elements with the same metaid in a SBML document !!");
    } catch (IllegalArgumentException e) {
      // success, the exception should be thrown there
    }

    // setting a new unique metaid to the reaction but not it's sub-elements
    clonedReaction.setMetaId("meta3");  
   
    System.out.println("Trying to add the cloned reaction to the model, with a new unique id and metaid. It is still not possible as the metaids are not unique.");
    try {
      operationSuccessful = m.addReaction(clonedReaction);
      throw new SBMLException("It should not be possible to add a reaction that has any sub-elements with a non unique metaid !!");
    } catch (IllegalArgumentException e) {
      // success, the exception should be thrown there
    }

    System.out.println("Trying to add the cloned reaction to the model, with a new unique id and metaid for all sub-elements.");
    // setting a new unique metaid to the reaction and all it's sub-elements
    clonedReaction.getReactant(0).setMetaId("meta4");

    // At the moment (rev 768), the reaction cannot be added to the model as the metaid 'meta3' as
    // been added in the list of metaids in the previous call to addReaction() where only the speciesReference id
    // was invalid
    try {
      operationSuccessful = m.addReaction(clonedReaction);

      if (operationSuccessful != true) {
        throw new SBMLException("It should be possible to add a reaction with an unique ids and metaids to a model !!");
      }
    } catch (IllegalArgumentException e) {
      // bug here
      System.out.println("Bug detected : there is a problem in the recursive adding of metaids !!!");
      System.out.println("The reaction was not added to the model where it should have been");
    }

    System.out.println("Cloned reaction parent and model should be set  : " + clonedReaction.getParent() + " " + clonedReaction.getModel());
    System.out.println("Model.getReaction(0) id                         : " + m.getReaction(0).getId());
    System.out.println("Model.getReaction(1)                            : " + m.getReaction(1));
    // System.out.println("Model.getReaction(1) parent                     : " + m.getReaction(1).getParent());

   
    // At the moment (rev 744), the species can be created and added to the model
    // This should no be possible as the id of the species is the same as the one
    // from the first reaction !!
    Species s1 = m.createSpecies("id1");

    System.out.println("\n\nNB species in the model (Should be 0)          : " + m.getNumSpecies());
    System.out.println(s1.getParent() + " " + s1.getModel());

    if (m.getNumSpecies() > 0) {
      // bug here
      System.out.println("Bug detected :  it should no be possible as the id of the species is the same as the one from the first reaction !!!");     
    }
  }
View Full Code Here


  private Model M;

  @Before
  public void setUp() throws Exception {
    M = new Model(2, 4);
  }
View Full Code Here

  @SuppressWarnings("deprecation")
@Test public void test_read_l2v1_assignment()
  {
    SBMLReader reader = new SBMLReader();
    SBMLDocument d = null;
    Model m;
    Compartment c;
    Species s;
    Parameter gp;
    LocalParameter lp;
    AssignmentRule ar;
    Reaction r;
    SpeciesReference sr;
    KineticLaw kl;
    UnitDefinition ud;
    Reaction r1;
    ListOf<Compartment> loc;
    Compartment c1;
    ListOf<Rule> lor;
    AssignmentRule ar1;
    ListOf<Parameter> lop;
    Parameter p1;
    ListOf<Species> los;
    Species s1;
    String filename = new String( DATA_FOLDER + "/libsbml-test-data/" );
    filename += "l2v1-assignment.xml";
    try {
    d = reader.readSBML(filename);
  } catch (IOException e) {
    e.printStackTrace();
    assert(false);
  } catch (XMLStreamException e) {
    e.printStackTrace();
    assert(false);
  }

  System.out.println(" TestReadFromFile 5 : reading done.");
 
  assertTrue( d.getLevel() == 2 );
    assertTrue( d.getVersion() == 1 );
    m = d.getModel();
    assertTrue( m != null );
    assertTrue( m.getNumCompartments() == 1 );
    c = m.getCompartment(0);
    assertTrue( c != null );
    assertTrue( c.getId().equals( "cell") );
/*    ud = c.getDerivedUnitDefinition();
    assertTrue( ud.getNumUnits() == 1 );
    assertTrue( ud.getUnit(0).getKind() == Kind.LITRE );
    */
    loc = m.getListOfCompartments();
    c1 = loc.get(0);
    assertTrue( c1.equals(c) );
    c1 = loc.get("cell");
    assertTrue( c1.equals(c) );
    assertTrue( m.getNumSpecies() == 5 );
    s = m.getSpecies(0);
    assertTrue( s != null );
    assertTrue( s.getId().equals( "X0"  ) );
    assertTrue( s.getCompartment().equals( "cell") );
    assertTrue( s.getInitialConcentration() == 1.0 );
    los = m.getListOfSpecies();
    s1 = los.get(0);
    assertTrue( s1.equals(s) );
    s1 = los.get("X0");
    assertTrue( s1.equals(s) );
    s = m.getSpecies(1);
    assertTrue( s != null );
    assertTrue( s.getId().equals( "X1"  ) );
    assertTrue( s.getCompartment().equals( "cell") );
    assertTrue( s.getInitialConcentration() == 0.0 );
    s = m.getSpecies(2);
    assertTrue( s != null );
    assertTrue( s.getId().equals( "T"   ) );
    assertTrue( s.getCompartment().equals( "cell") );
    assertTrue( s.getInitialConcentration() == 0.0 );
    s = m.getSpecies(3);
    assertTrue( s != null );
    assertTrue( s.getId().equals( "S1"  ) );
    assertTrue( s.getCompartment().equals( "cell") );
    assertTrue( s.getInitialConcentration() == 0.0 );
    s = m.getSpecies(4);
    assertTrue( s != null );
    assertTrue( s.getId().equals( "S2"  ) );
    assertTrue( s.getCompartment().equals( "cell") );
    assertTrue( s.getInitialConcentration() == 0.0 );
    assertTrue( m.getNumParameters() == 1 );
    gp = m.getParameter(0);
    assertTrue( gp != null );
    assertTrue( gp.getId().equals( "Keq") );
    assertTrue( gp.getValue() == 2.5 );
    lop = m.getListOfParameters();
    p1 = lop.get(0);
    assertTrue( p1.equals(gp) );
    p1 = lop.get("Keq");
    assertTrue( p1.equals(gp) );
    /*
    ud = gp.getDerivedUnitDefinition();
    assertTrue( ud.getNumUnits() == 0 );
    assertTrue( m.getNumRules() == 2 );
    */
    ar = (AssignmentRulem.getRule(0);
    assertTrue( ar != null );
    assertTrue( ar.getVariable().equals( "S1"           ) );
    assertTrue( ar.getFormula().equals( "T/(1+Keq)") );
    /*
    ud = ar.getDerivedUnitDefinition();
    assertTrue( ud.getNumUnits() == 2 );
    assertTrue( ud.getUnit(0).getKind() == Kind.MOLE );
    assertTrue( ud.getUnit(0).getExponent() == 1 );
    assertTrue( ud.getUnit(1).getKind() == Kind.LITRE );
    assertTrue( ud.getUnit(1).getExponent() == -1 );
    */
    assertTrue( ar.containsUndeclaredUnits() == true );
    lor = m.getListOfRules();
    ar1 = (AssignmentRule) lor.get(0);
    assertTrue( ar1.equals(ar) );
    ar1 = (AssignmentRule) lor.get("S1");
    assertTrue( ar1.equals(ar) );
    ar = (AssignmentRulem.getRule(1);
    assertTrue( ar != null );
    assertTrue( ar.getVariable().equals( "S2"      ) );
    assertTrue( ar.getFormula().equals( "Keq*S1") );
    assertTrue( m.getNumReactions() == 2 );
    r = m.getReaction(0);
    assertTrue( r != null );
    assertTrue( r.getId().equals( "in") );
    assertTrue( r.getNumReactants() == 1 );
    assertTrue( r.getNumProducts() == 1 );
    sr = r.getReactant(0);
    assertTrue( sr != null );
    assertTrue( sr.getSpecies().equals( "X0") );
    sr = r.getProduct(0);
    assertTrue( sr != null );
    assertTrue( sr.getSpecies().equals( "T" ) );
    kl = r.getKineticLaw();
    assertTrue( kl != null );
    assertTrue( kl.getFormula().equals( "k1*X0") );
    assertTrue( kl.getLocalParameterCount() == 1 );
    r1 = (Reaction) kl.getParentSBMLObject();
    assertTrue( r1 != null );
    assertTrue( r1.getId().equals( "in") );
    assertTrue( r1.getNumReactants() == 1 );
    assertTrue( r1.getNumProducts() == 1 );
    lp = kl.getLocalParameter(0);
    assertTrue( lp != null );
    assertTrue( lp.getId().equals( "k1") );
    assertTrue( lp.getValue() == 0.1 );
    kl = (KineticLaw) lp.getParentSBMLObject().getParentSBMLObject();
    assertTrue( kl != null );
    assertTrue( kl.getFormula().equals( "k1*X0") );
    assertTrue( kl.getLocalParameterCount() == 1 );
    r = m.getReaction(1);
    assertTrue( r != null );
    assertTrue( r.getId().equals( "out") );
    assertTrue( r.getNumReactants() == 1 );
    assertTrue( r.getNumProducts() == 1 );
    sr = r.getReactant(0);
View Full Code Here

   * @throws SBMLException
   */
  public EventTest() throws ParseException, XMLStreamException, SBMLException {
    SBMLDocument doc = new SBMLDocument(3, 1);
    doc.addTreeNodeChangeListener(this);
    Model model = doc.createModel("event_model");
    Compartment c = model.createCompartment("compartment");
    model.createSpecies("s1", c);
    model.createSpecies("s2", c);
    Event ev = model.createEvent();
    Trigger trigger = ev.createTrigger(false, true, ASTNode.parseFormula("3 >= 2"));
    trigger.setMath(ASTNode.geq(new ASTNode(ASTNode.Type.NAME_TIME),
        new ASTNode(10)));
    ev.createPriority(ASTNode.parseFormula("25"));
    ev.createDelay(ASTNode.parseFormula("2"));
View Full Code Here

  @SuppressWarnings("deprecation")
@Test public void test_read_l2v1_assignment()
  {
    SBMLReader reader = new SBMLReader();
    SBMLDocument d = null;
    Model m;
    Compartment c;
    Species s;
    Parameter gp;
    LocalParameter lp;
    AssignmentRule ar;
    Reaction r;
    SpeciesReference sr;
    KineticLaw kl;
    UnitDefinition ud;
    Reaction r1;
    ListOf<Compartment> loc;
    Compartment c1;
    ListOf<Rule> lor;
    AssignmentRule ar1;
    ListOf<Parameter> lop;
    Parameter p1;
    ListOf<Species> los;
    Species s1;
    String filename = new String( DATA_FOLDER + "/libsbml-test-data/" );
    filename += "l2v1-assignment.xml";
    try {
    d = reader.readSBML(filename);
  } catch (IOException e) {
    e.printStackTrace();
    assert(false);
  } catch (XMLStreamException e) {
    e.printStackTrace();
    assert(false);
  }

  System.out.println(" TestReadFromFile 5 : reading done.");
 
  assertTrue( d.getLevel() == 2 );
    assertTrue( d.getVersion() == 1 );
    m = d.getModel();
    assertTrue( m != null );
    assertTrue( m.getNumCompartments() == 1 );
    c = m.getCompartment(0);
    assertTrue( c != null );
    assertTrue( c.getId().equals( "cell") );
/*    ud = c.getDerivedUnitDefinition();
    assertTrue( ud.getNumUnits() == 1 );
    assertTrue( ud.getUnit(0).getKind() == Kind.LITRE );
    */
    loc = m.getListOfCompartments();
    c1 = loc.get(0);
    assertTrue( c1.equals(c) );
    c1 = loc.get("cell");
    assertTrue( c1.equals(c) );
    assertTrue( m.getNumSpecies() == 5 );
    s = m.getSpecies(0);
    assertTrue( s != null );
    assertTrue( s.getId().equals( "X0"  ) );
    assertTrue( s.getCompartment().equals( "cell") );
    assertTrue( s.getInitialConcentration() == 1.0 );
    los = m.getListOfSpecies();
    s1 = los.get(0);
    assertTrue( s1.equals(s) );
    s1 = los.get("X0");
    assertTrue( s1.equals(s) );
    s = m.getSpecies(1);
    assertTrue( s != null );
    assertTrue( s.getId().equals( "X1"  ) );
    assertTrue( s.getCompartment().equals( "cell") );
    assertTrue( s.getInitialConcentration() == 0.0 );
    s = m.getSpecies(2);
    assertTrue( s != null );
    assertTrue( s.getId().equals( "T"   ) );
    assertTrue( s.getCompartment().equals( "cell") );
    assertTrue( s.getInitialConcentration() == 0.0 );
    s = m.getSpecies(3);
    assertTrue( s != null );
    assertTrue( s.getId().equals( "S1"  ) );
    assertTrue( s.getCompartment().equals( "cell") );
    assertTrue( s.getInitialConcentration() == 0.0 );
    s = m.getSpecies(4);
    assertTrue( s != null );
    assertTrue( s.getId().equals( "S2"  ) );
    assertTrue( s.getCompartment().equals( "cell") );
    assertTrue( s.getInitialConcentration() == 0.0 );
    assertTrue( m.getNumParameters() == 1 );
    gp = m.getParameter(0);
    assertTrue( gp != null );
    assertTrue( gp.getId().equals( "Keq") );
    assertTrue( gp.getValue() == 2.5 );
    lop = m.getListOfParameters();
    p1 = lop.get(0);
    assertTrue( p1.equals(gp) );
    p1 = lop.get("Keq");
    assertTrue( p1.equals(gp) );
    /*
    ud = gp.getDerivedUnitDefinition();
    assertTrue( ud.getNumUnits() == 0 );
    assertTrue( m.getNumRules() == 2 );
    */
    ar = (AssignmentRulem.getRule(0);
    assertTrue( ar != null );
    assertTrue( ar.getVariable().equals( "S1"           ) );
    assertTrue( ar.getFormula().equals( "T/(1+Keq)") );
    /*
    ud = ar.getDerivedUnitDefinition();
    assertTrue( ud.getNumUnits() == 2 );
    assertTrue( ud.getUnit(0).getKind() == Kind.MOLE );
    assertTrue( ud.getUnit(0).getExponent() == 1 );
    assertTrue( ud.getUnit(1).getKind() == Kind.LITRE );
    assertTrue( ud.getUnit(1).getExponent() == -1 );
    */
    assertTrue( ar.containsUndeclaredUnits() == true );
    lor = m.getListOfRules();
    ar1 = (AssignmentRule) lor.get(0);
    assertTrue( ar1.equals(ar) );
    ar1 = (AssignmentRule) lor.get("S1");
    assertTrue( ar1.equals(ar) );
    ar = (AssignmentRulem.getRule(1);
    assertTrue( ar != null );
    assertTrue( ar.getVariable().equals( "S2"      ) );
    assertTrue( ar.getFormula().equals( "Keq*S1") );
    assertTrue( m.getNumReactions() == 2 );
    r = m.getReaction(0);
    assertTrue( r != null );
    assertTrue( r.getId().equals( "in") );
    assertTrue( r.getNumReactants() == 1 );
    assertTrue( r.getNumProducts() == 1 );
    sr = r.getReactant(0);
    assertTrue( sr != null );
    assertTrue( sr.getSpecies().equals( "X0") );
    sr = r.getProduct(0);
    assertTrue( sr != null );
    assertTrue( sr.getSpecies().equals( "T" ) );
    kl = r.getKineticLaw();
    assertTrue( kl != null );
    assertTrue( kl.getFormula().equals( "k1*X0") );
    assertTrue( kl.getLocalParameterCount() == 1 );
    r1 = (Reaction) kl.getParentSBMLObject();
    assertTrue( r1 != null );
    assertTrue( r1.getId().equals( "in") );
    assertTrue( r1.getNumReactants() == 1 );
    assertTrue( r1.getNumProducts() == 1 );
    lp = kl.getLocalParameter(0);
    assertTrue( lp != null );
    assertTrue( lp.getId().equals( "k1") );
    assertTrue( lp.getValue() == 0.1 );
    kl = (KineticLaw) lp.getParentSBMLObject().getParentSBMLObject();
    assertTrue( kl != null );
    assertTrue( kl.getFormula().equals( "k1*X0") );
    assertTrue( kl.getLocalParameterCount() == 1 );
    r = m.getReaction(1);
    assertTrue( r != null );
    assertTrue( r.getId().equals( "out") );
    assertTrue( r.getNumReactants() == 1 );
    assertTrue( r.getNumProducts() == 1 );
    sr = r.getReactant(0);
View Full Code Here

  }


  public boolean coefficientCheck() {
    boolean check = true;
    Model model = getModel();
    ListOf<Parameter> params = model.getListOfParameters();
    ListOf<DiffusionCoefficient> diffCoeffs = new ListOf<DiffusionCoefficient>();
    ListOf<AdvectionCoefficient> advCoeffs = new ListOf<AdvectionCoefficient>();

    for (Parameter p: params) {
      SpatialParameterPlugin paramPlugin =
View Full Code Here

        return compSBMLDoc.getListOfModelDefinitions();
      }
    } // end SBMLDocument
    else if (contextObject instanceof Model)
    {
      Model model = (Model) contextObject;
      CompModelPlugin compModel = null;

      if (model.getExtension(namespaceURI) != null) {
        compModel = (CompModelPlugin) model.getExtension(namespaceURI);
      } else {
        compModel = new CompModelPlugin(model);
        model.addExtension(namespaceURI, compModel);
      }

      if (elementName.equals(CompConstants.listOfSubmodels))
      {
        return compModel.getListOfSubmodels();
View Full Code Here

  /**
   * Direct access to the {@link GraphicalObject} linked to this
   * {@link TextGlyph}.
   */
  public GraphicalObject getGraphicalObjectInstance() {
    Model model = getModel();
    return (GraphicalObject) (isSetGraphicalObject() && (model != null) ? model.findNamedSBase(getGraphicalObject()) : null);
  }
View Full Code Here

  /**
   * Method to test if an instance of a {@link GraphicalObject} with the id
   * given by {@link #getGraphicalObject()} can be found in the {@link Model}.
   */
  public boolean isSetGraphicalObjectInstance() {
    Model model = getModel();
    return isSetGraphicalObject() && (model != null) && (model.findNamedSBase(getGraphicalObject()) != null);
  }
View Full Code Here

  InvalidPropertiesFormatException, IOException,
  ClassNotFoundException {
    String fileName = DATA_FOLDER + "/groups/groups1.xml";

    SBMLDocument doc = new SBMLReader().readSBMLFile(fileName);
    Model model = doc.getModel();

    System.out.println("Model extension objects: "
        + model.getExtension(GROUPS_NAMESPACE));
    GroupsModelPlugin extendedModel = (GroupsModelPlugin) model
        .getExtension(GROUPS_NAMESPACE);

    System.out.println("Nb Groups = "
        + extendedModel.getListOfGroups().size());
View Full Code Here

TOP

Related Classes of org.sbml.jsbml.Model

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.