Search in sources :

Example 1 with UnresolvedParameter

use of cbit.vcell.model.Kinetics.UnresolvedParameter in project vcell by virtualcell.

the class SBMLImporter method addReactions.

/**
 * addReactions:
 */
protected void addReactions(VCMetaData metaData) {
    if (sbmlModel == null) {
        throw new SBMLImportException("SBML model is NULL");
    }
    ListOf<Reaction> reactions = sbmlModel.getListOfReactions();
    final int numReactions = reactions.size();
    if (numReactions == 0) {
        lg.info("No Reactions");
        return;
    }
    // all reactions
    ArrayList<ReactionStep> vcReactionList = new ArrayList<>();
    // just the fast ones
    ArrayList<ReactionStep> fastReactionList = new ArrayList<>();
    Model vcModel = vcBioModel.getSimulationContext(0).getModel();
    ModelUnitSystem vcModelUnitSystem = vcModel.getUnitSystem();
    SpeciesContext[] vcSpeciesContexts = vcModel.getSpeciesContexts();
    try {
        for (Reaction sbmlRxn : reactions) {
            ReactionStep vcReaction = null;
            String rxnName = sbmlRxn.getId();
            boolean bReversible = true;
            if (sbmlRxn.isSetReversible()) {
                bReversible = sbmlRxn.getReversible();
            }
            // Check of reaction annotation is present; if so, does it have
            // an embedded element (flux or simpleRxn).
            // Create a fluxReaction or simpleReaction accordingly.
            Element sbmlImportRelatedElement = sbmlAnnotationUtil.readVCellSpecificAnnotation(sbmlRxn);
            Structure reactionStructure = getReactionStructure(sbmlRxn, vcSpeciesContexts, sbmlImportRelatedElement);
            if (sbmlImportRelatedElement != null) {
                Element embeddedRxnElement = getEmbeddedElementInAnnotation(sbmlImportRelatedElement, REACTION);
                if (embeddedRxnElement != null) {
                    if (embeddedRxnElement.getName().equals(XMLTags.FluxStepTag)) {
                        // If embedded element is a flux reaction, set flux
                        // reaction's strucure, flux carrier, physicsOption
                        // from the element attributes.
                        String structName = embeddedRxnElement.getAttributeValue(XMLTags.StructureAttrTag);
                        CastInfo<Membrane> ci = SBMLHelper.getTypedStructure(Membrane.class, vcModel, structName);
                        if (!ci.isGood()) {
                            throw new SBMLImportException("Appears that the flux reaction is occuring on " + ci.actualName() + ", not a membrane.");
                        }
                        vcReaction = new FluxReaction(vcModel, ci.get(), null, rxnName, bReversible);
                        vcReaction.setModel(vcModel);
                        // Set the fluxOption on the flux reaction based on
                        // whether it is molecular, molecular & electrical,
                        // electrical.
                        String fluxOptionStr = embeddedRxnElement.getAttributeValue(XMLTags.FluxOptionAttrTag);
                        if (fluxOptionStr.equals(XMLTags.FluxOptionMolecularOnly)) {
                            ((FluxReaction) vcReaction).setPhysicsOptions(ReactionStep.PHYSICS_MOLECULAR_ONLY);
                        } else if (fluxOptionStr.equals(XMLTags.FluxOptionMolecularAndElectrical)) {
                            ((FluxReaction) vcReaction).setPhysicsOptions(ReactionStep.PHYSICS_MOLECULAR_AND_ELECTRICAL);
                        } else if (fluxOptionStr.equals(XMLTags.FluxOptionElectricalOnly)) {
                            ((FluxReaction) vcReaction).setPhysicsOptions(ReactionStep.PHYSICS_ELECTRICAL_ONLY);
                        } else {
                            localIssueList.add(new Issue(vcReaction, issueContext, IssueCategory.SBMLImport_Reaction, "Unknown FluxOption : " + fluxOptionStr + " for SBML reaction : " + rxnName, Issue.SEVERITY_WARNING));
                        // logger.sendMessage(VCLogger.Priority.MediumPriority,
                        // VCLogger.ErrorType.ReactionError,
                        // "Unknown FluxOption : " + fluxOptionStr +
                        // " for SBML reaction : " + rxnName);
                        }
                    } else if (embeddedRxnElement.getName().equals(XMLTags.SimpleReactionTag)) {
                        // if embedded element is a simple reaction, set
                        // simple reaction's structure from element
                        // attributes
                        vcReaction = new SimpleReaction(vcModel, reactionStructure, rxnName, bReversible);
                    }
                } else {
                    vcReaction = new SimpleReaction(vcModel, reactionStructure, rxnName, bReversible);
                }
            } else {
                vcReaction = new SimpleReaction(vcModel, reactionStructure, rxnName, bReversible);
            }
            // set annotations and notes on vcReactions[i]
            sbmlAnnotationUtil.readAnnotation(vcReaction, sbmlRxn);
            sbmlAnnotationUtil.readNotes(vcReaction, sbmlRxn);
            // the limit on the reactionName length.
            if (rxnName.length() > 64) {
                String freeTextAnnotation = metaData.getFreeTextAnnotation(vcReaction);
                if (freeTextAnnotation == null) {
                    freeTextAnnotation = "";
                }
                StringBuffer oldRxnAnnotation = new StringBuffer(freeTextAnnotation);
                oldRxnAnnotation.append("\n\n" + rxnName);
                metaData.setFreeTextAnnotation(vcReaction, oldRxnAnnotation.toString());
            }
            // Now add the reactants, products, modifiers as specified by
            // the sbmlRxn
            addReactionParticipants(sbmlRxn, vcReaction);
            KineticLaw kLaw = sbmlRxn.getKineticLaw();
            Kinetics kinetics = null;
            if (kLaw != null) {
                // Convert the formula from kineticLaw into MathML and then
                // to an expression (infix) to be used in VCell kinetics
                ASTNode sbmlRateMath = kLaw.getMath();
                Expression kLawRateExpr = getExpressionFromFormula(sbmlRateMath);
                Expression vcRateExpression = new Expression(kLawRateExpr);
                // modifier (catalyst) to the reaction.
                for (int k = 0; k < vcSpeciesContexts.length; k++) {
                    if (vcRateExpression.hasSymbol(vcSpeciesContexts[k].getName())) {
                        if ((vcReaction.getReactant(vcSpeciesContexts[k].getName()) == null) && (vcReaction.getProduct(vcSpeciesContexts[k].getName()) == null) && (vcReaction.getCatalyst(vcSpeciesContexts[k].getName()) == null)) {
                            // This means that the speciesContext is not a
                            // reactant, product or modifier : it has to be
                            // added to the VC Rxn as a catalyst
                            vcReaction.addCatalyst(vcSpeciesContexts[k]);
                        }
                    }
                }
                // set kinetics on VCell reaction
                if (bSpatial) {
                    // if spatial SBML ('isSpatial' attribute set), create
                    // DistributedKinetics)
                    SpatialReactionPlugin ssrplugin = (SpatialReactionPlugin) sbmlRxn.getPlugin(SBMLUtils.SBML_SPATIAL_NS_PREFIX);
                    // 'spatial'
                    if (ssrplugin != null && ssrplugin.getIsLocal()) {
                        kinetics = new GeneralKinetics(vcReaction);
                    } else {
                        kinetics = new GeneralLumpedKinetics(vcReaction);
                    }
                } else {
                    kinetics = new GeneralLumpedKinetics(vcReaction);
                }
                // set kinetics on vcReaction
                vcReaction.setKinetics(kinetics);
                // If the name of the rate parameter has been changed by
                // user, or matches with global/local param,
                // it has to be changed.
                resolveRxnParameterNameConflicts(sbmlRxn, kinetics, sbmlImportRelatedElement);
                /**
                 * Now, based on the kinetic law expression, see if the rate
                 * is expressed in concentration/time or substance/time : If
                 * the compartment_id of the compartment corresponding to
                 * the structure in which the reaction takes place occurs in
                 * the rate law expression, it is in concentration/time;
                 * divide it by the compartment size and bring in the rate
                 * law as 'Distributed' kinetics. If not, the rate law is in
                 * substance/time; bring it in (as is) as 'Lumped' kinetics.
                 */
                ListOf<LocalParameter> localParameters = kLaw.getListOfLocalParameters();
                for (LocalParameter p : localParameters) {
                    String paramName = p.getId();
                    KineticsParameter kineticsParameter = kinetics.getKineticsParameter(paramName);
                    if (kineticsParameter == null) {
                        // add unresolved for now to prevent errors in kinetics.setParameterValue(kp,vcRateExpression) below
                        kinetics.addUnresolvedParameter(paramName);
                    }
                }
                KineticsParameter kp = kinetics.getAuthoritativeParameter();
                if (lg.isDebugEnabled()) {
                    lg.debug("Setting " + kp.getName() + ":  " + vcRateExpression.infix());
                }
                kinetics.setParameterValue(kp, vcRateExpression);
                // If there are any global parameters used in the kinetics,
                // and if they have species,
                // check if the species are already reactionParticipants in
                // the reaction. If not, add them as catalysts.
                KineticsProxyParameter[] kpps = kinetics.getProxyParameters();
                for (int j = 0; j < kpps.length; j++) {
                    if (kpps[j].getTarget() instanceof ModelParameter) {
                        ModelParameter mp = (ModelParameter) kpps[j].getTarget();
                        HashSet<String> refSpeciesNameHash = new HashSet<String>();
                        getReferencedSpeciesInExpr(mp.getExpression(), refSpeciesNameHash);
                        java.util.Iterator<String> refSpIterator = refSpeciesNameHash.iterator();
                        while (refSpIterator.hasNext()) {
                            String spName = refSpIterator.next();
                            org.sbml.jsbml.Species sp = sbmlModel.getSpecies(spName);
                            ArrayList<ReactionParticipant> rpArray = getVCReactionParticipantsFromSymbol(vcReaction, sp.getId());
                            if (rpArray == null || rpArray.size() == 0) {
                                // This means that the speciesContext is not
                                // a reactant, product or modifier : it has
                                // to be added as a catalyst
                                vcReaction.addCatalyst(vcModel.getSpeciesContext(sp.getId()));
                            }
                        }
                    }
                }
                // model - local params cannot be defined by rules.
                for (LocalParameter param : localParameters) {
                    String paramName = param.getId();
                    Expression exp = new Expression(param.getValue());
                    String unitString = param.getUnits();
                    VCUnitDefinition paramUnit = sbmlUnitIdentifierHash.get(unitString);
                    if (paramUnit == null) {
                        paramUnit = vcModelUnitSystem.getInstance_TBD();
                    }
                    // check if sbml local param is in kinetic params list;
                    // if so, add its value.
                    boolean lpSet = false;
                    KineticsParameter kineticsParameter = kinetics.getKineticsParameter(paramName);
                    if (kineticsParameter != null) {
                        if (lg.isDebugEnabled()) {
                            lg.debug("Setting local " + kineticsParameter.getName() + ":  " + exp.infix());
                        }
                        kineticsParameter.setExpression(exp);
                        kineticsParameter.setUnitDefinition(paramUnit);
                        lpSet = true;
                    } else {
                        UnresolvedParameter ur = kinetics.getUnresolvedParameter(paramName);
                        if (ur != null) {
                            kinetics.addUserDefinedKineticsParameter(paramName, exp, paramUnit);
                            lpSet = true;
                        }
                    }
                    if (!lpSet) {
                        // check if it is a proxy parameter (specifically,
                        // speciesContext or model parameter (structureSize
                        // too)).
                        KineticsProxyParameter kpp = kinetics.getProxyParameter(paramName);
                        // and units to local param values
                        if (kpp != null && kpp.getTarget() instanceof ModelParameter) {
                            kinetics.convertParameterType(kpp, false);
                            kineticsParameter = kinetics.getKineticsParameter(paramName);
                            kinetics.setParameterValue(kineticsParameter, exp);
                            kineticsParameter.setUnitDefinition(paramUnit);
                        }
                    }
                }
            } else {
                // sbmlKLaw was null, so creating a GeneralKinetics with 0.0
                // as rate.
                kinetics = new GeneralKinetics(vcReaction);
            }
            // end - if-else KLaw != null
            // set the reaction kinetics, and add reaction to the vcell
            // model.
            kinetics.resolveUndefinedUnits();
            // System.out.println("ADDED SBML REACTION : \"" + rxnName +
            // "\" to VCModel");
            vcReactionList.add(vcReaction);
            if (sbmlRxn.isSetFast() && sbmlRxn.getFast()) {
                fastReactionList.add(vcReaction);
            }
        }
        // end - for vcReactions
        ReactionStep[] array = vcReactionList.toArray(new ReactionStep[vcReactionList.size()]);
        vcModel.setReactionSteps(array);
        final ReactionContext rc = vcBioModel.getSimulationContext(0).getReactionContext();
        for (ReactionStep frs : fastReactionList) {
            final ReactionSpec rs = rc.getReactionSpec(frs);
            rs.setReactionMapping(ReactionSpec.FAST);
        }
    } catch (ModelPropertyVetoException mpve) {
        throw new SBMLImportException(mpve.getMessage(), mpve);
    } catch (Exception e1) {
        e1.printStackTrace(System.out);
        throw new SBMLImportException(e1.getMessage(), e1);
    }
}
Also used : Issue(org.vcell.util.Issue) ArrayList(java.util.ArrayList) FluxReaction(cbit.vcell.model.FluxReaction) SpeciesContext(cbit.vcell.model.SpeciesContext) GeneralKinetics(cbit.vcell.model.GeneralKinetics) KineticsParameter(cbit.vcell.model.Kinetics.KineticsParameter) ReactionContext(cbit.vcell.mapping.ReactionContext) HashSet(java.util.HashSet) KineticsProxyParameter(cbit.vcell.model.Kinetics.KineticsProxyParameter) ReactionSpec(cbit.vcell.mapping.ReactionSpec) ModelPropertyVetoException(cbit.vcell.model.ModelPropertyVetoException) ModelParameter(cbit.vcell.model.Model.ModelParameter) VCUnitDefinition(cbit.vcell.units.VCUnitDefinition) ReactionStep(cbit.vcell.model.ReactionStep) Kinetics(cbit.vcell.model.Kinetics) GeneralKinetics(cbit.vcell.model.GeneralKinetics) GeneralLumpedKinetics(cbit.vcell.model.GeneralLumpedKinetics) KineticLaw(org.sbml.jsbml.KineticLaw) ReactionParticipant(cbit.vcell.model.ReactionParticipant) Element(org.jdom.Element) UnresolvedParameter(cbit.vcell.model.Kinetics.UnresolvedParameter) GeneralLumpedKinetics(cbit.vcell.model.GeneralLumpedKinetics) ASTNode(org.sbml.jsbml.ASTNode) Membrane(cbit.vcell.model.Membrane) Structure(cbit.vcell.model.Structure) ModelUnitSystem(cbit.vcell.model.ModelUnitSystem) SpatialReactionPlugin(org.sbml.jsbml.ext.spatial.SpatialReactionPlugin) SimpleReaction(cbit.vcell.model.SimpleReaction) Reaction(org.sbml.jsbml.Reaction) SimpleReaction(cbit.vcell.model.SimpleReaction) FluxReaction(cbit.vcell.model.FluxReaction) InteriorPoint(org.sbml.jsbml.ext.spatial.InteriorPoint) XMLStreamException(javax.xml.stream.XMLStreamException) SbmlException(org.vcell.sbml.SbmlException) IOException(java.io.IOException) PropertyVetoException(java.beans.PropertyVetoException) SBMLException(org.sbml.jsbml.SBMLException) ModelPropertyVetoException(cbit.vcell.model.ModelPropertyVetoException) ExpressionException(cbit.vcell.parser.ExpressionException) LocalParameter(org.sbml.jsbml.LocalParameter) Expression(cbit.vcell.parser.Expression) Model(cbit.vcell.model.Model) BioModel(cbit.vcell.biomodel.BioModel)

