public static void Main(String[] args)
    {
        // create a new datamodel
        CDataModel dataModel = CRootContainer.addDatamodel();

        if (args.Length != 1)
        {
            Console.WriteLine("Need one argument: SBML | CPS filename.");
            Environment.Exit(1);
        }

        String filename = args[0];

        try
        {
            String ext = System.IO.Path.GetExtension(filename);
            if (ext.Trim().ToLowerInvariant().EndsWith("xml"))
            {
                // load the model without progress report
                dataModel.importSBML(filename);
            }
            else
            {
                // load the model without progress report
                dataModel.loadModel(filename);
            }
        }
        catch
        {
            Console.WriteLine("Error while loading the model from file named \"" + filename + "\".");
            Environment.Exit(1);
        }
        try
        {
            CModel model          = dataModel.getModel();
            int    numAnnotations = model.getNumUnsupportedAnnotations();
            Console.WriteLine("The model has: " + numAnnotations + " unsupported annotations.");

            if (numAnnotations == 0)
            {
                Console.WriteLine("adding custom annotation");
                // we don't have an annotation, so lets add one
                if (!model.addUnsupportedAnnotation("http://myannotation.org", "<test xmlns='http://myannotation.org' value='blaaaahaaa'/>"))
                {
                    Console.WriteLine("couldn't set annotation: ");
                    Console.WriteLine(CCopasiMessage.getAllMessageText());
                }
            }
            Console.WriteLine("The name of the first is: " + model.getUnsupportedAnnotationName(0));
            Console.WriteLine("The raw xml of the first is: " + model.getUnsupportedAnnotation(0));
        }
        catch (Exception ex)
        {
            Console.WriteLine("Error: " + ex.Message);
        }
    }
Пример #2
0
    public static void Main(String[] args)
    {
        // create a new datamodel
        CDataModel dataModel = CRootContainer.addDatamodel();

        if (args.Length != 2)
        {
            Console.WriteLine("Need two arguments: filename and filter.");
            Environment.Exit(1);
        }

        String filename = args[0];

        try
        {
            String ext = System.IO.Path.GetExtension(filename);
            if (ext.Trim().ToLowerInvariant() == "xml")
            {
                // load the model without progress report
                dataModel.importSBML(filename);
            }
            else
            {
                // load the model without progress report
                dataModel.loadModel(filename);
            }
        }
        catch
        {
            Console.WriteLine("Error while loading the model from file named \"" + filename + "\".");
            Environment.Exit(1);
        }
        try
        {
            // clear warnings / error messages
            CCopasiMessage.clearDeque();

            // convert
            String translation = dataModel.exportMathModelToString(args[1]);

            // if conversion failed print message
            if (string.IsNullOrEmpty(translation))
            {
                Console.WriteLine("Translation failed: ");
                Console.WriteLine(CCopasiMessage.getAllMessageText());
            }

            // print translation
            Console.WriteLine(translation);
        }
        catch
        {
            Console.WriteLine("Error. Exporting the model to math failed.");
        }
    }
