Search in sources :

Example 1 with ModelQuantity

use of cbit.vcell.model.ModelQuantity 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) 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 2 with ModelQuantity

use of cbit.vcell.model.ModelQuantity in project vcell by virtualcell.

the class ReactionRulePropertiesTableModel 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;
    }
    Object o = getValueAt(rowIndex);
    if (!(o instanceof Parameter)) {
        return false;
    }
    Parameter parameter = (Parameter) o;
    if (reactionRule != null && reactionRule.getKineticLaw().getLocalParameter(RbmKineticLawParameterType.MassActionReverseRate) == parameter) {
        if (!reactionRule.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 LocalParameter) && (((LocalParameter) parameter).getRole() != RbmKineticLaw.RbmKineticLawParameterType.UserDefined)) {
                return false;
            }
            if (parameter instanceof UnresolvedParameter) {
                return false;
            }
            if (parameter instanceof LocalProxyParameter) {
                LocalProxyParameter kpp = (LocalProxyParameter) 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 : LocalParameter(cbit.vcell.mapping.ParameterContext.LocalParameter) LocalProxyParameter(cbit.vcell.mapping.ParameterContext.LocalProxyParameter) SymbolTableEntry(cbit.vcell.parser.SymbolTableEntry) ModelQuantity(cbit.vcell.model.ModelQuantity) Model(cbit.vcell.model.Model) LocalParameter(cbit.vcell.mapping.ParameterContext.LocalParameter) ModelParameter(cbit.vcell.model.Model.ModelParameter) Parameter(cbit.vcell.model.Parameter) LocalProxyParameter(cbit.vcell.mapping.ParameterContext.LocalProxyParameter) UnresolvedParameter(cbit.vcell.mapping.ParameterContext.UnresolvedParameter) UnresolvedParameter(cbit.vcell.mapping.ParameterContext.UnresolvedParameter) SpeciesContext(cbit.vcell.model.SpeciesContext)

Example 3 with ModelQuantity

use of cbit.vcell.model.ModelQuantity in project vcell by virtualcell.

the class ReactionRulePropertiesTableModel method setValueAt.

public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
    Object o = getValueAt(rowIndex);
    if (!(o instanceof Parameter)) {
        return;
    }
    Parameter parameter = (Parameter) o;
    // try {
    switch(columnIndex) {
        case COLUMN_NAME:
            {
                try {
                    if (aValue instanceof String) {
                        String newName = (String) aValue;
                        if (!parameter.getName().equals(newName)) {
                            if (parameter instanceof LocalParameter) {
                                reactionRule.getKineticLaw().renameParameter(parameter.getName(), newName);
                            } else if (parameter instanceof LocalProxyParameter) {
                                parameter.setName(newName);
                            }
                            fireTableRowsUpdated(rowIndex, rowIndex);
                        }
                    }
                } catch (ExpressionException e) {
                    e.printStackTrace(System.out);
                    PopupGenerator.showErrorDialog(ownerTable, "Error changing parameter name:\n" + e.getMessage());
                } catch (PropertyVetoException e) {
                    e.printStackTrace(System.out);
                    PopupGenerator.showErrorDialog(ownerTable, "Error changing parameter name:\n" + e.getMessage());
                }
                break;
            }
        case COLUMN_IS_GLOBAL:
            {
                if (aValue.equals(Boolean.FALSE)) {
                    // check box has been <unset> (<true> to <false>) : change param from global to local
                    if ((parameter instanceof LocalProxyParameter) && ((((LocalProxyParameter) parameter).getTarget() instanceof Model.ReservedSymbol) || (((LocalProxyParameter) parameter).getTarget() instanceof SpeciesContext) || (((LocalProxyParameter) parameter).getTarget() instanceof ModelQuantity))) {
                        PopupGenerator.showErrorDialog(ownerTable, "Parameter : \'" + parameter.getName() + "\' is a " + ((LocalProxyParameter) parameter).getTarget().getClass() + " in the model; cannot convert it to a local kinetic parameter.");
                    } else {
                        try {
                            reactionRule.getKineticLaw().convertParameterType(parameter, false);
                        } catch (PropertyVetoException pve) {
                            pve.printStackTrace(System.out);
                            PopupGenerator.showErrorDialog(ownerTable, "Unable to convert parameter : \'" + parameter.getName() + "\' to local kinetics parameter : " + pve.getMessage());
                        } catch (ExpressionBindingException e) {
                            e.printStackTrace(System.out);
                            PopupGenerator.showErrorDialog(ownerTable, "Unable to convert parameter : \'" + parameter.getName() + "\' to local kinetics parameter : " + e.getMessage());
                        }
                    }
                } else {
                    // check box has been <set> (<false> to <true>) : change param from local to global
                    if ((parameter instanceof LocalParameter) && (((LocalParameter) parameter).getRole() != RbmKineticLaw.RbmKineticLawParameterType.UserDefined)) {
                        PopupGenerator.showErrorDialog(ownerTable, "Parameter : \'" + parameter.getName() + "\' is a pre-defined kinetics parameter (not user-defined); cannot convert it to a model level (global) parameter.");
                    } else {
                        ModelParameter mp = reactionRule.getModel().getModelParameter(parameter.getName());
                        // model already had the model parameter 'param', but check if 'param' value is different from
                        // model parameter with same name. If it is, the local value will be overridden by global (model) param
                        // value, and user should be warned.
                        String choice = "Ok";
                        if (mp != null && !(mp.getExpression().compareEqual(parameter.getExpression()))) {
                            String msgStr = "Model already has a global parameter named : \'" + parameter.getName() + "\'; with value = \'" + mp.getExpression().infix() + "\'; This local parameter \'" + parameter.getName() + "\' with value = \'" + parameter.getExpression().infix() + "\' will be overridden by the global value. \nPress \'Ok' to override " + "local value with global value of \'" + parameter.getName() + "\'. \nPress \'Cancel\' to retain new local value.";
                            choice = PopupGenerator.showWarningDialog(ownerTable, msgStr, new String[] { "Ok", "Cancel" }, "Ok");
                        }
                        if (choice.equals("Ok")) {
                            try {
                                // Now 'parameter' is a local kinetic parameter. If it is not numeric, and if its expression
                                // contains other local kinetic parameters, warn user that 'parameter' cannot be promoted because
                                // of its expression containing other local parameters.
                                boolean bPromoteable = true;
                                if (!parameter.getExpression().isNumeric()) {
                                    String[] symbols = parameter.getExpression().getSymbols();
                                    for (int i = 0; i < symbols.length; i++) {
                                        if (reactionRule.getKineticLaw().getLocalParameter(symbols[i]) != null) {
                                            PopupGenerator.showErrorDialog(ownerTable, "Parameter \'" + parameter.getName() + "\' contains other local kinetic parameters; Cannot convert it to global until the referenced parameters are global.");
                                            bPromoteable = false;
                                        }
                                    }
                                }
                                if (bPromoteable) {
                                    reactionRule.getKineticLaw().convertParameterType(parameter, true);
                                }
                            } catch (PropertyVetoException pve) {
                                pve.printStackTrace(System.out);
                                PopupGenerator.showErrorDialog(ownerTable, "Cannot convert parameter \'" + parameter.getName() + "\' to global parameter : " + pve.getMessage());
                            } catch (ExpressionBindingException e) {
                                e.printStackTrace(System.out);
                                PopupGenerator.showErrorDialog(ownerTable, "Cannot convert parameter \'" + parameter.getName() + "\' to global parameter : " + e.getMessage());
                            }
                        }
                    }
                }
                fireTableRowsUpdated(rowIndex, rowIndex);
                break;
            }
        case COLUMN_VALUE:
            {
                try {
                    if (aValue instanceof ScopedExpression) {
                        // }
                        throw new RuntimeException("unexpected value type ScopedExpression");
                    } else if (aValue instanceof String) {
                        String newExpressionString = (String) aValue;
                        if (parameter instanceof LocalParameter) {
                            LocalParameter localParameter = (LocalParameter) parameter;
                            reactionRule.getKineticLaw().setParameterValue(localParameter, new Expression(newExpressionString), true);
                        } else if (parameter instanceof LocalProxyParameter) {
                            parameter.setExpression(new Expression(newExpressionString));
                        }
                    }
                    reactionRule.getKineticLaw().resolveUndefinedUnits();
                    fireTableRowsUpdated(rowIndex, rowIndex);
                } catch (java.beans.PropertyVetoException e) {
                    e.printStackTrace(System.out);
                    PopupGenerator.showErrorDialog(ownerTable, "Error:\n" + e.getMessage());
                } catch (ExpressionException e) {
                    e.printStackTrace(System.out);
                    PopupGenerator.showErrorDialog(ownerTable, "Expression error:\n" + e.getMessage());
                }
                break;
            }
        case COLUMN_UNITS:
            {
                try {
                    if (aValue instanceof String && parameter instanceof LocalParameter && ((LocalParameter) parameter).getRole() == RbmKineticLaw.RbmKineticLawParameterType.UserDefined) {
                        String newUnitString = (String) aValue;
                        LocalParameter kineticsParm = (LocalParameter) parameter;
                        ModelUnitSystem modelUnitSystem = reactionRule.getModel().getUnitSystem();
                        if (!kineticsParm.getUnitDefinition().getSymbol().equals(newUnitString)) {
                            kineticsParm.setUnitDefinition(modelUnitSystem.getInstance(newUnitString));
                            reactionRule.getKineticLaw().resolveUndefinedUnits();
                            fireTableRowsUpdated(rowIndex, rowIndex);
                        }
                    }
                } catch (VCUnitException e) {
                    e.printStackTrace(System.out);
                    PopupGenerator.showErrorDialog(ownerTable, "Error changing parameter unit:\n" + e.getMessage());
                }
                break;
            }
    }
// }catch (java.beans.PropertyVetoException e){
// e.printStackTrace(System.out);
// }
}
Also used : LocalProxyParameter(cbit.vcell.mapping.ParameterContext.LocalProxyParameter) SpeciesContext(cbit.vcell.model.SpeciesContext) ExpressionBindingException(cbit.vcell.parser.ExpressionBindingException) ExpressionException(cbit.vcell.parser.ExpressionException) LocalParameter(cbit.vcell.mapping.ParameterContext.LocalParameter) PropertyVetoException(java.beans.PropertyVetoException) VCUnitException(cbit.vcell.units.VCUnitException) ModelParameter(cbit.vcell.model.Model.ModelParameter) ScopedExpression(cbit.gui.ScopedExpression) ModelQuantity(cbit.vcell.model.ModelQuantity) ScopedExpression(cbit.gui.ScopedExpression) Expression(cbit.vcell.parser.Expression) LocalParameter(cbit.vcell.mapping.ParameterContext.LocalParameter) ModelParameter(cbit.vcell.model.Model.ModelParameter) Parameter(cbit.vcell.model.Parameter) LocalProxyParameter(cbit.vcell.mapping.ParameterContext.LocalProxyParameter) UnresolvedParameter(cbit.vcell.mapping.ParameterContext.UnresolvedParameter) ModelUnitSystem(cbit.vcell.model.ModelUnitSystem)

