public void test_SBMLConvertStrict_convertNonStrictSBO()
 {
     SBMLDocument d = new  SBMLDocument(2,4);
       Model m = d.createModel();
       Compartment c = m.createCompartment();
       c.setId( "c");
       c.setConstant(false);
       (c).setSBOTerm(64);
       assertTrue( d.setLevelAndVersion(2,3,true) == false );
       assertTrue( d.getLevel() == 2 );
       assertTrue( d.getVersion() == 4 );
       assertTrue( d.setLevelAndVersion(2,2,true) == false );
       assertTrue( d.getLevel() == 2 );
       assertTrue( d.getVersion() == 4 );
       assertTrue( d.setLevelAndVersion(2,1,true) == true );
       assertTrue( d.getLevel() == 2 );
       assertTrue( d.getVersion() == 1 );
       Compartment c1 = d.getModel().getCompartment(0);
       assertTrue( (c1).getSBOTerm() == -1 );
       assertTrue( d.setLevelAndVersion(1,2,true) == true );
       assertTrue( d.getLevel() == 1 );
       assertTrue( d.getVersion() == 2 );
       Compartment c2 = d.getModel().getCompartment(0);
       assertTrue( (c2).getSBOTerm() == -1 );
       d = null;
 }
 public void setUp()
 {
     string filename = "../../annotation/test/test-data/annotationL3.xml";
       d = libsbml.readSBML(filename);
       m = d.getModel();
       c = m.getCompartment(0);
 }
Example #3
0
 public void test_SBMLDocument_setLevelAndVersion()
 {
     SBMLDocument d = new  SBMLDocument(2,2);
       Model m1 = new  Model(2,2);
       d.setModel(m1);
       assertTrue( d.setLevelAndVersion(2,3,false) == true );
       assertTrue( d.setLevelAndVersion(2,1,false) == true );
       assertTrue( d.setLevelAndVersion(1,2,false) == true );
       assertTrue( d.setLevelAndVersion(1,1,false) == false );
       d = null;
 }
Example #4
0
 public void test_SBMLDocument_createWith()
 {
     SBMLDocument d = new  SBMLDocument(1,2);
       assertTrue( d.getTypeCode() == libsbml.SBML_DOCUMENT );
       assertTrue( d.getNotes() == null );
       assertTrue( d.getAnnotation() == null );
       assertTrue( d.getLevel() == 1 );
       assertTrue( d.getVersion() == 2 );
       assertTrue( d.getNumErrors() == 0 );
       d = null;
 }
 public void test_internal_consistency_check_99902()
 {
     SBMLDocument d = new SBMLDocument(2,4);
       long errors;
       Compartment c = new Compartment(2,4);
       d.setLevelAndVersion(1,2,false);
       Model m = d.createModel();
       c.setCompartmentType("hh");
       c.setId("c");
       m.addCompartment(c);
       errors = d.checkInternalConsistency();
       assertTrue( errors == 1 );
       assertTrue( d.getError(0).getErrorId() == 10103 );
       d = null;
 }
 public void test_internal_consistency_check_99903()
 {
     SBMLDocument d = new SBMLDocument(2,4);
       long errors;
       Compartment c = new Compartment(2,4);
       d.setLevelAndVersion(1,2,false);
       Model m = d.createModel();
       c.setConstant(true);
       c.setId("c");
       m.addCompartment(c);
       Rule r = m.createAssignmentRule();
       r.setVariable("c");
       r.setFormula("2*3");
       errors = d.checkInternalConsistency();
       assertTrue( errors == 3 );
       d = null;
 }
Example #7
0
 public void test_SBMLConvert_convertFromL3()
 {
     SBMLDocument d = new  SBMLDocument(3,1);
       Model m = d.createModel();
       string sid =  "C";
       Compartment c = m.createCompartment();
       c.setId(sid);
       c.setSize(1.2);
       c.setUnits( "volume");
       assertTrue( d.setLevelAndVersion(1,1,true) == false );
       assertTrue( d.setLevelAndVersion(1,2,true) == false );
       assertTrue( d.setLevelAndVersion(2,1,true) == false );
       assertTrue( d.setLevelAndVersion(2,2,true) == false );
       assertTrue( d.setLevelAndVersion(2,3,true) == false );
       assertTrue( d.setLevelAndVersion(2,4,true) == false );
       assertTrue( d.setLevelAndVersion(3,1,true) == true );
 }