Пример #3
0
    static void Main(string[] args)
    {
        Debug.Assert(CRootContainer.getRoot() != null);
        // create a new datamodel
        CDataModel dataModel = CRootContainer.addDatamodel();

        Debug.Assert(CRootContainer.getDatamodelList().size() == 1);
        // the only argument to the main routine should be the name of an SBML file
        if (args.Length == 1)
        {
            string filename = args[0];
            try
            {
                // load the model
                dataModel.importSBML(filename);
            }
            catch
            {
                System.Console.Error.WriteLine("Error while importing the model from file named \"" + filename + "\".");
                System.Environment.Exit(1);
            }
            CModel model = dataModel.getModel();
            Debug.Assert(model != null);
            // create a report with the correct filename and all the species against
            // time.
            CReportDefinitionVector reports = dataModel.getReportDefinitionList();
            // create a new report definition object
            CReportDefinition report = reports.createReportDefinition("Report", "Output for timecourse");
            // set the task type for the report definition to timecourse
            report.setTaskType(CTaskEnum.Task_timeCourse);
            // we don't want a table
            report.setIsTable(false);
            // the entries in the output should be seperated by a ", "
            report.setSeparator(new CCopasiReportSeparator(", "));

            // we need a handle to the header and the body
            // the header will display the ids of the metabolites and "time" for
            // the first column
            // the body will contain the actual timecourse data
            ReportItemVector header = report.getHeaderAddr();
            ReportItemVector body   = report.getBodyAddr();

            body.Add(new CRegisteredCommonName(model.getObject(new CCommonName("Reference=Time")).getCN().getString()));
            body.Add(new CRegisteredCommonName(report.getSeparator().getCN().getString()));
            header.Add(new CRegisteredCommonName(new CDataString("time").getCN().getString()));
            header.Add(new CRegisteredCommonName(report.getSeparator().getCN().getString()));

            uint i, iMax = (uint)model.getMetabolites().size();
            for (i = 0; i < iMax; ++i)
            {
                CMetab metab = model.getMetabolite(i);
                Debug.Assert(metab != null);
                // we don't want output for FIXED metabolites right now
                if (metab.getStatus() != CModelEntity.Status_FIXED)
                {
                    // we want the concentration oin the output
                    // alternatively, we could use "Reference=Amount" to get the
                    // particle number
                    body.Add(new CRegisteredCommonName(metab.getObject(new CCommonName("Reference=Concentration")).getCN().getString()));
                    // add the corresponding id to the header
                    header.Add(new CRegisteredCommonName(new CDataString(metab.getSBMLId()).getCN().getString()));
                    // after each entry, we need a seperator
                    if (i != iMax - 1)
                    {
                        body.Add(new CRegisteredCommonName(report.getSeparator().getCN().getString()));
                        header.Add(new CRegisteredCommonName(report.getSeparator().getCN().getString()));
                    }
                }
            }


            // get the trajectory task object
            CTrajectoryTask trajectoryTask = (CTrajectoryTask)dataModel.getTask("Time-Course");

            // run a deterministic time course
            trajectoryTask.setMethodType(CTaskEnum.Method_deterministic);

            // pass a pointer of the model to the problem
            trajectoryTask.getProblem().setModel(dataModel.getModel());

            // actiavate the task so that it will be run when the model is saved
            // and passed to CopasiSE
            trajectoryTask.setScheduled(true);

            // set the report for the task
            trajectoryTask.getReport().setReportDefinition(report);
            // set the output filename
            trajectoryTask.getReport().setTarget("example3.txt");
            // don't append output if the file exists, but overwrite the file
            trajectoryTask.getReport().setAppend(false);

            // get the problem for the task to set some parameters
            CTrajectoryProblem problem = (CTrajectoryProblem)trajectoryTask.getProblem();

            // simulate 100 steps
            problem.setStepNumber(100);
            // start at time 0
            dataModel.getModel().setInitialTime(0.0);
            // simulate a duration of 10 time units
            problem.setDuration(10);
            // tell the problem to actually generate time series data
            problem.setTimeSeriesRequested(true);

            // set some parameters for the LSODA method through the method
            CTrajectoryMethod method = (CTrajectoryMethod)trajectoryTask.getMethod();

            CCopasiParameter parameter = method.getParameter("Absolute Tolerance");
            Debug.Assert(parameter != null);
            Debug.Assert(parameter.getType() == CCopasiParameter.Type_DOUBLE);
            parameter.setDblValue(1.0e-12);

            bool result = true;
            try
            {
                // now we run the actual trajectory
                result = trajectoryTask.processWithOutputFlags(true, (int)CCopasiTask.ONLY_TIME_SERIES);
            }
            catch
            {
                System.Console.Error.WriteLine("Error. Running the time course simulation failed.");
                String lastErrors = trajectoryTask.getProcessError();
                // check if there are additional error messages
                if (!string.IsNullOrEmpty(lastErrors))
                {
                    // print the messages in chronological order
                    System.Console.Error.WriteLine(lastErrors);
                }

                System.Environment.Exit(1);
            }
            if (result == false)
            {
                System.Console.Error.WriteLine("An error occured while running the time course simulation.");
                String lastErrors = trajectoryTask.getProcessError();
                // check if there are additional error messages
                if (!string.IsNullOrEmpty(lastErrors))
                {
                    // print the messages in chronological order
                    System.Console.Error.WriteLine(lastErrors);
                }

                System.Environment.Exit(1);
            }

            // look at the timeseries
            CTimeSeries timeSeries = trajectoryTask.getTimeSeries();
            // we simulated 100 steps, including the initial state, this should be
            // 101 step in the timeseries
            Debug.Assert(timeSeries.getRecordedSteps() == 101);
            System.Console.WriteLine("The time series consists of " + System.Convert.ToString(timeSeries.getRecordedSteps()) + ".");
            System.Console.WriteLine("Each step contains " + System.Convert.ToString(timeSeries.getNumVariables()) + " variables.");
            System.Console.WriteLine("The final state is: ");
            iMax = (uint)timeSeries.getNumVariables();
            uint lastIndex = (uint)timeSeries.getRecordedSteps() - 1;
            for (i = 0; i < iMax; ++i)
            {
                // here we get the particle number (at least for the species)
                // the unit of the other variables may not be particle numbers
                // the concentration data can be acquired with getConcentrationData
                System.Console.WriteLine(timeSeries.getTitle(i) + ": " + System.Convert.ToString(timeSeries.getData(lastIndex, i)));
            }
        }
        else
        {
            System.Console.Error.WriteLine("Usage: example3 SBMLFILE");
            System.Environment.Exit(1);
        }
    }