Search in sources :

Example 31 with GeometryClass

use of cbit.vcell.geometry.GeometryClass in project vcell by virtualcell.

the class StructureMapping method setGeometryClass.

public void setGeometryClass(GeometryClass argGeometryClass) throws PropertyVetoException {
    GeometryClass oldValue = this.geometryClass;
    fireVetoableChange("geometryClass", oldValue, argGeometryClass);
    this.geometryClass = argGeometryClass;
    firePropertyChange("geometryClass", oldValue, argGeometryClass);
}
Also used : GeometryClass(cbit.vcell.geometry.GeometryClass)

Example 32 with GeometryClass

use of cbit.vcell.geometry.GeometryClass in project vcell by virtualcell.

the class GeometryContext method gatherIssues.

/**
 * Insert the method's description here.
 * Creation date: (11/1/2005 9:48:55 AM)
 * @param issueList java.util.Vector
 */
public void gatherIssues(IssueContext issueContext, List<Issue> issueList) {
    issueContext = issueContext.newChildContext(ContextType.Geometry, getGeometry());
    GeometrySpec geometrySpec = getGeometry().getGeometrySpec();
    if (geometrySpec != null) {
        geometrySpec.gatherIssues(issueContext, getGeometry(), issueList);
    }
    for (int i = 0; fieldStructureMappings != null && i < fieldStructureMappings.length; i++) {
        fieldStructureMappings[i].gatherIssues(issueContext, issueList);
    }
    for (GeometryClass gc : fieldGeometry.getGeometryClasses()) {
        Structure[] structuresFromGeometryClass = getStructuresFromGeometryClass(gc);
        if (structuresFromGeometryClass == null || structuresFromGeometryClass.length == 0) {
            UnmappedGeometryClass unmappedGeometryClass = new UnmappedGeometryClass(gc);
            Issue issue = new Issue(unmappedGeometryClass, issueContext, IssueCategory.GeometryClassNotMapped, "Subdomain '" + gc.getName() + "' is not mapped to any physiological structure.", Issue.SEVERITY_WARNING);
            issueList.add(issue);
        }
    }
    if (getSimulationContext().isStoch() && getGeometry().getDimension() != 0 && getGeometry().getDimension() != 3) {
        Issue issue = new Issue(this, issueContext, IssueCategory.Smoldyn_Geometry_3DWarning, "VCell spatial stochastic models only support 3D geometry.", Issue.SEVERITY_ERROR);
        issueList.add(issue);
    }
}
Also used : GeometrySpec(cbit.vcell.geometry.GeometrySpec) GeometryClass(cbit.vcell.geometry.GeometryClass) Issue(org.vcell.util.Issue) Structure(cbit.vcell.model.Structure)

Example 33 with GeometryClass

use of cbit.vcell.geometry.GeometryClass in project vcell by virtualcell.

the class ParticleMathMapping method combineHybrid.