Example #8
0
 public void test_SBMLDocument_setLevelAndVersion_Error()
 {
     SBMLDocument d = new  SBMLDocument();
       d.setLevelAndVersion(2,1,true);
       Model m1 = new  Model(2,1);
       Unit u = new  Unit(2,1);
       u.setKind(libsbml.UnitKind_forName("mole"));
       u.setOffset(3.2);
       UnitDefinition ud = new  UnitDefinition(2,1);
       ud.setId( "ud");
       ud.addUnit(u);
       m1.addUnitDefinition(ud);
       d.setModel(m1);
       assertTrue( d.setLevelAndVersion(2,2,true) == false );
       assertTrue( d.setLevelAndVersion(2,3,true) == false );
       assertTrue( d.setLevelAndVersion(1,2,true) == false );
       assertTrue( d.setLevelAndVersion(1,1,true) == false );
       d = null;
 }
 public void test_SBMLConvertStrict_convertL1ParamRule()
 {
     SBMLDocument d = new  SBMLDocument(1,2);
       Model m = d.createModel();
       Compartment c = m.createCompartment();
       c.setId( "c");
       Parameter p = m.createParameter();
       p.setId( "p");
       Parameter p1 = m.createParameter();
       p1.setId( "p1");
       ASTNode math = libsbml.parseFormula("p");
       Rule ar = m.createAssignmentRule();
       ar.setVariable( "p1");
       ar.setMath(math);
       ar.setUnits( "mole");
       assertTrue( d.setLevelAndVersion(2,1,true) == true );
       assertTrue( d.getLevel() == 2 );
       assertTrue( d.getVersion() == 1 );
       Rule r1 = d.getModel().getRule(0);
       assertTrue( r1.getUnits() == "" );
       d = null;
 }
Example #10
0
 public void test_SBMLConvert_addModifiersToReaction()
 {
     SBMLDocument d = new  SBMLDocument(1,2);
       Model m = d.createModel();
       Reaction r = m.createReaction();
       KineticLaw kl = r.createKineticLaw();
       kl.setFormula( "k1*S1*S2*S3*S4*S5");
       SimpleSpeciesReference ssr1;
       SimpleSpeciesReference ssr2;
       Species s1 = m.createSpecies();
       s1.setId( "S1" );
       Species s2 = m.createSpecies();
       s2.setId( "S2");
       Species s3 = m.createSpecies();
       s3.setId( "S3");
       Species s4 = m.createSpecies();
       s4.setId( "S4");
       Species s5 = m.createSpecies();
       s5.setId( "S5");
       SpeciesReference sr1 = r.createReactant();
       SpeciesReference sr2 = r.createReactant();
       SpeciesReference sr3 = r.createProduct();
       sr1.setSpecies( "S1");
       sr2.setSpecies( "S2");
       sr3.setSpecies( "S5");
       assertTrue( r.getNumModifiers() == 0 );
       assertTrue( d.setLevelAndVersion(2,1,false) == true );
       assertTrue( d.getLevel() == 2 );
       assertTrue( d.getVersion() == 1 );
       assertTrue( m.getReaction(0).getNumModifiers() == 2 );
       ssr1 = m.getReaction(0).getModifier(0);
       ssr2 = m.getReaction(0).getModifier(1);
       assertTrue((  "S3" == ssr1.getSpecies() ));
       assertTrue((  "S4" == ssr2.getSpecies() ));
       d = null;
 }
 internal static HandleRef getCPtr(SBMLDocument obj)
 {
     return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
 }
Example #12
0
 /**
  * Writes the given SBML document @p d to an in-memory string and
  * returns the string.
  *
  * This is a convenience function that uses the
  * SBMLWriter::writeSBMLToString(SBMLDocument d) method internally,
  * yet does not require the caller to create an SBMLWriter object first.
  *
  * @param d an SBMLDocument object to be written out in XML format
  *
  * @return the string on success and @c null if one of the underlying parser
  * components fail.
  *
  * @if clike @warning Note that the string is owned by the caller and
  * should be freed (with the normal string <c>free()</c> C++
  * function) after it is no longer needed.@endif
  */
 public static string writeSBMLToString(SBMLDocument d)
 {
     string ret = libsbmlPINVOKE.writeSBMLToString(SBMLDocument.getCPtr(d));
     return ret;
 }