Example 2 with UnresolvedParameter

use of cbit.vcell.model.Kinetics.UnresolvedParameter in project vcell by virtualcell.

the class BioModelParametersTableModel method propertyChange.

@Override
public void propertyChange(java.beans.PropertyChangeEvent evt) {
    super.propertyChange(evt);
    if (evt.getSource() instanceof EditableSymbolTableEntry) {
        int changeRow = getRowIndex((EditableSymbolTableEntry) evt.getSource());
        if (changeRow >= 0) {
            fireTableRowsUpdated(changeRow, changeRow);
        }
    } else {
        String propertyName = evt.getPropertyName();
        if (evt.getSource() == bioModel.getModel()) {
            if (propertyName.equals(Model.PROPERTY_NAME_MODEL_PARAMETERS)) {
                ModelParameter[] oldValue = (ModelParameter[]) evt.getOldValue();
                if (oldValue != null) {
                    for (EditableSymbolTableEntry parameter : oldValue) {
                        parameter.removePropertyChangeListener(this);
                    }
                }
                ModelParameter[] newValue = (ModelParameter[]) evt.getNewValue();
                if (newValue != null) {
                    for (EditableSymbolTableEntry parameter : newValue) {
                        parameter.addPropertyChangeListener(this);
                    }
                }
                refreshData();
            } else if (propertyName.equals(Model.PROPERTY_NAME_SPECIES_CONTEXTS)) {
                SpeciesContext[] oldValue = (SpeciesContext[]) evt.getOldValue();
                if (oldValue != null) {
                    for (SpeciesContext sc : oldValue) {
                        sc.removePropertyChangeListener(this);
                    }
                }
                SpeciesContext[] newValue = (SpeciesContext[]) evt.getNewValue();
                if (newValue != null) {
                    for (SpeciesContext sc : newValue) {
                        sc.addPropertyChangeListener(this);
                    }
                }
                refreshData();
            } else if (propertyName.equals(Model.PROPERTY_NAME_REACTION_STEPS)) {
                ReactionStep[] oldValue = (ReactionStep[]) evt.getOldValue();
                if (oldValue != null) {
                    for (ReactionStep reactionStep : oldValue) {
                        reactionStep.removePropertyChangeListener(this);
                        reactionStep.getKinetics().removePropertyChangeListener(this);
                        for (KineticsParameter kineticsEditableSymbolTableEntry : reactionStep.getKinetics().getKineticsParameters()) {
                            kineticsEditableSymbolTableEntry.removePropertyChangeListener(this);
                        }
                        for (ProxyParameter proxyEditableSymbolTableEntry : reactionStep.getKinetics().getProxyParameters()) {
                            proxyEditableSymbolTableEntry.removePropertyChangeListener(this);
                        }
                        for (UnresolvedParameter unresolvedEditableSymbolTableEntry : reactionStep.getKinetics().getUnresolvedParameters()) {
                            unresolvedEditableSymbolTableEntry.removePropertyChangeListener(this);
                        }
                    }
                }
                ReactionStep[] newValue = (ReactionStep[]) evt.getNewValue();
                if (newValue != null) {
                    for (ReactionStep reactionStep : newValue) {
                        reactionStep.addPropertyChangeListener(this);
                        reactionStep.getKinetics().addPropertyChangeListener(this);
                        for (KineticsParameter kineticsEditableSymbolTableEntry : reactionStep.getKinetics().getKineticsParameters()) {
                            kineticsEditableSymbolTableEntry.addPropertyChangeListener(this);
                        }
                        for (ProxyParameter proxyEditableSymbolTableEntry : reactionStep.getKinetics().getProxyParameters()) {
                            proxyEditableSymbolTableEntry.addPropertyChangeListener(this);
                        }
                        for (UnresolvedParameter unresolvedEditableSymbolTableEntry : reactionStep.getKinetics().getUnresolvedParameters()) {
                            unresolvedEditableSymbolTableEntry.addPropertyChangeListener(this);
                        }
                    }
                }
                refreshData();
            } else if (evt.getPropertyName().equals(RbmModelContainer.PROPERTY_NAME_REACTION_RULE_LIST)) {
                List<ReactionRule> oldValue = (List<ReactionRule>) evt.getOldValue();
                if (oldValue != null) {
                    for (ReactionRule rs : oldValue) {
                        rs.removePropertyChangeListener(this);
                    }
                }
                List<ReactionRule> newValue = (List<ReactionRule>) evt.getNewValue();
                if (newValue != null) {
                    for (ReactionRule rs : newValue) {
                        rs.addPropertyChangeListener(this);
                    }
                }
                refreshData();
            }
        } else if (evt.getSource() == bioModel) {
            if (propertyName.equals(BioModel.PROPERTY_NAME_SIMULATION_CONTEXTS)) {
                SimulationContext[] oldValue = (SimulationContext[]) evt.getOldValue();
                for (SimulationContext simulationContext : oldValue) {
                    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);
                    }
                }
                SimulationContext[] newValue = (SimulationContext[]) evt.getNewValue();
                for (SimulationContext simulationContext : newValue) {
                    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);
                    }
                }
                refreshData();
            }
        } else if (evt.getSource() instanceof GeometryContext && evt.getPropertyName().equals(GeometryContext.PROPERTY_STRUCTURE_MAPPINGS)) {
            StructureMapping[] oldValue = (StructureMapping[]) evt.getOldValue();
            if (oldValue != null) {
                for (StructureMapping mapping : oldValue) {
                    mapping.removePropertyChangeListener(this);
                    for (EditableSymbolTableEntry parameter : mapping.getParameters()) {
                        parameter.removePropertyChangeListener(this);
                    }
                }
            }
            StructureMapping[] newValue = (StructureMapping[]) evt.getNewValue();
            if (newValue != null) {
                for (StructureMapping mapping : newValue) {
                    mapping.addPropertyChangeListener(this);
                    for (EditableSymbolTableEntry parameter : mapping.getParameters()) {
                        parameter.addPropertyChangeListener(this);
                    }
                }
            }
            refreshData();
        } else if (evt.getSource() instanceof ReactionStep && (evt.getPropertyName().equals(ReactionStep.PROPERTY_NAME_KINETICS))) {
            Kinetics oldValue = (Kinetics) evt.getOldValue();
            if (oldValue != null) {
                oldValue.removePropertyChangeListener(this);
                for (KineticsParameter kineticsEditableSymbolTableEntry : oldValue.getKineticsParameters()) {
                    kineticsEditableSymbolTableEntry.removePropertyChangeListener(this);
                }
                for (ProxyParameter proxyEditableSymbolTableEntry : oldValue.getProxyParameters()) {
                    proxyEditableSymbolTableEntry.removePropertyChangeListener(this);
                }
                for (UnresolvedParameter unresolvedEditableSymbolTableEntry : oldValue.getUnresolvedParameters()) {
                    unresolvedEditableSymbolTableEntry.removePropertyChangeListener(this);
                }
            }
            Kinetics newValue = (Kinetics) evt.getNewValue();
            if (newValue != null) {
                newValue.addPropertyChangeListener(this);
                for (KineticsParameter kineticsEditableSymbolTableEntry : newValue.getKineticsParameters()) {
                    kineticsEditableSymbolTableEntry.addPropertyChangeListener(this);
                }
                for (ProxyParameter proxyEditableSymbolTableEntry : newValue.getProxyParameters()) {
                    proxyEditableSymbolTableEntry.addPropertyChangeListener(this);
                }
                for (UnresolvedParameter unresolvedEditableSymbolTableEntry : newValue.getUnresolvedParameters()) {
                    unresolvedEditableSymbolTableEntry.addPropertyChangeListener(this);
                }
            }
            refreshData();
        } else if (evt.getSource() instanceof SimulationContext && evt.getPropertyName().equals(SimulationContext.PROPERTY_NAME_SPATIALPROCESSES)) {
            SpatialProcess[] oldValue = (SpatialProcess[]) evt.getOldValue();
            if (oldValue != null) {
                for (SpatialProcess process : oldValue) {
                    process.removePropertyChangeListener(this);
                    for (EditableSymbolTableEntry parameter : process.getParameters()) {
                        parameter.removePropertyChangeListener(this);
                    }
                }
            }
            SpatialProcess[] newValue = (SpatialProcess[]) evt.getNewValue();
            if (newValue != null) {
                for (SpatialProcess process : newValue) {
                    process.addPropertyChangeListener(this);
                    for (EditableSymbolTableEntry parameter : process.getParameters()) {
                        parameter.addPropertyChangeListener(this);
                    }
                }
            }
            refreshData();
        } else if (evt.getSource() instanceof SimulationContext && evt.getPropertyName().equals(SimulationContext.PROPERTY_NAME_SPATIALOBJECTS)) {
            SpatialObject[] oldValue = (SpatialObject[]) evt.getOldValue();
            if (oldValue != null) {
                for (SpatialObject spatialObject : oldValue) {
                    spatialObject.removePropertyChangeListener(this);
                }
            }
            SpatialObject[] newValue = (SpatialObject[]) evt.getNewValue();
            if (newValue != null) {
                for (SpatialObject spatialObject : newValue) {
                    spatialObject.addPropertyChangeListener(this);
                }
            }
            refreshData();
        } else if (evt.getSource() instanceof SpatialObject && evt.getPropertyName().equals(SpatialObject.PROPERTY_NAME_QUANTITYCATEGORIESENABLED)) {
            refreshData();
        } else if (evt.getSource() instanceof SimulationContext && evt.getPropertyName().equals(SimulationContext.PROPERTY_NAME_SIMULATIONCONTEXTPARAMETERS)) {
            SimulationContextParameter[] oldValue = (SimulationContextParameter[]) evt.getOldValue();
            if (oldValue != null) {
                for (SimulationContextParameter param : oldValue) {
                    param.removePropertyChangeListener(this);
                }
            }
            SimulationContextParameter[] newValue = (SimulationContextParameter[]) evt.getNewValue();
            if (newValue != null) {
                for (SimulationContextParameter param : newValue) {
                    param.addPropertyChangeListener(this);
                }
            }
            refreshData();
        } else if (evt.getSource() instanceof Kinetics && (evt.getPropertyName().equals(Kinetics.PROPERTY_NAME_KINETICS_PARAMETERS))) {
            EditableSymbolTableEntry[] oldValue = (EditableSymbolTableEntry[]) evt.getOldValue();
            if (oldValue != null) {
                for (int i = 0; i < oldValue.length; i++) {
                    oldValue[i].removePropertyChangeListener(this);
                }
            }
            EditableSymbolTableEntry[] newValue = (EditableSymbolTableEntry[]) evt.getNewValue();
            if (newValue != null) {
                for (int i = 0; i < newValue.length; i++) {
                    newValue[i].addPropertyChangeListener(this);
                }
            }
            refreshData();
        // } else if(evt.getSource() instanceof ReactionRuleEmbedded) {
        // ReactionRuleEmbedded reactionRule = (ReactionRuleEmbedded) evt.getSource();
        // int changeRow = getRowIndex(reactionRule);
        // if (changeRow >= 0) {
        // fireTableRowsUpdated(changeRow, changeRow);
        // }
        }
    }
}
Also used : UnresolvedParameter(cbit.vcell.model.Kinetics.UnresolvedParameter) SpeciesContext(cbit.vcell.model.SpeciesContext) SpeciesContextSpec(cbit.vcell.mapping.SpeciesContextSpec) StructureMapping(cbit.vcell.mapping.StructureMapping) SpatialObject(cbit.vcell.mapping.spatial.SpatialObject) KineticsParameter(cbit.vcell.model.Kinetics.KineticsParameter) SpatialProcess(cbit.vcell.mapping.spatial.processes.SpatialProcess) ArrayList(java.util.ArrayList) List(java.util.List) GeometryContext(cbit.vcell.mapping.GeometryContext) ReactionRule(cbit.vcell.model.ReactionRule) SimulationContext(cbit.vcell.mapping.SimulationContext) SimulationContextParameter(cbit.vcell.mapping.SimulationContext.SimulationContextParameter) LocalParameter(cbit.vcell.mapping.ParameterContext.LocalParameter) ModelParameter(cbit.vcell.model.Model.ModelParameter) ElectricalStimulus(cbit.vcell.mapping.ElectricalStimulus) ProxyParameter(cbit.vcell.model.ProxyParameter) ReactionStep(cbit.vcell.model.ReactionStep) Kinetics(cbit.vcell.model.Kinetics) EditableSymbolTableEntry(cbit.vcell.model.EditableSymbolTableEntry)