private void combineHybrid() throws MappingException, ExpressionException, MatrixException, MathException, ModelException {
    ArrayList<SpeciesContext> continuousSpecies = new ArrayList<SpeciesContext>();
    ArrayList<ParticleVariable> continuousSpeciesParticleVars = new ArrayList<ParticleVariable>();
    ArrayList<SpeciesContext> stochSpecies = new ArrayList<SpeciesContext>();
    // 
    // categorize speciesContexts as continuous and stochastic
    // 
    SpeciesContextSpec[] scsArray = getSimulationContext().getReactionContext().getSpeciesContextSpecs();
    continuousSpecies = new ArrayList<SpeciesContext>();
    stochSpecies = new ArrayList<SpeciesContext>();
    for (SpeciesContextSpec speciesContextSpec : scsArray) {
        if (!getSimulationContext().isStoch() || speciesContextSpec.isForceContinuous()) {
            continuousSpecies.add(speciesContextSpec.getSpeciesContext());
            Variable variable = getMathSymbolMapping().getVariable(speciesContextSpec.getSpeciesContext());
            if (variable instanceof ParticleVariable) {
                continuousSpeciesParticleVars.add((ParticleVariable) variable);
            }
        } else {
            stochSpecies.add(speciesContextSpec.getSpeciesContext());
        }
    }
    if (continuousSpecies.isEmpty()) {
        return;
    }
    // 
    // create continuous mathDescription ... add stochastic variables and processes to the continuous Math and use this.
    // 
    DiffEquMathMapping mathMapping = new DiffEquMathMapping(getSimulationContext(), callback, networkGenerationRequirements);
    mathMapping.refresh(null);
    MathDescription contMathDesc = mathMapping.getMathDescription();
    // 
    // get list of all continuous variables
    // 
    HashMap<String, Variable> allContinuousVars = new HashMap<String, Variable>();
    Enumeration<Variable> enumVar = contMathDesc.getVariables();
    while (enumVar.hasMoreElements()) {
        Variable var = enumVar.nextElement();
        allContinuousVars.put(var.getName(), var);
    }
    // 
    // replace those continuous variables and equations for stochastic speciesContexts
    // with the particleVariables and particleProperties
    // (ParticleJumpProcesses removed later)
    // 
    ModelUnitSystem unitSystem = getSimulationContext().getModel().getUnitSystem();
    for (SpeciesContext stochSpeciesContext : stochSpecies) {
        Variable contVar = mathMapping.getMathSymbolMapping().getVariable(stochSpeciesContext);
        Variable stochVar = getMathSymbolMapping().getVariable(stochSpeciesContext);
        allContinuousVars.put(stochVar.getName(), stochVar);
        // 
        // replace continuous "concentration" VolVariable/MemVariable for this particle with a Function for concentration
        // 
        allContinuousVars.remove(contVar);
        VCUnitDefinition sizeUnit = unitSystem.getLengthUnit().raiseTo(new RationalNumber(stochSpeciesContext.getStructure().getDimension()));
        VCUnitDefinition stochasticDensityUnit = unitSystem.getStochasticSubstanceUnit().divideBy(sizeUnit);
        VCUnitDefinition continuousDensityUnit = unitSystem.getConcentrationUnit(stochSpeciesContext.getStructure());
        if (stochasticDensityUnit.isEquivalent(continuousDensityUnit)) {
            allContinuousVars.put(contVar.getName(), new Function(contVar.getName(), new Expression(stochVar, getNameScope()), contVar.getDomain()));
        } else {
            Expression conversionFactorExp = getUnitFactor(continuousDensityUnit.divideBy(stochasticDensityUnit));
            allContinuousVars.put(contVar.getName(), new Function(contVar.getName(), Expression.mult(new Expression(stochVar, getNameScope()), conversionFactorExp), contVar.getDomain()));
        }
        // 
        // remove continuous equation
        // 
        Enumeration<SubDomain> contSubDomains = contMathDesc.getSubDomains();
        while (contSubDomains.hasMoreElements()) {
            SubDomain contSubDomain = contSubDomains.nextElement();
            contSubDomain.removeEquation(contVar);
            if (contSubDomain instanceof MembraneSubDomain) {
                ((MembraneSubDomain) contSubDomain).removeJumpCondition(contVar);
            }
        }
        // 
        // remove all continuous variables for speciesContextSpec parameters (e.g. initial conditions, diffusion rates, boundary conditions, velocities)
        // 
        SpeciesContextSpec scs = getSimulationContext().getReactionContext().getSpeciesContextSpec(stochSpeciesContext);
        Parameter[] scsParameters = scs.getParameters();
        for (Parameter parameter : scsParameters) {
            Variable continuousScsParmVariable = mathMapping.getMathSymbolMapping().getVariable(parameter);
            allContinuousVars.remove(continuousScsParmVariable);
        }
        // 
        // copy ParticleJumpProcess and ParticleProperties to the continuous math
        // 
        SubDomain contSubDomain = contMathDesc.getSubDomain(contVar.getDomain().getName());
        SubDomain stochSubDomain = mathDesc.getSubDomain(stochVar.getDomain().getName());
        ParticleProperties particleProperties = stochSubDomain.getParticleProperties(stochVar);
        contSubDomain.addParticleProperties(particleProperties);
    }
    // 
    // add all ParticleJumpProcesses to the continuous model
    // 
    Enumeration<SubDomain> enumStochSubdomains = mathDesc.getSubDomains();
    while (enumStochSubdomains.hasMoreElements()) {
        SubDomain stochSubdomain = enumStochSubdomains.nextElement();
        SubDomain contSubdomain = contMathDesc.getSubDomain(stochSubdomain.getName());
        for (ParticleJumpProcess particleJumpProcess : stochSubdomain.getParticleJumpProcesses()) {
            // 
            // modify "selection list" (particleVariables), probability rate, and actions if referenced particleVariable is to be "forced continuous"
            // 
            ParticleVariable[] selectedParticles = particleJumpProcess.getParticleVariables();
            for (ParticleVariable particleVariable : selectedParticles) {
                if (continuousSpeciesParticleVars.contains(particleVariable)) {
                    particleJumpProcess.remove(particleVariable);
                    JumpProcessRateDefinition jumpProcessRateDefinition = particleJumpProcess.getParticleRateDefinition();
                    if (jumpProcessRateDefinition instanceof MacroscopicRateConstant) {
                        MacroscopicRateConstant macroscopicRateConstant = (MacroscopicRateConstant) jumpProcessRateDefinition;
                        macroscopicRateConstant.setExpression(Expression.mult(macroscopicRateConstant.getExpression(), new Expression(particleVariable, null)));
                    } else if (jumpProcessRateDefinition instanceof InteractionRadius) {
                        throw new MappingException("cannot adjust interaction radius for reaction process " + particleJumpProcess.getName() + ", particle " + particleVariable.getName() + " is continuous");
                    } else {
                        throw new MappingException("rate definition type " + jumpProcessRateDefinition.getClass().getSimpleName() + " not yet implemented for hybrid PDE/Particle math generation");
                    }
                }
                Iterator<Action> iterAction = particleJumpProcess.getActions().iterator();
                while (iterAction.hasNext()) {
                    Action action = iterAction.next();
                    if (continuousSpeciesParticleVars.contains(action.getVar())) {
                        iterAction.remove();
                    }
                }
            }
            if (!particleJumpProcess.getActions().isEmpty()) {
                contSubdomain.addParticleJumpProcess(particleJumpProcess);
            }
        }
    }
    // 
    for (MathMappingParameter mathMappingParameter : fieldMathMappingParameters) {
        if (mathMappingParameter instanceof UnitFactorParameter) {
            String name = mathMappingParameter.getName();
            if (!allContinuousVars.containsKey(name)) {
                allContinuousVars.put(name, newFunctionOrConstant(name, mathMappingParameter.getExpression(), null));
            }
        }
    }
    // 
    // add constants and functions from the particle math that aren't already defined in the continuous math
    // 
    Enumeration<Variable> enumVars = mathDesc.getVariables();
    while (enumVars.hasMoreElements()) {
        Variable var = enumVars.nextElement();
        if (var instanceof Constant || var instanceof Function) {
            String name = var.getName();
            if (!allContinuousVars.containsKey(name)) {
                allContinuousVars.put(name, var);
            }
        }
    }
    contMathDesc.setAllVariables(allContinuousVars.values().toArray(new Variable[0]));
    mathDesc = contMathDesc;
    // 
    for (int i = 0; i < fieldMathMappingParameters.length; i++) {
        if (fieldMathMappingParameters[i] instanceof UnitFactorParameter) {
            GeometryClass geometryClass = fieldMathMappingParameters[i].getGeometryClass();
            Variable variable = newFunctionOrConstant(getMathSymbol(fieldMathMappingParameters[i], geometryClass), getIdentifierSubstitutions(fieldMathMappingParameters[i].getExpression(), fieldMathMappingParameters[i].getUnitDefinition(), geometryClass), fieldMathMappingParameters[i].getGeometryClass());
            if (mathDesc.getVariable(variable.getName()) == null) {
                mathDesc.addVariable(variable);
            }
        }
    }
    if (!mathDesc.isValid()) {
        System.out.println(mathDesc.getVCML_database());
        throw new MappingException("generated an invalid mathDescription: " + mathDesc.getWarning());
    }
    System.out.println("]]]]]]]]]]]]]]]]]]]]]] VCML string begin ]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]");
    System.out.println(mathDesc.getVCML());
    System.out.println("]]]]]]]]]]]]]]]]]]]]]] VCML string end ]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]");
}
Also used : GeometryClass(cbit.vcell.geometry.GeometryClass) MembraneSubDomain(cbit.vcell.math.MembraneSubDomain) Action(cbit.vcell.math.Action) VolumeParticleVariable(cbit.vcell.math.VolumeParticleVariable) MembraneParticleVariable(cbit.vcell.math.MembraneParticleVariable) ParticleVariable(cbit.vcell.math.ParticleVariable) Variable(cbit.vcell.math.Variable) MathDescription(cbit.vcell.math.MathDescription) HashMap(java.util.HashMap) VolumeParticleVariable(cbit.vcell.math.VolumeParticleVariable) MembraneParticleVariable(cbit.vcell.math.MembraneParticleVariable) ParticleVariable(cbit.vcell.math.ParticleVariable) MacroscopicRateConstant(cbit.vcell.math.MacroscopicRateConstant) Constant(cbit.vcell.math.Constant) ArrayList(java.util.ArrayList) SpeciesContext(cbit.vcell.model.SpeciesContext) CompartmentSubDomain(cbit.vcell.math.CompartmentSubDomain) SubDomain(cbit.vcell.math.SubDomain) MembraneSubDomain(cbit.vcell.math.MembraneSubDomain) Function(cbit.vcell.math.Function) MacroscopicRateConstant(cbit.vcell.math.MacroscopicRateConstant) RationalNumber(ucar.units_vcell.RationalNumber) ModelUnitSystem(cbit.vcell.model.ModelUnitSystem) JumpProcessRateDefinition(cbit.vcell.math.JumpProcessRateDefinition) InteractionRadius(cbit.vcell.math.InteractionRadius) ParticleJumpProcess(cbit.vcell.math.ParticleJumpProcess) VCUnitDefinition(cbit.vcell.units.VCUnitDefinition) Expression(cbit.vcell.parser.Expression) StructureMappingParameter(cbit.vcell.mapping.StructureMapping.StructureMappingParameter) Parameter(cbit.vcell.model.Parameter) KineticsParameter(cbit.vcell.model.Kinetics.KineticsParameter) SpeciesContextSpecProxyParameter(cbit.vcell.mapping.SpeciesContextSpec.SpeciesContextSpecProxyParameter) ModelParameter(cbit.vcell.model.Model.ModelParameter) SpeciesContextSpecParameter(cbit.vcell.mapping.SpeciesContextSpec.SpeciesContextSpecParameter) ParticleProperties(cbit.vcell.math.ParticleProperties)

