Search in sources :

Example 6 with Domain

use of cbit.vcell.math.Variable.Domain in project vcell by virtualcell.

the class XmlReader method getElectricalStimulus.

/**
 * This method process Electrical Stimulus, also called Clamps.
 * Creation date: (6/6/2002 4:46:18 PM)
 * @return cbit.vcell.mapping.ElectricalStimulus
 * @param param org.jdom.Element
 */
private ElectricalStimulus getElectricalStimulus(Element param, SimulationContext currentSimulationContext) throws XmlParseException {
    ElectricalStimulus clampStimulus = null;
    // get name
    // String name = unMangle( param.getAttributeValue(XMLTags.NameAttrTag) );
    // get Electrode
    Electrode electrode = getElectrode(param.getChild(XMLTags.ElectrodeTag, vcNamespace), currentSimulationContext);
    if (param.getAttributeValue(XMLTags.TypeAttrTag).equalsIgnoreCase(XMLTags.VoltageClampTag)) {
        // is a voltage clamp
        clampStimulus = new VoltageClampStimulus(electrode, "voltClampElectrode", new Expression(0.0), currentSimulationContext);
    } else if (param.getAttributeValue(XMLTags.TypeAttrTag).equalsIgnoreCase(XMLTags.CurrentDensityClampTag) || param.getAttributeValue(XMLTags.TypeAttrTag).equalsIgnoreCase(XMLTags.CurrentDensityClampTag_oldName)) {
        // is a current density clamp
        clampStimulus = new CurrentDensityClampStimulus(electrode, "currDensityClampElectrode", new Expression(0.0), currentSimulationContext);
    } else if (param.getAttributeValue(XMLTags.TypeAttrTag).equalsIgnoreCase(XMLTags.TotalCurrentClampTag)) {
        // is a "total" current clamp
        clampStimulus = new TotalCurrentClampStimulus(electrode, "totalCurrClampElectrode", new Expression(0.0), currentSimulationContext);
    }
    try {
        // transaction begin flag ... yeah, this is a hack
        clampStimulus.reading(true);
        // Read all of the parameters
        List<Element> list = param.getChildren(XMLTags.ParameterTag, vcNamespace);
        // add constants that may be used in the electrical stimulus.
        VariableHash varHash = new VariableHash();
        Model model = currentSimulationContext.getModel();
        addResevedSymbols(varHash, model);
        // 
        for (Element xmlParam : list) {
            String paramName = unMangle(xmlParam.getAttributeValue(XMLTags.NameAttrTag));
            String role = xmlParam.getAttributeValue(XMLTags.ParamRoleAttrTag);
            String paramExpStr = xmlParam.getText();
            Expression paramExp = unMangleExpression(paramExpStr);
            try {
                if (varHash.getVariable(paramName) == null) {
                    Domain domain = null;
                    varHash.addVariable(new Function(paramName, paramExp, domain));
                } else {
                    if (model.getReservedSymbolByName(paramName) != null) {
                        varHash.removeVariable(paramName);
                        Domain domain = null;
                        varHash.addVariable(new Function(paramName, paramExp, domain));
                    }
                }
            } catch (MathException e) {
                e.printStackTrace(System.out);
                throw new XmlParseException("error reordering parameters according to dependencies:", e);
            }
            LocalParameter tempParam = null;
            if (!role.equals(XMLTags.ParamRoleUserDefinedTag)) {
                if (role.equals(XMLTags.ParamRoleTotalCurrentTag)) {
                    if (clampStimulus instanceof TotalCurrentClampStimulus) {
                        tempParam = ((TotalCurrentClampStimulus) clampStimulus).getCurrentParameter();
                    } else {
                        varHash.removeVariable(paramName);
                        continue;
                    }
                } else if (role.equals(XMLTags.ParamRoleTotalCurrentDensityTag) || role.equals(XMLTags.ParamRoleTotalCurrentDensityOldNameTag)) {
                    if (clampStimulus instanceof CurrentDensityClampStimulus) {
                        tempParam = ((CurrentDensityClampStimulus) clampStimulus).getCurrentDensityParameter();
                    } else {
                        varHash.removeVariable(paramName);
                        continue;
                    }
                } else if (role.equals(XMLTags.ParamRolePotentialDifferenceTag)) {
                    if (clampStimulus instanceof VoltageClampStimulus) {
                        tempParam = ((VoltageClampStimulus) clampStimulus).getVoltageParameter();
                    } else {
                        varHash.removeVariable(paramName);
                        continue;
                    }
                }
            } else {
                continue;
            }
            if (tempParam == null) {
                throw new XmlParseException("parameter with role '" + role + "' not found in electricalstimulus");
            }
            // 
            if (!tempParam.getName().equals(paramName)) {
                LocalParameter multNameParam = clampStimulus.getLocalParameter(paramName);
                int n = 0;
                while (multNameParam != null) {
                    String tempName = paramName + "_" + n++;
                    clampStimulus.renameParameter(paramName, tempName);
                    multNameParam = clampStimulus.getLocalParameter(tempName);
                }
                clampStimulus.renameParameter(tempParam.getName(), paramName);
            }
        }
        // 
        // create unresolved parameters for all unresolved symbols
        // 
        String unresolvedSymbol = varHash.getFirstUnresolvedSymbol();
        while (unresolvedSymbol != null) {
            try {
                Domain domain = null;
                // will turn into an UnresolvedParameter.
                varHash.addVariable(new Function(unresolvedSymbol, new Expression(0.0), domain));
            } catch (MathException e) {
                e.printStackTrace(System.out);
                throw new XmlParseException(e.getMessage());
            }
            clampStimulus.addUnresolvedParameter(unresolvedSymbol);
            unresolvedSymbol = varHash.getFirstUnresolvedSymbol();
        }
        Variable[] sortedVariables = varHash.getTopologicallyReorderedVariables();
        ModelUnitSystem modelUnitSystem = model.getUnitSystem();
        for (int i = sortedVariables.length - 1; i >= 0; i--) {
            if (sortedVariables[i] instanceof Function) {
                Function paramFunction = (Function) sortedVariables[i];
                Element xmlParam = null;
                for (int j = 0; j < list.size(); j++) {
                    Element tempParam = (Element) list.get(j);
                    if (paramFunction.getName().equals(unMangle(tempParam.getAttributeValue(XMLTags.NameAttrTag)))) {
                        xmlParam = tempParam;
                        break;
                    }
                }
                if (xmlParam == null) {
                    // must have been an unresolved parameter
                    continue;
                }
                String symbol = xmlParam.getAttributeValue(XMLTags.VCUnitDefinitionAttrTag);
                VCUnitDefinition unit = null;
                if (symbol != null) {
                    unit = modelUnitSystem.getInstance(symbol);
                }
                LocalParameter tempParam = clampStimulus.getLocalParameter(paramFunction.getName());
                if (tempParam == null) {
                    clampStimulus.addUserDefinedParameter(paramFunction.getName(), paramFunction.getExpression(), unit);
                } else {
                    if (tempParam.getExpression() != null) {
                        // if the expression is null, it should remain null.
                        clampStimulus.setParameterValue(tempParam, paramFunction.getExpression());
                    }
                    tempParam.setUnitDefinition(unit);
                }
            }
        }
    } catch (java.beans.PropertyVetoException e) {
        e.printStackTrace(System.out);
        throw new XmlParseException("Exception while setting parameters for simContext : " + currentSimulationContext.getName(), e);
    } catch (ExpressionException e) {
        e.printStackTrace(System.out);
        throw new XmlParseException("Exception while settings parameters for simContext : " + currentSimulationContext.getName(), e);
    } finally {
        clampStimulus.reading(false);
    }
    return clampStimulus;
}
Also used : Electrode(cbit.vcell.mapping.Electrode) FilamentVariable(cbit.vcell.math.FilamentVariable) OutsideVariable(cbit.vcell.math.OutsideVariable) StochVolVariable(cbit.vcell.math.StochVolVariable) RandomVariable(cbit.vcell.math.RandomVariable) VolumeRandomVariable(cbit.vcell.math.VolumeRandomVariable) VolumeParticleVariable(cbit.vcell.math.VolumeParticleVariable) VolumeRegionVariable(cbit.vcell.math.VolumeRegionVariable) InsideVariable(cbit.vcell.math.InsideVariable) VolVariable(cbit.vcell.math.VolVariable) MembraneRegionVariable(cbit.vcell.math.MembraneRegionVariable) PointVariable(cbit.vcell.math.PointVariable) MembraneRandomVariable(cbit.vcell.math.MembraneRandomVariable) MembraneParticleVariable(cbit.vcell.math.MembraneParticleVariable) ParticleVariable(cbit.vcell.math.ParticleVariable) MemVariable(cbit.vcell.math.MemVariable) FilamentRegionVariable(cbit.vcell.math.FilamentRegionVariable) Variable(cbit.vcell.math.Variable) VariableHash(cbit.vcell.math.VariableHash) Element(org.jdom.Element) CurrentDensityClampStimulus(cbit.vcell.mapping.CurrentDensityClampStimulus) TotalCurrentClampStimulus(cbit.vcell.mapping.TotalCurrentClampStimulus) ExpressionException(cbit.vcell.parser.ExpressionException) LocalParameter(cbit.vcell.mapping.ParameterContext.LocalParameter) PropertyVetoException(java.beans.PropertyVetoException) ElectricalStimulus(cbit.vcell.mapping.ElectricalStimulus) AnnotatedFunction(cbit.vcell.solver.AnnotatedFunction) Function(cbit.vcell.math.Function) VCUnitDefinition(cbit.vcell.units.VCUnitDefinition) Expression(cbit.vcell.parser.Expression) VoltageClampStimulus(cbit.vcell.mapping.VoltageClampStimulus) MathException(cbit.vcell.math.MathException) MathModel(cbit.vcell.mathmodel.MathModel) Model(cbit.vcell.model.Model) PathwayModel(org.vcell.pathway.PathwayModel) RelationshipModel(org.vcell.relationship.RelationshipModel) BioModel(cbit.vcell.biomodel.BioModel) 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) ModelUnitSystem(cbit.vcell.model.ModelUnitSystem)