Example 3 with UnresolvedParameter

use of cbit.vcell.model.Kinetics.UnresolvedParameter in project vcell by virtualcell.

the class ParameterTableModel method isCellEditable.

/**
 * Insert the method's description here.
 * Creation date: (2/24/01 12:27:46 AM)
 * @return boolean
 * @param rowIndex int
 * @param columnIndex int
 */
public boolean isCellEditable(int rowIndex, int columnIndex) {
    if (!bEditable) {
        return false;
    }
    Parameter parameter = getValueAt(rowIndex);
    if (reactionStep != null && parameter instanceof KineticsParameter) {
        KineticsParameter kp = (KineticsParameter) parameter;
        if (kp.getRole() == Kinetics.ROLE_KReverse) {
            if (!reactionStep.isReversible()) {
                // disable Kr if rule is not reversible
                return false;
            }
        }
    }
    switch(columnIndex) {
        case COLUMN_NAME:
            return parameter.isNameEditable();
        case COLUMN_DESCRIPTION:
            return false;
        case COLUMN_IS_GLOBAL:
            // if the parameter is reaction rate param or a ReservedSymbol in the model, it should not be editable
            if ((parameter instanceof KineticsParameter) && (((KineticsParameter) parameter).getRole() != Kinetics.ROLE_UserDefined)) {
                return false;
            }
            if (parameter instanceof UnresolvedParameter) {
                return false;
            }
            if (parameter instanceof KineticsProxyParameter) {
                KineticsProxyParameter kpp = (KineticsProxyParameter) parameter;
                SymbolTableEntry ste = kpp.getTarget();
                if ((ste instanceof Model.ReservedSymbol) || (ste instanceof SpeciesContext) || (ste instanceof ModelQuantity)) {
                    return false;
                }
            }
            return true;
        case COLUMN_VALUE:
            return parameter.isExpressionEditable();
        case COLUMN_UNITS:
            return parameter.isUnitEditable();
    }
    return false;
}
Also used : SymbolTableEntry(cbit.vcell.parser.SymbolTableEntry) KineticsProxyParameter(cbit.vcell.model.Kinetics.KineticsProxyParameter) KineticsParameter(cbit.vcell.model.Kinetics.KineticsParameter) ModelQuantity(cbit.vcell.model.ModelQuantity) VCellSortTableModel(cbit.vcell.client.desktop.biomodel.VCellSortTableModel) Model(cbit.vcell.model.Model) ProxyParameter(cbit.vcell.model.ProxyParameter) ModelParameter(cbit.vcell.model.Model.ModelParameter) KineticsProxyParameter(cbit.vcell.model.Kinetics.KineticsProxyParameter) Parameter(cbit.vcell.model.Parameter) KineticsParameter(cbit.vcell.model.Kinetics.KineticsParameter) UnresolvedParameter(cbit.vcell.model.Kinetics.UnresolvedParameter) UnresolvedParameter(cbit.vcell.model.Kinetics.UnresolvedParameter) SpeciesContext(cbit.vcell.model.SpeciesContext)

