Search in sources :

Example 16 with Kinetics

use of cbit.vcell.model.Kinetics 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 17 with Kinetics

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

the class ReactionElectricalPropertiesPanel method enableControls.

/**
 * Comment
 */
private void enableControls(Kinetics kinetics) {
    Kinetics kt = kinetics;
    boolean bEnableMolecular = true;
    boolean bEnableCurrent = true;
    if (kt != null) {
        if (kt.getKineticsDescription().isElectrical()) {
            bEnableCurrent = false;
        } else {
            bEnableMolecular = false;
        }
    } else {
        bEnableCurrent = false;
        bEnableMolecular = false;
    }
    getMolecularCheckbox().setEnabled(bEnableMolecular);
    getCurrentCheckbox().setEnabled(bEnableCurrent);
}
Also used : Kinetics(cbit.vcell.model.Kinetics)

Example 18 with Kinetics

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

the class ReactionElectricalPropertiesPanel method setkinetics1.

/**
 * Set the kinetics1 to a new value.
 * @param newValue cbit.vcell.model.Kinetics
 */
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private void setkinetics1(Kinetics newValue) {
    if (ivjkinetics1 != newValue) {
        try {
            Kinetics oldValue = getkinetics1();
            ivjkinetics1 = newValue;
            connPtoP2SetSource();
            connEtoM7(ivjkinetics1);
            connEtoC2(ivjkinetics1);
            firePropertyChange("kinetics", oldValue, newValue);
        // user code begin {1}
        // user code end
        } catch (java.lang.Throwable ivjExc) {
            // user code begin {2}
            // user code end
            handleException(ivjExc);
        }
    }
    ;
// user code begin {3}
// user code end
}
Also used : Kinetics(cbit.vcell.model.Kinetics)

Example 19 with Kinetics

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

the class ReactionElectricalPropertiesPanel method setKinetics.

/**
 * Sets the kinetics property (cbit.vcell.model.Kinetics) value.
 * @param kinetics The new value for the property.
 * @see #getKinetics
 */
public void setKinetics(Kinetics kinetics) {
    Kinetics oldValue = fieldKinetics;
    fieldKinetics = kinetics;
    firePropertyChange("kinetics", oldValue, kinetics);
}
Also used : Kinetics(cbit.vcell.model.Kinetics)

Example 20 with Kinetics

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

the class TransformMassActionTableModel method getValueAt.

// end of method getRowCount()
/**
 * display data in table
 */
public Object getValueAt(int row, int col) {
    try {
        if (row < 0 || row >= getRowCount()) {
            throw new RuntimeException("TransformMassActionTableModel.getValueAt(), row = " + row + " out of range [" + 0 + "," + (getRowCount() - 1) + "]");
        }
        if (col < 0 || col >= NUM_COLUMNS) {
            throw new RuntimeException("TransfromMassActionTableModel.getValueAt(), column = " + col + " out of range [" + 0 + "," + (NUM_COLUMNS - 1) + "]");
        }
        Kinetics origKinetics = getModel().getReactionSteps()[row].getKinetics();
        MassActionSolver.MassActionFunction maFunc = transMAs.getTransformedReactionSteps()[row].getMassActionFunction();
        switch(col) {
            case COLUMN_REACTION:
                {
                    return getModel().getReactionSteps()[row].getName();
                }
            case COLUMN_REACTIONTYPE:
                {
                    if (getModel().getReactionSteps()[row] instanceof SimpleReaction) {
                        return "reaction";
                    } else {
                        return "flux";
                    }
                }
            case COLUMN_KINETICS:
                {
                    if (origKinetics != null) {
                        return origKinetics.getKineticsDescription().getDescription();
                    }
                    return null;
                }
            case COLUMN_RATE:
                {
                    if (origKinetics != null) {
                        Kinetics.KineticsParameter ratePara = origKinetics.getKineticsParameterFromRole(Kinetics.ROLE_ReactionRate);
                        if (ratePara != null && ratePara.getExpression() != null) {
                            return new ScopedExpression(ratePara.getExpression(), ratePara.getNameScope(), false, true, null);
                        }
                    }
                    return null;
                }
            case COLUMN_TRANSFORM:
                {
                    // so the checkbox will not be ticked for flux regardless it can be transformed or not.
                    return getIsSelected(row);
                }
            case COLUMN_FORWARDRATE:
                {
                    if (maFunc != null && maFunc.getForwardRate() != null) {
                        return new ScopedExpression(maFunc.getForwardRate(), null, false, true, null);
                    }
                    return null;
                }
            case COLUMN_REVERSERATE:
                {
                    if (maFunc != null && maFunc.getReverseRate() != null) {
                        return new ScopedExpression(maFunc.getReverseRate(), null, false, true, null);
                    }
                    return null;
                }
            case COLUMN_REMARK:
                {
                    if (transMAs.getTransformedReactionSteps()[row] != null) {
                        return transMAs.getTransformedReactionSteps()[row].getTransformRemark();
                    }
                    return null;
                }
            default:
                {
                    return null;
                }
        }
    } catch (Exception ex) {
        ex.printStackTrace(System.out);
        return null;
    }
}
Also used : SimpleReaction(cbit.vcell.model.SimpleReaction) ScopedExpression(cbit.gui.ScopedExpression) KineticsParameter(cbit.vcell.model.Kinetics.KineticsParameter) MassActionKinetics(cbit.vcell.model.MassActionKinetics) Kinetics(cbit.vcell.model.Kinetics) MassActionSolver(cbit.vcell.model.MassActionSolver)

Aggregations

Kinetics (cbit.vcell.model.Kinetics)31 KineticsParameter (cbit.vcell.model.Kinetics.KineticsParameter)21 ReactionStep (cbit.vcell.model.ReactionStep)17 Expression (cbit.vcell.parser.Expression)16 ModelParameter (cbit.vcell.model.Model.ModelParameter)11 ExpressionException (cbit.vcell.parser.ExpressionException)11 ReactionParticipant (cbit.vcell.model.ReactionParticipant)10 SpeciesContext (cbit.vcell.model.SpeciesContext)10 MassActionKinetics (cbit.vcell.model.MassActionKinetics)9 ModelUnitSystem (cbit.vcell.model.ModelUnitSystem)9 SimpleReaction (cbit.vcell.model.SimpleReaction)9 PropertyVetoException (java.beans.PropertyVetoException)9 LumpedKinetics (cbit.vcell.model.LumpedKinetics)8 VCUnitDefinition (cbit.vcell.units.VCUnitDefinition)8 Model (cbit.vcell.model.Model)7 Parameter (cbit.vcell.model.Parameter)7 Product (cbit.vcell.model.Product)7 Reactant (cbit.vcell.model.Reactant)7 FluxReaction (cbit.vcell.model.FluxReaction)6 StructureMapping (cbit.vcell.mapping.StructureMapping)5