Search in sources :

Example 11 with SpeciesContextSpec

use of cbit.vcell.mapping.SpeciesContextSpec in project vcell by virtualcell.

the class StochMathMapping_4_8 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.
 */
private void refreshVariables() throws MappingException {
    // 
    // non-constant dependant variables(means rely on other contants/functions) require a function
    // 
    Enumeration<SpeciesContextMapping> enum1 = getSpeciesContextMappings();
    while (enum1.hasMoreElements()) {
        SpeciesContextMapping scm = enum1.nextElement();
        SpeciesContextSpec scs = getSimulationContext().getReactionContext().getSpeciesContextSpec(scm.getSpeciesContext());
        if (scm.getDependencyExpression() != null && !scs.isConstant()) {
            // scm.setVariable(new Function(scm.getSpeciesContext().getName(),scm.getDependencyExpression()));
            scm.setVariable(null);
        }
    }
    // 
    // non-constant independant variables require either a membrane or volume variable
    // 
    enum1 = getSpeciesContextMappings();
    // stochastic substance unit from modelUnitSystem
    ModelUnitSystem modelUnitSystem = getSimulationContext().getModel().getUnitSystem();
    VCUnitDefinition stochSubstanceUnit = modelUnitSystem.getStochasticSubstanceUnit();
    while (enum1.hasMoreElements()) {
        SpeciesContextMapping scm = (SpeciesContextMapping) enum1.nextElement();
        SpeciesContextSpec scs = getSimulationContext().getReactionContext().getSpeciesContextSpec(scm.getSpeciesContext());
        // stochastic variable is always a function of size.
        MathMapping_4_8.SpeciesCountParameter spCountParm = null;
        try {
            String countName = scs.getSpeciesContext().getName() + BIO_PARAM_SUFFIX_SPECIES_COUNT;
            Expression countExp = new Expression(0.0);
            spCountParm = addSpeciesCountParameter(countName, countExp, MathMapping_4_8.PARAMETER_ROLE_COUNT, stochSubstanceUnit, scs);
        } 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.getName()), scs.getSpeciesContext());
            concExp.bindExpression(this);
            addSpeciesConcentrationParameter(concName, concExp, MathMapping_4_8.PARAMETER_ROLE_CONCENRATION, scs.getSpeciesContext().getUnitDefinition(), scs);
        } catch (Exception e) {
            e.printStackTrace();
            throw new MappingException(e.getMessage());
        }
        if (scm.getDependencyExpression() == null && !scs.isConstant()) {
            scm.setVariable(new StochVolVariable(getMathSymbol(spCountParm, getSimulationContext().getGeometryContext().getStructureMapping(scs.getSpeciesContext().getStructure()))));
            mathSymbolMapping.put(scm.getSpeciesContext(), scm.getVariable().getName());
        }
    }
}
Also used : SpeciesContextMapping(cbit.vcell.mapping.SpeciesContextMapping) SpeciesContextSpec(cbit.vcell.mapping.SpeciesContextSpec) PropertyVetoException(java.beans.PropertyVetoException) MatrixException(cbit.vcell.matrix.MatrixException) ModelException(cbit.vcell.model.ModelException) ExpressionException(cbit.vcell.parser.ExpressionException) MappingException(cbit.vcell.mapping.MappingException) MathException(cbit.vcell.math.MathException) MappingException(cbit.vcell.mapping.MappingException) PropertyVetoException(java.beans.PropertyVetoException) VCUnitDefinition(cbit.vcell.units.VCUnitDefinition) Expression(cbit.vcell.parser.Expression) StochVolVariable(cbit.vcell.math.StochVolVariable) ModelUnitSystem(cbit.vcell.model.ModelUnitSystem)

Example 12 with SpeciesContextSpec

use of cbit.vcell.mapping.SpeciesContextSpec in project vcell by virtualcell.

the class IssueTableModel method getSourceObjectPathDescription.

