Search in sources :

Example 1 with CentroidComponent

use of cbit.vcell.math.ComputeCentroidComponentEquation.CentroidComponent in project vcell by virtualcell.

the class CompartmentSubDomain method parse.

@Override
protected void parse(MathDescription mathDesc, String token, CommentStringTokenizer tokens) throws MathException, ExpressionException {
    if (token.equalsIgnoreCase(VCML.Handle)) {
        // 
        // throw away "handle information" deprecated
        // 
        token = tokens.nextToken();
        // handle = Integer.valueOf(token).intValue();
        return;
    }
    if (token.equalsIgnoreCase(VCML.Priority)) {
        // legacy support; just ignore this token
        token = tokens.nextToken();
        return;
    }
    if (token.equalsIgnoreCase(VCML.BoundaryXm)) {
        String type = tokens.nextToken();
        boundaryConditionTypeXm = new BoundaryConditionType(type);
        return;
    }
    if (token.equalsIgnoreCase(VCML.BoundaryXp)) {
        String type = tokens.nextToken();
        boundaryConditionTypeXp = new BoundaryConditionType(type);
        return;
    }
    if (token.equalsIgnoreCase(VCML.BoundaryYm)) {
        String type = tokens.nextToken();
        boundaryConditionTypeYm = new BoundaryConditionType(type);
        return;
    }
    if (token.equalsIgnoreCase(VCML.BoundaryYp)) {
        String type = tokens.nextToken();
        boundaryConditionTypeYp = new BoundaryConditionType(type);
        return;
    }
    if (token.equalsIgnoreCase(VCML.BoundaryZm)) {
        String type = tokens.nextToken();
        boundaryConditionTypeZm = new BoundaryConditionType(type);
        return;
    }
    if (token.equalsIgnoreCase(VCML.BoundaryZp)) {
        String type = tokens.nextToken();
        boundaryConditionTypeZp = new BoundaryConditionType(type);
        return;
    }
    if (token.equalsIgnoreCase(VCML.BoundaryConditionSpec)) {
        String name = tokens.nextToken();
        String type = tokens.nextToken();
        BoundaryConditionSpec bcs = new BoundaryConditionSpec(name, new BoundaryConditionType(type));
        addBoundaryConditionSpec(bcs);
        return;
    }
    if (token.equalsIgnoreCase(VCML.PdeEquation)) {
        token = tokens.nextToken();
        boolean bSteady = false;
        if (token.equals(VCML.Steady)) {
            bSteady = true;
            token = tokens.nextToken();
        }
        Variable var = mathDesc.getVariable(token);
        if (var == null) {
            throw new MathFormatException("variable " + token + " not defined");
        }
        if (!(var instanceof VolVariable)) {
            throw new MathFormatException("variable " + token + " not a VolumeVariable");
        }
        PdeEquation pde = new PdeEquation((VolVariable) var, bSteady);
        pde.read(tokens, mathDesc);
        addEquation(pde);
        return;
    }
    if (token.equalsIgnoreCase(VCML.OdeEquation)) {
        token = tokens.nextToken();
        Variable var = mathDesc.getVariable(token);
        if (var == null) {
            throw new MathFormatException("variable " + token + " not defined");
        }
        if (!(var instanceof VolVariable)) {
            throw new MathFormatException("variable " + token + " not a VolumeVariable");
        }
        OdeEquation ode = new OdeEquation((VolVariable) var, null, null);
        ode.read(tokens, mathDesc);
        addEquation(ode);
        return;
    }
    if (token.equalsIgnoreCase(VCML.VolumeRegionEquation)) {
        token = tokens.nextToken();
        Variable var = mathDesc.getVariable(token);
        if (var == null) {
            throw new MathFormatException("variable " + token + " not defined");
        }
        if (!(var instanceof VolumeRegionVariable)) {
            throw new MathFormatException("variable " + token + " not a VolumeRegionVariable");
        }
        VolumeRegionEquation vre = new VolumeRegionEquation((VolumeRegionVariable) var, null);
        vre.read(tokens, mathDesc);
        addEquation(vre);
        return;
    }
    if (token.equalsIgnoreCase(VCML.ComputeCentroidX) || token.equalsIgnoreCase(VCML.ComputeCentroidY) || token.equalsIgnoreCase(VCML.ComputeCentroidZ)) {
        CentroidComponent component = null;
        if (token.equalsIgnoreCase(VCML.ComputeCentroidX)) {
            component = CentroidComponent.X;
        } else if (token.equalsIgnoreCase(VCML.ComputeCentroidY)) {
            component = CentroidComponent.Y;
        } else if (token.equalsIgnoreCase(VCML.ComputeCentroidZ)) {
            component = CentroidComponent.Z;
        }
        token = tokens.nextToken();
        Variable var = mathDesc.getVariable(token);
        if (var == null) {
            throw new MathFormatException("variable " + token + " not defined");
        }
        if (!(var instanceof VolumeRegionVariable)) {
            throw new MathFormatException("variable " + token + " not a VolumeRegionVariable");
        }
        ComputeCentroidComponentEquation computeCentroidEq = new ComputeCentroidComponentEquation((VolumeRegionVariable) var, component);
        computeCentroidEq.read(tokens, mathDesc);
        addEquation(computeCentroidEq);
        return;
    }
    if (token.equalsIgnoreCase(VCML.ComputeDistanceToMembrane) || token.equalsIgnoreCase(VCML.ComputeDirectionToMembraneX) || token.equalsIgnoreCase(VCML.ComputeDirectionToMembraneY) || token.equalsIgnoreCase(VCML.ComputeDirectionToMembraneZ)) {
        MembraneMetricComponent component = null;
        if (token.equalsIgnoreCase(VCML.ComputeDistanceToMembrane)) {
            component = MembraneMetricComponent.distanceToMembrane;
        } else if (token.equalsIgnoreCase(VCML.ComputeDirectionToMembraneX)) {
            component = MembraneMetricComponent.directionToMembraneX;
        } else if (token.equalsIgnoreCase(VCML.ComputeDirectionToMembraneY)) {
            component = MembraneMetricComponent.directionToMembraneY;
        } else if (token.equalsIgnoreCase(VCML.ComputeDirectionToMembraneZ)) {
            component = MembraneMetricComponent.directionToMembraneZ;
        }
        token = tokens.nextToken();
        Variable var = mathDesc.getVariable(token);
        if (var == null) {
            throw new MathFormatException("variable " + token + " not defined");
        }
        if (!(var instanceof VolVariable)) {
            throw new MathFormatException("variable " + token + " not a VolumeVariable");
        }
        ComputeMembraneMetricEquation computeMembraneMetricEq = new ComputeMembraneMetricEquation((VolVariable) var, component);
        computeMembraneMetricEq.read(tokens, mathDesc);
        addEquation(computeMembraneMetricEq);
        return;
    }
    /**
     * ParticleJumpProcess name A B {
     *    MacroscopicRateConstant dkdkdk;
     *    Action destroy A
     *    Action destroy B
     *    Action create C
     * }
     */
    if (token.equalsIgnoreCase(VCML.ParticleJumpProcess)) {
        ParticleJumpProcess particleJumpProcess = ParticleJumpProcess.fromVCML(mathDesc, tokens);
        addParticleJumpProcess(particleJumpProcess);
        return;
    }
    if (token.equalsIgnoreCase(VCML.ParticleProperties)) {
        ParticleProperties pp = new ParticleProperties(mathDesc, tokens);
        if (pp.getVariable().getDomain().getName().equals(this.getName())) {
            addParticleProperties(pp);
        } else {
            throw new MathException("Variable (" + pp.getVariable().getName() + ") is defined in domain " + pp.getVariable().getDomain().getName() + ". \nHowever the variable particle properties of " + pp.getVariable().getName() + " is defined in domain " + this.getName() + ". \nPlease check your model.");
        }
        return;
    }
    if (token.equalsIgnoreCase(VCML.FastSystem)) {
        FastSystem fs = new FastSystem(mathDesc);
        fs.read(tokens, mathDesc);
        setFastSystem(fs);
        return;
    }
    // Variable initial conditions as count
    if (token.equalsIgnoreCase(VCML.VarIniCount_Old) || token.equalsIgnoreCase(VCML.VarIniCount)) {
        token = tokens.nextToken();
        Variable var = mathDesc.getVariable(token);
        if (var == null) {
            throw new MathFormatException("variable " + token + " not defined");
        }
        if (!(var instanceof StochVolVariable)) {
            throw new MathFormatException("variable " + token + " not a Stochastic Volume Variable");
        }
        Expression varIniExp = parseAndBind(mathDesc, tokens);
        VarIniCount vic = new VarIniCount(var, varIniExp);
        addVarIniCondition(vic);
        return;
    }
    // Variable inital conditions as concentration
    if (token.equalsIgnoreCase(VCML.VarIniPoissonExpectedCount)) {
        token = tokens.nextToken();
        Variable var = mathDesc.getVariable(token);
        if (var == null) {
            throw new MathFormatException("variable " + token + " not defined");
        }
        if (!(var instanceof StochVolVariable)) {
            throw new MathFormatException("variable " + token + " not a Stochastic Volume Variable");
        }
        Expression varIniExp = parseAndBind(mathDesc, tokens);
        VarIniPoissonExpectedCount vic = new VarIniPoissonExpectedCount(var, varIniExp);
        addVarIniCondition(vic);
        return;
    }
    // Jump processes
    if (token.equalsIgnoreCase(VCML.JumpProcess)) {
        JumpProcess jump = null;
        token = tokens.nextToken();
        String name = token;
        token = tokens.nextToken();
        if (!token.equalsIgnoreCase(VCML.BeginBlock))
            throw new MathFormatException("unexpected token " + token + " expecting " + VCML.BeginBlock);
        token = tokens.nextToken();
        if (token.equalsIgnoreCase(VCML.ProbabilityRate)) {
            Expression probExp = MathFunctionDefinitions.fixFunctionSyntax(tokens);
            // check if probability functions contain "t", which is not allowed.
            Expression extProb = MathUtilities.substituteFunctions(probExp, mathDesc).flatten();
            String[] symbols = extProb.getSymbols();
            if (symbols != null) {
                for (int i = 0; i < symbols.length; i++) {
                    if (symbols[i].equals("t")) {
                        throw new MathFormatException("Unexpected symbol \'t\'  in probability rate of jump process " + name + ". Probability rate should not be a function of t.");
                    }
                }
            }
            probExp.bindExpression(mathDesc);
            jump = new JumpProcess(name, probExp);
            addJumpProcess(jump);
        } else {
            throw new MathFormatException("unexpected identifier " + token);
        }
        if (jump != null) {
            while (tokens.hasMoreTokens()) {
                token = tokens.nextToken();
                if (token.equalsIgnoreCase(VCML.EndBlock)) {
                    break;
                }
                if (token.equalsIgnoreCase(VCML.Action)) {
                    token = tokens.nextToken();
                    Variable var = mathDesc.getVariable(token);
                    if (var == null) {
                        throw new MathFormatException("variable " + token + " not defined");
                    }
                    if (!(var instanceof StochVolVariable)) {
                        throw new MathFormatException("variable " + token + " not a Stochastic Volume Variable");
                    }
                    String opera = tokens.nextToken();
                    if (!opera.equals(Action.ACTION_INC)) {
                        throw new MathFormatException("expected 'INC' for action, found " + opera);
                    }
                    Expression exp = parseAndBind(mathDesc, tokens);
                    Action action = Action.createIncrementAction(var, exp);
                    jump.addAction(action);
                } else
                    throw new MathFormatException("unexpected identifier " + token);
            }
        }
        return;
    }
    throw new MathFormatException("unexpected identifier " + token);
}
Also used : CentroidComponent(cbit.vcell.math.ComputeCentroidComponentEquation.CentroidComponent) MembraneMetricComponent(cbit.vcell.math.ComputeMembraneMetricEquation.MembraneMetricComponent) Expression(cbit.vcell.parser.Expression)

