Search in sources :

Example 1 with SimContextTransformation

use of cbit.vcell.mapping.SimContextTransformer.SimContextTransformation in project vcell by virtualcell.

the class StochMathMapping method refreshVariables.

/**
 * Map speciesContext to variable, used for structural analysis (slow reactions and fast reactions)
 * Creation date: (10/25/2006 8:59:43 AM)
 * @exception cbit.vcell.mapping.MappingException The exception description.
 */
@Override
protected void refreshVariables() throws MappingException {
    // 
    // stochastic species need  species variables require either a membrane or volume variable
    // 
    Enumeration<SpeciesContextMapping> enum1 = getSpeciesContextMappings();
    while (enum1.hasMoreElements()) {
        SpeciesContextMapping scm = (SpeciesContextMapping) enum1.nextElement();
        SpeciesContextSpec scs = getSimulationContext().getReactionContext().getSpeciesContextSpec(scm.getSpeciesContext());
        // stochastic variable is always a function of size.
        SpeciesCountParameter spCountParm = null;
        try {
            String countName = scs.getSpeciesContext().getName() + BIO_PARAM_SUFFIX_SPECIES_COUNT;
            Expression countExp = new Expression(0.0);
            spCountParm = addSpeciesCountParameter(countName, countExp, PARAMETER_ROLE_SPECIES_COUNT, scs.getInitialCountParameter().getUnitDefinition(), scs.getSpeciesContext());
        } catch (PropertyVetoException pve) {
            pve.printStackTrace();
            throw new MappingException(pve.getMessage());
        }
        // add concentration of species as MathMappingParameter - this will map to species concentration function
        try {
            String concName = scs.getSpeciesContext().getName() + BIO_PARAM_SUFFIX_SPECIES_CONCENTRATION;
            Expression concExp = getExpressionAmtToConc(new Expression(spCountParm, getNameScope()), scs.getSpeciesContext().getStructure());
            concExp.bindExpression(this);
            addSpeciesConcentrationParameter(concName, concExp, PARAMETER_ROLE_SPECIES_CONCENRATION, scs.getSpeciesContext().getUnitDefinition(), scs.getSpeciesContext());
        } catch (Exception e) {
            e.printStackTrace();
            throw new MappingException(e.getMessage(), e);
        }
        // we always add variables, all species are independent variables, no matter they are constant or not.
        String countMathSymbol = getMathSymbol(spCountParm, getSimulationContext().getGeometryContext().getStructureMapping(scs.getSpeciesContext().getStructure()).getGeometryClass());
        scm.setVariable(new StochVolVariable(countMathSymbol));
    }
    // 
    // if the original (untransformed) model has any explicit observables (which are rule-based components), then the transformed model maps these observables to "Concentration" ModelParameters.
    // 
    // for symmetry with the RuleBasedMathMapping, we want to generate a "_Count" version of these observables if applicable.
    // 
    // so if a rule-to-network "transformation" was performed, we want to find those ModelParameters which map to Observables (concentrations) so that we can generate an additional "Count" function (by scaling by compartment size and performing a unit conversion).
    // 
    SimContextTransformation transformation = getTransformation();
    if (transformation != null) {
        ModelEntityMapping[] modelEntityMappings = transformation.modelEntityMappings;
        if (modelEntityMappings != null) {
            for (ModelEntityMapping mem : modelEntityMappings) {
                if (mem.newModelObj instanceof ModelParameter && mem.origModelObj instanceof RbmObservable) {
                    ModelParameter concObservableParameter = (ModelParameter) mem.newModelObj;
                    RbmObservable observable = (RbmObservable) mem.origModelObj;
                    try {
                        Expression countExp = getExpressionConcToExpectedCount(new Expression(concObservableParameter, getNameScope()), observable.getStructure());
                        // countExp.bindExpression(this);
                        addObservableCountParameter(concObservableParameter.getName() + BIO_PARAM_SUFFIX_SPECIES_COUNT, countExp, PARAMETER_ROLE_OBSERVABLE_COUNT, getSimulationContext().getModel().getUnitSystem().getStochasticSubstanceUnit(), observable);
                    } catch (ExpressionException | PropertyVetoException e) {
                        e.printStackTrace();
                        throw new MappingException(e.getMessage(), e);
                    }
                }
            }
        }
    }
}
Also used : ModelEntityMapping(cbit.vcell.mapping.SimContextTransformer.ModelEntityMapping) RbmObservable(cbit.vcell.model.RbmObservable) SimContextTransformation(cbit.vcell.mapping.SimContextTransformer.SimContextTransformation) PropertyVetoException(java.beans.PropertyVetoException) MatrixException(cbit.vcell.matrix.MatrixException) ModelException(cbit.vcell.model.ModelException) ExpressionException(cbit.vcell.parser.ExpressionException) MathException(cbit.vcell.math.MathException) ExpressionException(cbit.vcell.parser.ExpressionException) PropertyVetoException(java.beans.PropertyVetoException) ModelParameter(cbit.vcell.model.Model.ModelParameter) Expression(cbit.vcell.parser.Expression) StochVolVariable(cbit.vcell.math.StochVolVariable)

Aggregations

ModelEntityMapping (cbit.vcell.mapping.SimContextTransformer.ModelEntityMapping)1 SimContextTransformation (cbit.vcell.mapping.SimContextTransformer.SimContextTransformation)1 MathException (cbit.vcell.math.MathException)1 StochVolVariable (cbit.vcell.math.StochVolVariable)1 MatrixException (cbit.vcell.matrix.MatrixException)1 ModelParameter (cbit.vcell.model.Model.ModelParameter)1 ModelException (cbit.vcell.model.ModelException)1 RbmObservable (cbit.vcell.model.RbmObservable)1 Expression (cbit.vcell.parser.Expression)1 ExpressionException (cbit.vcell.parser.ExpressionException)1 PropertyVetoException (java.beans.PropertyVetoException)1