Search in sources :

Example 36 with ModelParameter

use of cbit.vcell.model.Model.ModelParameter in project vcell by virtualcell.

the class BioModelParametersTableModel method bioModelChange.

@Override
protected void bioModelChange(PropertyChangeEvent evt) {
    super.bioModelChange(evt);
    BioModel oldValue = (BioModel) evt.getOldValue();
    if (oldValue != null) {
        for (EditableSymbolTableEntry parameter : oldValue.getModel().getModelParameters()) {
            parameter.removePropertyChangeListener(this);
        }
        for (SpeciesContext sc : oldValue.getModel().getSpeciesContexts()) {
            sc.removePropertyChangeListener(this);
        }
        for (ReactionStep reactionStep : oldValue.getModel().getReactionSteps()) {
            reactionStep.removePropertyChangeListener(this);
            Kinetics kinetics = reactionStep.getKinetics();
            kinetics.removePropertyChangeListener(this);
            for (KineticsParameter kineticsEditableSymbolTableEntry : kinetics.getKineticsParameters()) {
                kineticsEditableSymbolTableEntry.removePropertyChangeListener(this);
            }
            for (ProxyParameter proxyEditableSymbolTableEntry : kinetics.getProxyParameters()) {
                proxyEditableSymbolTableEntry.removePropertyChangeListener(this);
            }
            for (UnresolvedParameter unresolvedEditableSymbolTableEntry : kinetics.getUnresolvedParameters()) {
                unresolvedEditableSymbolTableEntry.removePropertyChangeListener(this);
            }
        }
        for (SimulationContext simulationContext : oldValue.getSimulationContexts()) {
            simulationContext.removePropertyChangeListener(this);
            simulationContext.getGeometryContext().removePropertyChangeListener(this);
            for (StructureMapping mapping : simulationContext.getGeometryContext().getStructureMappings()) {
                mapping.removePropertyChangeListener(this);
                for (EditableSymbolTableEntry parameter : mapping.getParameters()) {
                    parameter.removePropertyChangeListener(this);
                }
            }
            simulationContext.getReactionContext().removePropertyChangeListener(this);
            for (SpeciesContextSpec spec : simulationContext.getReactionContext().getSpeciesContextSpecs()) {
                spec.removePropertyChangeListener(this);
                for (EditableSymbolTableEntry parameter : spec.getParameters()) {
                    parameter.removePropertyChangeListener(this);
                }
            }
            for (ElectricalStimulus elect : simulationContext.getElectricalStimuli()) {
                elect.removePropertyChangeListener(this);
                for (EditableSymbolTableEntry parameter : elect.getParameters()) {
                    parameter.removePropertyChangeListener(this);
                }
            }
            for (SpatialObject spatialObject : simulationContext.getSpatialObjects()) {
                spatialObject.removePropertyChangeListener(this);
            }
            for (SpatialProcess spatialProcess : simulationContext.getSpatialProcesses()) {
                spatialProcess.removePropertyChangeListener(this);
                for (LocalParameter p : spatialProcess.getParameters()) {
                    p.removePropertyChangeListener(this);
                }
            }
            for (SimulationContextParameter p : simulationContext.getSimulationContextParameters()) {
                p.removePropertyChangeListener(this);
            }
        }
    }
    BioModel newValue = (BioModel) evt.getNewValue();
    if (newValue != null) {
        for (ModelParameter modelEditableSymbolTableEntry : newValue.getModel().getModelParameters()) {
            modelEditableSymbolTableEntry.addPropertyChangeListener(this);
        }
        for (SpeciesContext sc : newValue.getModel().getSpeciesContexts()) {
            sc.addPropertyChangeListener(this);
        }
        for (ReactionStep reactionStep : newValue.getModel().getReactionSteps()) {
            reactionStep.addPropertyChangeListener(this);
            Kinetics kinetics = reactionStep.getKinetics();
            kinetics.addPropertyChangeListener(this);
            for (KineticsParameter kineticsEditableSymbolTableEntry : kinetics.getKineticsParameters()) {
                kineticsEditableSymbolTableEntry.addPropertyChangeListener(this);
            }
            for (ProxyParameter proxyEditableSymbolTableEntry : kinetics.getProxyParameters()) {
                proxyEditableSymbolTableEntry.addPropertyChangeListener(this);
            }
            for (UnresolvedParameter unresolvedEditableSymbolTableEntry : kinetics.getUnresolvedParameters()) {
                unresolvedEditableSymbolTableEntry.addPropertyChangeListener(this);
            }
        }
        for (SimulationContext simulationContext : newValue.getSimulationContexts()) {
            simulationContext.addPropertyChangeListener(this);
            simulationContext.getGeometryContext().addPropertyChangeListener(this);
            for (StructureMapping mapping : simulationContext.getGeometryContext().getStructureMappings()) {
                mapping.addPropertyChangeListener(this);
                for (EditableSymbolTableEntry parameter : mapping.getParameters()) {
                    parameter.addPropertyChangeListener(this);
                }
            }
            simulationContext.getReactionContext().addPropertyChangeListener(this);
            for (SpeciesContextSpec spec : simulationContext.getReactionContext().getSpeciesContextSpecs()) {
                spec.addPropertyChangeListener(this);
                for (EditableSymbolTableEntry parameter : spec.getParameters()) {
                    parameter.addPropertyChangeListener(this);
                }
            }
            for (ElectricalStimulus elect : simulationContext.getElectricalStimuli()) {
                elect.addPropertyChangeListener(this);
                for (EditableSymbolTableEntry parameter : elect.getParameters()) {
                    parameter.addPropertyChangeListener(this);
                }
            }
            for (SpatialObject spatialObject : simulationContext.getSpatialObjects()) {
                spatialObject.addPropertyChangeListener(this);
            }
            for (SpatialProcess spatialProcess : simulationContext.getSpatialProcesses()) {
                spatialProcess.addPropertyChangeListener(this);
                for (LocalParameter p : spatialProcess.getParameters()) {
                    p.addPropertyChangeListener(this);
                }
            }
            for (SimulationContextParameter p : simulationContext.getSimulationContextParameters()) {
                p.addPropertyChangeListener(this);
            }
        }
    }
}
Also used : UnresolvedParameter(cbit.vcell.model.Kinetics.UnresolvedParameter) SpeciesContext(cbit.vcell.model.SpeciesContext) SimulationContext(cbit.vcell.mapping.SimulationContext) SpeciesContextSpec(cbit.vcell.mapping.SpeciesContextSpec) SimulationContextParameter(cbit.vcell.mapping.SimulationContext.SimulationContextParameter) StructureMapping(cbit.vcell.mapping.StructureMapping) SpatialObject(cbit.vcell.mapping.spatial.SpatialObject) LocalParameter(cbit.vcell.mapping.ParameterContext.LocalParameter) ElectricalStimulus(cbit.vcell.mapping.ElectricalStimulus) ModelParameter(cbit.vcell.model.Model.ModelParameter) ProxyParameter(cbit.vcell.model.ProxyParameter) KineticsParameter(cbit.vcell.model.Kinetics.KineticsParameter) SpatialProcess(cbit.vcell.mapping.spatial.processes.SpatialProcess) BioModel(cbit.vcell.biomodel.BioModel) ReactionStep(cbit.vcell.model.ReactionStep) Kinetics(cbit.vcell.model.Kinetics) EditableSymbolTableEntry(cbit.vcell.model.EditableSymbolTableEntry)

