Search in sources :

Example 1 with GeneralConstraint

use of cbit.vcell.constraints.GeneralConstraint in project vcell by virtualcell.

the class GeneralConstraintsTableModel method setValueAt.

public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
    System.out.println("GeneralConstraintsTableModel().setValueAt(" + aValue + "," + rowIndex + "," + columnIndex + ")");
    if (rowIndex < 0 || rowIndex >= getRowCount()) {
        throw new RuntimeException("GeneralConstraintsTableModel.setValueAt(), row = " + rowIndex + " out of range [" + 0 + "," + (getRowCount() - 1) + "]");
    }
    if (columnIndex < 0 || columnIndex >= NUM_COLUMNS) {
        throw new RuntimeException("GeneralConstraintsTableModel.setValueAt(), column = " + columnIndex + " out of range [" + 0 + "," + (NUM_COLUMNS - 1) + "]");
    }
    GeneralConstraint generalConstraint = getConstraintContainerImpl().getGeneralConstraints(rowIndex);
    try {
        switch(columnIndex) {
            case COLUMN_EXPRESSION:
                {
                    try {
                        if (aValue instanceof ScopedExpression) {
                            // generalConstraint.setExpression(exp);
                            throw new RuntimeException("unexpected value type ScopedExpression");
                        } else if (aValue instanceof String) {
                            String newExpressionString = (String) aValue;
                            generalConstraint.setExpression(new Expression(newExpressionString));
                        }
                        fireTableRowsUpdated(rowIndex, rowIndex);
                    } catch (ExpressionException e) {
                        e.printStackTrace(System.out);
                        DialogUtils.showErrorDialog(ownerTable, "Expression error:\n" + e.getMessage());
                    }
                    break;
                }
            case COLUMN_DESCRIPTION:
                {
                    if (aValue instanceof String) {
                        generalConstraint.setDescription((String) aValue);
                        fireTableRowsUpdated(rowIndex, rowIndex);
                    } else {
                        System.out.println("ConstraintsTableModel.setValueAt(), unsupported type " + aValue.getClass().getName() + " for COLUMN_DESCRIPTION");
                    }
                    break;
                }
            case COLUMN_INCLUDED:
                {
                    if (aValue instanceof Boolean) {
                        getConstraintContainerImpl().setActive(generalConstraint, ((Boolean) aValue).booleanValue());
                        fireTableRowsUpdated(rowIndex, rowIndex);
                    } else {
                        System.out.println("ConstraintsTableModel.setValueAt(), unsupported type " + aValue.getClass().getName() + " for COLUMN_INCLUDED");
                    }
                    break;
                }
        }
    } catch (java.beans.PropertyVetoException e) {
        e.printStackTrace(System.out);
    }
}
Also used : ScopedExpression(cbit.gui.ScopedExpression) ScopedExpression(cbit.gui.ScopedExpression) Expression(cbit.vcell.parser.Expression) GeneralConstraint(cbit.vcell.constraints.GeneralConstraint) ExpressionException(cbit.vcell.parser.ExpressionException)

Example 2 with GeneralConstraint

use of cbit.vcell.constraints.GeneralConstraint in project vcell by virtualcell.

the class ConstraintTableCellRenderer method getTableCellRendererComponent.

/**
 * Insert the method's description here.
 * Creation date: (8/7/2001 1:11:37 PM)
 * @return java.awt.Component
 * @param table javax.swing.JTable
 * @param value java.lang.Object
 * @param isSelected boolean
 * @param hasFocus boolean
 * @param row int
 * @param column int
 */
public java.awt.Component getTableCellRendererComponent(javax.swing.JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
    GeneralConstraint generalConstraint = getGeneralConstraintsTableModel().getConstraintContainerImpl().getGeneralConstraints(row);
    if (!getGeneralConstraintsTableModel().getConstraintContainerImpl().getConsistent(generalConstraint)) {
        if (isSelected) {
            setForeground(java.awt.Color.white);
            setBackground(java.awt.Color.red);
        } else {
            setForeground(java.awt.Color.red);
            setBackground(java.awt.Color.white);
        }
    } else {
        if (isSelected) {
            setForeground(java.awt.Color.white);
            setBackground(java.awt.Color.blue.darker().darker());
        } else {
            setForeground(java.awt.Color.black);
            setBackground(java.awt.Color.white);
        }
    }
    return this;
}
Also used : GeneralConstraint(cbit.vcell.constraints.GeneralConstraint)