Example 4 with ModelQuantity

use of cbit.vcell.model.ModelQuantity in project vcell by virtualcell.

the class ParameterTableModel method setValueAt.

public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
    Parameter parameter = getValueAt(rowIndex);
    // try {
    switch(columnIndex) {
        case COLUMN_NAME:
            {
                try {
                    if (aValue instanceof String) {
                        String newName = (String) aValue;
                        if (!parameter.getName().equals(newName)) {
                            if (parameter instanceof Kinetics.KineticsParameter) {
                                reactionStep.getKinetics().renameParameter(parameter.getName(), newName);
                            } else if (parameter instanceof Kinetics.KineticsProxyParameter) {
                                parameter.setName(newName);
                            }
                            fireTableRowsUpdated(rowIndex, rowIndex);
                        }
                    }
                } catch (ExpressionException e) {
                    e.printStackTrace(System.out);
                    PopupGenerator.showErrorDialog(ownerTable, "Error changing parameter name:\n" + e.getMessage());
                } catch (java.beans.PropertyVetoException e) {
                    e.printStackTrace(System.out);
                    PopupGenerator.showErrorDialog(ownerTable, "Error changing parameter name:\n" + e.getMessage());
                }
                break;
            }
        case COLUMN_IS_GLOBAL:
            {
                if (aValue.equals(Boolean.FALSE)) {
                    // check box has been <unset> (<true> to <false>) : change param from global to local
                    if ((parameter instanceof KineticsProxyParameter) && ((((KineticsProxyParameter) parameter).getTarget() instanceof Model.ReservedSymbol) || (((KineticsProxyParameter) parameter).getTarget() instanceof SpeciesContext) || (((KineticsProxyParameter) parameter).getTarget() instanceof ModelQuantity))) {
                        PopupGenerator.showErrorDialog(ownerTable, "Parameter : \'" + parameter.getName() + "\' is a " + ((KineticsProxyParameter) parameter).getTarget().getClass() + " in the model; cannot convert it to a local kinetic parameter.");
                    } else {
                        try {
                            reactionStep.getKinetics().convertParameterType(parameter, false);
                        } catch (PropertyVetoException pve) {
                            pve.printStackTrace(System.out);
                            PopupGenerator.showErrorDialog(ownerTable, "Unable to convert parameter : \'" + parameter.getName() + "\' to local kinetics parameter : " + pve.getMessage());
                        } catch (ExpressionBindingException e) {
                            e.printStackTrace(System.out);
                            PopupGenerator.showErrorDialog(ownerTable, "Unable to convert parameter : \'" + parameter.getName() + "\' to local kinetics parameter : " + e.getMessage());
                        }
                    }
                } else {
                    // check box has been <set> (<false> to <true>) : change param from local to global
                    if ((parameter instanceof KineticsParameter) && (((KineticsParameter) parameter).getRole() != Kinetics.ROLE_UserDefined)) {
                        PopupGenerator.showErrorDialog(ownerTable, "Parameter : \'" + parameter.getName() + "\' is a pre-defined kinetics parameter (not user-defined); cannot convert it to a model level (global) parameter.");
                    } else {
                        ModelParameter mp = reactionStep.getKinetics().getReactionStep().getModel().getModelParameter(parameter.getName());
                        // model already had the model parameter 'param', but check if 'param' value is different from
                        // model parameter with same name. If it is, the local value will be overridden by global (model) param
                        // value, and user should be warned.
                        String choice = "Ok";
                        if (mp != null && !(mp.getExpression().compareEqual(parameter.getExpression()))) {
                            String msgStr = "Model already has a global parameter named : \'" + parameter.getName() + "\'; with value = \'" + mp.getExpression().infix() + "\'; This local parameter \'" + parameter.getName() + "\' with value = \'" + parameter.getExpression().infix() + "\' will be overridden by the global value. \nPress \'Ok' to override " + "local value with global value of \'" + parameter.getName() + "\'. \nPress \'Cancel\' to retain new local value.";
                            choice = PopupGenerator.showWarningDialog(ownerTable, msgStr, new String[] { "Ok", "Cancel" }, "Ok");
                        }
                        if (choice.equals("Ok")) {
                            try {
                                // Now 'parameter' is a local kinetic parameter. If it is not numeric, and if its expression
                                // contains other local kinetic parameters, warn user that 'parameter' cannot be promoted because
                                // of its expression containing other local parameters.
                                boolean bPromoteable = true;
                                if (!parameter.getExpression().isNumeric()) {
                                    String[] symbols = parameter.getExpression().getSymbols();
                                    for (int i = 0; i < symbols.length; i++) {
                                        if (reactionStep.getKinetics().getKineticsParameter(symbols[i]) != null) {
                                            PopupGenerator.showErrorDialog(ownerTable, "Parameter \'" + parameter.getName() + "\' contains other local kinetic parameters; Cannot convert it to global until the referenced parameters are global.");
                                            bPromoteable = false;
                                        }
                                    }
                                }
                                if (bPromoteable) {
                                    reactionStep.getKinetics().convertParameterType(parameter, true);
                                }
                            } catch (PropertyVetoException pve) {
                                pve.printStackTrace(System.out);
                                PopupGenerator.showErrorDialog(ownerTable, "Cannot convert parameter \'" + parameter.getName() + "\' to global parameter : " + pve.getMessage());
                            } catch (ExpressionBindingException e) {
                                e.printStackTrace(System.out);
                                PopupGenerator.showErrorDialog(ownerTable, "Cannot convert parameter \'" + parameter.getName() + "\' to global parameter : " + e.getMessage());
                            }
                        }
                    }
                }
                fireTableRowsUpdated(rowIndex, rowIndex);
                break;
            }
        case COLUMN_VALUE:
            {
                try {
                    if (aValue instanceof ScopedExpression) {
                        // }
                        throw new RuntimeException("unexpected value type ScopedExpression");
                    } else if (aValue instanceof String) {
                        String newExpressionString = (String) aValue;
                        if (parameter instanceof Kinetics.KineticsParameter) {
                            reactionStep.getKinetics().setParameterValue((Kinetics.KineticsParameter) parameter, new Expression(newExpressionString));
                        } else if (parameter instanceof Kinetics.KineticsProxyParameter) {
                            parameter.setExpression(new Expression(newExpressionString));
                        }
                    }
                    reactionStep.getKinetics().resolveUndefinedUnits();
                    fireTableRowsUpdated(rowIndex, rowIndex);
                } catch (java.beans.PropertyVetoException e) {
                    e.printStackTrace(System.out);
                    PopupGenerator.showErrorDialog(ownerTable, "Error:\n" + e.getMessage());
                } catch (ExpressionException e) {
                    e.printStackTrace(System.out);
                    PopupGenerator.showErrorDialog(ownerTable, "Expression error:\n" + e.getMessage());
                }
                break;
            }
        case COLUMN_UNITS:
            {
                try {
                    if (aValue instanceof String && parameter instanceof Kinetics.KineticsParameter && ((Kinetics.KineticsParameter) parameter).getRole() == Kinetics.ROLE_UserDefined) {
                        String newUnitString = (String) aValue;
                        Kinetics.KineticsParameter kineticsParm = (Kinetics.KineticsParameter) parameter;
                        ModelUnitSystem modelUnitSystem = reactionStep.getModel().getUnitSystem();
                        if (!kineticsParm.getUnitDefinition().getSymbol().equals(newUnitString)) {
                            kineticsParm.setUnitDefinition(modelUnitSystem.getInstance(newUnitString));
                            reactionStep.getKinetics().resolveUndefinedUnits();
                            fireTableRowsUpdated(rowIndex, rowIndex);
                        }
                    }
                } catch (VCUnitException e) {
                    e.printStackTrace(System.out);
                    PopupGenerator.showErrorDialog(ownerTable, "Error changing parameter unit:\n" + e.getMessage());
                }
                break;
            }
    }