Example 37 with ModelParameter

use of cbit.vcell.model.Model.ModelParameter in project vcell by virtualcell.

the class XmlReader method getModel.

/**
 * This method creates a Model object from a XML element.
 * Creation date: (3/14/2001 6:14:37 PM)
 * @return cbit.vcell.model.Model
 * @param param org.jdom.Element
 */
private Model getModel(Element param) throws XmlParseException {
    if (param == null) {
        throw new XmlParseException("Invalid 'NULL' XML 'model' element arrived!");
    }
    // Get version, if any
    Model newmodel = null;
    Version version = getVersion(param.getChild(XMLTags.VersionTag, vcNamespace));
    // if forcedModelUnitSystem has been set, ues that (could be overriding unit system for SBML export)
    if (forcedModelUnitSystem != null) {
        newmodel = new Model(version, forcedModelUnitSystem);
    } else {
        Element unitSystemNode = param.getChild(XMLTags.ModelUnitSystemTag, vcNamespace);
        if (unitSystemNode != null) {
            ModelUnitSystem modelUnitSystem = getUnitSystem(unitSystemNode);
            newmodel = new Model(version, modelUnitSystem);
        } else {
            newmodel = new Model(version);
        }
    }
    try {
        // Set attributes
        newmodel.setName(unMangle(param.getAttributeValue(XMLTags.NameAttrTag)));
        // Add annotation
        String annotationText = param.getChildText(XMLTags.AnnotationTag, vcNamespace);
        if (annotationText != null && annotationText.length() > 0) {
            newmodel.setDescription(unMangle(annotationText));
        }
        // Add global parameters
        Element globalParamsElement = param.getChild(XMLTags.ModelParametersTag, vcNamespace);
        if (globalParamsElement != null) {
            ModelParameter[] modelParams = getModelParams(globalParamsElement, newmodel);
            // add global/model param to model - done inside getModelParam by passing newModel
            newmodel.setModelParameters(modelParams);
        }
        // Add Species (Compounds)
        Iterator<Element> iterator = param.getChildren(XMLTags.SpeciesTag, vcNamespace).iterator();
        ArrayList<Species> speciesList = new ArrayList<Species>();
        while (iterator.hasNext()) {
            org.jdom.Element temp = (Element) iterator.next();
            speciesList.add(getSpecies(temp));
        }
        newmodel.setSpecies(speciesList.toArray(new Species[speciesList.size()]));
        // Add Structures
        LinkedList<Structure> newstructures = new LinkedList<Structure>();
        // (features)
        List<Element> children = param.getChildren(XMLTags.FeatureTag, vcNamespace);
        for (Element featureElement : children) {
            newstructures.add(getFeature(featureElement));
        }
        // (Membrane)
        children = param.getChildren(XMLTags.MembraneTag, vcNamespace);
        for (Element memElement : children) {
            newstructures.add(getMembrane(newmodel, memElement, newstructures));
        }
        if (newstructures.size() > 0) {
            Structure[] structarray = new Structure[newstructures.size()];
            newstructures.toArray(structarray);
            // Add all the retrieved structures
            newmodel.setStructures(structarray);
        }
        // retrieve the RbmModelContainer, if present - must be done before we retrieve species context!
        Element element = param.getChild(XMLTags.RbmModelContainerTag, vcNamespace);
        if (element != null) {
            getRbmModelContainer(element, newmodel);
        } else {
            lg.info("RbmModelContainer is missing.");
        }
        // Add SpeciesContexts
        children = param.getChildren(XMLTags.SpeciesContextTag, vcNamespace);
        SpeciesContext[] newspeccon = new SpeciesContext[children.size()];
        int scCounter = 0;
        for (Element scElement : children) {
            newspeccon[scCounter] = getSpeciesContext(scElement, newmodel);
            scCounter++;
        }
        newmodel.setSpeciesContexts(newspeccon);
        // Retrieve rateRules and add to model
        // Element rateRuleVarsElement = param.getChild(XMLTags.RateRuleVariablesTag, vcNamespace);
        // if(rateRuleVarsElement != null){
        // RateRuleVariable[] rateRuleVars = getRateRuleVariables(rateRuleVarsElement, newmodel);
        // newmodel.setRateRuleVariables(rateRuleVars);
        // }
        // Add Reaction steps (if available)
        // (Simplereaction)
        // Create a varHash with reserved symbols and global parameters, if any, to pass on to Kinetics
        // must create new hash for each reaction and flux, since each kinetics uses new variables hash
        iterator = param.getChildren(XMLTags.SimpleReactionTag, vcNamespace).iterator();
        ArrayList<ReactionStep> reactionStepList = new ArrayList<ReactionStep>();
        while (iterator.hasNext()) {
            org.jdom.Element temp = iterator.next();
            reactionStepList.add(getSimpleReaction(temp, newmodel));
        }
        // (fluxStep)
        iterator = param.getChildren(XMLTags.FluxStepTag, vcNamespace).iterator();
        while (iterator.hasNext()) {
            org.jdom.Element temp = iterator.next();
            reactionStepList.add(getFluxReaction(temp, newmodel));
        }
        newmodel.setReactionSteps(reactionStepList.toArray(new ReactionStep[reactionStepList.size()]));
        // Add Diagrams
        children = param.getChildren(XMLTags.DiagramTag, vcNamespace);
        if (children.size() > 0) {
            Diagram[] newdiagrams = new Diagram[children.size()];
            int diagramCounter = 0;
            for (Element diagramElement : children) {
                newdiagrams[diagramCounter] = getDiagram(diagramElement, newmodel);
                diagramCounter++;
            }
            reorderDiagramsInPlace_UponRead(docVCellSoftwareVersion, newdiagrams, newmodel.getStructureTopology());
            // if(docVCellSoftwareVersion != null && !docVCellSoftwareVersion.isValid() && docVCellSoftwareVersion.getMajorVersion()<=5 && docVCellSoftwareVersion.getMinorVersion() <=2){
            // //In Vcell 5.2 and previous we need to order diagrams topologically, in 5.3 and later the diagrams are displayed as they are ordered when read from document
            // final StructureTopology structureTopology = newmodel.getStructureTopology();
            // Arrays.sort(newdiagrams, new Comparator<Diagram>() {
            // @Override
            // public int compare(Diagram o1, Diagram o2) {
            // return getStructureLevel(o1.getStructure(), structureTopology) - getStructureLevel(o2.getStructure(), structureTopology);
            // }
            // });
            // }
            newmodel.setDiagrams(newdiagrams);
        }
    } catch (java.beans.PropertyVetoException e) {
        e.printStackTrace();
        throw new XmlParseException(e);
    } catch (ModelException e) {
        e.printStackTrace();
    }
    // model param expresions are not bound when they are read in, since they could be functions of each other or structures/speciesContexts.
    // Hence bind the model param exprs at the end, after reading all model level quantities.
    ModelParameter[] modelParameters = newmodel.getModelParameters();
    for (int i = 0; modelParameters != null && i < modelParameters.length; i++) {
        try {
            modelParameters[i].getExpression().bindExpression(newmodel);
        } catch (ExpressionBindingException e) {
            e.printStackTrace(System.out);
            throw new RuntimeException("Error binding global parameter '" + modelParameters[i].getName() + "' to model." + e.getMessage());
        }
    }
    return newmodel;
}
Also used : Element(org.jdom.Element) ArrayList(java.util.ArrayList) SpeciesContext(cbit.vcell.model.SpeciesContext) PropertyVetoException(java.beans.PropertyVetoException) Version(org.vcell.util.document.Version) RedistributionVersion(cbit.vcell.solvers.mb.MovingBoundarySolverOptions.RedistributionVersion) SimulationVersion(org.vcell.util.document.SimulationVersion) VCellSoftwareVersion(org.vcell.util.document.VCellSoftwareVersion) Structure(cbit.vcell.model.Structure) DBFormalSpecies(cbit.vcell.model.DBFormalSpecies) Species(cbit.vcell.model.Species) DBSpecies(cbit.vcell.model.DBSpecies) ModelUnitSystem(cbit.vcell.model.ModelUnitSystem) ModelException(cbit.vcell.model.ModelException) ExpressionBindingException(cbit.vcell.parser.ExpressionBindingException) LinkedList(java.util.LinkedList) Diagram(cbit.vcell.model.Diagram) ModelParameter(cbit.vcell.model.Model.ModelParameter) ReactionStep(cbit.vcell.model.ReactionStep) MathModel(cbit.vcell.mathmodel.MathModel) Model(cbit.vcell.model.Model) PathwayModel(org.vcell.pathway.PathwayModel) RelationshipModel(org.vcell.relationship.RelationshipModel) BioModel(cbit.vcell.biomodel.BioModel) Element(org.jdom.Element)

