@Override public boolean check(ValidationContext ctx, SpeciesReference sr) { // Can't be a Modifier if (sr.isSetStoichiometryMath()) { return !sr.isSetStoichiometry(); } return true; } };
@Override public int getChildCount() { return super.getChildCount() + (isSetStoichiometryMath() ? 1 : 0); }
@Override public String getDerivedUnits() { if (isSetStoichiometryMath()) { return stoichiometryMath.getDerivedUnits(); } return Unit.Kind.DIMENSIONLESS.toString(); }
@Override public TreeNode getChildAt(int index) { if (index < 0) { throw new IndexOutOfBoundsException(MessageFormat.format( resourceBundle.getString("IndexSurpassesBoundsException"), index, 0)); } int count = super.getChildCount(), pos = 0; if (index < count) { return super.getChildAt(index); } else { index -= count; } if (isSetStoichiometryMath()) { if (pos == index) { return getStoichiometryMath(); } pos++; } throw new IndexOutOfBoundsException(MessageFormat.format( resourceBundle.getString("IndexExceedsBoundsException"), index, Math.min(pos, 0))); }
/** * Returns the number of {@link StoichiometryMath} in the {@link Model}. * * @return the number of {@link StoichiometryMath} in the {@link Model}. * @deprecated since SBML L3V1 */ @Deprecated public int getStoichiometryMathCount() { int count = 0; if (isSetListOfReactions()) { for (Reaction r : getListOfReactions()) { for (SpeciesReference sr : r.getListOfReactants()) { if (sr.isSetStoichiometryMath()) { count++; } } for (SpeciesReference sr : r.getListOfProducts()) { if (sr.isSetStoichiometryMath()) { count++; } } } } return count; }
@Override public boolean containsUndeclaredUnits() { if (isSetStoichiometryMath()) { return getStoichiometryMath().containsUndeclaredUnits(); } return isSetStoichiometry() ? false : true; }
@Override public String printSpeciesReference() { StringBuilder sb = new StringBuilder(); if (isSetStoichiometry() && (getStoichiometry() != 1d)) { sb.append(StringTools.toString(getStoichiometry())); sb.append(' '); } else if (isSetStoichiometryMath()) { sb.append(getStoichiometryMath().getMath().toFormula()); sb.append(' '); } sb.append(super.printSpeciesReference()); return sb.toString(); }
/** * Sets the stoichiometry of this {@link SpeciesReference}. * * @param stoichiometry */ public void setStoichiometry(double stoichiometry) { if ((getLevel() == 1) && (getVersion() == 2)) { int stoch = (int) stoichiometry; if ((stoch < 0) || (stoch - stoichiometry != 0d)) { throw new IllegalArgumentException(MessageFormat.format( ILLEGAL_STOCHIOMETRY_VALUE, "stoichiometry", stoichiometry)); } } Double oldStoichiometry = this.stoichiometry; this.stoichiometry = Double.valueOf(stoichiometry); if (isSetStoichiometryMath()) { stoichiometryMath = null; } if (Double.isNaN(stoichiometry)) { isSetStoichiometry = false; } else { isSetStoichiometry = true; } firePropertyChange(TreeNodeChangeEvent.stoichiometry, oldStoichiometry, this.stoichiometry); }
private boolean checkStoichiometryMath(Model m, SpeciesReference ref, Set<String> definedSpecies) { if (ref.isSetStoichiometryMath() && ref.getStoichiometryMath().isSetMath()) { Queue<ASTNode> queue = new LinkedList<ASTNode>(); queue.offer(ref.getStoichiometryMath().getMath()); while (!queue.isEmpty()) { ASTNode node = queue.poll(); if (node.isName()) { String name = (node.getName() != null) ? node.getName() : ""; if (m.getSpecies(name) != null && !definedSpecies.contains(name)) { return false; } } queue.addAll(node.getListOfNodes()); } } return true; } };
reactionEqn.append(" + "); if (reactant.isSetStoichiometryMath()) { reactionEqn.append(reactant.getStoichiometryMath().getMath() .compile(this)); reactionEqn.append(" + "); if (product.isSetStoichiometryMath()) { reactionEqn.append(product.getStoichiometryMath().getMath() .compile(this));
@Override public UnitDefinition getDerivedUnitDefinition() { if (isSetStoichiometryMath()) { return stoichiometryMath.getDerivedUnitDefinition(); } UnitDefinition ud = new UnitDefinition(getLevel(), getVersion()); ud.addUnit(Unit.Kind.DIMENSIONLESS); return ud; }
/** * Creates a SpeciesReference instance from a given SpeciesReference. * * @param speciesReference */ @SuppressWarnings("deprecation") public SpeciesReference(SpeciesReference speciesReference) { super(speciesReference); if (speciesReference.isSetStoichiometryMath()) { setStoichiometryMath(speciesReference.getStoichiometryMath() .clone()); } if (speciesReference.isSetStoichiometry()) { setStoichiometry(new Double(speciesReference.getStoichiometry())); } else { stoichiometry = speciesReference.stoichiometry == null ? null : new Double(speciesReference.stoichiometry); } if (speciesReference.isSetConstant()) { setConstant(new Boolean(speciesReference.isConstant())); } else { constant = speciesReference.constant == null ? null : new Boolean(speciesReference.constant); } if (speciesReference.isSetDenominator) { setDenominator(new Integer(speciesReference.getDenominator())); } else { denominator = speciesReference.denominator == null ? null : new Integer(speciesReference.denominator); } }
reactionEqn.append(" + "); if (reactant.isSetStoichiometryMath()) { reactionEqn.append(reactant.getStoichiometryMath().getMath().toASTNode2() .compile((ASTNode2Compiler) this)); reactionEqn.append(" + "); if (product.isSetStoichiometryMath()) { reactionEqn.append(product.getStoichiometryMath().getMath().toASTNode2() .compile((ASTNode2Compiler) this));