Example 7 with Domain

use of cbit.vcell.math.Variable.Domain in project vcell by virtualcell.

the class XmlReader method getFilamentVariable.

/**
 * This method returns a FilamentVariable object from a XML Element.
 * Creation date: (5/16/2001 2:56:34 PM)
 * @return cbit.vcell.math.FilamentVariable
 * @param param org.jdom.Element
 */
private FilamentVariable getFilamentVariable(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 filVariable object
    FilamentVariable filVariable = new FilamentVariable(name, domain);
    transcribeComments(param, filVariable);
    return filVariable;
}
Also used : FilamentVariable(cbit.vcell.math.FilamentVariable) 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 8 with Domain

use of cbit.vcell.math.Variable.Domain in project vcell by virtualcell.

the class XmlReader method getProjectionDataGenerator.

private ProjectionDataGenerator getProjectionDataGenerator(Element element) {
    String name = unMangle(element.getAttributeValue(XMLTags.NameAttrTag));
    String domainStr = unMangle(element.getAttributeValue(XMLTags.DomainAttrTag));
    Domain domain = null;
    if (domainStr != null) {
        domain = new Domain(domainStr);
    }
    Element e = element.getChild(XMLTags.ProjectionAxis, vcNamespace);
    String axis = e.getText();
    // ProjectionDataGenerator.Axis axis = ProjectionDataGenerator.Axis.valueOf(s);
    e = element.getChild(XMLTags.ProjectionOperation, vcNamespace);
    String operation = e.getText();
    // ProjectionDataGenerator.Operation operation = ProjectionDataGenerator.Operation.valueOf(s);
    e = element.getChild(XMLTags.FunctionTag, vcNamespace);
    String s = e.getText();
    Expression exp = unMangleExpression(s);
    ProjectionDataGenerator projectionDataGenerator = new ProjectionDataGenerator(name, domain, axis, operation, exp);
    return projectionDataGenerator;
}
Also used : Expression(cbit.vcell.parser.Expression) Element(org.jdom.Element) ProjectionDataGenerator(cbit.vcell.math.ProjectionDataGenerator) 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 9 with Domain

