001/* ---------------------------------------------------------------------------- 002 * This file was automatically generated by SWIG (http://www.swig.org). 003 * Version 2.0.11 004 * 005 * Do not make changes to this file unless you know what you are doing--modify 006 * the SWIG interface file instead. 007 * ----------------------------------------------------------------------------- */ 008 009package org.sbml.libsbml; 010 011/** 012 * 013 * Implementation of SBML Level 2's StoichiometryMath construct. 014 * <p> 015 * <h2>Stoichiometries in SBML Level 2</h2> 016 * <p> 017 * In SBML Level 2, product and reactant stoichiometries can be specified 018 * using <em>either</em> the 'stoichiometry' attribute or a 'stoichiometryMath' 019 * element in a {@link SpeciesReference} object. The 'stoichiometry' attribute is 020 * of type <code>double</code> and should contain values greater than zero (0). The 021 * 'stoichiometryMath' element is implemented as an element containing a 022 * MathML expression. These two are mutually exclusive; only one of 023 * 'stoichiometry' or 'stoichiometryMath' should be defined in a given 024 * {@link SpeciesReference} instance. When neither the attribute nor the element 025 * is present, the value of 'stoichiometry' in the enclosing 026 * {@link SpeciesReference} instance defaults to <code>1.</code> 027 * <p> 028 * For maximum interoperability, {@link SpeciesReference}'s 'stoichiometry' 029 * attribute should be used in preference to 'stoichiometryMath' when a 030 * species' stoichiometry is a simple scalar number (integer or decimal). 031 * When the stoichiometry is a rational number, or when it is a more 032 * complicated formula, 'stoichiometryMath' must be used. The MathML 033 * expression in 'stoichiometryMath' may also refer to identifiers of 034 * entities in a model (except reaction identifiers). However, the only 035 * species identifiers that can be used in 'stoichiometryMath' are those 036 * referenced in the enclosing {@link Reaction}'s list of reactants, products and 037 * modifiers. 038 * <p> 039 * The 'stoichiometry' attribute and the 'stoichiometryMath' element, when 040 * either is used, is each interpreted as a factor applied to the reaction 041 * rate to produce the rate of change of the species identified by the 042 * 'species' attribute in the enclosing {@link SpeciesReference}. This is the 043 * normal interpretation of a stoichiometry, but in SBML, one additional 044 * consideration has to be taken into account. The reaction rate, which is 045 * the result of the {@link KineticLaw}'s 'math' element, is always in the model's 046 * <em>substance</em> per <em>time</em> units. However, the rate of change of the 047 * species will involve the species' <em>substance</em> units (i.e., the units 048 * identified by the {@link Species} object's 'substanceUnits' attribute), and 049 * these units may be different from the model's default <em>substance</em> 050 * units. If the units <em>are</em> different, the stoichiometry must 051 * incorporate a conversion factor for converting the model's <em>substance</em> 052 * units to the species' <em>substance</em> units. The conversion factor is 053 * assumed to be included in the scalar value of the 'stoichiometry' 054 * attribute if 'stoichiometry' is used. If instead 'stoichiometryMath' is 055 * used, then the product of the model's 'substance' units times the 056 * 'stoichiometryMath' units must match the <em>substance</em> units of the 057 * species. Note that in either case, if the species' units and the 058 * model's default <em>substance</em> units are the same, the stoichiometry ends 059 * up being a dimensionless number and equivalent to the standard chemical 060 * stoichiometry found in textbooks. Examples and more explanations of 061 * this are given in the SBML specification. 062 * <p> 063 * The following is a simple example of a species reference for species 064 * <code>'X0'</code>, with stoichiometry <code>2</code>, in a list of reactants within a reaction 065 * having the identifier <code>'J1':</code> 066 * <div class='fragment'><pre> 067 <model> 068 ... 069 <listOfReactions> 070 <reaction id='J1'> 071 <listOfReactants> 072 <speciesReference species='X0' stoichiometry='2'> 073 </listOfReactants> 074 ... 075 </reaction> 076 ... 077 </listOfReactions> 078 ... 079 </model> 080 </pre></div> 081 * <p> 082 * The following is a more complex example of a species reference for 083 * species <code>'X0'</code>, with a stoichiometry formula consisting of 084 * a rational number: 085 * <div class='fragment'><pre> 086 <model> 087 ... 088 <listOfReactions> 089 <reaction id='J1'> 090 <listOfReactants> 091 <speciesReference species='X0'> 092 <stoichiometryMath> 093 <math xmlns='http://www.w3.org/1998/Math/MathML'> 094 <cn type='rational'> 3 <sep/> 2 </cn> 095 </math> 096 </stoichiometryMath> 097 </speciesReference> 098 </listOfReactants> 099 ... 100 </reaction> 101 ... 102 </listOfReactions> 103 ... 104 </model> 105 </pre></div> 106 * <p> 107 * Additional discussions of stoichiometries and implications for species 108 * and reactions are included in the documentation of {@link SpeciesReference} 109 * class. 110 * <p> 111 * <h2>Stoichiometries in SBML Level 3</h2> 112 * <p> 113 * The {@link StoichiometryMath} construct is not defined in SBML Level 3 114 * Version 1 Core. Instead, Level 3 defines the identifier of 115 * {@link SpeciesReference} objects as a stand-in for the stoichiometry of the 116 * reactant or product being referenced, and allows that identifier to be 117 * used elsewhere in SBML models, including (for example) {@link InitialAssignment} 118 * objects. This makes it possible to achieve the same effect as 119 * {@link StoichiometryMath}, but with other SBML objects. For instance, to 120 * produce a stoichiometry value that is a rational number, a model can use 121 * {@link InitialAssignment} to assign the identifier of a {@link SpeciesReference} object 122 * to a MathML expression evaluating to a rational number. This is 123 * analogous to the same way that, in Level 2, the model would use 124 * {@link StoichiometryMath} with a MathML expression evaluating to a rational 125 * number. 126 * <p> 127 * In SBML Level 2, the stoichiometry of a reactant or product is a 128 * combination of both a <em>biochemical stoichiometry</em> (meaning, the 129 * standard stoichiometry of a species in a reaction) and any necessary 130 * unit conversion factors. The introduction of an explicit attribute on 131 * the {@link Species} object for a conversion factor allows Level 3 to avoid 132 * having to overload the meaning of stoichiometry. In Level 3, the 133 * stoichiometry given by a {@link SpeciesReference} object in a reaction is a 134 * 'proper' biochemical stoichiometry, meaning a dimensionless number free 135 * of unit conversions. 136 * <p> 137 * @see SpeciesReference 138 * @see Reaction 139 */ 140 141public class StoichiometryMath extends SBase { 142 private long swigCPtr; 143 144 protected StoichiometryMath(long cPtr, boolean cMemoryOwn) 145 { 146 super(libsbmlJNI.StoichiometryMath_SWIGUpcast(cPtr), cMemoryOwn); 147 swigCPtr = cPtr; 148 } 149 150 protected static long getCPtr(StoichiometryMath obj) 151 { 152 return (obj == null) ? 0 : obj.swigCPtr; 153 } 154 155 protected static long getCPtrAndDisown (StoichiometryMath obj) 156 { 157 long ptr = 0; 158 159 if (obj != null) 160 { 161 ptr = obj.swigCPtr; 162 obj.swigCMemOwn = false; 163 } 164 165 return ptr; 166 } 167 168 protected void finalize() { 169 delete(); 170 } 171 172 public synchronized void delete() { 173 if (swigCPtr != 0) { 174 if (swigCMemOwn) { 175 swigCMemOwn = false; 176 libsbmlJNI.delete_StoichiometryMath(swigCPtr); 177 } 178 swigCPtr = 0; 179 } 180 super.delete(); 181 } 182 183 184/** 185 * Creates a new {@link StoichiometryMath} object using the given SBML <code>level</code> 186 * values. 187 * <p> 188 * @param level a long integer, the SBML Level to assign to this {@link StoichiometryMath} 189 * <p> 190 * @param version a long integer, the SBML Version to assign to this 191 * {@link StoichiometryMath} 192 * <p> 193 * The {@link StoichiometryMath} construct exists only in SBML Level 2. It 194 * is an optional construct available for defining the stoichiometries of 195 * reactants and products in {@link Reaction} objects. Note that a different 196 * mechanism is used in SBML Level 3, where {@link StoichiometryMath} is not 197 * available. Please consult the top of this libSBML {@link StoichiometryMath} 198 * documentation for more information about the differences between SBML 199 * Level 2 and 3 with respect to stoichiometries. 200 * <p> 201 * @throws SBMLConstructorException 202 * Thrown if the given <code>level</code> and <code>version</code> combination, or this kind 203 * of SBML object, are either invalid or mismatched with respect to the 204 * parent {@link SBMLDocument} object. 205 * <p> 206 * @note Upon the addition of a {@link StoichiometryMath} object to an 207 * {@link SBMLDocument} (e.g., using 208 * {@link SpeciesReference#createStoichiometryMath()}), the SBML Level, SBML 209 * Version and XML namespace of the document <em>override</em> the values used 210 * when creating the {@link StoichiometryMath} object via this constructor. This 211 * is necessary to ensure that an SBML document is a consistent 212 * structure. Nevertheless, the ability to supply the values at the time 213 * of creation of a {@link StoichiometryMath} is an important aid to producing 214 * valid SBML. Knowledge of the intented SBML Level and Version 215 * determine whether it is valid to assign a particular value to an 216 * attribute, or whether it is valid to add an object to an existing 217 * {@link SBMLDocument}. 218 */ public 219 StoichiometryMath(long level, long version) throws org.sbml.libsbml.SBMLConstructorException { 220 this(libsbmlJNI.new_StoichiometryMath__SWIG_0(level, version), true); 221 } 222 223 224/** 225 * Creates a new {@link StoichiometryMath} object using the given {@link SBMLNamespaces} object 226 * <code>sbmlns</code>. 227 * <p> 228 * The {@link SBMLNamespaces} object encapsulates SBML Level/Version/namespaces 229 * information. It is used to communicate the SBML Level, Version, and 230 * (in Level 3) packages used in addition to SBML Level 3 Core. 231 * A common approach to using this class constructor is to create an 232 * {@link SBMLNamespaces} object somewhere in a program, once, then pass it to 233 * object constructors such as this one when needed. 234 * <p> 235 * @param sbmlns an {@link SBMLNamespaces} object. 236 * <p> 237 * The {@link StoichiometryMath} construct exists only in SBML Level 2. It 238 * is an optional construct available for defining the stoichiometries of 239 * reactants and products in {@link Reaction} objects. Note that a different 240 * mechanism is used in SBML Level 3, where {@link StoichiometryMath} is not 241 * available. Please consult the top of this libSBML {@link StoichiometryMath} 242 * documentation for more information about the differences between SBML 243 * Level 2 and 3 with respect to stoichiometries. 244 * <p> 245 * @throws SBMLConstructorException 246 * Thrown if the given <code>level</code> and <code>version</code> combination, or this kind 247 * of SBML object, are either invalid or mismatched with respect to the 248 * parent {@link SBMLDocument} object. 249 * <p> 250 * @note Upon the addition of a {@link StoichiometryMath} object to an 251 * {@link SBMLDocument} (e.g., using 252 * {@link SpeciesReference#createStoichiometryMath()}), the SBML XML namespace 253 * of the document <em>overrides</em> the value used when creating the 254 * {@link StoichiometryMath} object via this constructor. This is necessary to 255 * ensure that an SBML document is a consistent structure. Nevertheless, 256 * the ability to supply the values at the time of creation of a 257 * {@link StoichiometryMath} is an important aid to producing valid SBML. 258 * Knowledge of the intented SBML Level and Version determine whether it 259 * is valid to assign a particular value to an attribute, or whether it 260 * is valid to add an object to an existing {@link SBMLDocument}. 261 */ public 262 StoichiometryMath(SBMLNamespaces sbmlns) throws org.sbml.libsbml.SBMLConstructorException { 263 this(libsbmlJNI.new_StoichiometryMath__SWIG_1(SBMLNamespaces.getCPtr(sbmlns), sbmlns), true); 264 } 265 266 267/** 268 * Copy constructor; creates a copy of this {@link StoichiometryMath}. 269 * <p> 270 * @param orig the object to copy. 271 * <p> 272 * @throws SBMLConstructorException 273 * Thrown if the argument <code>orig</code> is <code>null.</code> 274 */ public 275 StoichiometryMath(StoichiometryMath orig) throws org.sbml.libsbml.SBMLConstructorException { 276 this(libsbmlJNI.new_StoichiometryMath__SWIG_2(StoichiometryMath.getCPtr(orig), orig), true); 277 } 278 279 280/** 281 * Creates and returns a deep copy of this {@link StoichiometryMath} object. 282 * <p> 283 * @return a (deep) copy of this {@link StoichiometryMath}. 284 */ public 285 StoichiometryMath cloneObject() { 286 long cPtr = libsbmlJNI.StoichiometryMath_cloneObject(swigCPtr, this); 287 return (cPtr == 0) ? null : new StoichiometryMath(cPtr, true); 288 } 289 290 291/** 292 * Retrieves the mathematical formula within this {@link StoichiometryMath} and 293 * return it as an AST. 294 * <p> 295 * @return the math of this {@link StoichiometryMath}. 296 * <p> 297 * The {@link StoichiometryMath} construct exists only in SBML Level 2. It 298 * is an optional construct available for defining the stoichiometries of 299 * reactants and products in {@link Reaction} objects. Note that a different 300 * mechanism is used in SBML Level 3, where {@link StoichiometryMath} is not 301 * available. Please consult the top of this libSBML {@link StoichiometryMath} 302 * documentation for more information about the differences between SBML 303 * Level 2 and 3 with respect to stoichiometries. 304 */ public 305 ASTNode getMath() { 306 long cPtr = libsbmlJNI.StoichiometryMath_getMath(swigCPtr, this); 307 return (cPtr == 0) ? null : new ASTNode(cPtr, false); 308 } 309 310 311/** 312 * Predicate to test whether the math for this {@link StoichiometryMath} object 313 * is set. 314 * <p> 315 * @return <code>true</code> if the formula (meaning the <code>math</code> subelement) of 316 * this {@link StoichiometryMath} is set, <code>false</code> otherwise. 317 * <p> 318 * The {@link StoichiometryMath} construct exists only in SBML Level 2. It 319 * is an optional construct available for defining the stoichiometries of 320 * reactants and products in {@link Reaction} objects. Note that a different 321 * mechanism is used in SBML Level 3, where {@link StoichiometryMath} is not 322 * available. Please consult the top of this libSBML {@link StoichiometryMath} 323 * documentation for more information about the differences between SBML 324 * Level 2 and 3 with respect to stoichiometries. 325 */ public 326 boolean isSetMath() { 327 return libsbmlJNI.StoichiometryMath_isSetMath(swigCPtr, this); 328 } 329 330 331/** 332 * Sets the 'math' expression of this {@link StoichiometryMath} instance to a 333 * copy of the given {@link ASTNode}. 334 * <p> 335 * @param math an {@link ASTNode} representing a formula tree. 336 * <p> 337 * @return integer value indicating success/failure of the 338 * function. The possible values 339 * returned by this function are: 340 * <ul> 341 * <li> {@link libsbmlConstants#LIBSBML_OPERATION_SUCCESS LIBSBML_OPERATION_SUCCESS } 342 * <li> {@link libsbmlConstants#LIBSBML_INVALID_OBJECT LIBSBML_INVALID_OBJECT } 343 * </ul> 344 * <p> 345 * The {@link StoichiometryMath} construct exists only in SBML Level 2. It 346 * is an optional construct available for defining the stoichiometries of 347 * reactants and products in {@link Reaction} objects. Note that a different 348 * mechanism is used in SBML Level 3, where {@link StoichiometryMath} is not 349 * available. Please consult the top of this libSBML {@link StoichiometryMath} 350 * documentation for more information about the differences between SBML 351 * Level 2 and 3 with respect to stoichiometries. 352 */ public 353 int setMath(ASTNode math) { 354 return libsbmlJNI.StoichiometryMath_setMath(swigCPtr, this, ASTNode.getCPtr(math), math); 355 } 356 357 358/** 359 * Calculates and returns a {@link UnitDefinition} object that expresses the 360 * units returned by the math expression in this {@link StoichiometryMath} 361 * object. 362 * <p> 363 * The units are calculated based on the mathematical expression in the 364 * {@link StoichiometryMath} and the model quantities referenced by 365 * <code><ci></code> elements used within that expression. The 366 * {@link StoichiometryMath#getDerivedUnitDefinition()} method returns the 367 * calculated units. 368 * <p> 369 * Note that the functionality that facilitates unit analysis depends 370 * on the model as a whole. Thus, in cases where the object has not 371 * been added to a model or the model itself is incomplete, 372 * unit analysis is not possible and this method will return <code>null.</code> 373 * <p> 374 * @warning Note that it is possible the 'math' expression in the 375 * {@link StoichiometryMath} instance contains literal numbers or parameters with 376 * undeclared units. In those cases, it is not possible to calculate the 377 * units of the overall expression without making assumptions. LibSBML 378 * does not make assumptions about the units, and 379 * {@link StoichiometryMath#getDerivedUnitDefinition()} only returns the units 380 * as far as it is able to determine them. For example, in an expression 381 * <em>X + Y</em>, if <em>X</em> has unambiguously-defined units and 382 * <em>Y</em> does not, it will return the units of <em>X</em>. When 383 * using this method, <strong>it is critical that callers also invoke the 384 * method</strong> {@link StoichiometryMath#containsUndeclaredUnits()} 385 * <strong>to determine whether this situation holds</strong>. Callers 386 * should take suitable action in those situations. 387 * <p> 388 * @return a {@link UnitDefinition} that expresses the units of the math, 389 * or <code>null</code> if one cannot be constructed. 390 * <p> 391 * @see #containsUndeclaredUnits() 392 */ public 393 UnitDefinition getDerivedUnitDefinition() { 394 long cPtr = libsbmlJNI.StoichiometryMath_getDerivedUnitDefinition__SWIG_0(swigCPtr, this); 395 return (cPtr == 0) ? null : new UnitDefinition(cPtr, false); 396 } 397 398 399/** 400 * Predicate returning <code>true</code> if the math 401 * expression of this {@link StoichiometryMath} object contains literal numbers 402 * or parameters with undeclared units. 403 * <p> 404 * The {@link StoichiometryMath#getDerivedUnitDefinition()} method returns what 405 * libSBML computes the units of the Stoichiometry to be, to the extent 406 * that libSBML can compute them. However, if the expression contains 407 * literal numbers or parameters with undeclared units, libSBML may not 408 * be able to compute the full units of the expression and will only 409 * return what it can compute. Callers should always use 410 * {@link StoichiometryMath#containsUndeclaredUnits()} when using 411 * {@link StoichiometryMath#getDerivedUnitDefinition()} to decide whether the 412 * returned units may be incomplete. 413 * <p> 414 * @return <code>true</code> if the math expression of this {@link StoichiometryMath} 415 * includes numbers/parameters with undeclared units, <code>false</code> otherwise. 416 * <p> 417 * @note A return value of <code>true</code> indicates that the {@link UnitDefinition} 418 * returned by {@link StoichiometryMath#getDerivedUnitDefinition()} may not 419 * accurately represent the units of the expression. 420 * <p> 421 * @see #getDerivedUnitDefinition() 422 */ public 423 boolean containsUndeclaredUnits() { 424 return libsbmlJNI.StoichiometryMath_containsUndeclaredUnits__SWIG_0(swigCPtr, this); 425 } 426 427 428/** 429 * Returns the libSBML type code of this object instance. 430 * <p> 431 * LibSBML attaches an identifying code to every 432 * kind of SBML object. These are known as <em>SBML type codes</em>. In 433 * other languages, the set of type codes is stored in an enumeration; in 434 * the Java language interface for libSBML, the type codes are defined as 435 * static integer constants in the interface class {@link 436 * libsbmlConstants}. The names of the type codes all begin with the 437 * characters <code>SBML_.</code> 438 * <p> 439 * @return the SBML type code for this object, or {@link libsbmlConstants#SBML_UNKNOWN SBML_UNKNOWN} (default). 440 * <p> 441 * @see #getElementName() 442 */ public 443 int getTypeCode() { 444 return libsbmlJNI.StoichiometryMath_getTypeCode(swigCPtr, this); 445 } 446 447 448/** 449 * Returns the XML element name of this object, which for {@link StoichiometryMath}, is 450 * always <code>'stoichiometryMath'.</code> 451 * <p> 452 * @return the name of this element, i.e., <code>'stoichiometryMath'.</code> 453 */ public 454 String getElementName() { 455 return libsbmlJNI.StoichiometryMath_getElementName(swigCPtr, this); 456 } 457 458 459/** 460 * Predicate returning <code>true</code> if 461 * all the required elements for this {@link StoichiometryMath} object 462 * have been set. 463 * <p> 464 * @note The required elements for a {@link StoichiometryMath} object are: 465 * <ul> 466 * <li> 'math' 467 * </ul> 468 * <p> 469 * @return a boolean value indicating whether all the required 470 * elements for this object have been defined. 471 */ public 472 boolean hasRequiredElements() { 473 return libsbmlJNI.StoichiometryMath_hasRequiredElements(swigCPtr, this); 474 } 475 476 477/** 478 * Finds this {@link StoichiometryMath}'s {@link SpeciesReference} parent and calls unsetStoichiometryMath() on it, indirectly deleting itself. Overridden from the {@link SBase} function since the parent is not a {@link ListOf}. 479 * <p> 480 * @return integer value indicating success/failure of the 481 * function. The possible values 482 * returned by this function are: 483 * <ul> 484 * <li> {@link libsbmlConstants#LIBSBML_OPERATION_SUCCESS LIBSBML_OPERATION_SUCCESS } 485 * <li> {@link libsbmlConstants#LIBSBML_OPERATION_FAILED LIBSBML_OPERATION_FAILED } 486 * </ul> 487 */ public 488 int removeFromParentAndDelete() { 489 return libsbmlJNI.StoichiometryMath_removeFromParentAndDelete(swigCPtr, this); 490 } 491 492 493/** 494 * Renames all the SIdRef attributes on this element, including any found in MathML 495 */ public 496 void renameSIdRefs(String oldid, String newid) { 497 libsbmlJNI.StoichiometryMath_renameSIdRefs(swigCPtr, this, oldid, newid); 498 } 499 500 501/** 502 * Renames all the UnitSIdRef attributes on this element 503 */ public 504 void renameUnitSIdRefs(String oldid, String newid) { 505 libsbmlJNI.StoichiometryMath_renameUnitSIdRefs(swigCPtr, this, oldid, newid); 506 } 507 508 509/** 510 * Replace all nodes with the name 'id' from the child 'math' object with the provided function. 511 * <p> 512 * @internal 513 */ public 514 void replaceSIDWithFunction(String id, ASTNode function) { 515 libsbmlJNI.StoichiometryMath_replaceSIDWithFunction(swigCPtr, this, id, ASTNode.getCPtr(function), function); 516 } 517 518}