Example 3 with GeneralConstraint

use of cbit.vcell.constraints.GeneralConstraint in project vcell by virtualcell.

the class ConstraintsGraphModel method refreshAll.

public void refreshAll() {
    Set<Shape> unwantedShapes = new HashSet<Shape>();
    unwantedShapes.addAll(getShapes());
    for (Shape shape : getShapes()) {
        if (shape instanceof ConstraintVarNode) {
            ((ConstraintVarNode) shape).setDegree(1);
        }
    }
    ContainerShape containerShape = (ContainerShape) getShapeFromModelObject(getConstraintContainerImpl());
    if (containerShape == null) {
        containerShape = new SimpleContainerShape(getConstraintContainerImpl(), this, "constraint network");
        containerShape.setLabel("constraint network");
        addShape(containerShape);
    }
    containerShape.refreshLabel();
    unwantedShapes.remove(containerShape);
    // 
    // add nodes for GeneralConstraints and edges to its Variables (add Variable when necessary)
    // 
    GeneralConstraint[] generalConstraints = getConstraintContainerImpl().getGeneralConstraints();
    for (int i = 0; i < generalConstraints.length; i++) {
        String[] symbols = generalConstraints[i].getExpression().getSymbols();
        if (symbols == null) {
            continue;
        }
        GeneralConstraintNode generalConstraintNode = (GeneralConstraintNode) getShapeFromModelObject(generalConstraints[i]);
        if (generalConstraintNode == null) {
            generalConstraintNode = new GeneralConstraintNode(generalConstraints[i], this, symbols.length);
            containerShape.addChildShape(generalConstraintNode);
            addShape(generalConstraintNode);
        }
        generalConstraintNode.refreshLabel();
        unwantedShapes.remove(generalConstraintNode);
        for (int j = 0; j < symbols.length; j++) {
            ConstraintVarNode constraintVarNode = (ConstraintVarNode) getShapeFromLabel(symbols[j]);
            if (constraintVarNode == null) {
                constraintVarNode = new ConstraintVarNode(symbols[j], this, 1);
                containerShape.addChildShape(constraintVarNode);
                addShape(constraintVarNode);
            } else {
                constraintVarNode.setDegree(constraintVarNode.getDegree() + 1);
            }
            constraintVarNode.refreshLabel();
            unwantedShapes.remove(constraintVarNode);
            ConstraintDependencyEdgeShape constraintDependencyEdgeShape = null;
            for (Shape shape : getShapes()) {
                if (shape instanceof ConstraintDependencyEdgeShape) {
                    if (((ConstraintDependencyEdgeShape) shape).getConstraintShape() == generalConstraintNode && ((ConstraintDependencyEdgeShape) shape).getVarShape() == constraintVarNode) {
                        constraintDependencyEdgeShape = (ConstraintDependencyEdgeShape) shape;
                    }
                }
            }
            if (constraintDependencyEdgeShape == null) {
                constraintDependencyEdgeShape = new ConstraintDependencyEdgeShape(generalConstraintNode, constraintVarNode, this);
                containerShape.addChildShape(constraintDependencyEdgeShape);
                addShape(constraintDependencyEdgeShape);
            }
            unwantedShapes.remove(constraintDependencyEdgeShape);
        }
    }
    // 
    // add nodes for SimpleBounds and edges to its Variables (add Variable when necessary)
    // 
    cbit.vcell.constraints.SimpleBounds[] simpleBounds = getConstraintContainerImpl().getSimpleBounds();
    for (int i = 0; i < simpleBounds.length; i++) {
        BoundsNode boundsNode = (BoundsNode) getShapeFromModelObject(simpleBounds[i]);
        if (boundsNode == null) {
            boundsNode = new BoundsNode(simpleBounds[i], this);
            containerShape.addChildShape(boundsNode);
            addShape(boundsNode);
        }
        boundsNode.refreshLabel();
        unwantedShapes.remove(boundsNode);
        ConstraintVarNode constraintVarNode = (ConstraintVarNode) getShapeFromLabel(simpleBounds[i].getIdentifier());
        if (constraintVarNode == null) {
            constraintVarNode = new ConstraintVarNode(simpleBounds[i].getIdentifier(), this, 1);
            containerShape.addChildShape(constraintVarNode);
            addShape(constraintVarNode);
        } else {
            constraintVarNode.setDegree(constraintVarNode.getDegree() + 1);
        }
        constraintVarNode.refreshLabel();
        unwantedShapes.remove(constraintVarNode);
        ConstraintDependencyEdgeShape constraintDependencyEdgeShape = null;
        for (Shape shape : getShapes()) {
            if (shape instanceof ConstraintDependencyEdgeShape) {
                if (((ConstraintDependencyEdgeShape) shape).getConstraintShape() == boundsNode && ((ConstraintDependencyEdgeShape) shape).getVarShape() == constraintVarNode) {
                    constraintDependencyEdgeShape = (ConstraintDependencyEdgeShape) shape;
                }
            }
        }
        if (constraintDependencyEdgeShape == null) {
            constraintDependencyEdgeShape = new ConstraintDependencyEdgeShape(boundsNode, constraintVarNode, this);
            containerShape.addChildShape(constraintDependencyEdgeShape);
            addShape(constraintDependencyEdgeShape);
        }
        constraintDependencyEdgeShape.refreshLabel();
        unwantedShapes.remove(constraintDependencyEdgeShape);
    }
    for (Shape unwantedShape : unwantedShapes) {
        removeShape(unwantedShape);
    }
    fireGraphChanged(new GraphEvent(this));
}
Also used : SimpleContainerShape(cbit.gui.graph.SimpleContainerShape) ContainerShape(cbit.gui.graph.ContainerShape) Shape(cbit.gui.graph.Shape) SimpleBounds(cbit.vcell.constraints.SimpleBounds) GeneralConstraint(cbit.vcell.constraints.GeneralConstraint) SimpleContainerShape(cbit.gui.graph.SimpleContainerShape) GeneralConstraint(cbit.vcell.constraints.GeneralConstraint) GraphEvent(cbit.gui.graph.GraphEvent) SimpleContainerShape(cbit.gui.graph.SimpleContainerShape) ContainerShape(cbit.gui.graph.ContainerShape) HashSet(java.util.HashSet)