use of cbit.vcell.math.Variable.Domain in project vcell by virtualcell.

the class XmlReader method getExplicitDataGenerator.

private ExplicitDataGenerator getExplicitDataGenerator(Element element) {
    String name = unMangle(element.getAttributeValue(XMLTags.NameAttrTag));
    String domainStr = unMangle(element.getAttributeValue(XMLTags.DomainAttrTag));
    Domain domain = null;
    if (domainStr != null) {
        domain = new Domain(domainStr);
    }
    String temp = element.getText();
    Expression exp = unMangleExpression(temp);
    ExplicitDataGenerator explicitDataGenerator = new ExplicitDataGenerator(name, domain, exp);
    return explicitDataGenerator;
}
Also used : Expression(cbit.vcell.parser.Expression) ExplicitDataGenerator(cbit.vcell.math.ExplicitDataGenerator) 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 10 with Domain

use of cbit.vcell.math.Variable.Domain in project vcell by virtualcell.

the class XmlReader method getFunction.

/**
 * This method returns a Function variable object from a XML Element.
 * Creation date: (5/16/2001 3:45:21 PM)
 * @return cbit.vcell.math.Function
 * @param param org.jdom.Element
 * @exception cbit.vcell.xml.XmlParseException The exception description.
 */
private Function getFunction(Element param) throws XmlParseException {
    // get attributes
    String name = unMangle(param.getAttributeValue(XMLTags.NameAttrTag));
    /**
     * ---------------------------------------------------------------
     * ATTENTATION: this is a quick fix for a specific user to load his model
     * with a function name as "ATP/ADP".  This syntax is not allowed.
     *-----------------------------------------------------------------------
     */
    if (name.equals("ATP/ADP")) {
        name = "ATP_ADP_renamed";
        System.err.print("Applying species function name change ATP/ADP to ATP_ADP for a specific user (key=2288008)");
        Thread.dumpStack();
    }
    String domainStr = unMangle(param.getAttributeValue(XMLTags.DomainAttrTag));
    Domain domain = null;
    if (domainStr != null) {
        domain = new Domain(domainStr);
    }
    String temp = param.getText();
    Expression exp = unMangleExpression(temp);
    // -- create new Function --
    Function function = new Function(name, exp, domain);
    transcribeComments(param, function);
    return function;
}
Also used : AnnotatedFunction(cbit.vcell.solver.AnnotatedFunction) Function(cbit.vcell.math.Function) Expression(cbit.vcell.parser.Expression) 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)