Example 4 with UnresolvedParameter

use of cbit.vcell.model.Kinetics.UnresolvedParameter in project vcell by virtualcell.

the class SBMLImporter method addReactions.

/**
 * addReactions:
 */
protected void addReactions(VCMetaData metaData, Map<String, String> vcToSbmlNameMap, Map<String, String> sbmlToVcNameMap) {
    if (sbmlModel == null) {
        throw new SBMLImportException("SBML model is NULL");
    }
    ListOf<Reaction> reactions = sbmlModel.getListOfReactions();
    final int numReactions = reactions.size();
    if (numReactions == 0) {
        lg.info("No Reactions");
        return;
    }
    // all reactions
    ArrayList<ReactionStep> vcReactionList = new ArrayList<>();
    // just the fast ones
    ArrayList<ReactionStep> fastReactionList = new ArrayList<>();
    Model vcModel = vcBioModel.getSimulationContext(0).getModel();
    ModelUnitSystem vcModelUnitSystem = vcModel.getUnitSystem();
    SpeciesContext[] vcSpeciesContexts = vcModel.getSpeciesContexts();
    try {
        for (Reaction sbmlRxn : reactions) {
            ReactionStep vcReaction = null;
            String rxnSbmlId = sbmlRxn.getId();
            String rxnSbmlName = sbmlRxn.getName();
            if (isRestrictedXYZT(rxnSbmlId)) {
                // simply rename any x,y,z reaction if non-spatial model
                rxnSbmlId = "r_" + rxnSbmlId;
                vcToSbmlNameMap.put(rxnSbmlId, sbmlRxn.getId());
                sbmlToVcNameMap.put(sbmlRxn.getId(), rxnSbmlId);
            }
            boolean bReversible = true;
            if (sbmlRxn.isSetReversible()) {
                bReversible = sbmlRxn.getReversible();
            }
            // Check of reaction annotation is present; if so, does it have
            // an embedded element (flux or simpleRxn).
            // Create a fluxReaction or simpleReaction accordingly.
            Element sbmlImportRelatedElement = sbmlAnnotationUtil.readVCellSpecificAnnotation(sbmlRxn);
            Structure reactionStructure = getReactionStructure(sbmlRxn, vcSpeciesContexts, sbmlImportRelatedElement);
            if (sbmlImportRelatedElement != null) {
                Element embeddedRxnElement = getEmbeddedElementInAnnotation(sbmlImportRelatedElement, REACTION);
                if (embeddedRxnElement != null) {
                    if (embeddedRxnElement.getName().equals(XMLTags.FluxStepTag)) {
                        // If embedded element is a flux reaction, set flux
                        // reaction's strucure, flux carrier, physicsOption
                        // from the element attributes.
                        String structName = embeddedRxnElement.getAttributeValue(XMLTags.StructureAttrTag);
                        CastInfo<Membrane> ci = SBMLHelper.getTypedStructure(Membrane.class, vcModel, structName);
                        if (!ci.isGood()) {
                            throw new SBMLImportException("Appears that the flux reaction is occuring on " + ci.actualName() + ", not a membrane.");
                        }
                        vcReaction = new FluxReaction(vcModel, ci.get(), null, rxnSbmlId, bReversible);
                        vcReaction.setModel(vcModel);
                        // Set the fluxOption on the flux reaction based on
                        // whether it is molecular, molecular & electrical,
                        // electrical.
                        String fluxOptionStr = embeddedRxnElement.getAttributeValue(XMLTags.FluxOptionAttrTag);
                        if (fluxOptionStr.equals(XMLTags.FluxOptionMolecularOnly)) {
                            ((FluxReaction) vcReaction).setPhysicsOptions(ReactionStep.PHYSICS_MOLECULAR_ONLY);
                        } else if (fluxOptionStr.equals(XMLTags.FluxOptionMolecularAndElectrical)) {
                            ((FluxReaction) vcReaction).setPhysicsOptions(ReactionStep.PHYSICS_MOLECULAR_AND_ELECTRICAL);
                        } else if (fluxOptionStr.equals(XMLTags.FluxOptionElectricalOnly)) {
                            ((FluxReaction) vcReaction).setPhysicsOptions(ReactionStep.PHYSICS_ELECTRICAL_ONLY);
                        } else {
                            localIssueList.add(new Issue(vcReaction, issueContext, IssueCategory.SBMLImport_Reaction, "Unknown FluxOption : " + fluxOptionStr + " for SBML reaction : " + rxnSbmlId, Issue.SEVERITY_WARNING));
                        // logger.sendMessage(VCLogger.Priority.MediumPriority,
                        // VCLogger.ErrorType.ReactionError,
                        // "Unknown FluxOption : " + fluxOptionStr +
                        // " for SBML reaction : " + rxnName);
                        }
                    } else if (embeddedRxnElement.getName().equals(XMLTags.SimpleReactionTag)) {
                        // if embedded element is a simple reaction, set
                        // simple reaction's structure from element attributes
                        vcReaction = new SimpleReaction(vcModel, reactionStructure, rxnSbmlId, bReversible);
                    }
                } else {
                    vcReaction = new SimpleReaction(vcModel, reactionStructure, rxnSbmlId, bReversible);
                }
            } else {
                vcReaction = new SimpleReaction(vcModel, reactionStructure, rxnSbmlId, bReversible);
            }
            if (rxnSbmlName != null && !rxnSbmlName.isEmpty()) {
                vcReaction.setSbmlName(rxnSbmlName);
            }
            // set annotations and notes on vcReactions[i]
            sbmlAnnotationUtil.readAnnotation(vcReaction, sbmlRxn);
            sbmlAnnotationUtil.readNotes(vcReaction, sbmlRxn);
            // the limit on the reactionName length.
            if (rxnSbmlId.length() > 64) {
                String freeTextAnnotation = metaData.getFreeTextAnnotation(vcReaction);
                if (freeTextAnnotation == null) {
                    freeTextAnnotation = "";
                }
                StringBuffer oldRxnAnnotation = new StringBuffer(freeTextAnnotation);
                oldRxnAnnotation.append("\n\n" + rxnSbmlId);
                metaData.setFreeTextAnnotation(vcReaction, oldRxnAnnotation.toString());
            }
            // Now add the reactants, products, modifiers as specified by
            // the sbmlRxn
            addReactionParticipants(sbmlRxn, vcReaction, sbmlToVcNameMap);
            KineticLaw kLaw = sbmlRxn.getKineticLaw();
            Kinetics kinetics = null;
            if (kLaw != null) {
                // Convert the formula from kineticLaw into MathML and then
                // to an expression (infix) to be used in VCell kinetics
                ASTNode sbmlRateMath = kLaw.getMath();
                Expression kLawRateExpr = getExpressionFromFormula(sbmlRateMath);
                // we don't need to make sure it's not spatial here, we checked before renaming the variables
                for (Map.Entry<String, String> entry : sbmlToVcNameMap.entrySet()) {
                    String sbmlName = entry.getKey();
                    String vcName = entry.getValue();
                    kLawRateExpr.substituteInPlace(new Expression(sbmlName), new Expression(vcName));
                }
                Expression vcRateExpression = new Expression(kLawRateExpr);
                // modifier (catalyst) to the reaction.
                for (int k = 0; k < vcSpeciesContexts.length; k++) {
                    SpeciesContext sc = vcSpeciesContexts[k];
                    if (vcRateExpression.hasSymbol(sc.getName())) {
                        ReactionParticipant r = vcReaction.getReactant(sc.getName());
                        ReactionParticipant p = vcReaction.getProduct(sc.getName());
                        ReactionParticipant c = vcReaction.getCatalyst(sc.getName());
                        if ((r == null) && (p == null) && (c == null)) {
                            // This means that the speciesContext is not a
                            // reactant, product or modifier : it has to be
                            // added to the VC Rxn as a catalyst
                            vcReaction.addCatalyst(sc);
                        }
                    }
                }
                // set kinetics on VCell reaction
                if (bSpatial) {
                    // if spatial SBML ('isSpatial' attribute set), create
                    // DistributedKinetics)
                    SpatialReactionPlugin ssrplugin = (SpatialReactionPlugin) sbmlRxn.getPlugin(SBMLUtils.SBML_SPATIAL_NS_PREFIX);
                    // (a) the requiredElements attributes should be 'spatial'
                    if (ssrplugin != null && ssrplugin.getIsLocal()) {
                        kinetics = new GeneralKinetics(vcReaction);
                    } else {
                        kinetics = new GeneralLumpedKinetics(vcReaction);
                    }
                } else {
                    kinetics = new GeneralLumpedKinetics(vcReaction);
                }
                // set kinetics on vcReaction
                vcReaction.setKinetics(kinetics);
                // If the name of the rate parameter has been changed by
                // user, or matches with global/local param, it has to be changed.
                resolveRxnParameterNameConflicts(sbmlRxn, kinetics, sbmlImportRelatedElement);
                /**
                 * Now, based on the kinetic law expression, see if the rate
                 * is expressed in concentration/time or substance/time : If
                 * the compartment_id of the compartment corresponding to
                 * the structure in which the reaction takes place occurs in
                 * the rate law expression, it is in concentration/time;
                 * divide it by the compartment size and bring in the rate
                 * law as 'Distributed' kinetics. If not, the rate law is in
                 * substance/time; bring it in (as is) as 'Lumped' kinetics.
                 */
                ListOf<LocalParameter> localParameters = kLaw.getListOfLocalParameters();
                for (LocalParameter p : localParameters) {
                    String paramName = p.getId();
                    KineticsParameter kineticsParameter = kinetics.getKineticsParameter(paramName);
                    if (kineticsParameter == null) {
                        // add unresolved for now to prevent errors in kinetics.setParameterValue(kp,vcRateExpression) below
                        kinetics.addUnresolvedParameter(paramName);
                    }
                }
                KineticsParameter kp = kinetics.getAuthoritativeParameter();
                if (lg.isDebugEnabled()) {
                    lg.debug("Setting " + kp.getName() + ":  " + vcRateExpression.infix());
                }
                kinetics.setParameterValue(kp, vcRateExpression);
                // If there are any global parameters used in the kinetics,
                // and if they have species,
                // check if the species are already reactionParticipants in
                // the reaction. If not, add them as catalysts.
                KineticsProxyParameter[] kpps = kinetics.getProxyParameters();
                for (int j = 0; j < kpps.length; j++) {
                    if (kpps[j].getTarget() instanceof ModelParameter) {
                        ModelParameter mp = (ModelParameter) kpps[j].getTarget();
                        HashSet<String> refSpeciesNameHash = new HashSet<String>();
                        getReferencedSpeciesInExpr(mp.getExpression(), refSpeciesNameHash);
                        java.util.Iterator<String> refSpIterator = refSpeciesNameHash.iterator();
                        while (refSpIterator.hasNext()) {
                            String spName = refSpIterator.next();
                            org.sbml.jsbml.Species sp = sbmlModel.getSpecies(spName);
                            String spId = sp.getId();
                            String vcSpeciesName = spId;
                            if (sbmlToVcNameMap.get(spId) != null) {
                                vcSpeciesName = sbmlToVcNameMap.get(spId);
                            }
                            ArrayList<ReactionParticipant> rpArray = getVCReactionParticipantsFromSymbol(vcReaction, vcSpeciesName);
                            if (rpArray == null || rpArray.size() == 0) {
                                // This means that the speciesContext is not a reactant,
                                // product or modifier : it has to be added as a catalyst
                                vcReaction.addCatalyst(vcModel.getSpeciesContext(vcSpeciesName));
                            }
                        }
                    }
                }
                // model - local params cannot be defined by rules.
                for (LocalParameter param : localParameters) {
                    String paramName = param.getId();
                    Expression exp = new Expression(param.getValue());
                    String unitString = param.getUnits();
                    VCUnitDefinition paramUnit = sbmlUnitIdentifierHash.get(unitString);
                    if (paramUnit == null) {
                        paramUnit = vcModelUnitSystem.getInstance_TBD();
                    }
                    // check if sbml local param is in kinetic params list;
                    // if so, add its value.
                    boolean lpSet = false;
                    KineticsParameter kineticsParameter = kinetics.getKineticsParameter(paramName);
                    if (kineticsParameter != null) {
                        if (lg.isDebugEnabled()) {
                            lg.debug("Setting local " + kineticsParameter.getName() + ":  " + exp.infix());
                        }
                        kineticsParameter.setExpression(exp);
                        kineticsParameter.setUnitDefinition(paramUnit);
                        lpSet = true;
                    } else {
                        UnresolvedParameter ur = kinetics.getUnresolvedParameter(paramName);
                        if (ur != null) {
                            kinetics.addUserDefinedKineticsParameter(paramName, exp, paramUnit);
                            lpSet = true;
                        }
                    }
                    if (!lpSet) {
                        // check if it is a proxy parameter (specifically,
                        // speciesContext or model parameter (structureSize
                        // too)).
                        KineticsProxyParameter kpp = kinetics.getProxyParameter(paramName);
                        // and units to local param values
                        if (kpp != null && kpp.getTarget() instanceof ModelParameter) {
                            kinetics.convertParameterType(kpp, false);
                            kineticsParameter = kinetics.getKineticsParameter(paramName);
                            kinetics.setParameterValue(kineticsParameter, exp);
                            kineticsParameter.setUnitDefinition(paramUnit);
                        }
                    }
                }
            } else {
                // sbmlKLaw was null, so creating a GeneralKinetics with 0.0
                // as rate.
                kinetics = new GeneralKinetics(vcReaction);
            }
            // end - if-else KLaw != null
            // set the reaction kinetics, and add reaction to the vcell
            // model.
            kinetics.resolveUndefinedUnits();
            // System.out.println("ADDED SBML REACTION : \"" + rxnName +
            // "\" to VCModel");
            vcReactionList.add(vcReaction);
            if (sbmlRxn.isSetFast() && sbmlRxn.getFast()) {
                fastReactionList.add(vcReaction);
            }
        }
        // end - for vcReactions
        ReactionStep[] array = vcReactionList.toArray(new ReactionStep[vcReactionList.size()]);
        vcModel.setReactionSteps(array);
        final ReactionContext rc = vcBioModel.getSimulationContext(0).getReactionContext();
        for (ReactionStep frs : fastReactionList) {
            final ReactionSpec rs = rc.getReactionSpec(frs);
            rs.setReactionMapping(ReactionSpec.FAST);
        }
    } catch (ModelPropertyVetoException mpve) {
        throw new SBMLImportException(mpve.getMessage(), mpve);
    } catch (Exception e1) {
        e1.printStackTrace(System.out);
        throw new SBMLImportException(e1.getMessage(), e1);
    }
}
Also used : Issue(org.vcell.util.Issue) ArrayList(java.util.ArrayList) FluxReaction(cbit.vcell.model.FluxReaction) SpeciesContext(cbit.vcell.model.SpeciesContext) GeneralKinetics(cbit.vcell.model.GeneralKinetics) KineticsParameter(cbit.vcell.model.Kinetics.KineticsParameter) ReactionContext(cbit.vcell.mapping.ReactionContext) HashSet(java.util.HashSet) KineticsProxyParameter(cbit.vcell.model.Kinetics.KineticsProxyParameter) ReactionSpec(cbit.vcell.mapping.ReactionSpec) ModelPropertyVetoException(cbit.vcell.model.ModelPropertyVetoException) ModelParameter(cbit.vcell.model.Model.ModelParameter) VCUnitDefinition(cbit.vcell.units.VCUnitDefinition) ReactionStep(cbit.vcell.model.ReactionStep) Kinetics(cbit.vcell.model.Kinetics) DistributedKinetics(cbit.vcell.model.DistributedKinetics) GeneralKinetics(cbit.vcell.model.GeneralKinetics) GeneralLumpedKinetics(cbit.vcell.model.GeneralLumpedKinetics) LumpedKinetics(cbit.vcell.model.LumpedKinetics) KineticLaw(org.sbml.jsbml.KineticLaw) Map(java.util.Map) HashMap(java.util.HashMap) ReactionParticipant(cbit.vcell.model.ReactionParticipant) Element(org.jdom.Element) UnresolvedParameter(cbit.vcell.model.Kinetics.UnresolvedParameter) GeneralLumpedKinetics(cbit.vcell.model.GeneralLumpedKinetics) ASTNode(org.sbml.jsbml.ASTNode) Membrane(cbit.vcell.model.Membrane) Structure(cbit.vcell.model.Structure) ModelUnitSystem(cbit.vcell.model.ModelUnitSystem) SpatialReactionPlugin(org.sbml.jsbml.ext.spatial.SpatialReactionPlugin) SimpleReaction(cbit.vcell.model.SimpleReaction) Reaction(org.sbml.jsbml.Reaction) SimpleReaction(cbit.vcell.model.SimpleReaction) FluxReaction(cbit.vcell.model.FluxReaction) InteriorPoint(org.sbml.jsbml.ext.spatial.InteriorPoint) XMLStreamException(javax.xml.stream.XMLStreamException) SbmlException(org.vcell.sbml.SbmlException) XmlParseException(cbit.vcell.xml.XmlParseException) IOException(java.io.IOException) PropertyVetoException(java.beans.PropertyVetoException) DivideByZeroException(cbit.vcell.parser.DivideByZeroException) SBMLException(org.sbml.jsbml.SBMLException) ExpressionBindingException(cbit.vcell.parser.ExpressionBindingException) ModelPropertyVetoException(cbit.vcell.model.ModelPropertyVetoException) ExpressionException(cbit.vcell.parser.ExpressionException) LocalParameter(org.sbml.jsbml.LocalParameter) Expression(cbit.vcell.parser.Expression) Model(cbit.vcell.model.Model) BioModel(cbit.vcell.biomodel.BioModel)

