Search in sources :

Example 1 with Domain

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

the class XmlReader method getVolumeParticleSpeciesPattern.

private VolumeParticleSpeciesPattern getVolumeParticleSpeciesPattern(Element param, MathDescription mathdes) throws XmlParseException {
    String name = unMangle(param.getAttributeValue(XMLTags.NameAttrTag));
    String domainStr = unMangle(param.getAttributeValue(XMLTags.DomainAttrTag));
    Domain domain = null;
    if (domainStr != null) {
        domain = new Domain(domainStr);
    }
    String location = unMangle(param.getAttributeValue(XMLTags.LocationAttrTag));
    VolumeParticleSpeciesPattern var = new VolumeParticleSpeciesPattern(name, domain, location);
    List<Element> molecularTypeList = param.getChildren(XMLTags.ParticleMolecularTypePatternTag, vcNamespace);
    for (Element molecularType : molecularTypeList) {
        ParticleMolecularTypePattern p = getParticleMolecularTypePattern(molecularType, mathdes);
        var.addMolecularTypePattern(p);
    }
    // for (Element levelElement : levelElementList) {
    return var;
}
Also used : Element(org.jdom.Element) VolumeParticleSpeciesPattern(cbit.vcell.math.VolumeParticleSpeciesPattern) 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) ParticleMolecularTypePattern(cbit.vcell.math.ParticleMolecularTypePattern)

Example 2 with Domain

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

the class XmlReader method readParameters.

private void readParameters(List<Element> parameterElements, ParameterContext parameterContext, HashMap<String, ParameterRoleEnum> roleHash, ParameterRoleEnum userDefinedRole, HashSet<String> xmlRolesTagsToIgnore, Model model) throws XmlParseException {
    String contextName = parameterContext.getNameScope().getName();
    try {
        // 
        // prepopulate varHash with reserved symbols
        // 
        VariableHash varHash = new VariableHash();
        addResevedSymbols(varHash, model);
        // 
        for (Element xmlParam : parameterElements) {
            String parsedParamName = unMangle(xmlParam.getAttributeValue(XMLTags.NameAttrTag));
            String parsedRoleString = xmlParam.getAttributeValue(XMLTags.ParamRoleAttrTag);
            String parsedExpressionString = xmlParam.getText();
            // 
            if (xmlRolesTagsToIgnore.contains(parsedRoleString)) {
                varHash.removeVariable(parsedParamName);
                continue;
            }
            Expression paramExp = null;
            if (parsedExpressionString.trim().length() > 0) {
                paramExp = unMangleExpression(parsedExpressionString);
            }
            if (varHash.getVariable(parsedParamName) == null) {
                Domain domain = null;
                varHash.addVariable(new Function(parsedParamName, paramExp, domain));
            } else {
                if (model.getReservedSymbolByName(parsedParamName) != null) {
                    varHash.removeVariable(parsedParamName);
                    Domain domain = null;
                    varHash.addVariable(new Function(parsedParamName, paramExp, domain));
                }
            }
            // 
            // get the parameter for this xml role string
            // 
            ParameterRoleEnum paramRole = roleHash.get(parsedRoleString);
            if (paramRole == null) {
                throw new XmlParseException("parameter '" + parsedParamName + "' has unexpected role '" + parsedRoleString + "' in '" + contextName + "'");
            }
            // 
            if (paramRole != userDefinedRole) {
                LocalParameter paramWithSameRole = parameterContext.getLocalParameterFromRole(paramRole);
                if (paramWithSameRole == null) {
                    throw new XmlParseException("can't find parameter with role '" + parsedRoleString + "' in '" + contextName + "'");
                }
                // 
                if (!paramWithSameRole.getName().equals(parsedParamName)) {
                    // 
                    // first rename other parameters with same name
                    // 
                    LocalParameter paramWithSameNameButDifferentRole = parameterContext.getLocalParameterFromName(parsedParamName);
                    if (paramWithSameNameButDifferentRole != null) {
                        // 
                        // find available name
                        // 
                        int n = 0;
                        String newName = parsedParamName + "_" + n++;
                        while (parameterContext.getEntry(newName) != null) {
                            newName = parsedParamName + "_" + n++;
                        }
                        parameterContext.renameLocalParameter(parsedParamName, newName);
                    }
                    // 
                    // then rename parameter with correct role
                    // 
                    parameterContext.renameLocalParameter(paramWithSameRole.getName(), parsedParamName);
                }
            }
        }
        // 
        // 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());
            }
            parameterContext.addUnresolvedParameter(unresolvedSymbol);
            unresolvedSymbol = varHash.getFirstUnresolvedSymbol();
        }
        // 
        // in topological order, add parameters to model (getting units also).
        // note that all pre-defined parameters already have the correct names
        // here we set expressions on pre-defined parameters and add user-defined parameters
        // 
        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 < parameterElements.size(); j++) {
                    Element tempParam = (Element) parameterElements.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 = parameterContext.getLocalParameterFromName(paramFunction.getName());
                if (tempParam == null) {
                    tempParam = parameterContext.addLocalParameter(paramFunction.getName(), new Expression(0.0), userDefinedRole, unit, userDefinedRole.getDescription());
                    parameterContext.setParameterValue(tempParam, paramFunction.getExpression(), true);
                } else {
                    if (tempParam.getExpression() != null) {
                        // if the expression is null, it should remain null.
                        parameterContext.setParameterValue(tempParam, paramFunction.getExpression(), true);
                    }
                    tempParam.setUnitDefinition(unit);
                }
            }
        }
    } catch (PropertyVetoException | ExpressionException | MathException e) {
        e.printStackTrace(System.out);
        throw new XmlParseException("Exception while setting parameters for '" + contextName + "': " + e.getMessage(), e);
    }
}
Also used : 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) ExpressionException(cbit.vcell.parser.ExpressionException) LocalParameter(cbit.vcell.mapping.ParameterContext.LocalParameter) PropertyVetoException(java.beans.PropertyVetoException) AnnotatedFunction(cbit.vcell.solver.AnnotatedFunction) Function(cbit.vcell.math.Function) VCUnitDefinition(cbit.vcell.units.VCUnitDefinition) Expression(cbit.vcell.parser.Expression) MathException(cbit.vcell.math.MathException) 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) ParameterRoleEnum(cbit.vcell.mapping.ParameterContext.ParameterRoleEnum) ModelUnitSystem(cbit.vcell.model.ModelUnitSystem)

