Search in sources :

Example 56 with SymbolTableEntry

use of cbit.vcell.parser.SymbolTableEntry in project vcell by virtualcell.

the class ReactionStep method getAutoCompleteSymbolFilter.

public AutoCompleteSymbolFilter getAutoCompleteSymbolFilter() {
    AutoCompleteSymbolFilter stef = new AutoCompleteSymbolFilter() {

        public boolean accept(SymbolTableEntry ste) {
            if (ste instanceof StructureSize) {
                if (((StructureSize) ste).getStructure() != structure) {
                    return false;
                }
            } else {
                if (structure instanceof Membrane) {
                    Membrane membrane = (Membrane) structure;
                    StructureTopology structTopology = getModel().getStructureTopology();
                    if (ste instanceof SpeciesContext) {
                        Structure entryStructure = ((SpeciesContext) ste).getStructure();
                        if (entryStructure != membrane && entryStructure != structTopology.getInsideFeature(membrane) && entryStructure != structTopology.getOutsideFeature(membrane)) {
                            return false;
                        }
                    } else if (ste instanceof MembraneVoltage) {
                        if (((MembraneVoltage) ste).getMembrane() != membrane) {
                            return false;
                        }
                    }
                } else {
                    if (ste instanceof SpeciesContext) {
                        Structure entryStructure = ((SpeciesContext) ste).getStructure();
                        if (entryStructure != structure) {
                            return false;
                        }
                    } else if (ste instanceof MembraneVoltage) {
                        return false;
                    }
                }
            }
            return true;
        }

        public boolean acceptFunction(String funcName) {
            return true;
        }
    };
    return stef;
}
Also used : AutoCompleteSymbolFilter(cbit.vcell.parser.AutoCompleteSymbolFilter) SymbolTableEntry(cbit.vcell.parser.SymbolTableEntry) StructureTopology(cbit.vcell.model.Model.StructureTopology) MembraneVoltage(cbit.vcell.model.Membrane.MembraneVoltage) StructureSize(cbit.vcell.model.Structure.StructureSize)

Example 57 with SymbolTableEntry

use of cbit.vcell.parser.SymbolTableEntry in project vcell by virtualcell.

the class ReactionStep method getLocalEntry.

public SymbolTableEntry getLocalEntry(String identifier) {
    // 
    // if resolved parameter exists, then return it
    // 
    SymbolTableEntry ste = getKinetics().getKineticsParameter(identifier);
    if (ste != null) {
        return ste;
    }
    // 
    // if unnresolved parameter exists, then return it
    // 
    ste = getKinetics().getUnresolvedParameter(identifier);
    if (ste != null) {
        return ste;
    }
    // 
    // if proxy parameter exists, then return it
    // 
    ste = getKinetics().getProxyParameter(identifier);
    if (ste != null) {
        return ste;
    }
    return null;
}
Also used : SymbolTableEntry(cbit.vcell.parser.SymbolTableEntry)

Example 58 with SymbolTableEntry

use of cbit.vcell.parser.SymbolTableEntry in project vcell by virtualcell.

the class ModelOptimizationMapping method getRemappedReferenceData.

/**
 * Gets the constraintData property (cbit.vcell.opt.ConstraintData) value.
 * @return The constraintData property value.
 * @see #setConstraintData
 */
