Search in sources :

Example 66 with Expression

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

the class SBPAXParameterExtractor method extractParameter.

public static Map<SBOTerm, ModelParameter> extractParameter(ReactionStep reaction, SBMeasurable measurable) throws PropertyVetoException {
    Map<SBOTerm, ModelParameter> sboToParameters = new HashMap<SBOTerm, ModelParameter>();
    Set<SBOTerm> sboTerms = SBPAXSBOExtractor.extractSBOTerms(measurable);
    String symbol = null;
    VCUnitDefinition targetUnit = null;
    Model model = reaction.getModel();
    ModelUnitSystem modelUnitSystem = model.getUnitSystem();
    Set<SBOTerm> termsWithUnituM = SetUtil.newSet(SBOList.sbo0000027MichaelisConstant, SBOList.sbo0000322MichaelisConstantForSubstrate);
    for (SBOTerm sboTerm : sboTerms) {
        if (termsWithUnituM.contains(sboTerm)) {
            targetUnit = modelUnitSystem.getVolumeConcentrationUnit();
        // targetUnit = VCUnitDefinition.UNIT_uM;
        }
        if (StringUtil.notEmpty(sboTerm.getSymbol())) {
            symbol = sboTerm.getSymbol();
        }
        for (int i = 0; i < symbol.length(); ++i) {
            char charAt = symbol.charAt(i);
            if (!Character.isJavaIdentifierPart(charAt)) {
                symbol = symbol.replace(charAt, '_');
            }
        }
    }
    VCUnitDefinition unit = UOMEUnitExtractor.extractVCUnitDefinition(measurable, modelUnitSystem);
    double conversionFactor = 1.0;
    if (targetUnit != null && unit != null && unit != modelUnitSystem.getInstance_TBD() && !targetUnit.equals(unit)) {
        // if(unit.equals(VCUnitDefinition.UNIT_M) && targetUnit.equals(VCUnitDefinition.UNIT_uM)) {
        if (unit.isCompatible(targetUnit)) {
            conversionFactor = unit.convertTo(conversionFactor, targetUnit);
            unit = targetUnit;
        }
    }
    ArrayList<Double> numbers = measurable.getNumber();
    if (StringUtil.isEmpty(symbol)) {
        symbol = "p" + (++nParameter);
    }
    for (Double number : numbers) {
        String parameterName = symbol + "_" + reaction.getName();
        if (model.getModelParameter(parameterName) != null) {
            int count = 0;
            while (model.getModelParameter(parameterName + "_" + count) != null) {
                ++count;
            }
            parameterName = parameterName + "_" + count;
        }
        ModelParameter parameter = model.new ModelParameter(parameterName, new Expression(conversionFactor * number.doubleValue()), Model.ROLE_UserDefined, unit);
        model.addModelParameter(parameter);
        for (SBOTerm sboTerm : sboTerms) {
            sboToParameters.put(sboTerm, parameter);
        }
    }
    return sboToParameters;
}
Also used : HashMap(java.util.HashMap) SBOTerm(org.vcell.pathway.sbo.SBOTerm) ModelParameter(cbit.vcell.model.Model.ModelParameter) VCUnitDefinition(cbit.vcell.units.VCUnitDefinition) Expression(cbit.vcell.parser.Expression) Model(cbit.vcell.model.Model) ModelUnitSystem(cbit.vcell.model.ModelUnitSystem)

Example 67 with Expression

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

the class RefinementLevel method setRoiExpression.

public void setRoiExpression(String roiExp) throws ExpressionException {
    Expression exp = null;
    if (roiExp != null) {
        roiExp = roiExp.trim();
        if (roiExp.length() > 0) {
            exp = new Expression(roiExp);
            exp.bindExpression(new SimpleSymbolTable(new String[] { "x", "y", "z" }));
        }
    }
    this.roiExpression = exp;
}
Also used : SimpleSymbolTable(cbit.vcell.parser.SimpleSymbolTable) Expression(cbit.vcell.parser.Expression)

Example 68 with Expression

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

the class SimulationContext method createRateRule.

public RateRule createRateRule(SymbolTableEntry varSTE) throws PropertyVetoException {
    String rateRuleName = getFreeRateRuleName();
    RateRule rateRule = new RateRule(rateRuleName, varSTE, new Expression(0.0), this);
    return addRateRule(rateRule);
}
Also used : Expression(cbit.vcell.parser.Expression)

Example 69 with Expression

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

the class SimulationContext method createSimulationContextParameter.

public SimulationContextParameter createSimulationContextParameter() {
    String name = "appParm0";
    while (getSimulationContextParameter(name) != null) {
        name = TokenMangler.getNextEnumeratedToken(name);
    }
    Expression expression = new Expression(1.0);
    int role = SimulationContext.ROLE_UserDefined;
    VCUnitDefinition unit = getModel().getUnitSystem().getInstance_DIMENSIONLESS();
    SimulationContextParameter parameter = new SimulationContextParameter(name, expression, role, unit);
    try {
        addSimulationContextParameter(parameter);
        return parameter;
    } catch (PropertyVetoException e) {
        e.printStackTrace();
        throw new RuntimeException("error creating new application parameter: " + e.getMessage(), e);
    }
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) VCUnitDefinition(cbit.vcell.units.VCUnitDefinition) Expression(cbit.vcell.parser.Expression)

Example 70 with Expression

use of cbit.vcell.parser.Expression 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

Expression (cbit.vcell.parser.Expression)549 ExpressionException (cbit.vcell.parser.ExpressionException)163 VCUnitDefinition (cbit.vcell.units.VCUnitDefinition)76 PropertyVetoException (java.beans.PropertyVetoException)73 Variable (cbit.vcell.math.Variable)69 ArrayList (java.util.ArrayList)58 Vector (java.util.Vector)56 MathException (cbit.vcell.math.MathException)55 VolVariable (cbit.vcell.math.VolVariable)53 SymbolTableEntry (cbit.vcell.parser.SymbolTableEntry)51 SpeciesContext (cbit.vcell.model.SpeciesContext)50 Element (org.jdom.Element)47 KineticsParameter (cbit.vcell.model.Kinetics.KineticsParameter)45 ExpressionBindingException (cbit.vcell.parser.ExpressionBindingException)45 Model (cbit.vcell.model.Model)43 Function (cbit.vcell.math.Function)42 Constant (cbit.vcell.math.Constant)41 ModelParameter (cbit.vcell.model.Model.ModelParameter)41 ModelUnitSystem (cbit.vcell.model.ModelUnitSystem)41 LocalParameter (cbit.vcell.mapping.ParameterContext.LocalParameter)38