public static void Main(String[] args)
    {
        if (args.Length == 0)
        {
            Console.WriteLine("Need one argument, copasi file");
            Environment.Exit(1);
        }

        CDataModel dataModel = CRootContainer.addDatamodel();

        if (!dataModel.loadModel(args[0]))
        {
            Console.WriteLine("Could not open file");
            Console.WriteLine(CCopasiMessage.getAllMessageText());
            Environment.Exit(1);
        }

        CModel model = dataModel.getModel();
        ModelParameterSetVectorN sets = model.getModelParameterSets();

        // if we don't have one, create one
        if (sets.size() == 0)
        {
            CModelParameterSet newSet = new CModelParameterSet("Current State", model);
            newSet.createFromModel();
            printParameterSet(newSet);
            sets.add(newSet);
        }

        // interrogate the exiting parameter sets
        printExistingParametersets(model.getModelParameterSets());
    }
    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);
        }
    }
예제 #3
0
    public static void Main(String[] args)
    {
        // create a new datamodel
        CCopasiDataModel dataModel = CCopasiRootContainer.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.");
        }
    }
예제 #4
0
    static void Main(string[] args)
    {
        if (args.Length == 0)
        {
            Console.WriteLine("usage: process_callback <cps file>");
            return;
        }

        var dataModel = CRootContainer.addDatamodel();

        if (!dataModel.loadModel(args[0]))
        {
            Console.WriteLine("Couldn't open the model: ");
            Console.WriteLine(CCopasiMessage.getAllMessageText());
            return;
        }

        var progress = new ProcessCallback();

        Console.CancelKeyPress += delegate {
            Console.WriteLine("Stop requested ... waiting for process to finish");
            progress.ShouldProceed = false;

            Thread.Sleep(30000);
        };


        for (uint i = 0; i < dataModel.getNumTasks(); ++i)
        {
            var task = dataModel.getTask(i);
            if (!task.isScheduled())
            {
                continue;
            }
            Console.WriteLine(string.Format("Running Scheduled Task: {0}, stop anytime using CTRL+C", task.getObjectName()));

            // set progress support
            task.setCallBack(progress);

            // execute the task
            task.process(true);

            // unset
            task.clearCallBack();
        }
    }
예제 #5
0
        /// <summary>
        /// Simulate a Step and return data
        /// </summary>
        /// <param name="stepDuration">Step duration in seconds.</param>
        public SimulationStep Step(double stepDuration)
        {
            CTrajectoryTask trajectoryTask = copasi.TrajectoryTask;

            CTrajectoryProblem problem = (CTrajectoryProblem)trajectoryTask.getProblem();

            problem.setDuration(stepDuration);

            currentTime += stepDuration;

            try
            {
                // now we run the actual trajectory
                trajectoryTask.processWithOutputFlags(true, (int)CCopasiTask.NO_OUTPUT);
            }
            catch
            {
                if (CCopasiMessage.size() > 0)
                {
                    throw new System.Exception("Running the time course simulation failed: " + CCopasiMessage.getAllMessageText(true));
                }

                throw new System.Exception("Running the time course simulation failed");
            }

            // Update the species properties that have changed
            ReactionCount[] reactionCount = new ReactionCount[reactionList.Count];

            for (int i = 0; i < reactionList.Count; i++)
            {
                CopasiReactionGroup r = reactionList[i];

                reactionCount[i] = r.CalcParticleFlux();
            }

            // clean up
            trajectoryTask.restore();

            return(new SimulationStep(reactionCount));
        }