Search in sources :

Example 11 with MemVariable

use of cbit.vcell.math.MemVariable in project vcell by virtualcell.

the class MathOverridesPanel method jMenuItemPaste_ActionPerformed.

/**
 * Comment
 */
private void jMenuItemPaste_ActionPerformed(java.awt.event.ActionEvent actionEvent) {
    java.util.Vector<String> pasteDescriptionsV = new java.util.Vector<String>();
    java.util.Vector<Expression> newConstantsV = new java.util.Vector<Expression>();
    java.util.Vector<String> changedParameterNamesV = new java.util.Vector<String>();
    try {
        if (actionEvent.getSource().equals(getJMenuItemPaste()) || actionEvent.getSource().equals(getJMenuItemPasteAll())) {
            int[] rows = null;
            if (actionEvent.getSource() == getJMenuItemPasteAll()) {
                rows = new int[getJTableFixed().getRowCount()];
                for (int i = 0; i < rows.length; i += 1) {
                    rows[i] = i;
                }
            } else {
                rows = getJTableFixed().getSelectedRows();
            }
            Object pasteThis = VCellTransferable.getFromClipboard(VCellTransferable.OBJECT_FLAVOR);
            for (int i = 0; i < rows.length; i += 1) {
                if (pasteThis instanceof VCellTransferable.ResolvedValuesSelection) {
                    VCellTransferable.ResolvedValuesSelection rvs = (VCellTransferable.ResolvedValuesSelection) pasteThis;
                    for (int j = 0; j < rvs.getPrimarySymbolTableEntries().length; j += 1) {
                        Constant pastedConstant = null;
                        if (rvs.getPrimarySymbolTableEntries()[j] instanceof Constant) {
                            pastedConstant = (Constant) rvs.getPrimarySymbolTableEntries()[j];
                        } else if (rvs.getAlternateSymbolTableEntries() != null && rvs.getAlternateSymbolTableEntries()[j] instanceof Constant) {
                            pastedConstant = (Constant) rvs.getAlternateSymbolTableEntries()[j];
                        }
                        // 
                        if (pastedConstant == null && (rvs.getPrimarySymbolTableEntries()[j] instanceof Function) || (rvs.getPrimarySymbolTableEntries()[j] instanceof VolVariable) || (rvs.getPrimarySymbolTableEntries()[j] instanceof VolumeRegionVariable) || (rvs.getPrimarySymbolTableEntries()[j] instanceof MemVariable) || (rvs.getPrimarySymbolTableEntries()[j] instanceof MembraneRegionVariable)) {
                            MathDescription mathDescription = getMathOverrides().getSimulation().getMathDescription();
                            Enumeration<Constant> constants = mathDescription.getConstants();
                            while (constants.hasMoreElements()) {
                                Constant constant = constants.nextElement();
                                if (constant.getName().startsWith(rvs.getPrimarySymbolTableEntries()[j].getName() + DiffEquMathMapping.MATH_FUNC_SUFFIX_SPECIES_INIT_CONC_UNIT_PREFIX)) {
                                    pastedConstant = new Constant(constant.getName(), rvs.getExpressionValues()[j]);
                                }
                            }
                        }
                        // 
                        // find row of math overrides table with the same name as the pastedConstant and propose to change that override to the pasted value
                        // 
                        String rowName = (String) getJTableFixed().getValueAt(rows[i], MathOverridesTableModel.COLUMN_PARAMETER);
                        if (pastedConstant != null && pastedConstant.getName().equals(rowName)) {
                            changedParameterNamesV.add(rowName);
                            newConstantsV.add(rvs.getExpressionValues()[j]);
                            String originalValueDescription = null;
                            if (getMathOverrides().getConstantArraySpec(rowName) != null) {
                                originalValueDescription = getMathOverrides().getConstantArraySpec(rowName).toString();
                            } else if (getMathOverrides().getActualExpression(rowName, 0) != null) {
                                originalValueDescription = getMathOverrides().getActualExpression(rowName, 0).infix();
                            } else {
                                throw new Exception("MathOverridesPanel can't find value for '" + rowName + "'");
                            }
                            pasteDescriptionsV.add(VCellCopyPasteHelper.formatPasteList(rowName, pastedConstant.getName(), originalValueDescription, rvs.getExpressionValues()[j].infix() + ""));
                        }
                    }
                }
            }
        }
    } catch (Throwable e) {
        PopupGenerator.showErrorDialog(this, "Paste failed during pre-check (no changes made).\n" + e.getClass().getName() + " " + e.getMessage(), e);
        return;
    }
    // Do paste
    try {
        if (pasteDescriptionsV.size() > 0) {
            String[] pasteDescriptionArr = new String[pasteDescriptionsV.size()];
            pasteDescriptionsV.copyInto(pasteDescriptionArr);
            String[] changedParameterNamesArr = new String[changedParameterNamesV.size()];
            changedParameterNamesV.copyInto(changedParameterNamesArr);
            VCellCopyPasteHelper.chooseApplyPaste(this, pasteDescriptionArr, getMathOverrides(), changedParameterNamesArr, newConstantsV);
        } else {
            PopupGenerator.showInfoDialog(this, "No paste items match the destination (no changes made).");
        }
    } catch (Throwable e) {
        PopupGenerator.showErrorDialog(this, "Paste Error\n" + e.getClass().getName() + " " + e.getMessage(), e);
    }
}
Also used : MembraneRegionVariable(cbit.vcell.math.MembraneRegionVariable) VolVariable(cbit.vcell.math.VolVariable) MathDescription(cbit.vcell.math.MathDescription) Constant(cbit.vcell.math.Constant) VCellTransferable(cbit.vcell.desktop.VCellTransferable) VolumeRegionVariable(cbit.vcell.math.VolumeRegionVariable) Function(cbit.vcell.math.Function) MemVariable(cbit.vcell.math.MemVariable) ScopedExpression(cbit.gui.ScopedExpression) Expression(cbit.vcell.parser.Expression)