private ReferenceData getRemappedReferenceData(MathMapping mathMapping) throws MappingException {
    if (modelOptimizationSpec.getReferenceData() == null) {
        return null;
    }
    // 
    // make sure time is mapped
    // 
    ReferenceData refData = modelOptimizationSpec.getReferenceData();
    ReferenceDataMappingSpec[] refDataMappingSpecs = modelOptimizationSpec.getReferenceDataMappingSpecs();
    RowColumnResultSet rowColResultSet = new RowColumnResultSet();
    Vector<SymbolTableEntry> modelObjectList = new Vector<SymbolTableEntry>();
    Vector<double[]> dataList = new Vector<double[]>();
    // 
    // find bound columns, (time is always mapped to the first column)
    // 
    int mappedColumnCount = 0;
    for (int i = 0; i < refDataMappingSpecs.length; i++) {
        SymbolTableEntry modelObject = refDataMappingSpecs[i].getModelObject();
        if (modelObject != null) {
            int mappedColumnIndex = mappedColumnCount;
            if (modelObject instanceof Model.ReservedSymbol && ((ReservedSymbol) modelObject).isTime()) {
                mappedColumnIndex = 0;
            }
            String origRefDataColumnName = refDataMappingSpecs[i].getReferenceDataColumnName();
            int origRefDataColumnIndex = refData.findColumn(origRefDataColumnName);
            if (origRefDataColumnIndex < 0) {
                throw new RuntimeException("reference data column named '" + origRefDataColumnName + "' not found");
            }
            double[] columnData = refData.getDataByColumn(origRefDataColumnIndex);
            if (modelObjectList.contains(modelObject)) {
                throw new RuntimeException("multiple reference data columns mapped to same model object '" + modelObject.getName() + "'");
            }
            modelObjectList.insertElementAt(modelObject, mappedColumnIndex);
            dataList.insertElementAt(columnData, mappedColumnIndex);
            mappedColumnCount++;
        }
    }
    // 
    if (modelObjectList.size() == 0) {
        throw new RuntimeException("reference data was not associated with model");
    }
    if (modelObjectList.size() == 1) {
        throw new RuntimeException("reference data was not associated with model, must map time and at least one other column");
    }
    boolean bFoundTimeVar = false;
    for (SymbolTableEntry ste : modelObjectList) {
        if (ste instanceof Model.ReservedSymbol && ((ReservedSymbol) ste).isTime()) {
            bFoundTimeVar = true;
            break;
        }
    }
    if (!bFoundTimeVar) {
        throw new RuntimeException("must map time column of reference data to model");
    }
    // 
    for (int i = 0; i < modelObjectList.size(); i++) {
        SymbolTableEntry modelObject = (SymbolTableEntry) modelObjectList.elementAt(i);
        try {
            // Find by name because MathSybolMapping has different 'objects' than refDataMapping 'objects'
            Variable variable = mathMapping.getMathSymbolMapping().findVariableByName(modelObject.getName());
            if (variable != null) {
                String symbol = variable.getName();
                rowColResultSet.addDataColumn(new ODESolverResultSetColumnDescription(symbol));
            } else if (modelObject instanceof Model.ReservedSymbol && ((Model.ReservedSymbol) modelObject).isTime()) {
                Model.ReservedSymbol time = (Model.ReservedSymbol) modelObject;
                String symbol = time.getName();
                rowColResultSet.addDataColumn(new ODESolverResultSetColumnDescription(symbol));
            }
        } catch (MathException | MatrixException | ExpressionException | ModelException e) {
            e.printStackTrace();
            throw new MappingException(e.getMessage(), e);
        }
    }
    // 
    // populate data columns (time and rest)
    // 
    double[] weights = new double[rowColResultSet.getColumnDescriptionsCount()];
    weights[0] = 1.0;
    int numRows = ((double[]) dataList.elementAt(0)).length;
    int numColumns = modelObjectList.size();
    for (int j = 0; j < numRows; j++) {
        double[] row = new double[numColumns];
        for (int i = 0; i < numColumns; i++) {
            row[i] = ((double[]) dataList.elementAt(i))[j];
            if (i > 0) {
                weights[i] += row[i] * row[i];
            }
        }
        rowColResultSet.addRow(row);
    }
    for (int i = 0; i < numColumns; i++) {
        if (weights[i] == 0) {
            weights[i] = 1;
        } else {
            weights[i] = 1 / weights[i];
        }
    }
    SimpleReferenceData remappedRefData = new SimpleReferenceData(rowColResultSet, weights);
    return remappedRefData;
}
Also used : ParameterVariable(cbit.vcell.math.ParameterVariable) Variable(cbit.vcell.math.Variable) ReservedSymbol(cbit.vcell.model.Model.ReservedSymbol) ReservedSymbol(cbit.vcell.model.Model.ReservedSymbol) ExpressionException(cbit.vcell.parser.ExpressionException) MappingException(cbit.vcell.mapping.MappingException) MatrixException(cbit.vcell.matrix.MatrixException) SymbolTableEntry(cbit.vcell.parser.SymbolTableEntry) ODESolverResultSetColumnDescription(cbit.vcell.math.ODESolverResultSetColumnDescription) Vector(java.util.Vector) RowColumnResultSet(cbit.vcell.math.RowColumnResultSet) ModelException(cbit.vcell.model.ModelException) SimpleReferenceData(cbit.vcell.opt.SimpleReferenceData) SimpleReferenceData(cbit.vcell.opt.SimpleReferenceData) ReferenceData(cbit.vcell.opt.ReferenceData) MathException(cbit.vcell.math.MathException) Model(cbit.vcell.model.Model)