Example #13
0
 /**
    * Validates the given SBMLDocument object.
    *
    * This is identical to calling setDocument(@if java SBMLDocument d @endif)
    * followed by validate().
    *
    * @param d the SBML document to validate
    *
    * @return the number of validation failures that occurred.  The objects
    * describing the actual failures can be retrieved using getFailures().
    */
 public long validate(SBMLDocument d)
 {
     return (long)libsbmlPINVOKE.SBMLValidator_validate__SWIG_1(swigCPtr, SBMLDocument.getCPtr(d));
 }
Example #14
0
        static void testWriteSBML(SBMLDocument d, string file)
        {
            try
            {
                if ( libsbml.writeSBML(d, file) == 0)
                {
                    ERR("[WriteSBML] Error: cannot write " + file);
                }
                else
                {
                    OK();
                }
             }
             catch (Exception e)
             {
                 ERR("[WriteSBML] (" + file + ") Error: Exception thrown : " + e.Message);
             }

             try
             {
                 string sbmlstr = libsbml.writeSBMLToString(d);

                 if ( libsbml.writeSBML(libsbml.readSBMLFromString(sbmlstr), file) == 0)
                 {
                     ERR("[WriteSBML] Error: cannot write " + file);
                 }
                 else
                 {
                     OK();
                 }
              }
              catch (Exception e)
              {
                  ERR("[WriteSBML] (" + file + ") Error: Exception thrown : " + e.Message);
              }
        }
Example #15
0
        static void testCreateSBML()
        {
            SBMLDocument d = new SBMLDocument(defLevel,defVersion);

            Model m = d.createModel();
            m.setId("testmodel");

            Compartment c1 = m.createCompartment();
            Compartment c2 = m.createCompartment();
            c1.setId("c1");
            c2.setId("c2");

            Species s1 = m.createSpecies();
            Species s2 = m.createSpecies();

            string id1 = "s1";
            string id2 = "s2";

            // strings with non-ASCII characters (multibyte characters)
            string n1  = "γ-lyase";
            string n2  = "β-synthase";

            s1.setId(id1);
            s1.setName(n1);
            s1.setCompartment("c1");

            s2.setId(id2);
            s2.setName(n2);
            s2.setCompartment("c2");

            string file = "test2.xml";

            try
            {
                if ( libsbml.writeSBML(d, file) == 0)
                {
                    ERR("[CreateSBML] Error: cannot write " + file);
                }
                else
                {
                    OK();
                }
            }
            catch (Exception e)
            {
                ERR("[CreateSBML] (" + file + ") Error: Exception thrown : " + e.Message);
            }

            testReadSBMLFromFile(file);
        }
 /**
    * Disables unused packages.
    *
    * This method walks through all extensions in the list of plugins of the
    * given SBML document @p doc, and disables all that are not being used.
    *
    * @param doc the SBMLDocument object whose unused package extensions
    * should be disabled.
    */
 public void disableUnusedPackages(SBMLDocument doc)
 {
     libsbmlPINVOKE.SBMLExtensionRegistry_disableUnusedPackages(swigCPtr, SBMLDocument.getCPtr(doc));
 }
Example #17
0
 public void setUp()
 {
     string filename = "../../annotation/test/test-data/annotation2.xml";
       d2 = libsbml.readSBML(filename);
       m2 = d2.getModel();
 }
        internal static HandleRef getCPtrAndDisown(SBMLDocument obj)
        {
            HandleRef ptr = new HandleRef(null, IntPtr.Zero);

            if (obj != null)
            {
            ptr             = obj.swigCPtr;
            obj.swigCMemOwn = false;
            }

            return ptr;
        }
 /**
    * Copy constructor; creates a copy of this SBMLDocument.
    */
 public SBMLDocument(SBMLDocument rhs)
     : this(libsbmlPINVOKE.new_SBMLDocument__SWIG_4(SBMLDocument.getCPtr(rhs)), true)
 {
     if (libsbmlPINVOKE.SWIGPendingException.Pending) throw libsbmlPINVOKE.SWIGPendingException.Retrieve();
 }