Example 12 with MemVariable

use of cbit.vcell.math.MemVariable in project vcell by virtualcell.

the class FastSystemAnalyzer method refreshFastVarList.

/**
 * @return java.util.Vector
 */
private void refreshFastVarList() throws MathException, ExpressionException {
    fastVarList.clear();
    // 
    // get list of unique (VolVariables and MemVariables) in fastRate expressions
    // 
    Enumeration<FastRate> fastRatesEnum = fastSystem.getFastRates();
    while (fastRatesEnum.hasMoreElements()) {
        FastRate fr = fastRatesEnum.nextElement();
        Expression exp = fr.getFunction();
        Enumeration<Variable> enum1 = MathUtilities.getRequiredVariables(exp, this);
        while (enum1.hasMoreElements()) {
            Variable var = enum1.nextElement();
            if (var instanceof VolVariable || var instanceof MemVariable) {
                if (!fastVarList.contains(var)) {
                    fastVarList.addElement(var);
                // System.out.println("FastSystemImplicit.refreshFastVarList(), FAST RATE VARIABLE: "+var.getName());
                }
            }
        }
    }
    // 
    // get list of all variables used in invariant expressions that are not used in fast rates
    // 
    Enumeration<FastInvariant> fastInvariantsEnum = fastSystem.getFastInvariants();
    while (fastInvariantsEnum.hasMoreElements()) {
        FastInvariant fi = (FastInvariant) fastInvariantsEnum.nextElement();
        Expression exp = fi.getFunction();
        // System.out.println("FastSystemImplicit.refreshFastVarList(), ORIGINAL FAST INVARIANT: "+exp);
        Enumeration<Variable> enum1 = MathUtilities.getRequiredVariables(exp, this);
        while (enum1.hasMoreElements()) {
            Variable var = enum1.nextElement();
            if (var instanceof VolVariable || var instanceof MemVariable) {
                if (!fastVarList.contains(var)) {
                    fastVarList.addElement(var);
                }
            }
        }
    }
    // 
    // verify that there are N equations (rates+invariants) and N unknowns (fastVariables)
    // 
    int numBoundFunctions = fastSystem.getNumFastInvariants() + fastSystem.getNumFastRates();
    if (fastVarList.size() != numBoundFunctions) {
        throw new MathException("FastSystem.checkDimension(), there are " + fastVarList.size() + " variables and " + numBoundFunctions + " FastInvariant's & FastRates");
    }
}
Also used : ReservedVariable(cbit.vcell.math.ReservedVariable) Variable(cbit.vcell.math.Variable) VolVariable(cbit.vcell.math.VolVariable) MemVariable(cbit.vcell.math.MemVariable) MemVariable(cbit.vcell.math.MemVariable) Expression(cbit.vcell.parser.Expression) VolVariable(cbit.vcell.math.VolVariable) MathException(cbit.vcell.math.MathException) FastRate(cbit.vcell.math.FastRate) FastInvariant(cbit.vcell.math.FastInvariant)