Aggregations

Domain (cbit.vcell.math.Variable.Domain)54 CompartmentSubDomain (cbit.vcell.math.CompartmentSubDomain)35 Expression (cbit.vcell.parser.Expression)34 MembraneSubDomain (cbit.vcell.math.MembraneSubDomain)28 PointSubDomain (cbit.vcell.math.PointSubDomain)22 FilamentSubDomain (cbit.vcell.math.FilamentSubDomain)19 VolVariable (cbit.vcell.math.VolVariable)15 ExpressionException (cbit.vcell.parser.ExpressionException)14 Function (cbit.vcell.math.Function)13 SubDomain (cbit.vcell.math.SubDomain)13 Variable (cbit.vcell.math.Variable)13 AnnotatedFunction (cbit.vcell.solver.AnnotatedFunction)10 Element (org.jdom.Element)10 Constant (cbit.vcell.math.Constant)9 MemVariable (cbit.vcell.math.MemVariable)9 VariableHash (cbit.vcell.math.VariableHash)9 VariableType (cbit.vcell.math.VariableType)9 VolumeRegionVariable (cbit.vcell.math.VolumeRegionVariable)8 GeometryClass (cbit.vcell.geometry.GeometryClass)7 SubVolume (cbit.vcell.geometry.SubVolume)7