Example #20
0
 /**
    * Writes the given SBML document to the output stream.
    *
    * @param d the SBML document to be written
    *
    * @param stream the stream object where the SBML is to be written.
    *
    * @return @c true on success and @c false if one of the underlying
    * parser components fail (rare).
    *
    * @see setProgramVersion(string version)
    * @see setProgramName(string name)
    */
 public bool writeSBML(SBMLDocument d, OStream stream)
 {
     bool ret = libsbmlPINVOKE.SBMLWriter_writeSBML__SWIG_1(swigCPtr, SBMLDocument.getCPtr(d), SWIGTYPE_p_std__ostream.getCPtr(stream.get_ostream()));
     if (libsbmlPINVOKE.SWIGPendingException.Pending) throw libsbmlPINVOKE.SWIGPendingException.Retrieve();
     return ret;
 }
 /**
    * Indicates whether this extension is being used by the given SBMLDocument.
    *
    * The default implementation returns @c true.  This means that when a
    * document had this extension enabled, it will not be possible to convert
    * it to SBML Level&nbsp;2 as we cannot make sure that the extension can be
    * converted.
    *
    * @param doc the SBML document to test.
    *
    * @return a boolean indicating whether the extension is actually being
    * used by the document.
    */
 public new bool isInUse(SBMLDocument doc)
 {
     bool ret = libsbmlPINVOKE.SBMLExtension_isInUse(swigCPtr, SBMLDocument.getCPtr(doc));
     return ret;
 }
Example #22
0
 /**
    * Writes the given SBML document to filename.
    *
    * @htmlinclude assuming-compressed-file.html
    *
    * @param d the SBML document to be written
    *
    * @param filename the name or full pathname of the file where the SBML
    * is to be written.
    *
    * @return @c true on success and @c false if the filename could not be
    * opened for writing.
    *
    * @note @htmlinclude note-writing-zipped-files.html
    *
    * @see setProgramVersion(string version)
    * @see setProgramName(string name)
    */
 public bool writeSBMLToFile(SBMLDocument d, string filename)
 {
     bool ret = libsbmlPINVOKE.SBMLWriter_writeSBMLToFile(swigCPtr, SBMLDocument.getCPtr(d), filename);
     return ret;
 }
 /**
    * Enables package extensions that support serialization to SBML annotations.
    *
    * SBML Level&nbsp;2 does not have a package mechanism in the way that SBML
    * Level&nbsp;3 does.  However, SBML annotations can be used to store SBML
    * constructs.  In fact, a widely-used approach to developing SBML
    * Level&nbsp;3 packages involves first using them as annotations.
    *
    * @param doc the SBMLDocument object for which this should be enabled.
    */
 public void enableL2NamespaceForDocument(SBMLDocument doc)
 {
     libsbmlPINVOKE.SBMLExtensionRegistry_enableL2NamespaceForDocument(swigCPtr, SBMLDocument.getCPtr(doc));
 }
Example #24
0
 /** */
 /* libsbml-internal */
 public string writeToString(SBMLDocument d)
 {
     string ret = libsbmlPINVOKE.SBMLWriter_writeToString(swigCPtr, SBMLDocument.getCPtr(d));
     return ret;
 }
Example #25
0
        static void testWriteCompressedSBML(SBMLDocument d, string file)
        {
            if ( SBMLWriter.hasZlib() )
            {
                //
                // write/read gzip file
                //
                string cfile = file + ".gz";
                try
                {
                    if ( libsbml.writeSBML(d, cfile) == 0)
                    {
                        ERR("[WriteCompressedSBML] Error: cannot write " + file + ".gz");
                    }
                    else
                    {
                        OK();
                    }
                 }
                 catch (Exception e)
                 {
                    ERR("[WriteCompressedSBML] (" + cfile + ") Error: Exception thrown : " + e.Message);
                 }

                 //
                 // write/read zip file
                 //
                 cfile = file + ".zip";
                 try
                 {
                     if ( libsbml.writeSBML(d, cfile) == 0)
                     {
                          ERR("[WriteCompressedSBML] Error: cannot write " + file + ".zip");
                      }
                      else
                      {
                          OK();
                      }
                  }
                  catch (Exception e)
                  {
                      ERR("[WriteCompressedSBML] (" + cfile + ") Error: Exception thrown : " + e.Message);
                  }
              }

              if ( SBMLWriter.hasBzip2() )
              {
                  //
                  // write/read bzip2 file
                  //
                  string cfile = file + ".bz2";
                  try
                  {
                      if (libsbml.writeSBML(d, cfile) == 0)
                      {
                          ERR("[WriteCompressedSBML] Error: cannot write " + cfile);
                      }
                      else
                      {
                          if ( libsbml.readSBML(cfile) == null)
                          {
                              ERR("[WriteCompressedSBML] Error: failed to read " + cfile);
                          }
                          else
                          {
                              OK();
                          }
                      }
                  }
                  catch (Exception e)
                  {
                      ERR("[WriteCompressedSBML] (" + cfile + ") Error: Exception thrown : " + e.Message);
                  }
              }
        }