Example 38 with ModelParameter

use of cbit.vcell.model.Model.ModelParameter in project vcell by virtualcell.

the class Xmlproducer method getXML.

/**
 * Outputs a XML version of a Model object
 * Creation date: (2/15/2001 11:39:27 AM)
 * @return Element
 * @param param cbit.vcell.model.Model
 */
private Element getXML(Model param) throws XmlParseException /*, cbit.vcell.parser.ExpressionException */
{
    Element modelnode = new Element(XMLTags.ModelTag);
    String versionName = (param.getName() != null) ? mangle(param.getName()) : "unnamed_model";
    // get Attributes
    modelnode.setAttribute(XMLTags.NameAttrTag, versionName);
    // modelnode.setAttribute(XMLTags.AnnotationAttrTag, this.mangle(param.getDescription()));
    if (param.getDescription() != null && param.getDescription().length() > 0) {
        Element annotationElem = new Element(XMLTags.AnnotationTag);
        annotationElem.setText(mangle(param.getDescription()));
        modelnode.addContent(annotationElem);
    }
    // get global parameters
    ModelParameter[] modelGlobals = param.getModelParameters();
    if (modelGlobals != null && modelGlobals.length > 0) {
        modelnode.addContent(getXML(modelGlobals));
    }
    // Get Species
    Species[] array = param.getSpecies();
    for (int i = 0; i < array.length; i++) {
        modelnode.addContent(getXML(array[i]));
    }
    // Get Structures(Features and Membranes). Add them in an ordered fashion, but it does not matter who comes first.
    try {
        ArrayList<Element> list = new ArrayList<Element>();
        Structure[] structarray = param.getStructures();
        for (int i = 0; i < structarray.length; i++) {
            Element structure = getXML(structarray[i], param);
            if (structarray[i] instanceof Feature)
                modelnode.addContent(structure);
            else
                list.add(structure);
        }
        for (int i = 0; i < list.size(); i++) {
            modelnode.addContent((Element) list.get(i));
        }
    } catch (XmlParseException e) {
        e.printStackTrace();
        throw new XmlParseException("An error occurred while procesing a Structure for the model " + versionName, e);
    }
    // Process SpeciesContexts
    SpeciesContext[] specarray = param.getSpeciesContexts();
    for (int i = 0; i < specarray.length; i++) {
        modelnode.addContent(getXML(specarray[i]));
    }
    // Get reaction Steps(Simple Reactions and Fluxtep)
    ReactionStep[] reactarray = param.getReactionSteps();
    for (int i = 0; i < reactarray.length; i++) {
        modelnode.addContent(getXML(reactarray[i]));
    }
    // add the rbmModelContainer elements
    RbmModelContainer rbmModelContainer = param.getRbmModelContainer();
    if (rbmModelContainer != null && !rbmModelContainer.isEmpty()) {
        Element rbmModelContainerElement = getXML(rbmModelContainer);
        {
            // for testing purposes only
            Document doc = new Document();
            Element clone = (Element) rbmModelContainerElement.clone();
            doc.setRootElement(clone);
            String xmlString = XmlUtil.xmlToString(doc, false);
            System.out.println(xmlString);
        }
        modelnode.addContent(rbmModelContainerElement);
    }
    // // Add rate rules
    // if (param.getRateRuleVariables()!=null && param.getRateRuleVariables().length>0){
    // modelnode.addContent( getXML(param.getRateRuleVariables()) );
    // }
    // Get Diagrams
    Diagram[] diagarray = param.getDiagrams();
    for (int i = 0; i < diagarray.length; i++) {
        modelnode.addContent(getXML(diagarray[i]));
    }
    // Add Metadata information
    if (param.getVersion() != null) {
        modelnode.addContent(getXML(param.getVersion(), param));
    }
    // add model UnitSystem
    ModelUnitSystem unitSystem = param.getUnitSystem();
    if (unitSystem != null) {
        modelnode.addContent(getXML(unitSystem));
    }
    return modelnode;
}
Also used : Element(org.jdom.Element) ArrayList(java.util.ArrayList) SpeciesContext(cbit.vcell.model.SpeciesContext) Document(org.jdom.Document) Feature(cbit.vcell.model.Feature) Diagram(cbit.vcell.model.Diagram) ModelParameter(cbit.vcell.model.Model.ModelParameter) RbmModelContainer(cbit.vcell.model.Model.RbmModelContainer) ReactionStep(cbit.vcell.model.ReactionStep) Structure(cbit.vcell.model.Structure) DBFormalSpecies(cbit.vcell.model.DBFormalSpecies) Species(cbit.vcell.model.Species) DBSpecies(cbit.vcell.model.DBSpecies) ModelUnitSystem(cbit.vcell.model.ModelUnitSystem)