Example 34 with GeometryClass

use of cbit.vcell.geometry.GeometryClass in project vcell by virtualcell.

the class AbstractMathMapping method addSpeciesCountParameter.

protected final SpeciesCountParameter addSpeciesCountParameter(String name, Expression expr, int role, VCUnitDefinition unitDefn, SpeciesContext argSpeciesContext) throws PropertyVetoException {
    GeometryClass geometryClass = simContext.getGeometryContext().getStructureMapping(argSpeciesContext.getStructure()).getGeometryClass();
    SpeciesCountParameter newParameter = new SpeciesCountParameter(name, expr, role, unitDefn, argSpeciesContext, geometryClass);
    MathMappingParameter previousParameter = getMathMappingParameter(name);
    if (previousParameter != null) {
        System.out.println("MathMappingParameter addCountParameter found duplicate parameter for name " + name);
        if (!previousParameter.compareEqual(newParameter)) {
            throw new RuntimeException("MathMappingParameter addCountParameter found duplicate parameter for name '" + name + "'.");
        }
        return (SpeciesCountParameter) previousParameter;
    }
    // expression.bindExpression(this);
    MathMappingParameter[] newParameters = (MathMappingParameter[]) BeanUtils.addElement(fieldMathMappingParameters, newParameter);
    setMathMapppingParameters(newParameters);
    return newParameter;
}
Also used : GeometryClass(cbit.vcell.geometry.GeometryClass)