// }catch (java.beans.PropertyVetoException e){
// e.printStackTrace(System.out);
// }
}
Also used : KineticsProxyParameter(cbit.vcell.model.Kinetics.KineticsProxyParameter) KineticsParameter(cbit.vcell.model.Kinetics.KineticsParameter) SpeciesContext(cbit.vcell.model.SpeciesContext) ExpressionBindingException(cbit.vcell.parser.ExpressionBindingException) ExpressionException(cbit.vcell.parser.ExpressionException) PropertyVetoException(java.beans.PropertyVetoException) VCUnitException(cbit.vcell.units.VCUnitException) ModelParameter(cbit.vcell.model.Model.ModelParameter) ScopedExpression(cbit.gui.ScopedExpression) ModelQuantity(cbit.vcell.model.ModelQuantity) KineticsParameter(cbit.vcell.model.Kinetics.KineticsParameter) ScopedExpression(cbit.gui.ScopedExpression) Expression(cbit.vcell.parser.Expression) KineticsProxyParameter(cbit.vcell.model.Kinetics.KineticsProxyParameter) 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) Kinetics(cbit.vcell.model.Kinetics) ModelUnitSystem(cbit.vcell.model.ModelUnitSystem)

Example 5 with ModelQuantity

use of cbit.vcell.model.ModelQuantity in project vcell by virtualcell.