Example 39 with ModelParameter

use of cbit.vcell.model.Model.ModelParameter in project vcell by virtualcell.

the class XmlReader method getModelParameter.

public ModelParameter getModelParameter(Element paramElement, Model model) {
    // get its attributes : name, role and unit definition
    String glParamName = unMangle(paramElement.getAttributeValue(XMLTags.NameAttrTag));
    String role = paramElement.getAttributeValue(XMLTags.ParamRoleAttrTag);
    ModelUnitSystem modelUnitSystem = model.getUnitSystem();
    int glParamRole = -1;
    if (role.equals(XMLTags.ParamRoleUserDefinedTag)) {
        glParamRole = Model.ROLE_UserDefined;
    } else {
        throw new RuntimeException("unknown type of model parameter (not user-defined)");
    }
    // 
    // int glParamRole = -1;
    // if (role.equals(XMLTags.ParamRoleUserDefinedTag)) {
    // glParamRole = Model.ROLE_UserDefined;
    // } else	if (role.equals(XMLTags.RoleVariableRateTag)) {
    // glParamRole = Model.ROLE_VariableRate;
    // } else {
    // throw new RuntimeException("unknown type of model parameter (not user-defined or variable rate)");
    // }
    String unitSymbol = paramElement.getAttributeValue(XMLTags.VCUnitDefinitionAttrTag);
    VCUnitDefinition glParamUnit = null;
    if (unitSymbol != null) {
        glParamUnit = modelUnitSystem.getInstance(unitSymbol);
    }
    // get parameter contents : expression; annotation, if any.
    String glParamExpStr = paramElement.getText();
    Expression glParamExp = unMangleExpression(glParamExpStr);
    String glParamAnnotation = null;
    String annotationText = paramElement.getChildText(XMLTags.AnnotationTag, vcNamespace);
    if (annotationText != null && annotationText.length() > 0) {
        glParamAnnotation = unMangle(annotationText);
    }
    // create new global parameter
    ModelParameter newGlParam = model.new ModelParameter(glParamName, glParamExp, glParamRole, glParamUnit);
    newGlParam.setModelParameterAnnotation(glParamAnnotation);
    return newGlParam;
}
Also used : ModelParameter(cbit.vcell.model.Model.ModelParameter) VCUnitDefinition(cbit.vcell.units.VCUnitDefinition) Expression(cbit.vcell.parser.Expression) ModelUnitSystem(cbit.vcell.model.ModelUnitSystem)