Example 13 with MemVariable

use of cbit.vcell.math.MemVariable in project vcell by virtualcell.

the class MathMapping_4_8 method refreshVariables.

/**
 * This method was created in VisualAge.
 */
private void refreshVariables() throws MappingException {
    // System.out.println("MathMapping.refreshVariables()");
    // 
    // non-constant dependent variables require a function
    // 
    Enumeration<SpeciesContextMapping> enum1 = getSpeciesContextMappings();
    while (enum1.hasMoreElements()) {
        SpeciesContextMapping scm = enum1.nextElement();
        SpeciesContextSpec scs = simContext.getReactionContext().getSpeciesContextSpec(scm.getSpeciesContext());
        if (scm.getDependencyExpression() != null && !scs.isConstant()) {
            // scm.setVariable(new Function(scm.getSpeciesContext().getName(),scm.getDependencyExpression()));
            scm.setVariable(null);
        }
    }
    enum1 = getSpeciesContextMappings();
    while (enum1.hasMoreElements()) {
        SpeciesContextMapping scm = enum1.nextElement();
        SpeciesContextSpec scs = simContext.getReactionContext().getSpeciesContextSpec(scm.getSpeciesContext());
        if (getSimulationContext().hasEventAssignment(scs.getSpeciesContext())) {
            scm.setDependencyExpression(null);
        }
    }
    // 
    // non-constant independent variables require either a membrane or volume variable
    // 
    enum1 = getSpeciesContextMappings();
    while (enum1.hasMoreElements()) {
        SpeciesContextMapping scm = (SpeciesContextMapping) enum1.nextElement();
        SpeciesContextSpec scs = simContext.getReactionContext().getSpeciesContextSpec(scm.getSpeciesContext());
        if (scm.getDependencyExpression() == null && (!scs.isConstant() || getSimulationContext().hasEventAssignment(scs.getSpeciesContext()))) {
            StructureMapping sm = simContext.getGeometryContext().getStructureMapping(scm.getSpeciesContext().getStructure());
            Structure struct = scm.getSpeciesContext().getStructure();
            if (struct instanceof Feature) {
                if (getResolved(sm)) {
                    scm.setVariable(getResolvedVolVariable(scm.getSpeciesContext().getSpecies()));
                } else {
                    scm.setVariable(new VolVariable(scm.getSpeciesContext().getName(), nullDomain));
                }
            } else if (struct instanceof Membrane) {
                if (getResolved(sm)) {
                    scm.setVariable(new MemVariable(scm.getSpeciesContext().getName(), nullDomain));
                } else {
                    scm.setVariable(new VolVariable(scm.getSpeciesContext().getName(), nullDomain));
                }
            } else {
                throw new MappingException("class " + scm.getSpeciesContext().getStructure().getClass() + " not supported");
            }
            mathSymbolMapping.put(scm.getSpeciesContext(), scm.getVariable().getName());
        }
    }
}
Also used : MemVariable(cbit.vcell.math.MemVariable) SpeciesContextMapping(cbit.vcell.mapping.SpeciesContextMapping) VolVariable(cbit.vcell.math.VolVariable) Membrane(cbit.vcell.model.Membrane) SpeciesContextSpec(cbit.vcell.mapping.SpeciesContextSpec) Structure(cbit.vcell.model.Structure) StructureMapping(cbit.vcell.mapping.StructureMapping) Feature(cbit.vcell.model.Feature) MappingException(cbit.vcell.mapping.MappingException)

Example 14 with MemVariable

use of cbit.vcell.math.MemVariable in project vcell by virtualcell.