the class SEDMLExporter method getSymbolTableEntryForModelEntity.

private SymbolTableEntry getSymbolTableEntryForModelEntity(MathSymbolMapping mathSymbolMapping, String paramName) {
    cbit.vcell.math.Variable mathVar = mathSymbolMapping.findVariableByName(paramName);
    SymbolTableEntry[] stEntries = mathSymbolMapping.getBiologicalSymbol(mathVar);
    if (stEntries == null || stEntries.length == 0) {
        throw new NullPointerException("No matching biological symbol for : " + paramName);
    }
    // if the extra stes in the array are KineticsProxyParameters/ModelQuantities, remove them from array. Should be left with only one entry for overriddenConstantName
    if (stEntries.length > 1) {
        // 
        // If there are more than one stEntries, usually, it is a regular ste (species, global parameter, structure, etc) together with
        // kineticsProxyParameters (that have the regular ste as target) or Model quantities (structure size, membrane voltage).
        // So filtering out the kinticProxyParametes should leave only the regular parameter,
        // which is what we want. If there are more, then there is a problem.
        // 
        ArrayList<SymbolTableEntry> steList = new ArrayList<SymbolTableEntry>(Arrays.asList(stEntries));
        for (int i = 0; i < stEntries.length; i++) {
            if (stEntries[i] instanceof ProxyParameter) {
                SymbolTableEntry ppTargetSte = ((ProxyParameter) stEntries[i]).getTarget();
                if (steList.contains(ppTargetSte) || ppTargetSte instanceof ModelQuantity) {
                    steList.remove(stEntries[i]);
                }
            }
            if (stEntries[i] instanceof ModelQuantity) {
                if (steList.contains(stEntries[i])) {
                    steList.remove(stEntries[i]);
                }
            }
        }
        // after removing proxy parameters, cannot have more than one ste in list
        if (steList.size() == 0) {
            throw new RuntimeException("No mapping entry for constant : '" + paramName + "'.");
        }
        if (steList.size() > 1) {
            throw new RuntimeException("Cannot have more than one mapping entry for constant : '" + paramName + "'.");
        }
        SymbolTableEntry[] stes = (SymbolTableEntry[]) steList.toArray(new SymbolTableEntry[0]);
        return stes[0];
    } else {
        return stEntries[0];
    }
}
Also used : SymbolTableEntry(cbit.vcell.parser.SymbolTableEntry) ProxyParameter(cbit.vcell.model.ProxyParameter) ModelQuantity(cbit.vcell.model.ModelQuantity) ArrayList(java.util.ArrayList)