Example 40 with ModelParameter

use of cbit.vcell.model.Model.ModelParameter in project vcell by virtualcell.

the class Kinetics method gatherIssues.

/**
 * Insert the method's description here.
 * Creation date: (5/12/2004 2:53:13 PM)
 */
public void gatherIssues(IssueContext issueContext, List<Issue> issueList) {
    issueContext = issueContext.newChildContext(ContextType.ModelProcessDynamics, this);
    // 
    for (int i = 0; fieldUnresolvedParameters != null && i < fieldUnresolvedParameters.length; i++) {
        issueList.add(new Issue(fieldUnresolvedParameters[i], issueContext, IssueCategory.UnresolvedParameter, "Unresolved parameter '" + fieldUnresolvedParameters[i].getName() + "' in reaction '" + reactionStep.getName() + "'", Issue.SEVERITY_ERROR));
    }
    // 
    for (int i = 0; fieldKineticsParameters != null && i < fieldKineticsParameters.length; i++) {
        if (fieldKineticsParameters[i].getRole() == ROLE_UserDefined) {
            try {
                if (!isReferenced(fieldKineticsParameters[i], 0)) {
                    issueList.add(new Issue(fieldKineticsParameters[i], issueContext, IssueCategory.KineticsUnreferencedParameter, "Unreferenced Kinetic Parameter '" + fieldKineticsParameters[i].getName() + "' in reaction '" + reactionStep.getName() + "'", Issue.SEVERITY_WARNING));
                }
            } catch (ExpressionException e) {
                issueList.add(new Issue(fieldKineticsParameters[i], issueContext, IssueCategory.KineticsExpressionError, "error resolving expression " + e.getMessage(), Issue.SEVERITY_WARNING));
            } catch (ModelException e) {
                issueList.add(new Issue(getReactionStep(), issueContext, IssueCategory.CyclicDependency, "cyclic dependency in the parameter definitions", Issue.SEVERITY_ERROR));
            }
        }
    }
    // 
    if (fieldKineticsParameters != null) {
        for (KineticsParameter kineticsParameter : fieldKineticsParameters) {
            if (kineticsParameter.getExpression() == null) {
                issueList.add(new Issue(kineticsParameter, issueContext, IssueCategory.KineticsExpressionMissing, "expression is missing", Issue.SEVERITY_INFO));
            } else {
                Expression exp = kineticsParameter.getExpression();
                String[] symbols = exp.getSymbols();
                String issueMessagePrefix = "Kinetic parameter '" + kineticsParameter.getName() + "' in reaction '" + getReactionStep().getName() + "' ";
                if (symbols != null) {
                    for (int j = 0; j < symbols.length; j++) {
                        SymbolTableEntry ste = exp.getSymbolBinding(symbols[j]);
                        if (ste instanceof KineticsProxyParameter) {
                            ste = ((KineticsProxyParameter) ste).getTarget();
                        }
                        if (ste == null) {
                            issueList.add(new Issue(kineticsParameter, issueContext, IssueCategory.KineticsExpressionUndefinedSymbol, issueMessagePrefix + "references undefined symbol '" + symbols[j] + "'", Issue.SEVERITY_ERROR));
                        } else if (ste instanceof SpeciesContext) {
                            if (!getReactionStep().getModel().contains((SpeciesContext) ste)) {
                                issueList.add(new Issue(kineticsParameter, issueContext, IssueCategory.KineticsExpressionUndefinedSymbol, issueMessagePrefix + "references undefined species '" + symbols[j] + "'", Issue.SEVERITY_ERROR));
                            }
                            if (reactionStep.countNumReactionParticipants((SpeciesContext) ste) == 0) {
                                issueList.add(new Issue(kineticsParameter, issueContext, IssueCategory.KineticsExpressionNonParticipantSymbol, issueMessagePrefix + "references species context '" + symbols[j] + "', but it is not a reactant/product/catalyst of this reaction", Issue.SEVERITY_WARNING));
                            }
                        } else if (ste instanceof ModelParameter) {
                            if (!getReactionStep().getModel().contains((ModelParameter) ste)) {
                                issueList.add(new Issue(kineticsParameter, issueContext, IssueCategory.KineticsExpressionUndefinedSymbol, issueMessagePrefix + "references undefined global parameter '" + symbols[j] + "'", Issue.SEVERITY_ERROR));
                            }
                        }
                    }
                }
            }
        }
        // looking for local param which masks a global and issueing a warning
        for (KineticsParameter kineticsParameter : fieldKineticsParameters) {
            String name = kineticsParameter.getName();
            SymbolTableEntry ste = getReactionStep().getNameScope().getExternalEntry(name, getReactionStep());
            String steName;
            if (ste != null) {
                if (ste instanceof Displayable) {
                    steName = ((Displayable) ste).getDisplayType() + " " + ste.getName();
                } else {
                    steName = ste.getClass().getSimpleName() + " " + ste.getName();
                }
                String msg = steName + " is overriden by a local parameter " + name + " in reaction " + getReactionStep().getName();
                issueList.add(new Issue(kineticsParameter, issueContext, IssueCategory.Identifiers, msg, Issue.SEVERITY_WARNING));
            }
        }
    }
    try {
        // 
        // determine unit consistency for each expression
        // 
        ModelUnitSystem modelUnitSystem = getReactionStep().getModel().getUnitSystem();
        VCUnitEvaluator unitEvaluator = new VCUnitEvaluator(modelUnitSystem);
        for (int i = 0; i < fieldKineticsParameters.length; i++) {
            try {
                VCUnitDefinition paramUnitDef = fieldKineticsParameters[i].getUnitDefinition();
                VCUnitDefinition expUnitDef = unitEvaluator.getUnitDefinition(fieldKineticsParameters[i].getExpression());
                if (paramUnitDef == null) {
                    issueList.add(new Issue(fieldKineticsParameters[i], issueContext, IssueCategory.Units, "defined unit is null", Issue.SEVERITY_WARNING));
                } else if (paramUnitDef.isTBD()) {
                    issueList.add(new Issue(fieldKineticsParameters[i], issueContext, IssueCategory.Units, "undefined unit " + modelUnitSystem.getInstance_TBD().getSymbol(), Issue.SEVERITY_WARNING));
                } else if (expUnitDef == null) {
                    issueList.add(new Issue(fieldKineticsParameters[i], issueContext, IssueCategory.Units, "computed unit is null", Issue.SEVERITY_WARNING));
                } else if (paramUnitDef.isTBD() || (!paramUnitDef.isEquivalent(expUnitDef) && !expUnitDef.isTBD())) {
                    issueList.add(new Issue(fieldKineticsParameters[i], issueContext, IssueCategory.Units, "inconsistent units, defined=[" + fieldKineticsParameters[i].getUnitDefinition().getSymbol() + "], computed=[" + expUnitDef.getSymbol() + "]", Issue.SEVERITY_WARNING));
                }
            } catch (VCUnitException e) {
                issueList.add(new Issue(fieldKineticsParameters[i], issueContext, IssueCategory.Units, e.getMessage(), Issue.SEVERITY_WARNING));
            } catch (ExpressionException e) {
                issueList.add(new Issue(fieldKineticsParameters[i], issueContext, IssueCategory.Units, e.getMessage(), Issue.SEVERITY_WARNING));
            }
        }
    } catch (Throwable e) {
        issueList.add(new Issue(getReactionStep(), issueContext, IssueCategory.Units, "unexpected exception: " + e.getMessage(), Issue.SEVERITY_INFO));
    }
    // 
    for (int i = 0; i < fieldKineticsParameters.length; i++) {
        RealInterval simpleBounds = bounds[fieldKineticsParameters[i].getRole()];
        if (simpleBounds != null) {
            String parmName = reactionStep.getNameScope().getName() + "." + fieldKineticsParameters[i].getName();
            issueList.add(new SimpleBoundsIssue(fieldKineticsParameters[i], issueContext, simpleBounds, "parameter " + parmName + ": must be within " + simpleBounds.toString()));
        }
    }
}
Also used : Displayable(org.vcell.util.Displayable) Issue(org.vcell.util.Issue) RealInterval(net.sourceforge.interval.ia_math.RealInterval) ExpressionException(cbit.vcell.parser.ExpressionException) VCUnitException(cbit.vcell.units.VCUnitException) ModelParameter(cbit.vcell.model.Model.ModelParameter) VCUnitEvaluator(cbit.vcell.parser.VCUnitEvaluator) SymbolTableEntry(cbit.vcell.parser.SymbolTableEntry) VCUnitDefinition(cbit.vcell.units.VCUnitDefinition) Expression(cbit.vcell.parser.Expression)