private String getSourceObjectPathDescription(VCDocument vcDocument, Issue issue) {
    VCAssert.assertValid(issue);
    Object source = issue.getSource();
    {
        IssueOrigin io = BeanUtils.downcast(IssueOrigin.class, source);
        if (io != null) {
            return io.getDescription();
        }
    }
    if (vcDocument instanceof BioModel) {
        BioModel bioModel = (BioModel) vcDocument;
        String description = "";
        if (source instanceof SymbolTableEntry) {
            if (source instanceof SpeciesContext) {
                description = "Model / Species";
            } else if (source instanceof RbmObservable) {
                description = "Model / Observables";
            } else {
                description = ((SymbolTableEntry) source).getNameScope().getPathDescription();
            }
        } else if (source instanceof MolecularType) {
            description = "Model / Molecules";
        } else if (source instanceof ReactionStep) {
            ReactionStep reactionStep = (ReactionStep) source;
            description = ((ReactionNameScope) reactionStep.getNameScope()).getPathDescription();
        } else if (source instanceof ReactionRule) {
            ReactionRule reactionRule = (ReactionRule) source;
            description = ((ReactionRuleNameScope) reactionRule.getNameScope()).getPathDescription();
        } else if (source instanceof SpeciesPattern) {
            // if (issue.getIssueContext().hasContextType(ContextType.SpeciesContext)){
            // description = "Model / Species";
            // }else if(issue.getIssueContext().hasContextType(ContextType.ReactionRule)) {
            // ReactionRule thing = (ReactionRule)issue.getIssueContext().getContextObject(ContextType.ReactionRule);
            // description = ((ReactionRuleNameScope)thing.getNameScope()).getPathDescription();
            // }else if(issue.getIssueContext().hasContextType(ContextType.RbmObservable)) {
            // description = "Model / Observables";
            // } else {
            System.err.println("Bad issue context for " + ((SpeciesPattern) source).toString());
            description = ((SpeciesPattern) source).toString();
        // }
        } else if (source instanceof Structure) {
            Structure structure = (Structure) source;
            description = "Model / " + structure.getTypeName() + "(" + structure.getName() + ")";
        } else if (source instanceof StructureMapping) {
            StructureMapping structureMapping = (StructureMapping) source;
            description = ((StructureMappingNameScope) structureMapping.getNameScope()).getPathDescription();
        } else if (source instanceof OutputFunctionIssueSource) {
            SimulationContext simulationContext = (SimulationContext) ((OutputFunctionIssueSource) source).getOutputFunctionContext().getSimulationOwner();
            description = "App(" + simulationContext.getName() + ") / " + "Simulations" + " / " + "Output Functions";
        } else if (source instanceof Simulation) {
            Simulation simulation = (Simulation) source;
            try {
                SimulationContext simulationContext = bioModel.getSimulationContext(simulation);
                description = "App(" + simulationContext.getName() + ") / Simulations";
            } catch (ObjectNotFoundException e) {
                e.printStackTrace();
                description = "App(" + "unknown" + ") / Simulations";
            }
        } else if (source instanceof UnmappedGeometryClass) {
            UnmappedGeometryClass unmappedGC = (UnmappedGeometryClass) source;
            description = "App(" + unmappedGC.getSimulationContext().getName() + ") / Subdomain(" + unmappedGC.getGeometryClass().getName() + ")";
        } else if (source instanceof GeometryContext) {
            description = "App(" + ((GeometryContext) source).getSimulationContext().getName() + ")";
        } else if (source instanceof ModelOptimizationSpec) {
            description = "App(" + ((ModelOptimizationSpec) source).getSimulationContext().getName() + ") / Parameter Estimation";
        } else if (source instanceof MicroscopeMeasurement) {
            description = "App(" + ((MicroscopeMeasurement) source).getSimulationContext().getName() + ") / Microscope Measurements";
        } else if (source instanceof SpatialObject) {
            description = "App(" + ((SpatialObject) source).getSimulationContext().getName() + ") / Spatial Objects";
        } else if (source instanceof SpatialProcess) {
            description = "App(" + ((SpatialProcess) source).getSimulationContext().getName() + ") / Spatial Processes";
        } else if (source instanceof SpeciesContextSpec) {
            SpeciesContextSpec scs = (SpeciesContextSpec) source;
            description = "App(" + scs.getSimulationContext().getName() + ") / Specifications / Species";
        } else if (source instanceof ReactionCombo) {
            ReactionCombo rc = (ReactionCombo) source;
            description = "App(" + rc.getReactionContext().getSimulationContext().getName() + ") / Specifications / Reactions";
        } else if (source instanceof RbmModelContainer) {
            IssueCategory ic = issue.getCategory();
            switch(ic) {
                case RbmMolecularTypesTableBad:
                    description = "Model / " + MolecularType.typeName + "s";
                    break;
                case RbmReactionRulesTableBad:
                    description = "Model / Reactions";
                    break;
                case RbmObservablesTableBad:
                    description = "Model / Observables";
                    break;
                case RbmNetworkConstraintsBad:
                    description = "Network Constrains";
                    break;
                default:
                    description = "Model";
                    break;
            }
        } else if (source instanceof SimulationContext) {
            SimulationContext sc = (SimulationContext) source;
            IssueCategory ic = issue.getCategory();
            switch(ic) {
                case RbmNetworkConstraintsBad:
                    description = "Specifications / Network";
                    break;
                default:
                    description = "Application";
                    break;
            }
        } else if (source instanceof Model) {
            description = "Model";
        } else if (source instanceof BioEvent) {
            return "Protocols / Events";
        } else if (source instanceof MathDescription) {
            return "Math Description";
        } else {
            System.err.println("unknown source type in IssueTableModel.getSourceObjectPathDescription(): " + source.getClass());
        }
        return description;
    } else if (vcDocument instanceof MathModel) {
        if (source instanceof Geometry) {
            return GuiConstants.DOCUMENT_EDITOR_FOLDERNAME_MATH_GEOMETRY;
        } else if (source instanceof OutputFunctionIssueSource) {
            return GuiConstants.DOCUMENT_EDITOR_FOLDERNAME_MATH_OUTPUTFUNCTIONS;
        } else if (source instanceof Simulation) {
            return "Simulation(" + ((Simulation) source).getName() + ")";
        } else {
            return GuiConstants.DOCUMENT_EDITOR_FOLDERNAME_MATH_VCML;
        }
    } else {
        System.err.println("unknown document type in IssueTableModel.getSourceObjectPathDescription()");
        return "";
    }
}
Also used : MathModel(cbit.vcell.mathmodel.MathModel) IssueCategory(org.vcell.util.Issue.IssueCategory) MathDescription(cbit.vcell.math.MathDescription) IssueOrigin(org.vcell.util.Issue.IssueOrigin) SpeciesContext(cbit.vcell.model.SpeciesContext) SpeciesContextSpec(cbit.vcell.mapping.SpeciesContextSpec) StructureMapping(cbit.vcell.mapping.StructureMapping) SpeciesPattern(org.vcell.model.rbm.SpeciesPattern) SpatialObject(cbit.vcell.mapping.spatial.SpatialObject) SymbolTableEntry(cbit.vcell.parser.SymbolTableEntry) OutputFunctionIssueSource(cbit.vcell.solver.OutputFunctionContext.OutputFunctionIssueSource) RbmModelContainer(cbit.vcell.model.Model.RbmModelContainer) ModelOptimizationSpec(cbit.vcell.modelopt.ModelOptimizationSpec) SpatialProcess(cbit.vcell.mapping.spatial.processes.SpatialProcess) UnmappedGeometryClass(cbit.vcell.mapping.GeometryContext.UnmappedGeometryClass) MicroscopeMeasurement(cbit.vcell.mapping.MicroscopeMeasurement) GeometryContext(cbit.vcell.mapping.GeometryContext) ReactionRuleNameScope(cbit.vcell.model.ReactionRule.ReactionRuleNameScope) Structure(cbit.vcell.model.Structure) ReactionCombo(cbit.vcell.mapping.ReactionSpec.ReactionCombo) ReactionRule(cbit.vcell.model.ReactionRule) RbmObservable(cbit.vcell.model.RbmObservable) SimulationContext(cbit.vcell.mapping.SimulationContext) MolecularType(org.vcell.model.rbm.MolecularType) Geometry(cbit.vcell.geometry.Geometry) Simulation(cbit.vcell.solver.Simulation) BioModel(cbit.vcell.biomodel.BioModel) ReactionStep(cbit.vcell.model.ReactionStep) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) MathModel(cbit.vcell.mathmodel.MathModel) Model(cbit.vcell.model.Model) BioModel(cbit.vcell.biomodel.BioModel) SpatialObject(cbit.vcell.mapping.spatial.SpatialObject) BioEvent(cbit.vcell.mapping.BioEvent)

