1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
// use mathml::MathNode;
use Math;
use Annotation;
use UnitSIdRef;
use *;
use ;
/// A compartment in SBML represents a bounded space in which species are located.
///
/// # Example
///
/// ```
/// use quick_xml::de::from_str;
/// use rust_sbml::Compartment;
///
/// let compartments: Vec<Compartment> = from_str(
/// "<compartment id='Extracellular' spatialDimensions='3' size='1e-14' constant='true'/>
/// <compartment id='PlasmaMembrane' spatialDimensions='2' size='1e-14' constant='true'/>
/// <compartment id='Cytosol' spatialDimensions='3' size='1e-15' constant='true'/>"
/// )
/// .unwrap();
/// assert!(compartments.iter() .any(|c| c.spatial_dimensions.unwrap() as i32 == 2));
/// assert!(compartments.iter()
/// .any(|c| c.id == "Cytosol"));
/// assert!(compartments.iter()
/// .all(|c| c.constant));
/// ```
/// A species in SBML refers to a pool of entities that
///
/// ⁻ are considered indistinguishable from each other for the purposes of the model;
/// - may participate in reactions;
/// - are located in a specific compartment.
///
/// # Example
///
/// ```
/// use quick_xml::de::from_str;
/// use rust_sbml::Species;
///
/// let species: Vec<Species> = from_str(
/// "<species id='Glucose' compartment='cell' initialConcentration='4'
/// hasOnlySubstanceUnits='false' boundaryCondition='false' constant='false'/>"
/// )
/// .unwrap();
/// assert_eq!(species[0].id, "Glucose");
/// assert_eq!(species[0].compartment, "cell");
/// assert_eq!(species[0].initial_concentration.unwrap() as u8, 4);
/// assert!(!species[0].constant);
/// assert!(!species[0].boundary_condition);
/// assert!(!species[0].has_only_substance_units);
/// ```
/// A Parameter is used in SBML to define a symbol associated with a value;
/// this symbol can then be used in mathematical formulas in a model.
///
/// # Example
/// ```
/// use quick_xml::de::from_str;
/// use rust_sbml::{Parameter, UnitSIdRef, UnitSId};
///
/// let parameter: Vec<Parameter> = from_str(
/// "<parameter id=\"tau2\" value=\"3e-2\" units=\"second\" constant=\"true\"/>
/// <parameter id=\"Km1\" value=\"10.7\" units=\"molesperlitre\" constant=\"true\"/>"
/// )
/// .unwrap();
/// assert_eq!(
/// parameter[0].units.to_owned().unwrap(),
/// UnitSIdRef::SIUnit(UnitSId::second)
/// );
/// assert_eq!(parameter[1].id, "Km1");
/// InitialAssigments provide a way to declare initial values that must be
/// computed (using a MathML expression).
///
/// # Example
///
/// ```
/// use quick_xml::de::from_str;
/// use rust_sbml::{InitialAssignment, mathml::MathNode};
///
/// let initial_assg: InitialAssignment = from_str(
/// r#"<initialAssignment symbol="x">
/// <math xmlns="http://www.w3.org/1998/Math/MathML"
/// xmlns:sbml="http://www.sbml.org/sbml/level3/version2/core">
/// <apply>
/// <ci> y </ci>
/// <times/>
/// <cn sbml:units="dimensionless"> 2 </cn>
/// </apply>
/// </math>
/// </initialAssignment>
/// "#).unwrap();
/// assert_eq!(initial_assg.symbol, String::from("x"));
/// ```
/// Provide a way for reactions to define species as products and reactants.
///
/// # Example
///
/// ```
/// use quick_xml::de::from_str;
/// use rust_sbml::Reaction;
///
/// let reactions: Reaction = from_str(
/// "<reaction id='J1' reversible='false' fbc:lowerFluxBound='-20'>
/// <listOfReactants>
/// <speciesReference species='X0' stoichiometry='2' constant='true'/>
/// <speciesReference species='X1' stoichiometry='1' constant='true'/>
/// </listOfReactants></reaction></listOfReactions></model>",
/// )
/// .unwrap();
/// println!("{:?}", reactions);
/// let mut specs_ref = reactions
/// .list_of_reactants
/// .species_references
/// .iter();
/// assert!(specs_ref
/// .any(|specref| specref.species == "X0"));
/// assert!(specs_ref
/// .any(|specref| {println!("{:?}", specref); specref.stoichiometry.unwrap() as i32 == 1}));
/// assert!(specs_ref
/// .all(|specref| specref.constant));
/// ```
/// The [`KineticLaw`] object within a Reaction object can contain a
/// ListOfLocalParameters object containing the definitions of local parameter
/// that are only accessible within the scope of that particular reaction.
/// The KineticLaw object class is used to describe the rate at which the
/// process defined by the Reaction takes place.
/// A reaction in SBML represents any kind of process that can change the
/// quantity of one or more species in a model. Examples of such processes can
/// include transformation, transport, molecular interactions, and more.
///
/// # Example
///
/// ```
/// use quick_xml::de::from_str;
/// use rust_sbml::Reaction;
///
/// let reactions: Reaction = from_str(
/// "<reaction id='J1' reversible='false' fbc:lowerFluxBound='-20'>
/// <listOfReactants>
/// <speciesReference species='X0' stoichiometry='2' constant='true'/>
/// </listOfReactants>
/// <kineticLaw>
/// <math xmlns='http://www.w3.org/1998/Math/MathML'>
/// <apply>
/// <times/> <ci> k </ci> <ci> S2 </ci> <ci> X0 </ci> <ci> c1 </ci>
/// </apply>
/// </math>
/// <listOfLocalParameters>
/// <localParameter id='k' value='0.1' units='per_concent_per_time'/>
/// </listOfLocalParameters>
/// </kineticLaw></reaction>"
/// )
/// .unwrap();
///
/// println!("{:?}", reactions);
/// assert!(reactions.kinetic_law.is_some());
/// assert!(reactions
/// .list_of_reactants
/// .species_references
/// .iter()
/// .any(|specref| specref.species == "X0"));
/// ```
/// The FunctionDefinition object associates an identifier with a function
/// definition. This identifier can then be4 used as the function called in
/// subsequent MathML apply elements.
///
/// # Example
/// ```
/// use quick_xml::de::from_str;
/// use rust_sbml::FunctionDefinition;
///
/// let function: FunctionDefinition = from_str(
/// r#"<functionDefinition id="pow3">
/// <math xmlns="http://www.w3.org/1998/Math/MathML"
/// xmlns:sbml="http://www.sbml.org/sbml/level3/version2/core">
/// <lambda>
/// <bvar><ci> x </ci></bvar>
/// <apply> <power/> <ci> x </ci> <cn sbml:units="dimensionless"> 3 </cn>
/// </apply>
/// </lambda>
/// </math>
/// </functionDefinition>"#).unwrap();
///
/// assert_eq!(function.id, "pow3");
/// ```
/// Rules provide additional ways to define the values of variables in a model, their
/// relationships, and the dynamical behaviors of those variables. Rules enable the encoding of
/// relationships that cannot be expressed using [`Reaction`]s alone nor by
/// an [`InitialAssignment`].
///
/// There are three function forms that involve a variable $x$; a function $f$;
/// $V$, a vector which does not include $x$; and $W$, a vector which may
/// include $x$.
///
/// # Example
///
/// The expression $k = \frac{k3}{k2}$ (from [the SBML3v2 spec](http://sbml.org/Special/specifications/sbml-level-3/version-2/core/release-2/sbml-level-3-version-2-release-2-core.pdf)):
///
/// ```
/// use quick_xml::de::from_str;
/// use rust_sbml::Rule;
///
/// let rule: Rule = from_str(
/// r#"<assignmentRule variable="k">
/// <math xmlns="http://www.w3.org/1998/Math/MathML">
/// <apply>
/// <divide/>
/// <ci> k3 </ci>
/// <ci> k2 </ci>
/// </apply>
/// </math>
/// </assignmentRule>"#).unwrap();
///
/// if let Rule::AssignmentRule { variable: k, .. } = rule {
/// assert_eq!(k.as_str(), "k");
/// } else {
/// panic!("Rule was not correctly parsed!")
/// }
/// ```
/// A XML `<message>` node.
/// The Constraint object is a mechanism for stating the assumptions under
/// which a model is designed to operate.
///
/// # Example
///
/// Constraint species “S1” so that $1 \le S1 \le 100$:
///
/// ```
/// use quick_xml::de::from_str;
/// use rust_sbml::Constraint;
///
/// let constraint: Constraint = from_str(
/// r#"<constraint>
/// <math xmlns="http://www.w3.org/1998/Math/MathML"
/// xmlns:sbml="http://www.sbml.org/sbml/level3/version2/core">
/// <apply>
/// <and/>
/// <apply> <lt/> <cn sbml:units="mole"> 1 </cn> <ci> S1 </ci>
/// </apply>
/// <apply> <lt/> <ci> S1 </ci> <cn sbml:units="mole"> 100 </cn>
/// </apply>
/// </apply>
/// </math>
/// <message>
/// <p xmlns="http://www.w3.org/1999/xhtml"> Species S1 is out of range. </p>
/// </message>
/// </constraint>"#).unwrap();
///
/// assert_eq!(constraint.message.unwrap().content.as_str(), "Species S1 is out of range.");
/// assert!(constraint.math.is_some())
/// ```
/// The Flux Balance Constraints package of SBML defines extensions for the
/// model, including the FBC Objective.
///
/// See the [FBC specification](http://co.mbine.org/specifications/sbml.level-3.version-1.fbc.version-2.release-1.pdf)
/// for more details.
///
/// # Example
///
/// ```
/// use quick_xml::de::from_str;
/// use rust_sbml::Objective;
///
/// let objectives: Vec<Objective> = from_str(
/// "<fbc:objective fbc:id=\"obj1\" fbc:type=\"maximize\">
/// <fbc:listOfFluxObjectives>
/// <fbc:fluxObjective fbc:reaction=\"R101\" fbc:coefficient=\"1\"/>
/// </fbc:listOfFluxObjectives>
/// </fbc:objective>
/// <fbc:objective fbc:id=\"obj2\" fbc:type=\"minimize\">
/// <fbc:listOfFluxObjectives>
/// <fbc:fluxObjective fbc:reaction=\"R102\" fbc:coefficient=\"-2.5\"/>
/// <fbc:fluxObjective fbc:reaction=\"R103\" fbc:coefficient=\"1\"/>
/// </fbc:listOfFluxObjectives>
/// </fbc:objective>").unwrap();
///
/// objectives.iter().any(|o| o.sense == "maximize");
/// objectives[1].list_of_flux_objectives.flux_objectives.iter().any(|r| r.reaction.to_owned().unwrap() == "R103");
/// ```
/// Relatively simple container for a model variable weighted by a signed
/// linear coefficient, defined in the Flux Balance Constraint package.