Example 3 with Domain

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

the class XmlReader method getVolumeRegionVariable.

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

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

the class XmlReader method getVolumeParticleObservable.

private VolumeParticleObservable getVolumeParticleObservable(Element param, VariableHash varHash) throws XmlParseException {
    String name = unMangle(param.getAttributeValue(XMLTags.NameAttrTag));
    String domainStr = unMangle(param.getAttributeValue(XMLTags.DomainAttrTag));
    Domain domain = null;
    if (domainStr != null) {
        domain = new Domain(domainStr);
    }
    String molecularTypeString = unMangle(param.getAttributeValue(XMLTags.ParticleMolecularTypePatternTag));
    ObservableType observableType = ObservableType.fromString(molecularTypeString);
    VolumeParticleObservable var = new VolumeParticleObservable(name, domain, observableType);
    String sequenceAttr = param.getAttributeValue(XMLTags.ParticleObservableSequenceTypeAttrTag);
    if (sequenceAttr != null) {
        Sequence sequence = Sequence.fromString(sequenceAttr);
        String sequenceLength = param.getAttributeValue(XMLTags.ParticleObservableSequenceLengthAttrTag);
        var.setSequence(sequence);
        if (sequence != Sequence.Multimolecular) {
            var.setQuantity(Integer.parseInt(sequenceLength));
        }
    } else {
        var.setSequence(Sequence.Multimolecular);
    }
    Element volumeParticleSpeciesPatternsElement = param.getChild(XMLTags.VolumeParticleSpeciesPatternsTag, vcNamespace);
    List<Element> volumeParticleSpeciesPatternList = volumeParticleSpeciesPatternsElement.getChildren(XMLTags.VolumeParticleSpeciesPatternTag, vcNamespace);
    for (Element volumeParticleSpeciesPattern : volumeParticleSpeciesPatternList) {
        String volumeParticleSpeciesPatternName = unMangle(volumeParticleSpeciesPattern.getAttributeValue(XMLTags.NameAttrTag));
        Variable v = varHash.getVariable(volumeParticleSpeciesPatternName);
        if (v == null) {
            throw new XmlParseException("failed to find VolumeParticleSpeciesPattern named " + volumeParticleSpeciesPatternName);
        }
        if (v instanceof ParticleSpeciesPattern) {
            var.addParticleSpeciesPattern((ParticleSpeciesPattern) v);
        } else {
            throw new XmlParseException("Variable " + volumeParticleSpeciesPatternName + " is not a ParticleSpeciesPattern");
        }
    }
    return var;
}
Also used : 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) ObservableType(cbit.vcell.math.ParticleObservable.ObservableType) Element(org.jdom.Element) ParticleSpeciesPattern(cbit.vcell.math.ParticleSpeciesPattern) VolumeParticleSpeciesPattern(cbit.vcell.math.VolumeParticleSpeciesPattern) Sequence(cbit.vcell.math.ParticleObservable.Sequence) 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) VolumeParticleObservable(cbit.vcell.math.VolumeParticleObservable)

Example 5 with Domain

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

the class XmlReader method getVolumeParticalVariable.

private VolumeParticleVariable getVolumeParticalVariable(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 VolVariable object
    VolumeParticleVariable var = new VolumeParticleVariable(name, domain);
    transcribeComments(param, var);
    return var;
}
Also used : VolumeParticleVariable(cbit.vcell.math.VolumeParticleVariable) 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