Example 13 with SpeciesContextSpec

use of cbit.vcell.mapping.SpeciesContextSpec in project vcell by virtualcell.

the class IssueTableModel method getSourceObjectDescription.

private String getSourceObjectDescription(VCDocument vcDocument, Issue issue) {
    if (vcDocument instanceof BioModel) {
        Object object = issue.getSource();
        {
            DecoratedIssueSource dis = BeanUtils.downcast(DecoratedIssueSource.class, object);
            if (dis != null) {
                return dis.getSourcePath();
            }
        }
        String description = "";
        if (object instanceof SymbolTableEntry) {
            description = ((SymbolTableEntry) object).getName();
        } else if (object instanceof ReactionStep) {
            description = ((ReactionStep) object).getName();
        } else if (object instanceof ReactionRule) {
            description = ((ReactionRule) object).getName();
        } else if (object instanceof SpeciesPattern) {
            // Object parent = issue.getIssueContext().getContextObject();
            // if (parent instanceof SpeciesContext){
            // description = ((SpeciesContext)parent).getName();
            // }
            // if (issue.getIssueContext().hasContextType(ContextType.SpeciesContext)){
            // SpeciesContext thing = (SpeciesContext)issue.getIssueContext().getContextObject(ContextType.SpeciesContext);
            // description = thing.getName();
            // }else if(issue.getIssueContext().hasContextType(ContextType.ReactionRule)) {
            // ReactionRule thing = (ReactionRule)issue.getIssueContext().getContextObject(ContextType.ReactionRule);
            // description = thing.getName();
            // }else if(issue.getIssueContext().hasContextType(ContextType.RbmObservable)) {
            // RbmObservable thing = (RbmObservable)issue.getIssueContext().getContextObject(ContextType.RbmObservable);
            // description = thing.getName();
            // } else {
            System.err.println("Bad issue context for " + ((SpeciesPattern) object).toString());
            description = ((SpeciesPattern) object).toString();
        // }
        } else if (object instanceof MolecularType) {
            description = ((MolecularType) object).getName();
        } else if (object instanceof MolecularComponent) {
            description = ((MolecularComponent) object).getName();
        } else if (object instanceof ComponentStateDefinition) {
            description = ((ComponentStateDefinition) object).getName();
        } else if (object instanceof Structure) {
            description = ((Structure) object).getName();
        } else if (object instanceof SubDomain) {
            description = ((SubDomain) object).getName();
        } else if (object instanceof Geometry) {
            description = ((Geometry) object).getName();
        } else if (object instanceof StructureMapping) {
            description = ((StructureMapping) object).getStructure().getName();
        } else if (object instanceof OutputFunctionIssueSource) {
            description = ((OutputFunctionIssueSource) object).getAnnotatedFunction().getName();
        } else if (object instanceof UnmappedGeometryClass) {
            description = ((UnmappedGeometryClass) object).getGeometryClass().getName();
        } else if (object instanceof MicroscopeMeasurement) {
            description = ((MicroscopeMeasurement) object).getName();
        } else if (object instanceof SpatialObject) {
            description = ((SpatialObject) object).getName();
        } else if (object instanceof SpatialProcess) {
            description = ((SpatialProcess) object).getName();
        } else if (object instanceof GeometryContext) {
            description = "Geometry";
        } else if (object instanceof ModelOptimizationSpec) {
            description = ((ModelOptimizationSpec) object).getParameterEstimationTask().getName();
        } else if (object instanceof Simulation) {
            description = ((Simulation) object).getName();
        } else if (object instanceof SpeciesContextSpec) {
            SpeciesContextSpec scs = (SpeciesContextSpec) object;
            description = scs.getSpeciesContext().getName();
        } else if (object instanceof ReactionCombo) {
            ReactionSpec rs = ((ReactionCombo) object).getReactionSpec();
            description = rs.getReactionStep().getName();
        } else if (object instanceof RbmModelContainer) {
            // RbmModelContainer mc = (RbmModelContainer)object;
            description = "Rules validator";
        } else if (object instanceof SimulationContext) {
            SimulationContext sc = (SimulationContext) object;
            description = sc.getName();
        } else if (object instanceof Model) {
            Model m = (Model) object;
            description = m.getName();
        } else if (object instanceof BioEvent) {
            return ((BioEvent) object).getName() + "";
        } else if (object instanceof MathDescription) {
            return ((MathDescription) object).getName() + "";
        } else {
            System.err.println("unknown object type in IssueTableModel.getSourceObjectDescription(): " + object.getClass());
        }
        return description;
    } else if (vcDocument instanceof MathModel) {
        Object object = issue.getSource();
        String description = "";
        if (object instanceof Variable) {
            description = ((Variable) object).getName();
        } else if (object instanceof SubDomain) {
            description = ((SubDomain) object).getName();
        } else if (object instanceof Geometry) {
            description = "Geometry";
        } else if (object instanceof OutputFunctionIssueSource) {
            description = ((OutputFunctionIssueSource) object).getAnnotatedFunction().getName();
        } else if (object instanceof MathDescription) {
            return "math";
        } else if (object instanceof Simulation) {
            return "Simulation " + ((Simulation) object).getName() + "";
        }
        return description;
    } else {
        System.err.println("unknown document type in IssueTableModel.getSourceObjectDescription()");
        return "";
    }
}
Also used : MathModel(cbit.vcell.mathmodel.MathModel) Variable(cbit.vcell.math.Variable) MathDescription(cbit.vcell.math.MathDescription) SpeciesContextSpec(cbit.vcell.mapping.SpeciesContextSpec) StructureMapping(cbit.vcell.mapping.StructureMapping) SpeciesPattern(org.vcell.model.rbm.SpeciesPattern) ComponentStateDefinition(org.vcell.model.rbm.ComponentStateDefinition) SpatialObject(cbit.vcell.mapping.spatial.SpatialObject) SubDomain(cbit.vcell.math.SubDomain) SymbolTableEntry(cbit.vcell.parser.SymbolTableEntry) OutputFunctionIssueSource(cbit.vcell.solver.OutputFunctionContext.OutputFunctionIssueSource) MolecularComponent(org.vcell.model.rbm.MolecularComponent) RbmModelContainer(cbit.vcell.model.Model.RbmModelContainer) SpatialProcess(cbit.vcell.mapping.spatial.processes.SpatialProcess) ModelOptimizationSpec(cbit.vcell.modelopt.ModelOptimizationSpec) UnmappedGeometryClass(cbit.vcell.mapping.GeometryContext.UnmappedGeometryClass) MicroscopeMeasurement(cbit.vcell.mapping.MicroscopeMeasurement) GeometryContext(cbit.vcell.mapping.GeometryContext) Structure(cbit.vcell.model.Structure) ReactionCombo(cbit.vcell.mapping.ReactionSpec.ReactionCombo) ReactionRule(cbit.vcell.model.ReactionRule) DecoratedIssueSource(cbit.vcell.client.desktop.DecoratedIssueSource) ReactionSpec(cbit.vcell.mapping.ReactionSpec) SimulationContext(cbit.vcell.mapping.SimulationContext) MolecularType(org.vcell.model.rbm.MolecularType) Geometry(cbit.vcell.geometry.Geometry) Simulation(cbit.vcell.solver.Simulation) BioModel(cbit.vcell.biomodel.BioModel) ReactionStep(cbit.vcell.model.ReactionStep) MathModel(cbit.vcell.mathmodel.MathModel) Model(cbit.vcell.model.Model) BioModel(cbit.vcell.biomodel.BioModel) SpatialObject(cbit.vcell.mapping.spatial.SpatialObject) BioEvent(cbit.vcell.mapping.BioEvent)