Example #26
0
 public void setUp()
 {
     D = new SBMLDocument();
       S = null;
 }
Example #27
0
 /**
    * Sets the current SBML document to the given SBMLDocument object.
    *
    * @param doc the document to use for this validation
    *
    * @return an integer value indicating the success/failure of the
    * validation.  @if clike The value is drawn from the enumeration
    * #OperationReturnValues_t. @endif The possible values returned by this
    * function are
    * @li @link libsbmlcs.libsbml.LIBSBML_OPERATION_SUCCESS LIBSBML_OPERATION_SUCCESS @endlink
    *
    * @see getDocument()
    */
 public int setDocument(SBMLDocument doc)
 {
     int ret = (SwigDerivedClassHasMethod("setDocument", swigMethodTypes3) ? libsbmlPINVOKE.SBMLValidator_setDocumentSwigExplicitSBMLValidator(swigCPtr, SBMLDocument.getCPtr(doc)) : libsbmlPINVOKE.SBMLValidator_setDocument(swigCPtr, SBMLDocument.getCPtr(doc)));
     return ret;
 }
Example #28
0
 public void test_WriteSBML_error()
 {
     SBMLDocument d = new SBMLDocument();
       SBMLWriter w = new SBMLWriter();
       assertEquals( false, w.writeSBML(d, "/tmp/impossible/path/should/fail") );
       assertTrue( d.getNumErrors() == 1 );
       assertTrue( d.getError(0).getErrorId() == libsbml.XMLFileUnwritable );
       d = null;
       w = null;
 }
Example #29
0
 /**
    * Sets the current SBML document to the given SBMLDocument object.
    *
    * @param doc the document to use for this conversion.
    *
    * @warning Even though the @p doc is 'const', it is immediately cast
    * to a non-version, which is then usually changed by the
    * converter upon a successful conversion.  This function is here
    * solely to preserve backwards compatibility.
    *
    * @return integer value indicating the success/failure of the operation.
    * @if clike The value is drawn from the enumeration
    * #OperationReturnValues_t. @endif The set of possible values that may
    * be returned ultimately depends on the specific subclass of
    * SBMLConverter being used, but the default method can return the
    * following values:
    * @li @link libsbmlcs.libsbml.LIBSBML_OPERATION_SUCCESS LIBSBML_OPERATION_SUCCESS @endlink
    */
 public int setDocument(SBMLDocument doc)
 {
     int ret = (SwigDerivedClassHasMethod("setDocument", swigMethodTypes6) ? libsbmlPINVOKE.SBMLConverter_setDocumentSwigExplicitSBMLConverter__SWIG_0(swigCPtr, SBMLDocument.getCPtr(doc)) : libsbmlPINVOKE.SBMLConverter_setDocument__SWIG_0(swigCPtr, SBMLDocument.getCPtr(doc)));
     return ret;
 }
Example #30
0
 /**
  * Writes the given SBML document @p d to the file @p filename.
  *
  * This is a convenience function that uses the
  * SBMLWriter::writeSBMLToFile(SBMLDocument d, string
  * filename) method internally, yet does not require the caller to create
  * an SBMLWriter object first.
  *
  * @htmlinclude assuming-compressed-file.html
  *
  * @param d an SBMLDocument object to be written out in XML format
  *
  * @param filename a string giving the path to a file where the XML
  * content is to be written.
  *
  * @return @c 1 on success and @c 0 (zero) if @p filename could not be
  * written.  Some possible reasons for failure include (a) being unable to
  * open the file, and (b) using a filename that indicates a compressed SBML
  * file (i.e., a filename ending in <c>&quot;.zip&quot;</c> or
  * similar) when the compression functionality has not been enabled in
  * the underlying copy of libSBML.
  *
  * @if clike @warning Note that the string is owned by the caller and
  * should be freed (with the normal string <c>free()</c> C++
  * function) after it is no longer needed.@endif
  *
  * @see SBMLWriter::hasZlib()
  * @see SBMLWriter::hasBzip2()
  */
 public static int writeSBMLToFile(SBMLDocument d, string filename)
 {
     int ret = libsbmlPINVOKE.writeSBMLToFile(SBMLDocument.getCPtr(d), filename);
     return ret;
 }