static void Main() { // initialize the backend library // since we are not interested in the arguments // that are passed to main, we pass 0 and NULL to // init Debug.Assert(CCopasiRootContainer.getRoot() != null); // create a new datamodel CCopasiDataModel dataModel = CCopasiRootContainer.addDatamodel(); Debug.Assert((dataModel != null)); Debug.Assert((CCopasiRootContainer.getDatamodelList().size() == 1)); // next we import a simple SBML model from a string // clear the message queue so that we only have error messages from the import in the queue CCopasiMessage.clearDeque(); bool result=true; try { result = dataModel.importSBMLFromString(MODEL_STRING); } catch { System.Console.Error.WriteLine("An exception has occured during the import of the SBML model"); System.Environment.Exit(1); } // check if the import was successful int mostSevere = CCopasiMessage.getHighestSeverity(); // if it was a filtered error, we convert it to an unfiltered type // the filtered error messages have the same value as the unfiltered, but they // have the 7th bit set which basically adds 128 to the value mostSevere = mostSevere & 127; // we assume that the import succeeded if the return value is true and // the most severe error message is not an error or an exception if (result != true && mostSevere < CCopasiMessage.ERROR) { System.Console.Error.WriteLine("Sorry. Model could not be imported."); System.Environment.Exit(1); } // get the trajectory task object CSteadyStateTask task = (CSteadyStateTask)dataModel.getTask("Steady-State"); CCopasiMessage.clearDeque(); try { // now we run the actual trajectory task.processWithOutputFlags(true, (int)CCopasiTask.ONLY_TIME_SERIES); } catch { System.Console.Error.WriteLine("Error. Running the scan failed."); String lastErrors = task.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); } // now we can get the result of the steady state calculation, e.g. the jacobian // matrix of the model at the steady state // here we can either get the jacobian as we did in example 8 as a matrix with // getJacobian, or we can use getJacobianAnnotated to get an annotated matrix // Corresponding methods for the reduced jacobian are getJacobianX and getJacobianXAnnotated CArrayAnnotation aj = task.getJacobianAnnotated(); Debug.Assert((aj != null)); if (aj != null) { // we do the output, but as in contrast to the jacobian in example 8, // we now have all the information for the output in one place // first the array annotation can tell us how many dimensions it has. // Since the matrix is a 2D array, it should have 2 dimensions Debug.Assert((aj.dimensionality() == 2)); // since the matrix has a dimensionality of 2, the inde for the underlaying abstract array // object is a vector with two unsigned int elements // First element is the index for the outer dimension and the second element is the index // for the inner dimension SizeTStdVector index=new SizeTStdVector(); // The constructor does not seem to interpret an integer argument // as the size // I though that in C# we might be able to achieve this using the Capacity property // but that didn't work. Maybe I was using it incorrectly since I don't really know C# // So for now, we just add two elements to the vector which seems to do the trick. index.Add(0); index.Add(0); // since the rows and columns have the same annotation for the jacobian, it doesn't matter // for which dimension we get the annotations StringStdVector annotations = aj.getAnnotationsString(1); System.Console.Out.NewLine = ""; System.Console.WriteLine(System.String.Format("Jacobian Matrix:{0}{0}", System.Environment.NewLine)); System.Console.Out.WriteLine(System.String.Format("{0,7}"," ")); for (int i = 0; i < annotations.Count; ++i) { Console.Out.WriteLine(System.String.Format("{0,7}",annotations[i])); } Console.WriteLine(System.String.Format("{0}", System.Environment.NewLine)); for (int i = 0; i < annotations.Count; ++i) { System.Console.Out.WriteLine(System.String.Format("{0,7} ", annotations[i])); index[0]=(uint)i; for (int j = 0; j < annotations.Count; ++j) { index[1]=(uint)j; System.Console.Out.WriteLine(System.String.Format("{0,7:G2} ",aj.array().get(index))); } System.Console.WriteLine(System.String.Format("{0}", System.Environment.NewLine)); } } System.Environment.Exit(0); }
static void Main() { // initialize the backend library // since we are not interested in the arguments // that are passed to main, we pass 0 and NULL to // init Debug.Assert(CCopasiRootContainer.getRoot() != null); // create a new datamodel CCopasiDataModel dataModel = CCopasiRootContainer.addDatamodel(); Debug.Assert((dataModel != null)); Debug.Assert((CCopasiRootContainer.getDatamodelList().size() == 1)); // next we import a simple SBML model from a string // clear the message queue so that we only have error messages from the import in the queue CCopasiMessage.clearDeque(); bool result = true; try { result = dataModel.importSBMLFromString(MODEL_STRING); } catch { System.Console.Error.WriteLine("An exception has occured during the import of the SBML model"); System.Environment.Exit(1); } // check if the import was successful int mostSevere = CCopasiMessage.getHighestSeverity(); // if it was a filtered error, we convert it to an unfiltered type // the filtered error messages have the same value as the unfiltered, but they // have the 7th bit set which basically adds 128 to the value mostSevere = mostSevere & 127; // we assume that the import succeeded if the return value is true and // the most severe error message is not an error or an exception if (result != true && mostSevere < CCopasiMessage.ERROR) { System.Console.Error.WriteLine("Sorry. Model could not be imported."); System.Environment.Exit(1); } // get the trajectory task object CSteadyStateTask task = (CSteadyStateTask)dataModel.getTask("Steady-State"); CCopasiMessage.clearDeque(); try { // now we run the actual trajectory task.processWithOutputFlags(true, (int)CCopasiTask.ONLY_TIME_SERIES); } catch { System.Console.Error.WriteLine("Error. Running the scan failed."); String lastErrors = task.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); } // now we can get the result of the steady state calculation, e.g. the jacobian // matrix of the model at the steady state // here we can either get the jacobian as we did in example 8 as a matrix with // getJacobian, or we can use getJacobianAnnotated to get an annotated matrix // Corresponding methods for the reduced jacobian are getJacobianX and getJacobianXAnnotated CArrayAnnotation aj = task.getJacobianAnnotated(); Debug.Assert((aj != null)); if (aj != null) { // we do the output, but as in contrast to the jacobian in example 8, // we now have all the information for the output in one place // first the array annotation can tell us how many dimensions it has. // Since the matrix is a 2D array, it should have 2 dimensions Debug.Assert((aj.dimensionality() == 2)); // since the matrix has a dimensionality of 2, the inde for the underlaying abstract array // object is a vector with two unsigned int elements // First element is the index for the outer dimension and the second element is the index // for the inner dimension SizeTStdVector index = new SizeTStdVector(); // The constructor does not seem to interpret an integer argument // as the size // I though that in C# we might be able to achieve this using the Capacity property // but that didn't work. Maybe I was using it incorrectly since I don't really know C# // So for now, we just add two elements to the vector which seems to do the trick. index.Add(0); index.Add(0); // since the rows and columns have the same annotation for the jacobian, it doesn't matter // for which dimension we get the annotations StringStdVector annotations = aj.getAnnotationsString(1); System.Console.Out.NewLine = ""; System.Console.WriteLine(System.String.Format("Jacobian Matrix:{0}{0}", System.Environment.NewLine)); System.Console.Out.WriteLine(System.String.Format("{0,7}", " ")); for (int i = 0; i < annotations.Count; ++i) { Console.Out.WriteLine(System.String.Format("{0,7}", annotations[i])); } Console.WriteLine(System.String.Format("{0}", System.Environment.NewLine)); for (int i = 0; i < annotations.Count; ++i) { System.Console.Out.WriteLine(System.String.Format("{0,7} ", annotations[i])); index[0] = (uint)i; for (int j = 0; j < annotations.Count; ++j) { index[1] = (uint)j; System.Console.Out.WriteLine(System.String.Format("{0,7:G2} ", aj.array().get(index))); } System.Console.WriteLine(System.String.Format("{0}", System.Environment.NewLine)); } } System.Environment.Exit(0); }