Example 59 with SymbolTableEntry

use of cbit.vcell.parser.SymbolTableEntry 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 60 with SymbolTableEntry

use of cbit.vcell.parser.SymbolTableEntry in project vcell by virtualcell.

the class GeometrySubVolumeTableModel method setGeometry.

/**
 * Sets the geometry property (cbit.vcell.geometry.Geometry) value.
 * @param geometry The new value for the property.
 * @see #getGeometry
 */
public void setGeometry(Geometry geometry) {
    if (fieldGeometry == geometry) {
        return;
    }
    Geometry oldValue = fieldGeometry;
    if (oldValue != null) {
        oldValue.getGeometrySpec().removePropertyChangeListener(this);
        for (SubVolume sv : oldValue.getGeometrySpec().getSubVolumes()) {
            sv.removePropertyChangeListener(this);
        }
    }
    fieldGeometry = geometry;
    if (fieldGeometry != null) {
        fieldGeometry.getGeometrySpec().addPropertyChangeListener(this);
        for (SubVolume sv : fieldGeometry.getGeometrySpec().getSubVolumes()) {
            sv.addPropertyChangeListener(this);
        }
        autoCompleteSymbolFilter = new AutoCompleteSymbolFilter() {

            public boolean accept(SymbolTableEntry ste) {
                int dimension = fieldGeometry.getDimension();
                if (ste.equals(ReservedVariable.X) || dimension > 1 && ste.equals(ReservedVariable.Y) || dimension > 2 && ste.equals(ReservedVariable.Z)) {
                    return true;
                }
                return false;
            }

            public boolean acceptFunction(String funcName) {
                return true;
            }
        };
    }
    firePropertyChange("geometry", oldValue, fieldGeometry);
}
Also used : Geometry(cbit.vcell.geometry.Geometry) AutoCompleteSymbolFilter(cbit.vcell.parser.AutoCompleteSymbolFilter) SymbolTableEntry(cbit.vcell.parser.SymbolTableEntry) SubVolume(cbit.vcell.geometry.SubVolume) AnalyticSubVolume(cbit.vcell.geometry.AnalyticSubVolume)

Aggregations

SymbolTableEntry (cbit.vcell.parser.SymbolTableEntry)115 Expression (cbit.vcell.parser.Expression)50 ExpressionException (cbit.vcell.parser.ExpressionException)20 Vector (java.util.Vector)20 ArrayList (java.util.ArrayList)19 SpeciesContext (cbit.vcell.model.SpeciesContext)18 ModelParameter (cbit.vcell.model.Model.ModelParameter)14 PropertyVetoException (java.beans.PropertyVetoException)14 VCUnitDefinition (cbit.vcell.units.VCUnitDefinition)13 Model (cbit.vcell.model.Model)12 KineticsParameter (cbit.vcell.model.Kinetics.KineticsParameter)11 HashMap (java.util.HashMap)11 SimulationContext (cbit.vcell.mapping.SimulationContext)10 Variable (cbit.vcell.math.Variable)10 LocalParameter (cbit.vcell.mapping.ParameterContext.LocalParameter)9 SpeciesContextSpec (cbit.vcell.mapping.SpeciesContextSpec)9 Parameter (cbit.vcell.model.Parameter)9 SingleXPlot2D (cbit.plot.SingleXPlot2D)8 MathException (cbit.vcell.math.MathException)8 ReservedVariable (cbit.vcell.math.ReservedVariable)8