Example 5 with UnresolvedParameter

use of cbit.vcell.model.Kinetics.UnresolvedParameter 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)

Aggregations

KineticsParameter (cbit.vcell.model.Kinetics.KineticsParameter)5 UnresolvedParameter (cbit.vcell.model.Kinetics.UnresolvedParameter)5 ModelParameter (cbit.vcell.model.Model.ModelParameter)5 SpeciesContext (cbit.vcell.model.SpeciesContext)5 Kinetics (cbit.vcell.model.Kinetics)4 ReactionStep (cbit.vcell.model.ReactionStep)4 BioModel (cbit.vcell.biomodel.BioModel)3 KineticsProxyParameter (cbit.vcell.model.Kinetics.KineticsProxyParameter)3 Model (cbit.vcell.model.Model)3 ProxyParameter (cbit.vcell.model.ProxyParameter)3 ArrayList (java.util.ArrayList)3 ReactionContext (cbit.vcell.mapping.ReactionContext)2 ReactionSpec (cbit.vcell.mapping.ReactionSpec)2 FluxReaction (cbit.vcell.model.FluxReaction)2 GeneralKinetics (cbit.vcell.model.GeneralKinetics)2 GeneralLumpedKinetics (cbit.vcell.model.GeneralLumpedKinetics)2 Membrane (cbit.vcell.model.Membrane)2 ModelPropertyVetoException (cbit.vcell.model.ModelPropertyVetoException)2 ModelUnitSystem (cbit.vcell.model.ModelUnitSystem)2 ReactionParticipant (cbit.vcell.model.ReactionParticipant)2