Aggregations

ModelParameter (cbit.vcell.model.Model.ModelParameter)46 Expression (cbit.vcell.parser.Expression)28 SpeciesContext (cbit.vcell.model.SpeciesContext)25 KineticsParameter (cbit.vcell.model.Kinetics.KineticsParameter)24 Model (cbit.vcell.model.Model)19 ReactionStep (cbit.vcell.model.ReactionStep)19 ExpressionException (cbit.vcell.parser.ExpressionException)16 Structure (cbit.vcell.model.Structure)15 PropertyVetoException (java.beans.PropertyVetoException)14 ModelUnitSystem (cbit.vcell.model.ModelUnitSystem)13 Parameter (cbit.vcell.model.Parameter)12 ArrayList (java.util.ArrayList)12 SpeciesContextSpecParameter (cbit.vcell.mapping.SpeciesContextSpec.SpeciesContextSpecParameter)11 VCUnitDefinition (cbit.vcell.units.VCUnitDefinition)11 LocalParameter (cbit.vcell.mapping.ParameterContext.LocalParameter)10 Vector (java.util.Vector)10 SpeciesContextSpec (cbit.vcell.mapping.SpeciesContextSpec)9 BioModel (cbit.vcell.biomodel.BioModel)8 StructureMapping (cbit.vcell.mapping.StructureMapping)8 Kinetics (cbit.vcell.model.Kinetics)8