Aggregations

ModelQuantity (cbit.vcell.model.ModelQuantity)5 ModelParameter (cbit.vcell.model.Model.ModelParameter)4 Parameter (cbit.vcell.model.Parameter)4 SpeciesContext (cbit.vcell.model.SpeciesContext)4 SymbolTableEntry (cbit.vcell.parser.SymbolTableEntry)3 ScopedExpression (cbit.gui.ScopedExpression)2 LocalParameter (cbit.vcell.mapping.ParameterContext.LocalParameter)2 LocalProxyParameter (cbit.vcell.mapping.ParameterContext.LocalProxyParameter)2 UnresolvedParameter (cbit.vcell.mapping.ParameterContext.UnresolvedParameter)2 KineticsParameter (cbit.vcell.model.Kinetics.KineticsParameter)2 KineticsProxyParameter (cbit.vcell.model.Kinetics.KineticsProxyParameter)2 UnresolvedParameter (cbit.vcell.model.Kinetics.UnresolvedParameter)2 Model (cbit.vcell.model.Model)2 ModelUnitSystem (cbit.vcell.model.ModelUnitSystem)2 Expression (cbit.vcell.parser.Expression)2 ExpressionBindingException (cbit.vcell.parser.ExpressionBindingException)2 ExpressionException (cbit.vcell.parser.ExpressionException)2 VCUnitException (cbit.vcell.units.VCUnitException)2 PropertyVetoException (java.beans.PropertyVetoException)2 VCellSortTableModel (cbit.vcell.client.desktop.biomodel.VCellSortTableModel)1