Example 14 with SpeciesContextSpec

use of cbit.vcell.mapping.SpeciesContextSpec in project vcell by virtualcell.

the class ITextWriter method writeReactionContext.

// ReactionContext - SpeciesContextSpec: ignored boundary conditions.
protected void writeReactionContext(Section simContextSection, SimulationContext simContext) throws DocumentException {
    ReactionContext rc = simContext.getReactionContext();
    if (rc == null) {
        return;
    }
    Section rcSection = null;
    // add reaction specs
    ReactionSpec[] reactionSpecs = rc.getReactionSpecs();
    Table reactionSpecTable = null;
    for (int i = 0; i < reactionSpecs.length; i++) {
        if (i == 0) {
            reactionSpecTable = getTable(4, 100, 1, 3, 3);
            // reactionSpecTable.setTableFitsPage(true);
            reactionSpecTable.addCell(createCell("Reaction Mapping", getBold(DEF_HEADER_FONT_SIZE), 4, 1, Element.ALIGN_CENTER, true));
            reactionSpecTable.addCell(createHeaderCell("Name", getBold(), 1));
            reactionSpecTable.addCell(createHeaderCell("Type", getBold(), 1));
            reactionSpecTable.addCell(createHeaderCell("Enabled (T/F)", getBold(), 1));
            reactionSpecTable.addCell(createHeaderCell("Fast (T/F)", getBold(), 1));
            reactionSpecTable.endHeaders();
        }
        String reactionName = reactionSpecs[i].getReactionStep().getName();
        String reactionType = reactionSpecs[i].getReactionStep().getDisplayType();
        reactionSpecTable.addCell(createCell(reactionName, getFont()));
        reactionSpecTable.addCell(createCell(reactionType, getFont()));
        reactionSpecTable.addCell(createCell((reactionSpecs[i].isExcluded() ? " F " : " T "), getFont()));
        reactionSpecTable.addCell(createCell((reactionSpecs[i].isFast() ? " T " : " F "), getFont()));
    }
    if (reactionSpecTable != null) {
        rcSection = simContextSection.addSection("Reaction Mapping For " + simContext.getName(), simContextSection.numberDepth() + 1);
        rcSection.add(reactionSpecTable);
    }
    // add species context specs
    SpeciesContextSpec[] speciesContSpecs = rc.getSpeciesContextSpecs();
    Table speciesSpecTable = null;
    int[] widths = { 2, 2, 4, 4, 1 };
    for (int i = 0; i < speciesContSpecs.length; i++) {
        if (i == 0) {
            speciesSpecTable = getTable(5, 100, 1, 3, 3);
            speciesSpecTable.addCell(createCell("Initial Conditions", getBold(DEF_HEADER_FONT_SIZE), 5, 1, Element.ALIGN_CENTER, true));
            speciesSpecTable.addCell(createHeaderCell("Species", getBold(), 1));
            speciesSpecTable.addCell(createHeaderCell("Structure", getBold(), 1));
            speciesSpecTable.addCell(createHeaderCell("Initial Conc.", getBold(), 1));
            speciesSpecTable.addCell(createHeaderCell("Diffusion Const.", getBold(), 1));
            speciesSpecTable.addCell(createHeaderCell("Fixed (T/F)", getBold(), 1));
            speciesSpecTable.endHeaders();
        }
        String speciesName = speciesContSpecs[i].getSpeciesContext().getSpecies().getCommonName();
        String structName = speciesContSpecs[i].getSpeciesContext().getStructure().getName();
        String diff = speciesContSpecs[i].getDiffusionParameter().getExpression().infix();
        VCUnitDefinition diffUnit = speciesContSpecs[i].getDiffusionParameter().getUnitDefinition();
        SpeciesContextSpecParameter initParam = speciesContSpecs[i].getInitialConditionParameter();
        String initConc = initParam == null ? "" : initParam.getExpression().infix();
        VCUnitDefinition initConcUnit = initParam == null ? null : initParam.getUnitDefinition();
        speciesSpecTable.addCell(createCell(speciesName, getFont()));
        speciesSpecTable.addCell(createCell(structName, getFont()));
        speciesSpecTable.addCell(createCell(initConc + (initConcUnit == null ? "" : "   " + initConcUnit.getSymbolUnicode()), getFont()));
        speciesSpecTable.addCell(createCell(diff + (diffUnit == null ? "" : "   " + diffUnit.getSymbolUnicode()), getFont()));
        speciesSpecTable.addCell(createCell((speciesContSpecs[i].isConstant() ? " T " : " F "), getFont()));
    }
    if (speciesSpecTable != null) {
        if (rcSection == null) {
            rcSection = simContextSection.addSection("Reaction Mapping For " + simContext.getName(), simContextSection.numberDepth() + 1);
        }
        speciesSpecTable.setWidths(widths);
        rcSection.add(speciesSpecTable);
    }
}
Also used : VCUnitDefinition(cbit.vcell.units.VCUnitDefinition) Table(com.lowagie.text.Table) ReactionSpec(cbit.vcell.mapping.ReactionSpec) ReactionContext(cbit.vcell.mapping.ReactionContext) SpeciesContextSpec(cbit.vcell.mapping.SpeciesContextSpec) Section(com.lowagie.text.Section) SpeciesContextSpecParameter(cbit.vcell.mapping.SpeciesContextSpec.SpeciesContextSpecParameter)