the class XmlReader method getMemVariable.

/**
 * This method returns a MemVariable object from a XML element.
 * Creation date: (5/16/2001 3:17:18 PM)
 * @return cbit.vcell.math.MemVariable
 * @param param org.jdom.Element
 */
private MemVariable getMemVariable(Element param) {
    String name = unMangle(param.getAttributeValue(XMLTags.NameAttrTag));
    String domainStr = unMangle(param.getAttributeValue(XMLTags.DomainAttrTag));
    Domain domain = null;
    if (domainStr != null) {
        domain = new Domain(domainStr);
    }
    // Create new memVariable
    MemVariable memVariable = new MemVariable(name, domain);
    transcribeComments(param, memVariable);
    return memVariable;
}
Also used : MemVariable(cbit.vcell.math.MemVariable) MembraneSubDomain(cbit.vcell.math.MembraneSubDomain) CompartmentSubDomain(cbit.vcell.math.CompartmentSubDomain) FilamentSubDomain(cbit.vcell.math.FilamentSubDomain) PointSubDomain(cbit.vcell.math.PointSubDomain) Domain(cbit.vcell.math.Variable.Domain)

Example 15 with MemVariable

use of cbit.vcell.math.MemVariable in project vcell by virtualcell.

the class XmlReader method getComputeNormal.

private ComputeNormalComponentEquation getComputeNormal(Element param, MathDescription mathDesc) throws XmlParseException {
    // get attributes
    String varname = unMangle(param.getAttributeValue(XMLTags.NameAttrTag));
    // find reference in the dictionnary
    // try a MembraneRegionVariable
    MemVariable varref = (MemVariable) mathDesc.getVariable(varname);
    if (varref == null) {
        throw new XmlParseException("The reference to the Membrane variable " + varname + " could not be resolved!");
    }
    NormalComponent normalComponent = null;
    String normalComponentString = param.getAttributeValue(XMLTags.ComputeNormalComponentAttrTag);
    if (normalComponentString.equals(XMLTags.ComputeNormalComponentAttrTagValue_X)) {
        normalComponent = NormalComponent.X;
    } else if (normalComponentString.equals(XMLTags.ComputeNormalComponentAttrTagValue_Y)) {
        normalComponent = NormalComponent.Y;
    } else if (normalComponentString.equals(XMLTags.ComputeNormalComponentAttrTagValue_Z)) {
        normalComponent = NormalComponent.Z;
    }
    ComputeNormalComponentEquation computeNormal = new ComputeNormalComponentEquation(varref, normalComponent);
    return computeNormal;
}
Also used : NormalComponent(cbit.vcell.math.ComputeNormalComponentEquation.NormalComponent) MemVariable(cbit.vcell.math.MemVariable) ComputeNormalComponentEquation(cbit.vcell.math.ComputeNormalComponentEquation)

Aggregations

MemVariable (cbit.vcell.math.MemVariable)21 VolVariable (cbit.vcell.math.VolVariable)19 Variable (cbit.vcell.math.Variable)15 MembraneRegionVariable (cbit.vcell.math.MembraneRegionVariable)14 VolumeRegionVariable (cbit.vcell.math.VolumeRegionVariable)13 MembraneSubDomain (cbit.vcell.math.MembraneSubDomain)10 ReservedVariable (cbit.vcell.math.ReservedVariable)10 Expression (cbit.vcell.parser.Expression)10 CompartmentSubDomain (cbit.vcell.math.CompartmentSubDomain)9 FilamentVariable (cbit.vcell.math.FilamentVariable)9 FilamentRegionVariable (cbit.vcell.math.FilamentRegionVariable)8 MathDescription (cbit.vcell.math.MathDescription)8 Constant (cbit.vcell.math.Constant)7 InsideVariable (cbit.vcell.math.InsideVariable)7 OutsideVariable (cbit.vcell.math.OutsideVariable)7 SubDomain (cbit.vcell.math.SubDomain)7 MathException (cbit.vcell.math.MathException)6 SubVolume (cbit.vcell.geometry.SubVolume)4 Equation (cbit.vcell.math.Equation)4 FastInvariant (cbit.vcell.math.FastInvariant)4