Example 35 with GeometryClass

use of cbit.vcell.geometry.GeometryClass in project vcell by virtualcell.

the class XmlReader method getFeatureMapping.

/**
 * This method retuns a FeatureMapping object from a XML representation.
 * Creation date: (5/7/2001 4:12:03 PM)
 * @return cbit.vcell.mapping.FeatureMapping
 * @param param org.jdom.Element
 */
private FeatureMapping getFeatureMapping(Element param, SimulationContext simulationContext) throws XmlParseException {
    // Retrieve attributes
    String featurename = unMangle(param.getAttributeValue(XMLTags.FeatureAttrTag));
    String geometryClassName = param.getAttributeValue(XMLTags.SubVolumeAttrTag);
    if (geometryClassName != null) {
        geometryClassName = unMangle(geometryClassName);
    } else {
        geometryClassName = param.getAttributeValue(XMLTags.GeometryClassAttrTag);
        if (geometryClassName != null) {
            geometryClassName = unMangle(geometryClassName);
        }
    }
    Feature featureref = (Feature) simulationContext.getModel().getStructure(featurename);
    if (featureref == null) {
        throw new XmlParseException("The Feature " + featurename + " could not be resolved!");
    }
    // *** Create new Feature Mapping ****
    FeatureMapping feamap = new FeatureMapping(featureref, simulationContext, simulationContext.getModel().getUnitSystem());
    // Set Size
    if (param.getAttributeValue(XMLTags.SizeTag) != null) {
        String size = unMangle(param.getAttributeValue(XMLTags.SizeTag));
        try {
            feamap.getSizeParameter().setExpression(unMangleExpression(size));
        } catch (ExpressionException e) {
            e.printStackTrace(System.out);
            throw new XmlParseException("An expressionException was fired when setting the size Expression " + size + " to a featureMapping!", e);
        }
    } else {
        try {
            feamap.getSizeParameter().setExpression(null);
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException("unexpected exception while setting structure size: " + e.getMessage());
        }
    }
    // Set Volume/unit_area if it exists
    if (param.getAttributeValue(XMLTags.VolumePerUnitAreaTag) != null) {
        String volPerUnitArea = unMangle(param.getAttributeValue(XMLTags.VolumePerUnitAreaTag));
        try {
            feamap.getVolumePerUnitAreaParameter().setExpression(unMangleExpression(volPerUnitArea));
        } catch (ExpressionException e) {
            e.printStackTrace(System.out);
            throw new XmlParseException("An expressionException was fired when setting the VolumePerUnitArea Expression " + volPerUnitArea + " to a featureMapping!", e);
        }
    }
    // Set Volume/unitVol if it exists
    if (param.getAttributeValue(XMLTags.VolumePerUnitVolumeTag) != null) {
        String volPerUnitVol = unMangle(param.getAttributeValue(XMLTags.VolumePerUnitVolumeTag));
        try {
            feamap.getVolumePerUnitVolumeParameter().setExpression(unMangleExpression(volPerUnitVol));
        } catch (ExpressionException e) {
            e.printStackTrace(System.out);
            throw new XmlParseException("An expressionException was fired when setting the size Expression " + volPerUnitVol + " to a featureMapping!", e);
        }
    }
    if (geometryClassName != null) {
        GeometryClass[] geometryClasses = simulationContext.getGeometry().getGeometryClasses();
        for (int i = 0; i < geometryClasses.length; i++) {
            if (geometryClasses[i].getName().equals(geometryClassName)) {
                try {
                    feamap.setGeometryClass(geometryClasses[i]);
                } catch (PropertyVetoException e) {
                    e.printStackTrace(System.out);
                    throw new XmlParseException("A propertyVetoException was fired when trying to set the subvolume or surface " + geometryClassName + " to a MembraneMapping!", e);
                }
            }
        }
    }
    // Set Boundary conditions
    Element tempElement = param.getChild(XMLTags.BoundariesTypesTag, vcNamespace);
    // Xm
    String temp = tempElement.getAttributeValue(XMLTags.BoundaryAttrValueXm);
    BoundaryConditionType bct = new BoundaryConditionType(temp);
    feamap.setBoundaryConditionTypeXm(bct);
    // Xp
    temp = tempElement.getAttributeValue(XMLTags.BoundaryAttrValueXp);
    bct = new BoundaryConditionType(temp);
    feamap.setBoundaryConditionTypeXp(bct);
    // Ym
    temp = tempElement.getAttributeValue(XMLTags.BoundaryAttrValueYm);
    bct = new BoundaryConditionType(temp);
    feamap.setBoundaryConditionTypeYm(bct);
    // Yp
    temp = tempElement.getAttributeValue(XMLTags.BoundaryAttrValueYp);
    bct = new BoundaryConditionType(temp);
    feamap.setBoundaryConditionTypeYp(bct);
    // Zm
    temp = tempElement.getAttributeValue(XMLTags.BoundaryAttrValueZm);
    bct = new BoundaryConditionType(temp);
    feamap.setBoundaryConditionTypeZm(bct);
    // Zp
    temp = tempElement.getAttributeValue(XMLTags.BoundaryAttrValueZp);
    bct = new BoundaryConditionType(temp);
    feamap.setBoundaryConditionTypeZp(bct);
    return feamap;
}
Also used : GeometryClass(cbit.vcell.geometry.GeometryClass) Element(org.jdom.Element) BoundaryConditionType(cbit.vcell.math.BoundaryConditionType) Feature(cbit.vcell.model.Feature) ExpressionException(cbit.vcell.parser.ExpressionException) GeometryException(cbit.vcell.geometry.GeometryException) MathFormatException(cbit.vcell.math.MathFormatException) MappingException(cbit.vcell.mapping.MappingException) PropertyVetoException(java.beans.PropertyVetoException) ImageException(cbit.image.ImageException) ExpressionBindingException(cbit.vcell.parser.ExpressionBindingException) ModelException(cbit.vcell.model.ModelException) DataConversionException(org.jdom.DataConversionException) ExpressionException(cbit.vcell.parser.ExpressionException) MathException(cbit.vcell.math.MathException) PropertyVetoException(java.beans.PropertyVetoException) FeatureMapping(cbit.vcell.mapping.FeatureMapping)

Aggregations

GeometryClass (cbit.vcell.geometry.GeometryClass)43 SubVolume (cbit.vcell.geometry.SubVolume)21 SurfaceClass (cbit.vcell.geometry.SurfaceClass)19 Expression (cbit.vcell.parser.Expression)18 ExpressionException (cbit.vcell.parser.ExpressionException)14 PropertyVetoException (java.beans.PropertyVetoException)13 Structure (cbit.vcell.model.Structure)12 StructureMapping (cbit.vcell.mapping.StructureMapping)8 MathDescription (cbit.vcell.math.MathDescription)7 MathException (cbit.vcell.math.MathException)7 Variable (cbit.vcell.math.Variable)7 SpeciesContext (cbit.vcell.model.SpeciesContext)7 ExpressionBindingException (cbit.vcell.parser.ExpressionBindingException)7 VCUnitDefinition (cbit.vcell.units.VCUnitDefinition)7 MappingException (cbit.vcell.mapping.MappingException)6 Domain (cbit.vcell.math.Variable.Domain)6 ModelException (cbit.vcell.model.ModelException)6 Parameter (cbit.vcell.model.Parameter)6 ArrayList (java.util.ArrayList)6 Geometry (cbit.vcell.geometry.Geometry)5