Example 15 with SpeciesContextSpec

use of cbit.vcell.mapping.SpeciesContextSpec in project vcell by virtualcell.

the class ModelOptimizationSpec method calculateTimeDependentModelObjects.

/**
 * Insert the method's description here.
 * Creation date: (11/29/2005 5:10:51 PM)
 * @return cbit.vcell.parser.SymbolTableEntry[]
 */
public static SymbolTableEntry[] calculateTimeDependentModelObjects(SimulationContext simulationContext) {
    Graph digraph = new Graph();
    // 
    // add time
    // 
    Model model = simulationContext.getModel();
    Node timeNode = new Node("t", model.getTIME());
    digraph.addNode(timeNode);
    // 
    // add all species concentrations (that are not fixed with a constant initial condition).
    // 
    SpeciesContextSpec[] scs = simulationContext.getReactionContext().getSpeciesContextSpecs();
    for (int i = 0; scs != null && i < scs.length; i++) {
        SpeciesContextSpecParameter initParam = scs[i].getInitialConditionParameter();
        Expression iniExp = initParam == null ? null : initParam.getExpression();
        if (!scs[i].isConstant() || (iniExp != null && !iniExp.isNumeric())) {
            String speciesContextScopedName = scs[i].getSpeciesContext().getNameScope().getAbsoluteScopePrefix() + scs[i].getSpeciesContext().getName();
            Node speciesContextNode = new Node(speciesContextScopedName, scs[i].getSpeciesContext());
            digraph.addNode(speciesContextNode);
            digraph.addEdge(new Edge(speciesContextNode, timeNode));
        }
    }
    // 
    // add all model (global) parameters that are not simple constants
    // 
    ModelParameter[] modelParams = model.getModelParameters();
    for (int i = 0; modelParams != null && i < modelParams.length; i++) {
        Expression exp = modelParams[i].getExpression();
        if (exp != null) {
            String[] symbols = exp.getSymbols();
            if (symbols != null && symbols.length > 0) {
                // 
                // add parameter to graph as a node (if not already there).
                // 
                String parameterScopedName = modelParams[i].getNameScope().getAbsoluteScopePrefix() + modelParams[i].getName();
                Node parameterNode = digraph.getNode(parameterScopedName);
                if (parameterNode == null) {
                    parameterNode = new Node(parameterScopedName, modelParams[i]);
                    digraph.addNode(parameterNode);
                }
                // 
                for (int k = 0; symbols != null && k < symbols.length; k++) {
                    SymbolTableEntry ste = exp.getSymbolBinding(symbols[k]);
                    if (ste == null) {
                        throw new RuntimeException("Error, symbol '" + symbols[k] + "' not bound in parameter '" + modelParams[i].getName() + "'");
                    }
                    String symbolScopedName = ste.getNameScope().getAbsoluteScopePrefix() + ste.getName();
                    Node symbolNode = digraph.getNode(symbolScopedName);
                    if (symbolNode == null) {
                        symbolNode = new Node(symbolScopedName, ste);
                        digraph.addNode(symbolNode);
                    }
                    digraph.addEdge(new Edge(parameterNode, symbolNode));
                }
            }
        }
    }
    // 
    // add all reaction parameters that are not simple constants
    // 
    ReactionStep[] reactionSteps = model.getReactionSteps();
    for (int i = 0; reactionSteps != null && i < reactionSteps.length; i++) {
        Parameter[] parameters = reactionSteps[i].getKinetics().getKineticsParameters();
        for (int j = 0; parameters != null && j < parameters.length; j++) {
            Expression exp = parameters[j].getExpression();
            if (exp != null) {
                String[] symbols = exp.getSymbols();
                if (symbols != null && symbols.length > 0) {
                    // 
                    // add parameter to graph as a node (if not already there).
                    // 
                    String parameterScopedName = parameters[j].getNameScope().getAbsoluteScopePrefix() + parameters[j].getName();
                    Node parameterNode = digraph.getNode(parameterScopedName);
                    if (parameterNode == null) {
                        parameterNode = new Node(parameterScopedName, parameters[j]);
                        digraph.addNode(parameterNode);
                    }
                    // 
                    for (int k = 0; symbols != null && k < symbols.length; k++) {
                        SymbolTableEntry ste = exp.getSymbolBinding(symbols[k]);
                        if (ste == null) {
                            throw new RuntimeException("Error, symbol '" + symbols[k] + "' not bound in parameter '" + parameters[j].getName() + "'");
                        }
                        String symbolScopedName = ste.getNameScope().getAbsoluteScopePrefix() + ste.getName();
                        Node symbolNode = digraph.getNode(symbolScopedName);
                        if (symbolNode == null) {
                            symbolNode = new Node(symbolScopedName, ste);
                            digraph.addNode(symbolNode);
                        }
                        digraph.addEdge(new Edge(parameterNode, symbolNode));
                    }
                }
            }
        }
    }
    // 
    for (Structure structure : model.getStructures()) {
        if (structure instanceof Membrane && ((MembraneMapping) simulationContext.getGeometryContext().getStructureMapping(structure)).getCalculateVoltage()) {
            MembraneVoltage membraneVoltage = ((Membrane) structure).getMembraneVoltage();
            String membraneVoltageScopedName = membraneVoltage.getNameScope().getAbsoluteScopePrefix() + membraneVoltage.getName();
            Node membraneVoltageNode = digraph.getNode(membraneVoltageScopedName);
            if (membraneVoltageNode == null) {
                membraneVoltageNode = new Node(membraneVoltageScopedName, membraneVoltage);
                digraph.addNode(membraneVoltageNode);
            }
            digraph.addEdge(new Edge(membraneVoltageNode, timeNode));
        }
    }
    Node[] timeDependentNodes = digraph.getDigraphAttractorSet(timeNode);
    SymbolTableEntry[] steArray = new SymbolTableEntry[timeDependentNodes.length];
    for (int i = 0; i < steArray.length; i++) {
        steArray[i] = (SymbolTableEntry) timeDependentNodes[i].getData();
    }
    return steArray;
}
Also used : Node(cbit.util.graph.Node) SpeciesContextSpec(cbit.vcell.mapping.SpeciesContextSpec) ModelParameter(cbit.vcell.model.Model.ModelParameter) SymbolTableEntry(cbit.vcell.parser.SymbolTableEntry) Graph(cbit.util.graph.Graph) Expression(cbit.vcell.parser.Expression) MembraneVoltage(cbit.vcell.model.Membrane.MembraneVoltage) ReactionStep(cbit.vcell.model.ReactionStep) Model(cbit.vcell.model.Model) Parameter(cbit.vcell.model.Parameter) KineticsParameter(cbit.vcell.model.Kinetics.KineticsParameter) ModelParameter(cbit.vcell.model.Model.ModelParameter) KineticsProxyParameter(cbit.vcell.model.Kinetics.KineticsProxyParameter) SpeciesContextSpecParameter(cbit.vcell.mapping.SpeciesContextSpec.SpeciesContextSpecParameter) Membrane(cbit.vcell.model.Membrane) Structure(cbit.vcell.model.Structure) Edge(cbit.util.graph.Edge) SpeciesContextSpecParameter(cbit.vcell.mapping.SpeciesContextSpec.SpeciesContextSpecParameter)