Example 2 with CentroidComponent

use of cbit.vcell.math.ComputeCentroidComponentEquation.CentroidComponent in project vcell by virtualcell.

the class XmlReader method getComputeCentroid.

private ComputeCentroidComponentEquation getComputeCentroid(Element param, MathDescription mathDesc) throws XmlParseException {
    // get attributes
    String varname = unMangle(param.getAttributeValue(XMLTags.NameAttrTag));
    // find reference in the dictionnary
    // try a MembraneRegionVariable
    VolumeRegionVariable varref = (VolumeRegionVariable) mathDesc.getVariable(varname);
    if (varref == null) {
        throw new XmlParseException("The reference to the Volume Region variable " + varname + " could not be resolved!");
    }
    CentroidComponent normalComponent = null;
    String normalComponentString = param.getAttributeValue(XMLTags.ComputeCentroidComponentAttrTag);
    if (normalComponentString.equals(XMLTags.ComputeCentroidComponentAttrTagValue_X)) {
        normalComponent = CentroidComponent.X;
    } else if (normalComponentString.equals(XMLTags.ComputeCentroidComponentAttrTagValue_Y)) {
        normalComponent = CentroidComponent.Y;
    } else if (normalComponentString.equals(XMLTags.ComputeCentroidComponentAttrTagValue_Z)) {
        normalComponent = CentroidComponent.Z;
    }
    ComputeCentroidComponentEquation centroid = new ComputeCentroidComponentEquation(varref, normalComponent);
    return centroid;
}
Also used : VolumeRegionVariable(cbit.vcell.math.VolumeRegionVariable) ComputeCentroidComponentEquation(cbit.vcell.math.ComputeCentroidComponentEquation) CentroidComponent(cbit.vcell.math.ComputeCentroidComponentEquation.CentroidComponent)

Aggregations

CentroidComponent (cbit.vcell.math.ComputeCentroidComponentEquation.CentroidComponent)2 ComputeCentroidComponentEquation (cbit.vcell.math.ComputeCentroidComponentEquation)1 MembraneMetricComponent (cbit.vcell.math.ComputeMembraneMetricEquation.MembraneMetricComponent)1 VolumeRegionVariable (cbit.vcell.math.VolumeRegionVariable)1 Expression (cbit.vcell.parser.Expression)1