Search in sources :

Example 26 with ExpressionException

use of cbit.vcell.parser.ExpressionException in project vcell by virtualcell.

the class XmlReader method getVarIniCount.

/**
 * This method return a VarIniCondition object from a XML element.
 * Creation date: (7/24/2006 5:26:05 PM)
 * @return cbit.vcell.math.VarIniCondition
 * @param param org.jdom.Element
 * @exception cbit.vcell.xml.XmlParseException The exception description.
 */
private VarIniCondition getVarIniCount(Element param, MathDescription md) throws XmlParseException, MathException, ExpressionException {
    // retrieve values
    Expression exp = unMangleExpression(param.getText());
    String name = unMangle(param.getAttributeValue(XMLTags.NameAttrTag));
    Variable var = md.getVariable(name);
    if (var == null) {
        throw new MathFormatException("variable " + name + " not defined");
    }
    if (!(var instanceof StochVolVariable)) {
        throw new MathFormatException("variable " + name + " not a Stochastic Volume Variable");
    }
    try {
        VarIniCondition varIni = new VarIniCount(var, exp);
        return varIni;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
Also used : VarIniCondition(cbit.vcell.math.VarIniCondition) FilamentVariable(cbit.vcell.math.FilamentVariable) OutsideVariable(cbit.vcell.math.OutsideVariable) StochVolVariable(cbit.vcell.math.StochVolVariable) RandomVariable(cbit.vcell.math.RandomVariable) VolumeRandomVariable(cbit.vcell.math.VolumeRandomVariable) VolumeParticleVariable(cbit.vcell.math.VolumeParticleVariable) VolumeRegionVariable(cbit.vcell.math.VolumeRegionVariable) InsideVariable(cbit.vcell.math.InsideVariable) VolVariable(cbit.vcell.math.VolVariable) MembraneRegionVariable(cbit.vcell.math.MembraneRegionVariable) PointVariable(cbit.vcell.math.PointVariable) MembraneRandomVariable(cbit.vcell.math.MembraneRandomVariable) MembraneParticleVariable(cbit.vcell.math.MembraneParticleVariable) ParticleVariable(cbit.vcell.math.ParticleVariable) MemVariable(cbit.vcell.math.MemVariable) FilamentRegionVariable(cbit.vcell.math.FilamentRegionVariable) Variable(cbit.vcell.math.Variable) Expression(cbit.vcell.parser.Expression) MathFormatException(cbit.vcell.math.MathFormatException) VarIniCount(cbit.vcell.math.VarIniCount) StochVolVariable(cbit.vcell.math.StochVolVariable) GeometryException(cbit.vcell.geometry.GeometryException) MathFormatException(cbit.vcell.math.MathFormatException) MappingException(cbit.vcell.mapping.MappingException) PropertyVetoException(java.beans.PropertyVetoException) ImageException(cbit.image.ImageException) ExpressionBindingException(cbit.vcell.parser.ExpressionBindingException) ModelException(cbit.vcell.model.ModelException) DataConversionException(org.jdom.DataConversionException) ExpressionException(cbit.vcell.parser.ExpressionException) MathException(cbit.vcell.math.MathException)

Example 27 with ExpressionException

use of cbit.vcell.parser.ExpressionException in project vcell by virtualcell.

the class CellQuanVCTranslator method addFunction.

private Function addFunction(Element temp, Element comp, String mangledName) {
    String expStr = null;
    Expression exp = null;
    Element parent = (Element) temp.getParent();
    Element sibling = parent.getChild(MathMLTags.APPLY, mathns);
    if (sibling == null) {
        // check if its value is assigned to another variable (i.e. A = B)
        @SuppressWarnings("unchecked") ArrayList<Element> list = new ArrayList<Element>(parent.getChildren(MathMLTags.IDENTIFIER, mathns));
        if (list.size() == 2) {
            expStr = (list.get(1)).getTextTrim();
        }
        if (expStr == null || expStr.length() == 0) {
            expStr = parent.getChildText(MathMLTags.CONSTANT, mathns);
        }
        if (expStr == null || expStr.length() == 0) {
            // check if 'piecewise'
            sibling = parent.getChild(MathMLTags.PIECEWISE, mathns);
        }
        if (expStr != null) {
            try {
                exp = new Expression(expStr);
                exp = processMathExp(comp, exp);
                nl.mangleString(expStr);
            } catch (ExpressionException e) {
                e.printStackTrace(System.out);
                throw new RuntimeException(e.getMessage());
            }
        }
    }
    if (sibling != null) {
        Element trimmedMath = new Element(CELLMLTags.MATH, mathns).addContent(sibling.detach());
        fixMathMLBug(trimmedMath);
        try {
            exp = (new ExpressionMathMLParser(null)).fromMathML(trimmedMath);
        } catch (ExpressionException e) {
            e.printStackTrace(System.out);
            throw new RuntimeException(e.getMessage());
        }
        exp = processMathExp(comp, exp);
        expStr = exp.infix();
        nl.mangleString(expStr);
    }
    Domain domain = null;
    return new Function(mangledName, exp, domain);
}
Also used : Function(cbit.vcell.math.Function) Expression(cbit.vcell.parser.Expression) Element(org.jdom.Element) ArrayList(java.util.ArrayList) ExpressionMathMLParser(cbit.vcell.parser.ExpressionMathMLParser) CompartmentSubDomain(cbit.vcell.math.CompartmentSubDomain) Domain(cbit.vcell.math.Variable.Domain) ExpressionException(cbit.vcell.parser.ExpressionException)

Example 28 with ExpressionException

use of cbit.vcell.parser.ExpressionException in project vcell by virtualcell.

the class SBPAXHMMIrrevLawBuilder method addKinetics.

public void addKinetics(KineticContext context) {
    try {
        ReactionStep reaction = context.getReaction();
        HMM_IRRKinetics kinetics = new HMM_IRRKinetics((SimpleReaction) reaction);
        NameScope modelScope = reaction.getModel().getNameScope();
        ModelParameter kMichaelis = context.getParameter(SBOList.MICHAELIS_CONST_FORW);
        if (kMichaelis != null) {
            KineticsParameter kmParameter = kinetics.getKmParameter();
            kmParameter.setExpression(new Expression(kMichaelis, modelScope));
            kmParameter.setUnitDefinition(kMichaelis.getUnitDefinition());
        }
        ModelParameter kcat = context.getParameter(SBOList.CATALYTIC_RATE_CONST_FORW);
        if (kcat != null && context.getCatalysts().size() == 1) {
            KineticsParameter vmaxParameter = kinetics.getVmaxParameter();
            Catalyst catalyst = context.getCatalysts().iterator().next();
            vmaxParameter.setExpression(Expression.mult(new Expression(kcat, modelScope), new Expression(catalyst.getSpeciesContext(), modelScope)));
        // vmaxParameter.setUnitDefinition(vMax.getUnitDefinition());
        } else {
            ModelParameter vMax = context.getParameter(SBOList.MAXIMAL_VELOCITY_FORW);
            if (vMax != null) {
                KineticsParameter vmaxParameter = kinetics.getVmaxParameter();
                vmaxParameter.setExpression(new Expression(vMax, modelScope));
                vmaxParameter.setUnitDefinition(vMax.getUnitDefinition());
            }
        }
    } catch (ExpressionException e) {
        e.printStackTrace();
    }
}
Also used : ModelParameter(cbit.vcell.model.Model.ModelParameter) KineticsParameter(cbit.vcell.model.Kinetics.KineticsParameter) NameScope(cbit.vcell.parser.NameScope) Expression(cbit.vcell.parser.Expression) HMM_IRRKinetics(cbit.vcell.model.HMM_IRRKinetics) ReactionStep(cbit.vcell.model.ReactionStep) Catalyst(cbit.vcell.model.Catalyst) ExpressionException(cbit.vcell.parser.ExpressionException)

Example 29 with ExpressionException

use of cbit.vcell.parser.ExpressionException in project vcell by virtualcell.

the class RefinementRoi method readVCML.

private void readVCML(CommentStringTokenizer tokens) throws DataAccessException {
    try {
        String token = tokens.nextToken();
        if (token.equalsIgnoreCase(VCML.RefinementRoi)) {
            token = tokens.nextToken();
            if (!token.equalsIgnoreCase(VCML.BeginBlock)) {
                throw new DataAccessException("unexpected token " + token + " expecting " + VCML.BeginBlock);
            }
        }
        while (tokens.hasMoreTokens()) {
            token = tokens.nextToken();
            if (token.equalsIgnoreCase(VCML.EndBlock)) {
                break;
            } else if (token.equalsIgnoreCase(VCML.RefinementRoiType)) {
                token = tokens.nextToken();
                type = RoiType.valueOf(token);
            } else if (token.equalsIgnoreCase(VCML.Level)) {
                token = tokens.nextToken();
                level = Integer.parseInt(token);
            } else if (token.equalsIgnoreCase(VCML.TagsGrow)) {
            // backward compatible
            } else if (token.equalsIgnoreCase(VCML.ROIExpression)) {
                token = tokens.readToSemicolon();
                try {
                    setRoiExpression(token);
                } catch (ExpressionException e) {
                    System.err.println("Invalid " + VCML.ROIExpression + ": " + token);
                }
            } else {
                throw new DataAccessException("unexpected identifier " + token);
            }
        }
    } catch (Throwable e) {
        e.printStackTrace(System.out);
        throw new DataAccessException("line #" + (tokens.lineIndex() + 1) + " Exception: " + e.getMessage());
    }
}
Also used : DataAccessException(org.vcell.util.DataAccessException) ExpressionException(cbit.vcell.parser.ExpressionException)

Example 30 with ExpressionException

use of cbit.vcell.parser.ExpressionException in project vcell by virtualcell.

the class SpeciesContextSpec method convertParticlesToConcentration.

public Expression convertParticlesToConcentration(Expression iniParticles) throws ExpressionException, MappingException {
    Expression iniConcentrationExpr = null;
    Structure structure = getSpeciesContext().getStructure();
    double structSize = computeStructureSize();
    if (structure instanceof Membrane) {
        // iniConcentration(molecules/um2) = particles/size(um2)
        try {
            iniConcentrationExpr = new Expression((iniParticles.evaluateConstant() * 1.0) / structSize);
        } catch (ExpressionException e) {
            iniConcentrationExpr = Expression.div(iniParticles, new Expression(structSize)).flatten();
        }
    } else {
        // convert concentration(particles/volume) to number of particles
        // particles = [iniParticles(uM)/size(um3)]*KMOLE
        // @Note : 'kMole' variable here is used only as a var name, it does not represent the previously known ReservedSymbol KMOLE.
        ModelUnitSystem modelUnitSystem = getSimulationContext().getModel().getUnitSystem();
        VCUnitDefinition stochasticToVolSubstance = modelUnitSystem.getVolumeSubstanceUnit().divideBy(modelUnitSystem.getStochasticSubstanceUnit());
        double stochasticToVolSubstanceScale = stochasticToVolSubstance.getDimensionlessScale().doubleValue();
        try {
            iniConcentrationExpr = new Expression((iniParticles.evaluateConstant() * stochasticToVolSubstanceScale / structSize));
        } catch (ExpressionException e) {
            Expression numeratorExpr = Expression.mult(iniParticles, new Expression(stochasticToVolSubstanceScale));
            Expression denominatorExpr = new Expression(structSize);
            iniConcentrationExpr = Expression.div(numeratorExpr, denominatorExpr).flatten();
        }
    }
    return iniConcentrationExpr;
}
Also used : VCUnitDefinition(cbit.vcell.units.VCUnitDefinition) Expression(cbit.vcell.parser.Expression) Membrane(cbit.vcell.model.Membrane) Structure(cbit.vcell.model.Structure) ExpressionException(cbit.vcell.parser.ExpressionException) ModelUnitSystem(cbit.vcell.model.ModelUnitSystem)

Aggregations

ExpressionException (cbit.vcell.parser.ExpressionException)199 Expression (cbit.vcell.parser.Expression)138 MathException (cbit.vcell.math.MathException)58 PropertyVetoException (java.beans.PropertyVetoException)51 DataAccessException (org.vcell.util.DataAccessException)34 ArrayList (java.util.ArrayList)32 Variable (cbit.vcell.math.Variable)30 IOException (java.io.IOException)29 Element (org.jdom.Element)26 ExpressionBindingException (cbit.vcell.parser.ExpressionBindingException)25 MappingException (cbit.vcell.mapping.MappingException)24 Function (cbit.vcell.math.Function)24 Vector (java.util.Vector)24 ModelException (cbit.vcell.model.ModelException)23 SolverException (cbit.vcell.solver.SolverException)23 CompartmentSubDomain (cbit.vcell.math.CompartmentSubDomain)22 VCUnitDefinition (cbit.vcell.units.VCUnitDefinition)21 Constant (cbit.vcell.math.Constant)20 MathDescription (cbit.vcell.math.MathDescription)19 Structure (cbit.vcell.model.Structure)18