Aggregations

SpeciesContextSpec (cbit.vcell.mapping.SpeciesContextSpec)58 Expression (cbit.vcell.parser.Expression)33 SpeciesContext (cbit.vcell.model.SpeciesContext)28 SimulationContext (cbit.vcell.mapping.SimulationContext)23 Model (cbit.vcell.model.Model)21 BioModel (cbit.vcell.biomodel.BioModel)19 StructureMapping (cbit.vcell.mapping.StructureMapping)17 ReactionStep (cbit.vcell.model.ReactionStep)16 Simulation (cbit.vcell.solver.Simulation)13 ReactionSpec (cbit.vcell.mapping.ReactionSpec)12 SpeciesContextSpecParameter (cbit.vcell.mapping.SpeciesContextSpec.SpeciesContextSpecParameter)12 KineticsParameter (cbit.vcell.model.Kinetics.KineticsParameter)12 Structure (cbit.vcell.model.Structure)12 ExpressionException (cbit.vcell.parser.ExpressionException)12 MathDescription (cbit.vcell.math.MathDescription)11 ModelParameter (cbit.vcell.model.Model.ModelParameter)11 FeatureMapping (cbit.vcell.mapping.FeatureMapping)10 SpeciesContextMapping (cbit.vcell.mapping.SpeciesContextMapping)10 Feature (cbit.vcell.model.Feature)10 Parameter (cbit.vcell.model.Parameter)10