@copasi/copasijs 0.0.0-stage → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/copasi.js ADDED
@@ -0,0 +1,1367 @@
1
+ /**
2
+ * @class COPASI
3
+ *
4
+ * This class wraps all the functions exported from
5
+ * emscripten and provides a more convenient interface.
6
+ */
7
+ class COPASI {
8
+
9
+ /**
10
+ * Time course method names.
11
+ * @enum {string}
12
+ */
13
+ TC = {
14
+ /** Deterministic (LSODA) */
15
+ LSODA: 'Deterministic (LSODA)',
16
+ /** Deterministic (RADAU5) */
17
+ RADAU5: 'Deterministic (RADAU5)',
18
+ /** Stochastic (Direct method) */
19
+ DIRECT_METHOD: 'Stochastic (Direct method)',
20
+ /** Stochastic (Gibson + Bruck) */
21
+ GIBSON_BRUCK: 'Stochastic (Gibson + Bruck)',
22
+ /** Stochastic (τ-Leap) */
23
+ TAULEAP: 'Stochastic (τ-Leap)',
24
+ };
25
+
26
+ /**
27
+ * Task names.
28
+ * @enum {string}
29
+ */
30
+ TaskNames = {
31
+ /** Time-Course */
32
+ TimeCourse: 'Time-Course',
33
+ /** Steady-State */
34
+ SteadyState: 'Steady-State',
35
+ /** Metabolic Control Analysis */
36
+ MetabolicControlAnalysis: 'Metabolic Control Analysis',
37
+ /** Linear Noise Approximation */
38
+ LinearNoiseApproximation: 'Linear Noise Approximation',
39
+ /** Parameter Estimation */
40
+ ParameterEstimation: 'Parameter Estimation',
41
+ /** Optimization */
42
+ Optimization: 'Optimization',
43
+ };
44
+
45
+ /**
46
+ * Constructs a new COPASI instance from the WASM module
47
+ * @param {object} Module the WASM module
48
+ *
49
+ */
50
+ constructor(Module) {
51
+ this.Module = Module;
52
+
53
+ // init runtime
54
+ this.initCps();
55
+ }
56
+
57
+ /**
58
+ * Initializes the COPASI library and ensures that a data model exists.
59
+ *
60
+ * Called automatically by the constructor.
61
+ *
62
+ * @returns {number} 0 if successful, -1 otherwise
63
+ */
64
+ initCps() {
65
+ return this.Module.initCps();
66
+ }
67
+
68
+ /**
69
+ * Destroys the API, data model and root container.
70
+ */
71
+ destroy() {
72
+ this.Module.destroy();
73
+ }
74
+
75
+ /**
76
+ * Returns the version of the COPASI library.
77
+ *
78
+ * @returns {string} the COPASI version
79
+ */
80
+ getVersion() {
81
+ return this.Module.getVersion();
82
+ }
83
+
84
+ /**
85
+ * Returns messages from the COPASI library.
86
+ *
87
+ * @param {number} [start=0] the start index of the messages
88
+ * @param {string} [filter=""] messages containing this string will be skipped
89
+ * (default `""` = no message will be skipped)
90
+ * @returns {string} the messages as string
91
+ */
92
+ getMessages(start = 0, filter = "") {
93
+ return this.Module.getMessages(start, filter);
94
+ }
95
+
96
+ /**
97
+ * Looks up the value of a model element by name or SBML id.
98
+ *
99
+ * @param {string} nameOrId the symbol to look up (name or SBML id)
100
+ * @returns {number} the value of the selected symbol
101
+ */
102
+ getValue(nameOrId) {
103
+ return this.Module.getModelValue(nameOrId);
104
+ }
105
+
106
+ /**
107
+ * Sets the value of a model element by name or SBML id.
108
+ *
109
+ * @param {string} nameOrId the symbol to set (name or SBML id)
110
+ * @param {number} value the value to set
111
+ */
112
+ setValue(nameOrId, value) {
113
+ this.Module.setModelValue(nameOrId, value);
114
+ }
115
+
116
+ /**
117
+ * Resets the model to the state after loading.
118
+ *
119
+ * Unlike {@link COPASI#reset}, this restores the full initial state
120
+ * captured when the model was loaded.
121
+ */
122
+ resetAll() {
123
+ this.Module.resetAll();
124
+ }
125
+
126
+ /**
127
+ * Runs a simulation for one output step.
128
+ *
129
+ * This is a convenience function equivalent to
130
+ * `simulateEx(startTime, startTime + stepSize, 1)`.
131
+ *
132
+ * @param {number} startTime the start time of the step
133
+ * @param {number} stepSize the size of the step
134
+ * @returns {number} the end time of the simulation
135
+ */
136
+ oneStep(startTime, stepSize) {
137
+ return this.Module.oneStep(startTime, stepSize);
138
+ }
139
+
140
+ /**
141
+ * loads an example (if the WASM module was compiled with FS support)
142
+ *
143
+ * @param {string} path
144
+ * @returns model information as an object
145
+ */
146
+ loadExample(path)
147
+ {
148
+ return JSON.parse(this.Module.loadFromFile(path));
149
+ }
150
+
151
+ /**
152
+ * Loads a model from a string containing the model in
153
+ * SBML or COPASI format.
154
+ *
155
+ * @param {string} modelCode in SBML or COPASI format
156
+ * @returns model information as an object
157
+ */
158
+ loadModel(modelCode)
159
+ {
160
+ return JSON.parse(this.Module.loadModel(modelCode));
161
+ }
162
+
163
+ /**
164
+ * Creates a new empty model.
165
+ *
166
+ * @returns model information as an object
167
+ */
168
+ newModel()
169
+ {
170
+ return JSON.parse(this.Module.newModel());
171
+ }
172
+
173
+ /**
174
+ * Loads a model from a COMBINE archive.
175
+ *
176
+ * @param {string} path the path to the COMBINE archive
177
+ * @returns model information as an object
178
+ */
179
+ loadCombineArchive(path)
180
+ {
181
+ return JSON.parse(this.Module.loadCombineArchive(path));
182
+ }
183
+
184
+ /**
185
+ * simulates the currently loaded model with its current
186
+ * time course settings.
187
+ *
188
+ * @param {boolean} [includeData=true] when false, numeric columns are omitted
189
+ * @returns {object} simulation results as object
190
+ */
191
+ simulate(includeData = true) {
192
+ return JSON.parse(this.Module.simulate(includeData));
193
+ }
194
+
195
+ /**
196
+ * simulates the currently loaded model with its current
197
+ * time course settings.
198
+ *
199
+ * @returns {number[][]} simulation results as 2D array
200
+ */
201
+ simulate2D() {
202
+ this.Module.simulate();
203
+ return this._vector2dToArray(this.Module.getSimulationResults2D());
204
+ }
205
+
206
+ /**
207
+ * simulates the currently loaded model from startTime to
208
+ * endTime with numPoints points.
209
+ *
210
+ * @param {number} startTime
211
+ * @param {number} endTime
212
+ * @param {number} numPoints
213
+ * @param {boolean} [includeData=true] when false, numeric columns are omitted
214
+ *
215
+ * @returns {object} simulation results as object
216
+ */
217
+ simulateEx(startTime, endTime, numPoints, includeData = true) {
218
+ return JSON.parse(this.Module.simulateEx(startTime, endTime, numPoints, includeData));
219
+ }
220
+
221
+ /**
222
+ * simulates the currently loaded model from startTime to
223
+ * endTime with numPoints points.
224
+ *
225
+ * @param {number} startTime
226
+ * @param {number} endTime
227
+ * @param {number} numPoints
228
+ *
229
+ * @returns {number[][]} simulation results as 2D array
230
+ */
231
+ simulateEx2D(startTime, endTime, numPoints) {
232
+ this.Module.simulateEx(startTime, endTime, numPoints);
233
+ return this._vector2dToArray(this.Module.getSimulationResults2D());
234
+ }
235
+
236
+ /**
237
+ * simulates the currently loaded model after applying
238
+ * the processing instructions.
239
+ *
240
+ * The problem / method options are the same as returned by
241
+ * {@link COPASI#timeCourseSettings}. To change initial conditions:
242
+ *
243
+ * ```json
244
+ * {
245
+ * "initial_values":
246
+ * {
247
+ * "name": value,
248
+ * ...
249
+ * }
250
+ * }
251
+ * ```
252
+ *
253
+ * If no specific reference is used, the initial concentration will be
254
+ * changed for species, and initial values for all other model entities.
255
+ * Specific references use COPASI display names, e.g. `[A]_0` for the
256
+ * initial concentration of species `A`, `Values[t].InitialValue` for a
257
+ * global parameter, or `(r1).k` for the local parameter `k` of reaction `r1`.
258
+ *
259
+ * @param {object|string} yamlProcessingOptions
260
+ * @param {boolean} [includeData=true] when false, numeric columns are omitted
261
+ * @returns {object} simulation results as object
262
+ */
263
+ simulateYaml(yamlProcessingOptions, includeData = true) {
264
+ if (typeof yamlProcessingOptions !== 'string') {
265
+ yamlProcessingOptions = JSON.stringify(yamlProcessingOptions);
266
+ }
267
+ return JSON.parse(this.Module.simulateYaml(yamlProcessingOptions, includeData));
268
+ }
269
+
270
+ /**
271
+ * simulates the currently loaded model after applying
272
+ * the processing instructions.
273
+ *
274
+ * The processing options are the same as for {@link COPASI#simulateYaml}.
275
+ *
276
+ * @param {object|string} yamlProcessingOptions
277
+ * @returns {number[][]} simulation results as 2D array
278
+ */
279
+ simulateYaml2D(yamlProcessingOptions) {
280
+ if (typeof yamlProcessingOptions !== 'string') {
281
+ yamlProcessingOptions = JSON.stringify(yamlProcessingOptions);
282
+ }
283
+ this.Module.simulateYaml(yamlProcessingOptions);
284
+ return this._vector2dToArray(this.Module.getSimulationResults2D());
285
+ }
286
+
287
+ /**
288
+ * resets the model
289
+ *
290
+ * after loading the model, its state was saved as parameterset,
291
+ * calling reset will apply that parameter set.
292
+ */
293
+ reset() {
294
+ // Add code here to reset the simulator
295
+ this.Module.reset();
296
+ }
297
+
298
+
299
+ /**
300
+ * Returns the COPASI version.
301
+ *
302
+ * @example
303
+ * var copasi = new COPASI(Module);
304
+ * console.log(copasi.version);
305
+ * // prints something like:
306
+ * // 4.32.284
307
+ * @type {string}
308
+ */
309
+ get version() {
310
+ return this.Module.getVersion();
311
+ }
312
+
313
+ /**
314
+ * Whether simulations automatically update the model.
315
+ * @type {boolean}
316
+ */
317
+ get autoUpdateModel() {
318
+ return this.Module.getAutoUpdateModel();
319
+ }
320
+
321
+ set autoUpdateModel(value) {
322
+ this.Module.setAutoUpdateModel(value);
323
+ }
324
+
325
+ /**
326
+ * Converts a WASM vector to a JavaScript array.
327
+ * @private
328
+ * @param {object} v WASM vector
329
+ * @returns {Array} the converted array
330
+ */
331
+ _vectorToArray(v) {
332
+ var result = [];
333
+ for (var i = 0; i < v.size(); i++) {
334
+ result.push(v.get(i));
335
+ }
336
+ return result;
337
+ }
338
+
339
+ /**
340
+ * Converts a WASM 2D vector to a JavaScript 2D array.
341
+ * @private
342
+ * @param {object} v WASM 2D vector
343
+ * @returns {Array[]} the converted 2D array
344
+ */
345
+ _vector2dToArray(v) {
346
+ var result = [];
347
+ for (var i = 0; i < v.size(); i++) {
348
+ result.push(this._vectorToArray(v.get(i)));
349
+ }
350
+ return result;
351
+ }
352
+
353
+ /**
354
+ * Returns floating species concentrations.
355
+ * @type {number[]}
356
+ */
357
+ get floatingSpeciesConcentrations() {
358
+ return this._vectorToArray(this.Module.getFloatingSpeciesConcentrations());
359
+ }
360
+
361
+ /**
362
+ * Returns rates of change of floating species.
363
+ * @type {number[]}
364
+ */
365
+ get ratesOfChange() {
366
+ return this._vectorToArray(this.Module.getRatesOfChange());
367
+ }
368
+
369
+ /**
370
+ * Returns floating species names.
371
+ * @type {string[]}
372
+ */
373
+ get floatingSpeciesNames() {
374
+ return this._vectorToArray(this.Module.getFloatingSpeciesNames());
375
+ }
376
+
377
+ /**
378
+ * Returns floating species ids.
379
+ * @type {string[]}
380
+ */
381
+ get floatingSpeciesIds() {
382
+ return this._vectorToArray(this.Module.getFloatingSpeciesIds());
383
+ }
384
+
385
+ /**
386
+ * Returns boundary species concentrations.
387
+ * @type {number[]}
388
+ */
389
+ get boundarySpeciesConcentrations() {
390
+ return this._vectorToArray(this.Module.getBoundarySpeciesConcentrations());
391
+ }
392
+
393
+ /**
394
+ * Returns boundary species names.
395
+ * @type {string[]}
396
+ */
397
+ get boundarySpeciesNames() {
398
+ return this._vectorToArray(this.Module.getBoundarySpeciesNames());
399
+ }
400
+
401
+ /**
402
+ * Returns boundary species ids.
403
+ * @type {string[]}
404
+ */
405
+ get boundarySpeciesIds() {
406
+ return this._vectorToArray(this.Module.getBoundarySpeciesIds());
407
+ }
408
+
409
+ /**
410
+ * Returns reaction names.
411
+ * @type {string[]}
412
+ */
413
+ get reactionNames() {
414
+ return this._vectorToArray(this.Module.getReactionNames());
415
+ }
416
+
417
+ /**
418
+ * Returns reaction ids.
419
+ * @type {string[]}
420
+ */
421
+ get reactionIds() {
422
+ return this._vectorToArray(this.Module.getReactionIds());
423
+ }
424
+ /**
425
+ * Returns reaction rates.
426
+ * @type {number[]}
427
+ */
428
+ get reactionRates() {
429
+ return this._vectorToArray(this.Module.getReactionRates());
430
+ }
431
+
432
+ /**
433
+ * Returns compartment names.
434
+ * @type {string[]}
435
+ */
436
+ get compartmentNames() {
437
+ return this._vectorToArray(this.Module.getCompartmentNames());
438
+ }
439
+
440
+ /**
441
+ * Returns compartment ids.
442
+ * @type {string[]}
443
+ */
444
+ get compartmentIds() {
445
+ return this._vectorToArray(this.Module.getCompartmentIds());
446
+ }
447
+ /**
448
+ * Returns compartment sizes.
449
+ * @type {number[]}
450
+ */
451
+ get compartmentSizes() {
452
+ return this._vectorToArray(this.Module.getCompartmentSizes());
453
+ }
454
+
455
+ /**
456
+ * Returns global parameter names.
457
+ * @type {string[]}
458
+ */
459
+ get globalParameterNames() {
460
+ return this._vectorToArray(this.Module.getGlobalParameterNames());
461
+ }
462
+
463
+ /**
464
+ * Returns global parameter ids.
465
+ * @type {string[]}
466
+ */
467
+ get globalParameterIds() {
468
+ return this._vectorToArray(this.Module.getGlobalParameterIds());
469
+ }
470
+ /**
471
+ * Returns global parameter values.
472
+ * @type {number[]}
473
+ */
474
+ get globalParameterValues() {
475
+ return this._vectorToArray(this.Module.getGlobalParameterValues());
476
+ }
477
+
478
+ /**
479
+ * Returns local parameter names.
480
+ *
481
+ * Local parameter names, consist of the reaction name in brackets, followed by a dot
482
+ * and the parameter name. So for example: `(reaction1).k1` for the
483
+ * local parameter `k1` of the reaction `reaction1`.
484
+ * @type {string[]}
485
+ */
486
+ get localParameterNames() {
487
+ return this._vectorToArray(this.Module.getLocalParameterNames());
488
+ }
489
+
490
+ /**
491
+ * Returns local parameter values.
492
+ * @type {number[]}
493
+ */
494
+ get localParameterValues() {
495
+ return this._vectorToArray(this.Module.getLocalParameterValues());
496
+ }
497
+
498
+ /**
499
+ * The time course settings as JSON object.
500
+ * @type {object}
501
+ */
502
+ get timeCourseSettings() {
503
+ return JSON.parse(this.Module.getTimeCourseSettings());
504
+ }
505
+
506
+ set timeCourseSettings(arg) {
507
+ // test wether arg is string, otherwise stringify
508
+ if (typeof arg !== 'string') {
509
+ arg = JSON.stringify(arg);
510
+ }
511
+ return this.Module.setTimeCourseSettings(arg);
512
+ }
513
+
514
+
515
+ /**
516
+ * The MCA settings as JSON object.
517
+ * @type {object}
518
+ */
519
+ get mcaSettings() {
520
+ return JSON.parse(this.Module.getMcaSettings());
521
+ }
522
+
523
+ set mcaSettings(arg) {
524
+ if (typeof arg !== 'string') {
525
+ arg = JSON.stringify(arg);
526
+ }
527
+ return this.Module.setMcaSettings(arg);
528
+ }
529
+
530
+
531
+ /**
532
+ * The LNA settings as JSON object.
533
+ * @type {object}
534
+ */
535
+ get lnaSettings() {
536
+ return JSON.parse(this.Module.getLNASettings());
537
+ }
538
+
539
+ set lnaSettings(arg) {
540
+ if (typeof arg !== 'string') {
541
+ arg = JSON.stringify(arg);
542
+ }
543
+ return this.Module.setLNASettings(arg);
544
+ }
545
+
546
+ /**
547
+ * Model information as object.
548
+ * @type {object}
549
+ */
550
+ get modelInfo() {
551
+ return JSON.parse(this.Module.getModelInfo());
552
+ }
553
+
554
+ /**
555
+ * Applies sparse model changes and returns the updated model information.
556
+ *
557
+ * The patch uses the same section names as {@link COPASI#modelInfo}.
558
+ * Omitted sections and omitted attributes are left unchanged. Array
559
+ * items are identified by `id` (SBML id) if present and non-empty,
560
+ * otherwise by `name`. Missing array items are not deleted.
561
+ *
562
+ * Each element may include `op: "update"` (default), `"create"`, or
563
+ * `"delete"`. Rename with `new_name` / `new_id`. Create requires `name`
564
+ * (plus `compartment` for species and `scheme` for reactions).
565
+ *
566
+ * @param {object|string} changes sparse model-change document
567
+ * @returns {object} updated model info (`status` / `messages` plus snapshot)
568
+ *
569
+ * @example
570
+ * copasi.applyModelChanges({
571
+ * species: [
572
+ * { name: "X", initial_concentration: 2.0 },
573
+ * { op: "create", name: "Z", compartment: "compartment", initial_concentration: 1 },
574
+ * { op: "delete", name: "Y" }
575
+ * ]
576
+ * });
577
+ */
578
+ applyModelChanges(changes) {
579
+ if (typeof changes !== 'string') {
580
+ changes = JSON.stringify(changes);
581
+ }
582
+ return JSON.parse(this.Module.applyModelChanges(changes));
583
+ }
584
+
585
+ /**
586
+ * Returns the selection list.
587
+ *
588
+ * The selection list controls what will be in the output of the
589
+ * simulation calls.
590
+ * @type {string[]}
591
+ */
592
+ get selectionList() {
593
+ return this._vectorToArray(this.Module.getSelectionList());
594
+ }
595
+
596
+ set selectionList(arg)
597
+ {
598
+ var vector = new this.Module.StringVector();
599
+ arg.forEach((item) => vector.push_back(item));
600
+ return this.Module.setSelectionList(vector);
601
+ }
602
+
603
+ /**
604
+ * Returns the selected values.
605
+ * @type {number[]}
606
+ */
607
+ get selectedValues() {
608
+ return this._vectorToArray(this.Module.getSelectedValues());
609
+ }
610
+
611
+ /**
612
+ * Resets the selection list to the default values.
613
+ *
614
+ * By default floating species concentrations, as well as elements
615
+ * with ODEs / assignments, are selected.
616
+ */
617
+ resetSelectionList() {
618
+ this.Module.resetSelectionList();
619
+ }
620
+
621
+ /**
622
+ * The jacobian as object.
623
+ * @type {object}
624
+ */
625
+ get jacobian() {
626
+ return JSON.parse(this.Module.getJacobian());
627
+ }
628
+
629
+ /**
630
+ * Returns the jacobian as 2D array.
631
+ * @type {number[][]}
632
+ */
633
+ get jacobian2D() {
634
+ return this._vector2dToArray(this.Module.getJacobian2D());
635
+ }
636
+
637
+ /**
638
+ * Returns the eigenvalues as 2D array.
639
+ * @type {number[][]}
640
+ */
641
+ get eigenValues2D() {
642
+ return this._vector2dToArray(this.Module.getEigenValues2D());
643
+ }
644
+
645
+ /**
646
+ * The reduced jacobian as object.
647
+ * @type {object}
648
+ */
649
+ get reducedJacobian() {
650
+ return JSON.parse(this.Module.getJacobianReduced());
651
+ }
652
+
653
+ /**
654
+ * Returns the reduced jacobian as 2D array.
655
+ * @type {number[][]}
656
+ */
657
+ get reducedJacobian2D() {
658
+ return this._vector2dToArray(this.Module.getJacobianReduced2D());
659
+ }
660
+
661
+ /**
662
+ * Returns the eigenvalues of the reduced Jacobian as 2D array.
663
+ * @type {number[][]}
664
+ */
665
+ get eigenValuesReduced2D() {
666
+ return this._vector2dToArray(this.Module.getEigenValuesReduced2D());
667
+ }
668
+
669
+ /**
670
+ * Retrieves the flux control coefficients for the model
671
+ *
672
+ * Note that computeMca must be called before this method
673
+ *
674
+ * @param {bool} scaled indicating whether the scaled (true) or unscaled coefficients should be returned
675
+ * @returns {object} the flux control coefficients as object
676
+ */
677
+ getFluxControlCoefficients(scaled)
678
+ {
679
+ return JSON.parse(this.Module.getFluxControlCoefficients(scaled));
680
+ }
681
+
682
+ /**
683
+ * Retrieves the flux control coefficients for the model as 2d array
684
+ *
685
+ * Note that computeMca must be called before this method
686
+ *
687
+ * @param {bool} scaled indicating whether the scaled (true) or unscaled coefficients should be returned
688
+ * @returns {number[][]} the flux control coefficients as 2D array
689
+ */
690
+ getFluxControlCoefficients2D(scaled)
691
+ {
692
+ return this._vector2dToArray(this.Module.getFluxControlCoefficients2D(scaled));
693
+ }
694
+
695
+ /**
696
+ * Retrieves the concentration control coefficients for the model
697
+ *
698
+ * Note that computeMca must be called before this method
699
+ *
700
+ * @param {bool} scaled indicating whether the scaled (true) or unscaled coefficients should be returned
701
+ * @returns {object} the concentration control coefficients as object
702
+ */
703
+ getConcentrationControlCoefficients(scaled)
704
+ {
705
+ return JSON.parse(this.Module.getConcentrationControlCoefficients(scaled));
706
+ }
707
+
708
+ /**
709
+ * Retrieves the concentration control coefficients for the model as 2d array
710
+ *
711
+ * Note that computeMca must be called before this method
712
+ *
713
+ * @param {bool} scaled indicating whether the scaled (true) or unscaled coefficients should be returned
714
+ * @returns {number[][]} the concentration control coefficients as 2D array
715
+ */
716
+ getConcentrationControlCoefficients2D(scaled)
717
+ {
718
+ return this._vector2dToArray(this.Module.getConcentrationControlCoefficients2D(scaled));
719
+ }
720
+
721
+ /**
722
+ * Retrieves the elasticities
723
+ *
724
+ * Note that computeMca must be called before this method
725
+ *
726
+ * @param {bool} scaled indicating whether the scaled (true) or unscaled coefficients should be returned
727
+ * @returns {object} the elasticites as object
728
+ */
729
+ getElasticities(scaled)
730
+ {
731
+ return JSON.parse(this.Module.getElasticities(scaled));
732
+ }
733
+
734
+ /**
735
+ * Returns the simulation results as object.
736
+ *
737
+ * Note that the time course tasks should have run first.
738
+ * @type {object}
739
+ */
740
+ get simulationResults() {
741
+ return JSON.parse(this.Module.getSimulationResults());
742
+ }
743
+
744
+ /**
745
+ * Last simulation as a shared Float64Array.
746
+ *
747
+ * Layout is row-major: `data[step * cols + variable]`.
748
+ * The array aliases WASM memory. It stays valid until the next
749
+ * simulation, or any call that grows the WASM heap. Copy with
750
+ * `data.slice()` to keep the numbers.
751
+ *
752
+ * @type {{rows: number, cols: number, data: Float64Array}}
753
+ */
754
+ get simulationMatrix() {
755
+ return this.Module.getSimulationMatrix();
756
+ }
757
+
758
+ /**
759
+ * Retrieves the elasticities as 2d array
760
+ *
761
+ * Note that computeMca must be called before this method
762
+ *
763
+ * @param {bool} scaled indicating whether the scaled (true) or unscaled coefficients should be returned
764
+ * @returns {number[][]} the elasticities as 2D array
765
+ */
766
+ getElasticities2D(scaled)
767
+ {
768
+ return this._vector2dToArray(this.Module.getElasticities2D(scaled));
769
+ }
770
+
771
+ /**
772
+ * Runs steady-state analysis.
773
+ *
774
+ * @param {boolean} stabilityAnalysis whether to perform stability analysis
775
+ * @param {boolean} updateModel whether to update the model with steady-state values
776
+ * @returns {number} closeness to steady state
777
+ */
778
+ steadyState(stabilityAnalysis = true, updateModel = true)
779
+ {
780
+ return this.Module.steadyState(stabilityAnalysis, updateModel);
781
+ }
782
+
783
+ /**
784
+ * Computes metabolic control analysis.
785
+ *
786
+ * @param {boolean} performSteadyState whether to compute steady state first
787
+ * @param {boolean} updateModel whether to update the model
788
+ * @returns {boolean} true if MCA completed successfully
789
+ */
790
+ computeMca(performSteadyState = true, updateModel = true)
791
+ {
792
+ return this.Module.computeMca(performSteadyState, updateModel);
793
+ }
794
+
795
+ /**
796
+ * The MCA protocol as String.
797
+ * @type {string}
798
+ */
799
+ get mcaProtocol() {
800
+ return this.Module.getMcaProtocol();
801
+ }
802
+
803
+ /**
804
+ * Runs the Linear Noise Approximation
805
+ * @param {bool} useInitialValues indicating whether the initial values should be used
806
+ * @returns {boolean} true if the LNA was run successfully
807
+ */
808
+ runLNA(useInitialValues = true)
809
+ {
810
+ return this.Module.runLNA(useInitialValues);
811
+ }
812
+
813
+ /**
814
+ * Retrieves the results of the Linear Noise Approximation
815
+ * @param {bool} scaled indicating whether the scaled (true) or unscaled results should be returned
816
+ * @returns {object} the results of the LNA as object
817
+ *
818
+ * ```json
819
+ * {
820
+ * "status": "Steady State found.",
821
+ * "covariance_matrix": {
822
+ * "rows": ["X", "Y"],
823
+ * "columns": ["X", "Y"],
824
+ * "values": [[...], ...]
825
+ * },
826
+ * "reduced_covariance_matrix": { ... },
827
+ * "reduced_b_matrix": { ... }
828
+ * }
829
+ * ```
830
+ */
831
+ getLNAResults(scaled = true)
832
+ {
833
+ return JSON.parse(this.Module.getLNAResults(scaled));
834
+ }
835
+
836
+ /**
837
+ * Retrieves the task setttings for the given task
838
+ * @param {string} taskName the name of the task to get
839
+ * @returns {object} the settings of the task as object
840
+ */
841
+ getTaskSettings(taskName)
842
+ {
843
+ return JSON.parse(this.Module.getTaskSettings(taskName));
844
+ }
845
+
846
+ /**
847
+ * Sets the task settings for the given task
848
+ * @param {string} taskName the name of the task to set
849
+ * @param {object|string} settings the settings as object or json string
850
+ * @returns {boolean} true if successful
851
+ */
852
+ setTaskSettings(taskName, settings)
853
+ {
854
+ if (typeof settings !== 'string') {
855
+ settings = JSON.stringify(settings);
856
+ }
857
+ return this.Module.setTaskSettings(taskName, settings);
858
+ }
859
+
860
+ /**
861
+ * Clears the last recorded messages from the COPASI library
862
+ */
863
+ clearMessages()
864
+ {
865
+ this.Module.clearMessages();
866
+ }
867
+
868
+ /**
869
+ * Returns the status of the last stability analysis.
870
+ *
871
+ * @returns {string} the status of the last stability analysis
872
+ */
873
+ getStabilityAnalysis() {
874
+ return this.Module.getStabilityAnalysis();
875
+ }
876
+
877
+ /**
878
+ * Returns the steady state protocol.
879
+ *
880
+ * @returns {string} the steady state protocol
881
+ */
882
+ getSteadyStateProtocol() {
883
+ return this.Module.getSteadyStateProtocol();
884
+ }
885
+
886
+ /**
887
+ * Returns the status of the last steady-state run.
888
+ *
889
+ * @returns {string} the status of the last steady-state run
890
+ */
891
+ getSteadyStateStatus() {
892
+ return this.Module.getSteadyStateStatus();
893
+ }
894
+
895
+ /**
896
+ * Returns the names of all available methods for a task.
897
+ *
898
+ * @param {string} taskName the name of the task to get the available methods for
899
+ * @returns {string[]} the names of all available methods for the task
900
+ */
901
+ getAvailableMethods(taskName) {
902
+ return this._vectorToArray(this.Module.getAvailableMethods(taskName));
903
+ }
904
+
905
+ /**
906
+ * Sets the method for the given task
907
+ * @param {string} taskName the name of the task to set the method for
908
+ * @param {string} methodName the name of the method to set
909
+ * @returns {boolean} true if successful
910
+ */
911
+ setMethod(taskName, methodName) {
912
+ return this.Module.setMethod(taskName, methodName);
913
+ }
914
+
915
+ /**
916
+ * The stoichiometry matrix as object.
917
+ * @type {object}
918
+ */
919
+ get stoichiometryMatrix() {
920
+ return JSON.parse(this.Module.getStoichiometryMatrix(false));
921
+ }
922
+
923
+ /**
924
+ * The reduced stoichiometry matrix as object.
925
+ * @type {object}
926
+ */
927
+ get reducedStoichiometryMatrix() {
928
+ return JSON.parse(this.Module.getStoichiometryMatrix(true));
929
+ }
930
+
931
+
932
+ /**
933
+ * The link matrix as object.
934
+ * @type {object}
935
+ */
936
+ get linkMatrix() {
937
+ return JSON.parse(this.Module.getLinkMatrix());
938
+ }
939
+
940
+ /**
941
+ * runs the optimization task with the current settings
942
+ * @param {boolean} useInitialValues whether to use initial values
943
+ * @returns {boolean} true if successful
944
+ */
945
+ runOptimization(useInitialValues = true) {
946
+ return this.Module.runOptimization(useInitialValues);
947
+ }
948
+
949
+
950
+ /**
951
+ * Returns the optimization items as object.
952
+ * @type {object}
953
+ */
954
+ get optItems() {
955
+ return JSON.parse(this.Module.getOptItems());
956
+ }
957
+
958
+ /**
959
+ * The optimization solution.
960
+ *
961
+ * ```json
962
+ * [
963
+ * {
964
+ * "name": "Values[x1]",
965
+ * "lower": -6.0,
966
+ * "upper": 6.0,
967
+ * "sol": 3.0
968
+ * }
969
+ * ]
970
+ * ```
971
+ * @type {object}
972
+ */
973
+ get optSolution() {
974
+ return JSON.parse(this.Module.getOptSolution());
975
+ }
976
+
977
+ /**
978
+ * Information about the last optimization run.
979
+ *
980
+ * ```json
981
+ * {
982
+ * "obj": 0.0,
983
+ * "f_evals": 42,
984
+ * "failed_evals_exception": 0,
985
+ * "failed_evals_nan": 0,
986
+ * "constraint_evals": 0,
987
+ * "failed_constraint_evals": 0,
988
+ * "cpu_time": 0.01,
989
+ * "evals_per_sec": 4200.0
990
+ * }
991
+ * ```
992
+ * @type {object}
993
+ */
994
+ get optStatistic() {
995
+ return JSON.parse(this.Module.getOptStatistic());
996
+ }
997
+
998
+ /**
999
+ * runs the parameter estimation task with the current settings
1000
+ * @param {boolean} useInitialValues whether to use initial values
1001
+ * @returns {boolean} true if successful
1002
+ */
1003
+ runParameterEstimation(useInitialValues = true) {
1004
+ return this.Module.runParameterEstimation(useInitialValues);
1005
+ }
1006
+
1007
+
1008
+ /**
1009
+ * The solution found for the fit parameters.
1010
+ *
1011
+ * ```json
1012
+ * [
1013
+ * {
1014
+ * "name": "(R1).k2",
1015
+ * "lower": 1e-6,
1016
+ * "upper": 1e6,
1017
+ * "sol": 4.0,
1018
+ * "affected": []
1019
+ * }
1020
+ * ]
1021
+ * ```
1022
+ * @type {object}
1023
+ */
1024
+ get fitSolution() {
1025
+ return JSON.parse(this.Module.getFitSolution());
1026
+ }
1027
+
1028
+ /**
1029
+ * The correlation matrix as object.
1030
+ * ```json
1031
+ * {
1032
+ * "columns": [
1033
+ * "'(v1).k'",
1034
+ * "'(v2).k1'"
1035
+ * ],
1036
+ * "rows": [
1037
+ * "'(v1).k'",
1038
+ * "'(v2).k1'"
1039
+ * ],
1040
+ * "values": [
1041
+ * [
1042
+ * 0.9999999999999999,
1043
+ * 0.9807337357504254
1044
+ * ],
1045
+ * [
1046
+ * 0.9807337357504254,
1047
+ * 0.9999999999999999
1048
+ * ]
1049
+ * ]
1050
+ * }```
1051
+ * @type {object}
1052
+ */
1053
+ get correlationMatrix() {
1054
+ return JSON.parse(this.Module.getCorrelationMatrix());
1055
+ }
1056
+
1057
+
1058
+ /**
1059
+ * The Fischer information matrix as object.
1060
+ *
1061
+ * This includes, the fisher information matrix, the eigenvalues and the eigenvectors.
1062
+ * both scaled and unscaled as data arrays.
1063
+ *
1064
+ * ```json
1065
+ * {
1066
+ * "fim": {
1067
+ * "columns": [
1068
+ * "'(v1).k'",
1069
+ * "'(v2).k1'"
1070
+ * ],
1071
+ * "rows": [
1072
+ * "'(v1).k'",
1073
+ * "'(v2).k1'"
1074
+ * ],
1075
+ * "values": [
1076
+ * [
1077
+ * 0.24181093286002556,
1078
+ * -0.3990170323770476
1079
+ * ],
1080
+ * [
1081
+ * -0.3990170323770476,
1082
+ * 0.6845492624601023
1083
+ * ]
1084
+ * ]
1085
+ * },
1086
+ * "fim_eigenvalues": {
1087
+ * "columns": [
1088
+ * "1"
1089
+ * ],
1090
+ * "rows": [
1091
+ * "1",
1092
+ * "2"
1093
+ * ],
1094
+ * "values": [
1095
+ * [
1096
+ * 0.00687000654739478
1097
+ * ],
1098
+ * [
1099
+ * 0.9194901887727329
1100
+ * ]
1101
+ * ]
1102
+ * },
1103
+ * "fim_eigenvectors": {
1104
+ * "columns": [
1105
+ * "'(v1).k'",
1106
+ * "'(v2).k1'"
1107
+ * ],
1108
+ * "rows": [
1109
+ * "1",
1110
+ * "2"
1111
+ * ],
1112
+ * "values": [
1113
+ * [
1114
+ * -0.8617217634867894,
1115
+ * -0.5073811213803857
1116
+ * ],
1117
+ * [
1118
+ * -0.5073811213803857,
1119
+ * 0.8617217634867894
1120
+ * ]
1121
+ * ]
1122
+ * },
1123
+ * "scaled_fim": {
1124
+ * "columns": [
1125
+ * "'(v1).k'",
1126
+ * "'(v2).k1'"
1127
+ * ],
1128
+ * "rows": [
1129
+ * "'(v1).k'",
1130
+ * "'(v2).k1'"
1131
+ * ],
1132
+ * "values": [
1133
+ * [
1134
+ * 1.2437725097746164,
1135
+ * -1.28974037014191
1136
+ * ],
1137
+ * [
1138
+ * -1.28974037014191,
1139
+ * 1.3904693009022884
1140
+ * ]
1141
+ * ]
1142
+ * },
1143
+ * "scaled_fim_eigenvalues": {
1144
+ * "columns": [
1145
+ * "1"
1146
+ * ],
1147
+ * "rows": [
1148
+ * "1",
1149
+ * "2"
1150
+ * ],
1151
+ * "values": [
1152
+ * [
1153
+ * 0.02529653279178934
1154
+ * ],
1155
+ * [
1156
+ * 2.608945277885115
1157
+ * ]
1158
+ * ]
1159
+ * },
1160
+ * "scaled_fim_eigenvectors": {
1161
+ * "columns": [
1162
+ * "'(v1).k'",
1163
+ * "'(v2).k1'"
1164
+ * ],
1165
+ * "rows": [
1166
+ * "1",
1167
+ * "2"
1168
+ * ],
1169
+ * "values": [
1170
+ * [
1171
+ * -0.7269040246878076,
1172
+ * -0.6867390617204377
1173
+ * ],
1174
+ * [
1175
+ * -0.6867390617204377,
1176
+ * 0.7269040246878076
1177
+ * ]
1178
+ * ]
1179
+ * }
1180
+ * }"
1181
+ * ```
1182
+ * @type {object}
1183
+ */
1184
+ get fischerInformationMatrix() {
1185
+ return JSON.parse(this.Module.getFim());
1186
+ }
1187
+
1188
+ /**
1189
+ * Returns the fit items as object.
1190
+ * @type {object}
1191
+ */
1192
+ get fitItems() {
1193
+ return JSON.parse(this.Module.getFitItems());
1194
+ }
1195
+
1196
+ /**
1197
+ * Information about the last parameter estimation run.
1198
+ *
1199
+ * ```json
1200
+ * {
1201
+ * "obj": 0.0,
1202
+ * "rms": 0.0,
1203
+ * "sd": 0.0,
1204
+ * "f_evals": 42,
1205
+ * "failed_evals_exception": 0,
1206
+ * "failed_evals_nan": 0,
1207
+ * "constraint_evals": 0,
1208
+ * "failed_constraint_evals": 0,
1209
+ * "cpu_time": 0.01,
1210
+ * "evals_per_sec": 4200.0,
1211
+ * "data_points": 100,
1212
+ * "valid_data_points": 100
1213
+ * }
1214
+ * ```
1215
+ * @type {object}
1216
+ */
1217
+ get fitStatistic() {
1218
+ return JSON.parse(this.Module.getFitStatistic());
1219
+ }
1220
+
1221
+ /**
1222
+ * Settings for the parameter estimation task.
1223
+ *
1224
+ * In addition to the fields returned by {@link COPASI#getTaskSettings},
1225
+ * this includes the fit items, constraints and data filenames.
1226
+ * @type {object}
1227
+ */
1228
+ get fitSettings() {
1229
+ return JSON.parse(this.Module.getFitSettings());
1230
+ }
1231
+
1232
+ /**
1233
+ * Settings for the optimization task.
1234
+ *
1235
+ * In addition to the fields returned by {@link COPASI#getTaskSettings},
1236
+ * this includes the objective function, subtask, optimization items
1237
+ * and constraints.
1238
+ * @type {object}
1239
+ */
1240
+ get optSettings() {
1241
+ return JSON.parse(this.Module.getOptSettings());
1242
+ }
1243
+
1244
+ /**
1245
+ * Runs the named task.
1246
+ *
1247
+ * @param {string} taskName the name of the task to run
1248
+ * @param {boolean} [useInitialValues=true] if true the initial values are used,
1249
+ * otherwise the current state is used
1250
+ * @returns {boolean} true if the task was run successfully
1251
+ */
1252
+ runTask(taskName, useInitialValues = true) {
1253
+ return this.Module.runTask(taskName, useInitialValues);
1254
+ }
1255
+
1256
+ /**
1257
+ * Definitions of all parameter estimation experiments.
1258
+ *
1259
+ * Each entry has the same format as {@link COPASI#getExperimentDefinition}.
1260
+ * @type {object[]}
1261
+ */
1262
+ get experimentDefinitions() {
1263
+ return JSON.parse(this.Module.getExperimentDefinitions());
1264
+ }
1265
+
1266
+ /**
1267
+ * Sets the definition of an experiment from an object or JSON string.
1268
+ *
1269
+ * @param {string} experimentName the name of the experiment to set the definition for
1270
+ * @param {object|string} experimentDefinition the definition as object or JSON string,
1271
+ * in the same format as {@link COPASI#getExperimentDefinition}
1272
+ * @returns {boolean} true if successful
1273
+ */
1274
+ setExperimentDefinition(experimentName, experimentDefinition) {
1275
+ if (typeof experimentDefinition !== 'string') {
1276
+ experimentDefinition = JSON.stringify(experimentDefinition);
1277
+ }
1278
+ return this.Module.setExperimentDefinition(experimentName, experimentDefinition);
1279
+ }
1280
+
1281
+ /**
1282
+ * Returns the definition of an experiment.
1283
+ *
1284
+ * @param {string} experimentName the name of the experiment to get the definition for
1285
+ * @returns {object} the experiment definition
1286
+ *
1287
+ * ```json
1288
+ * {
1289
+ * "name": "Experiment 1",
1290
+ * "filename": "data.csv",
1291
+ * "type": "Time-Course" | "Steady-State",
1292
+ * "separator": "\t",
1293
+ * "first_row": "1",
1294
+ * "last_row": "10",
1295
+ * "weight_method": "Mean" | "Mean Square" | "Standard Deviation" | "Value Scaling",
1296
+ * "normalize_per_experiment": "false",
1297
+ * "mapping": [{'column': 0,
1298
+ * 'type': 'independent',
1299
+ * 'cn': 'CN=Root,Model=Kinetics of a Michaelian enzyme measured spectrophotometrically,Vector=Compartments[compartment],Vector=Metabolites[S],Reference=InitialConcentration',
1300
+ * 'object': '[S]_0'},
1301
+ * {'column': 1, 'type': 'time'},
1302
+ * {'column': 2,
1303
+ * 'type': 'dependent',
1304
+ * 'cn': 'CN=Root,Model=Kinetics of a Michaelian enzyme measured spectrophotometrically,Vector=Values[signal],Reference=Value',
1305
+ * 'object': 'Values[signal]'}]
1306
+ * }
1307
+ * ```
1308
+ */
1309
+ getExperimentDefinition(experimentName) {
1310
+ return JSON.parse(this.Module.getExperimentDefinition(experimentName));
1311
+ }
1312
+
1313
+ /**
1314
+ * Names of all parameter estimation experiments.
1315
+ * @type {string[]}
1316
+ */
1317
+ get experimentNames() {
1318
+ return this._vectorToArray(this.Module.getExperimentNames());
1319
+ }
1320
+
1321
+ /**
1322
+ * Sets the data filename of an experiment. The file has to exist.
1323
+ *
1324
+ * @param {string} experimentName the name of the experiment to set the filename for
1325
+ * @param {string} experimentFilename the name of the file to use
1326
+ * @returns {boolean} true if successful
1327
+ */
1328
+ setExperimentFilename(experimentName, experimentFilename) {
1329
+ return this.Module.setExperimentFilename(experimentName, experimentFilename);
1330
+ }
1331
+
1332
+ /**
1333
+ * Returns the current fit of each experiment against the model.
1334
+ *
1335
+ * @param {boolean} [computeCurrentSolution=true] if true, the current
1336
+ * parameter estimation values are applied to the model first so that
1337
+ * subsequent experiment simulations use the current parameter values
1338
+ * @returns {object} the current fit for each experiment
1339
+ */
1340
+ getCurrentFit(computeCurrentSolution = true) {
1341
+ return JSON.parse(this.Module.getCurrentFit(computeCurrentSolution));
1342
+ }
1343
+
1344
+
1345
+ /**
1346
+ * Converts the model to an irreversible form.
1347
+ * @returns {object} the irreversible model see loadModel, or an object with the error message
1348
+ */
1349
+ convertToIrreversible() {
1350
+ return JSON.parse(this.Module.convertToIrreversible());
1351
+ }
1352
+
1353
+ /**
1354
+ * The indent level for the JSON output.
1355
+ * @type {number}
1356
+ */
1357
+ get indent() {
1358
+ return this.Module.getIndent();
1359
+ }
1360
+ set indent(value) {
1361
+ this.Module.setIndent(value);
1362
+ }
1363
+
1364
+ }
1365
+
1366
+ export { COPASI };
1367
+ export default COPASI;