Example 4 with GeneralConstraint

use of cbit.vcell.constraints.GeneralConstraint in project vcell by virtualcell.

the class ConstraintsGraphModel method setConstraintContainerImpl.

public void setConstraintContainerImpl(ConstraintContainerImpl constraintContainerImpl) {
    ConstraintContainerImpl oldValue = fieldConstraintContainerImpl;
    if (oldValue != null) {
        oldValue.removePropertyChangeListener(this);
        GeneralConstraint[] oldConstraints = oldValue.getGeneralConstraints();
        for (int i = 0; i < oldConstraints.length; i++) {
            oldConstraints[i].removePropertyChangeListener(this);
        }
        SimpleBounds[] oldSimpleBounds = oldValue.getSimpleBounds();
        for (int i = 0; i < oldSimpleBounds.length; i++) {
            oldSimpleBounds[i].removePropertyChangeListener(this);
        }
    }
    fieldConstraintContainerImpl = constraintContainerImpl;
    if (fieldConstraintContainerImpl != null) {
        fieldConstraintContainerImpl.addPropertyChangeListener(this);
        GeneralConstraint[] newConstraints = fieldConstraintContainerImpl.getGeneralConstraints();
        for (int i = 0; i < newConstraints.length; i++) {
            newConstraints[i].addPropertyChangeListener(this);
        }
        SimpleBounds[] newSimpleBounds = fieldConstraintContainerImpl.getSimpleBounds();
        for (int i = 0; i < newSimpleBounds.length; i++) {
            newSimpleBounds[i].addPropertyChangeListener(this);
        }
    }
    firePropertyChange("constraintContainerImpl", oldValue, constraintContainerImpl);
    refreshAll();
}
Also used : SimpleBounds(cbit.vcell.constraints.SimpleBounds) ConstraintContainerImpl(cbit.vcell.constraints.ConstraintContainerImpl) GeneralConstraint(cbit.vcell.constraints.GeneralConstraint) GeneralConstraint(cbit.vcell.constraints.GeneralConstraint)

Example 5 with GeneralConstraint

use of cbit.vcell.constraints.GeneralConstraint in project vcell by virtualcell.

the class ApplicationConstraintsGenerator method fromApplication.

