Parameter Scan - API - C#

34 views
Skip to first unread message

Luis Andrés Rojas Matey

unread,
Dec 4, 2020, 9:52:11 AM12/4/20
to COPASI User Forum
Hi!

I am trying to execute a Parameter Scan by using the API within C# language.

The lines from 51 to 58 are specifically to overwrite the default values when I set the "settings of the scan" (lines 45 & 46): [Program-cs.png].

The generated task in the model (model.cps) is very similar to the one created when I use CopasiUI program, except the specific 'Common Name' value element named 'Object' (line 11870): [model-cps.png].

According to the current source code of the COPASI (in C++), I suppose I can use at least two more ways to overwrite its value: [CScanProblem-cpp.png].

First option: by sending the 'Common Name' value as part of the 'CDataObject' argument of the method 'CScanProblem.addScanItem'. This approach is supported by the C# version, however, even if I try to set a dummy 'CDataObject' object with specific 'Common Name' value, the final value in the model is not the same as the one I set in the 'CDataObject' dummy object: [CScanProblem-cs.png].

Second option: by using the method 'CCopasiParameterGroup.addParameter'. According to the C++ code, the third argument can contain its value, however, in the C# version this third argument can only be a "flag": [CCopasiParameterGroup-cs.png].

So, my first question: what is the correct way to overwrite the default value (empty string) of that element?

Also, I have another doubt: when I try to "process" programmatically the task (even if I manually set the value of the element that I am not able to do it via API -as I explained before- in the CPS file and load the model from it) its result is always a False value (so the task is not running as expected): [process-cs.png].

I already tried by invoking the 'CScanTask.getProcessError' and 'CScanTask.getProcessWarning' methods to get some info, but both of them return empty strings. Notice that the "settings of the report" (not included in the screenshot of my C# code) generates the elements in the model (model.cps) as same as when I use CopasiUI program.

Then, my second question: how can I check the reason the task's "process" is returning a False value?

Thanks in advance.

Regards.

CCopasiParameterGroup-cs.png
CScanProblem-cpp.png
model-cps.png
CScanProblem-cs.png
process-cs.png
Program-cs.png

Frank Bergmann

unread,
Dec 4, 2020, 11:23:52 AM12/4/20
to COPASI User Forum
Hello, 

sorry for the trouble you are having, it seems indeed that it is not possible setting the cn values later on. I'll be working on that and we'll fix it. However, it is possible to set the object reference directly at the beginning, by calling addScanItem with the correct reference you need: 


      // get the object to scan
      var model = dm.getModel();
      var reference = model.getMetabolite("A").getInitialConcentrationReference();


      // setup scan
      var scanTask = dm.getTask("Scan");
      var problem = (CScanProblem)scanTask.getProblem();      

      var item = problem.addScanItem(CScanProblem.SCAN_LINEAR,  10, reference);
      item.getParameter("Minimum").setDblValue(0.1);
      item.getParameter("Maximum").setDblValue(10);


for your second question ... if the convenience methods do not work for you to get a result, you can run the task in 2 steps: 

      // or manually
      result = scanTask.initializeRaw((int)CCopasiTask.OUTPUT_UI); // all output
      if (!result)
      { 
        Console.Error.WriteLine(CCopasiMessage.getAllMessageText());
      }
      result = scanTask.processRaw(true); // use initial values
      if (!result)
      {
        Console.Error.WriteLine(CCopasiMessage.getAllMessageText());
      }

i'll attach a complete example that worked for me. Please let me know if you need more help. 

All the best

Frank
Program.cs

Frank Bergmann

unread,
Dec 4, 2020, 11:29:55 AM12/4/20
to COPASI User Forum
In the good tradition of answering my own post. In the next version, setting the CN value later on will work like this: 

      item.getParameter("Object").setCNValue(model.getMetabolite("B").getInitialConcentrationReference().getCN());

we already have a testing version available for this if you let me know what operating system / architecture you need it for i can send you a pre-release archive. 

best
Frank

Luis Andrés Rojas Matey

unread,
Dec 4, 2020, 12:13:50 PM12/4/20
to COPASI User Forum
Hi Frank!

Thank you very much for your answers/suggestions. I'll try them and let you know.

And yes, please send me the pre-release archive that has the enhancement. I'm currently using MacOS (x86-64).

Regards.

Reply all
Reply to author
Forward
0 new messages