/**
 * Insert the method's description here.
 * Creation date: (6/26/01 8:25:55 AM)
 * @return cbit.vcell.constraints.ConstraintContainerImpl
 */
public static ConstraintContainerImpl fromApplication(SimulationContext simContext) {
    try {
        ConstraintContainerImpl ccImpl = new ConstraintContainerImpl();
        // ====================
        // add physical limits
        // ====================
        // 
        // no negative concentrations
        // 
        cbit.vcell.model.Model model = simContext.getModel();
        cbit.vcell.model.SpeciesContext[] speciesContexts = model.getSpeciesContexts();
        for (int i = 0; i < speciesContexts.length; i++) {
            ccImpl.addSimpleBound(new SimpleBounds(speciesContexts[i].getName(), new RealInterval(0, Double.POSITIVE_INFINITY), AbstractConstraint.PHYSICAL_LIMIT, "non-negative concentration"));
        }
        for (int i = 0; i < speciesContexts.length; i++) {
            SpeciesContextSpecParameter initParam = (simContext.getReactionContext().getSpeciesContextSpec(speciesContexts[i])).getInitialConditionParameter();
            if (initParam != null) {
                double initialValue = initParam.getExpression().evaluateConstant();
                ccImpl.addSimpleBound(new SimpleBounds(speciesContexts[i].getName(), new RealInterval(initialValue), AbstractConstraint.MODELING_ASSUMPTION, "specified \"initialCondition\""));
            }
        }
        // =========================
        // add modeling assumptions
        // =========================
        // 
        // mass action forward and reverse rates should be non-negative
        // 
        cbit.vcell.model.ReactionStep[] reactionSteps = model.getReactionSteps();
        for (int i = 0; i < reactionSteps.length; i++) {
            Kinetics kinetics = reactionSteps[i].getKinetics();
            if (kinetics instanceof MassActionKinetics) {
                Expression forwardRateConstraintExp = new Expression(((MassActionKinetics) kinetics).getForwardRateParameter().getExpression().infix() + ">=0");
                forwardRateConstraintExp = getSteadyStateExpression(forwardRateConstraintExp);
                if (!forwardRateConstraintExp.compareEqual(new Expression(1.0))) {
                    ccImpl.addGeneralConstraint(new GeneralConstraint(forwardRateConstraintExp, AbstractConstraint.MODELING_ASSUMPTION, "non-negative forward rate"));
                }
                Expression reverseRateConstraintExp = new Expression(((MassActionKinetics) kinetics).getReverseRateParameter().getExpression().infix() + ">=0");
                reverseRateConstraintExp = getSteadyStateExpression(reverseRateConstraintExp);
                if (!reverseRateConstraintExp.compareEqual(new Expression(1.0))) {
                    ccImpl.addGeneralConstraint(new GeneralConstraint(reverseRateConstraintExp, AbstractConstraint.MODELING_ASSUMPTION, "non-negative reverse rate"));
                }
            }
            KineticsParameter authoritativeParameter = kinetics.getAuthoritativeParameter();
            Expression kineticRateConstraintExp = new Expression(authoritativeParameter.getName() + "==" + authoritativeParameter.getExpression().infix());
            kineticRateConstraintExp = getSteadyStateExpression(kineticRateConstraintExp);
            if (!kineticRateConstraintExp.compareEqual(new Expression(1.0))) {
                ccImpl.addGeneralConstraint(new GeneralConstraint(kineticRateConstraintExp, AbstractConstraint.MODELING_ASSUMPTION, "definition"));
            }
        }
        // 
        for (int i = 0; i < reactionSteps.length; i++) {
            Kinetics kinetics = reactionSteps[i].getKinetics();
            Kinetics.KineticsParameter[] parameters = kinetics.getKineticsParameters();
            for (int j = 0; j < parameters.length; j++) {
                Expression exp = parameters[j].getExpression();
                if (exp.getSymbols() == null || exp.getSymbols().length == 0) {
                    // 
                    try {
                        double constantValue = exp.evaluateConstant();
                        RealInterval interval = new RealInterval(constantValue);
                        ccImpl.addSimpleBound(new SimpleBounds(parameters[j].getName(), interval, AbstractConstraint.MODELING_ASSUMPTION, "model value"));
                    } catch (cbit.vcell.parser.ExpressionException e) {
                        System.out.println("error evaluating parameter " + parameters[j].getName() + " in reaction step " + reactionSteps[i].getName());
                    }
                } else {
                    Expression parameterDefinitionExp = new Expression(parameters[j].getName() + "==" + parameters[j].getExpression().infix());
                    parameterDefinitionExp = getSteadyStateExpression(parameterDefinitionExp);
                    if (!parameterDefinitionExp.compareEqual(new Expression(1.0))) {
                        ccImpl.addGeneralConstraint(new GeneralConstraint(parameterDefinitionExp, AbstractConstraint.MODELING_ASSUMPTION, "parameter definition"));
                    }
                }
            }
        }
        ccImpl.addSimpleBound(new SimpleBounds(model.getFARADAY_CONSTANT().getName(), new RealInterval(model.getFARADAY_CONSTANT().getExpression().evaluateConstant()), AbstractConstraint.PHYSICAL_LIMIT, "Faraday's constant"));
        ccImpl.addSimpleBound(new SimpleBounds(model.getTEMPERATURE().getName(), new RealInterval(300), AbstractConstraint.PHYSICAL_LIMIT, "Absolute Temperature Kelvin"));
        ccImpl.addSimpleBound(new SimpleBounds(model.getGAS_CONSTANT().getName(), new RealInterval(model.getGAS_CONSTANT().getExpression().evaluateConstant()), AbstractConstraint.PHYSICAL_LIMIT, "ideal gas constant"));
        ccImpl.addSimpleBound(new SimpleBounds(model.getKMILLIVOLTS().getName(), new RealInterval(model.getKMILLIVOLTS().getExpression().evaluateConstant()), AbstractConstraint.PHYSICAL_LIMIT, "ideal gas constant"));
        return ccImpl;
    } catch (cbit.vcell.parser.ExpressionException e) {
        e.printStackTrace(System.out);
        return null;
    } catch (java.beans.PropertyVetoException e) {
        e.printStackTrace(System.out);
        return null;
    }
}
Also used : SimpleBounds(cbit.vcell.constraints.SimpleBounds) GeneralConstraint(cbit.vcell.constraints.GeneralConstraint) RealInterval(net.sourceforge.interval.ia_math.RealInterval) AbstractConstraint(cbit.vcell.constraints.AbstractConstraint) GeneralConstraint(cbit.vcell.constraints.GeneralConstraint) KineticsParameter(cbit.vcell.model.Kinetics.KineticsParameter) Expression(cbit.vcell.parser.Expression) ConstraintContainerImpl(cbit.vcell.constraints.ConstraintContainerImpl) MassActionKinetics(cbit.vcell.model.MassActionKinetics) MassActionKinetics(cbit.vcell.model.MassActionKinetics) Kinetics(cbit.vcell.model.Kinetics) SpeciesContextSpecParameter(cbit.vcell.mapping.SpeciesContextSpec.SpeciesContextSpecParameter)

Aggregations

GeneralConstraint (cbit.vcell.constraints.GeneralConstraint)8 ConstraintContainerImpl (cbit.vcell.constraints.ConstraintContainerImpl)5 SimpleBounds (cbit.vcell.constraints.SimpleBounds)5 Expression (cbit.vcell.parser.Expression)4 AbstractConstraint (cbit.vcell.constraints.AbstractConstraint)3 RealInterval (net.sourceforge.interval.ia_math.RealInterval)3 SpeciesContextSpecParameter (cbit.vcell.mapping.SpeciesContextSpec.SpeciesContextSpecParameter)2 Kinetics (cbit.vcell.model.Kinetics)2 KineticsParameter (cbit.vcell.model.Kinetics.KineticsParameter)2 MassActionKinetics (cbit.vcell.model.MassActionKinetics)2 ExpressionException (cbit.vcell.parser.ExpressionException)2 ScopedExpression (cbit.gui.ScopedExpression)1 ContainerShape (cbit.gui.graph.ContainerShape)1 GraphEvent (cbit.gui.graph.GraphEvent)1 Shape (cbit.gui.graph.Shape)1 SimpleContainerShape (cbit.gui.graph.SimpleContainerShape)1 ConstraintSolver (cbit.vcell.constraints.ConstraintSolver)1 SubVolume (cbit.vcell.geometry.SubVolume)1 SurfaceClass (cbit.vcell.geometry.SurfaceClass)1 FeatureMapping (cbit.vcell.mapping.FeatureMapping)1