Search in sources :

Example 6 with GeometryClass

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

the class StructureAnalyzer method refreshTotalDependancies.

/**
 * This method was created by a SmartGuide.
 * @param b cbit.vcell.math.Matrix
 * @param vars java.lang.String[]
 */
private void refreshTotalDependancies() throws Exception {
    // 
    for (int v = 0; v < speciesContextMappings.length; v++) {
        speciesContextMappings[v].setDependencyExpression(null);
    }
    if (totalNullSpaceMatrix == null) {
        // System.out.println("the matrix has full rank, there are no dependencies");
        return;
    }
    if (speciesContextMappings.length != totalNullSpaceMatrix.getNumCols()) {
        throw new Exception("varName array not same dimension as b matrix");
    }
    StructureAnalyzer.Dependency[] dependencies = refreshTotalDependancies(totalNullSpaceMatrix, speciesContextMappings, mathMapping, false);
    VCUnitDefinition totalMassUnit = null;
    boolean bIsSpatial = mathMapping.getSimulationContext().getGeometry().getDimension() > 0;
    ModelUnitSystem modelUnitSystem = mathMapping.getSimulationContext().getModel().getUnitSystem();
    if (this instanceof VolumeStructureAnalyzer) {
        if (!bIsSpatial) {
            // VCUnitDefinition.UNIT_umol_um3_per_L; -> VCell vol substance unit
            totalMassUnit = modelUnitSystem.getVolumeSubstanceUnit();
        } else {
            // VCUnitDefinition.UNIT_uM;
            totalMassUnit = modelUnitSystem.getVolumeConcentrationUnit();
        }
    } else if (this instanceof MembraneStructureAnalyzer) {
        if (!bIsSpatial) {
            // VCUnitDefinition.UNIT_molecules;
            totalMassUnit = modelUnitSystem.getMembraneSubstanceUnit();
        } else {
            // VCUnitDefinition.UNIT_molecules_per_um2;
            totalMassUnit = modelUnitSystem.getMembraneConcentrationUnit();
        }
    }
    for (int i = 0; i < dependencies.length; i++) {
        String constantName = dependencies[i].invariantSymbolName;
        Expression constantExp = dependencies[i].conservedMoietyExpression;
        SpeciesContextMapping firstSCM = dependencies[i].speciesContextMapping;
        Expression exp = dependencies[i].dependencyExpression;
        // 
        // store totalMass parameter (e.g. K_xyz_total = xyz_init + wzy_init)
        // 
        GeometryClass geometryClass = mathMapping.getSimulationContext().getGeometryContext().getStructureMapping(firstSCM.getSpeciesContext().getStructure()).getGeometryClass();
        MathMappingParameter totalMassParameter = mathMapping.addMathMappingParameter(constantName, constantExp.flatten(), DiffEquMathMapping.PARAMETER_ROLE_TOTALMASS, totalMassUnit, geometryClass);
        // 
        // store dependency parameter (e.g. xyz = K_xyz_total - wzy)
        // 
        exp.bindExpression(mathMapping);
        firstSCM.setDependencyExpression(exp);
    }
}
Also used : GeometryClass(cbit.vcell.geometry.GeometryClass) VCUnitDefinition(cbit.vcell.units.VCUnitDefinition) Expression(cbit.vcell.parser.Expression) MathMappingParameter(cbit.vcell.mapping.AbstractMathMapping.MathMappingParameter) ModelUnitSystem(cbit.vcell.model.ModelUnitSystem)

Example 7 with GeometryClass

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

the class StructureMappingCartoon method refreshAll.

@Override
public void refreshAll() {
    {
        if (getGeometryContext() == null || getGeometryContext().getGeometry() == null) {
            return;
        }
        GeometryClass[] geometryClasses = getGeometryContext().getGeometry().getGeometryClasses();
        if (geometryClasses == null) {
            return;
        }
        for (int i = 0; i < geometryClasses.length; i++) {
            Shape testShape = getShapeFromModelObject(geometryClasses[i]);
            if (testShape instanceof GeometryClassLegendShape) {
                geometryClasses[i].removePropertyChangeListener((GeometryClassLegendShape) testShape);
            }
        }
    }
    clearAllShapes();
    if (getSimulationContext() == null) {
        fireGraphChanged(new GraphEvent(this));
        return;
    }
    GeometryContextGeometryShape geometryShape = new GeometryContextGeometryShape(this, getGeometryContext().getGeometry());
    GeometryContextStructureShape structureContainerShape = new GeometryContextStructureShape(this, getGeometryContext().getModel());
    GeometryContextContainerShape containerShape = new GeometryContextContainerShape(this, getGeometryContext(), structureContainerShape, geometryShape);
    addShape(containerShape);
    addShape(geometryShape);
    addShape(structureContainerShape);
    getGeometryContext().removePropertyChangeListener(this);
    getGeometryContext().addPropertyChangeListener(this);
    // create all StructureShapes
    Structure[] structures = getGeometryContext().getModel().getStructures();
    for (int i = 0; i < structures.length; i++) {
        StructureMappingStructureShape smShape = new StructureMappingStructureShape((Structure) structures[i], getGeometryContext().getModel(), this);
        addShape(smShape);
        structureContainerShape.addChildShape(smShape);
        structures[i].removePropertyChangeListener(this);
        structures[i].addPropertyChangeListener(this);
    }
    // create all SubvolumeLegendShapes (for legend)
    GeometryClass[] geometryClasses = getGeometryContext().getGeometry().getGeometryClasses();
    for (int i = 0; i < geometryClasses.length; i++) {
        GeometryClassLegendShape geometryClassLegendShape = new GeometryClassLegendShape(geometryClasses[i], getGeometryContext().getGeometry(), this, 10);
        geometryClasses[i].addPropertyChangeListener(geometryClassLegendShape);
        addShape(geometryClassLegendShape);
        geometryShape.addChildShape(geometryClassLegendShape);
    }
    if ((subVolumeContainerShape == null) || (subVolumeContainerShape.getModelObject() != getGeometryContext().getGeometry())) {
        subVolumeContainerShape = new SubVolumeContainerShape(getGeometryContext().getGeometry(), this);
    }
    subVolumeContainerShape.removeAllChildren();
    subVolumeContainerShape.setBrightImage(getGeometryContext().getGeometry().getGeometrySpec().getThumbnailImage().getCurrentValue());
    addShape(subVolumeContainerShape);
    geometryShape.addChildShape(subVolumeContainerShape);
    StructureMapping[] structureMappings = getGeometryContext().getStructureMappings();
    for (int i = 0; i < structureMappings.length; i++) {
        StructureMapping structureMapping = structureMappings[i];
        structureMapping.removePropertyChangeListener(this);
        structureMapping.addPropertyChangeListener(this);
        if (structureMapping.getGeometryClass() != null) {
            StructureShape sShape = (StructureShape) getShapeFromModelObject(structureMapping.getStructure());
            GeometryClassLegendShape geometryClassLegendShape = (GeometryClassLegendShape) getShapeFromModelObject(structureMapping.getGeometryClass());
            StructureMappingShape smShape = new StructureMappingShape(structureMapping, sShape, geometryClassLegendShape, this);
            addShape(smShape);
            containerShape.addChildShape(smShape);
        }
    }
    // // assign children to shapes according to heirarchy in Model
    // int nullParentCount=0;
    // Collection<Shape> shapes = getShapes();
    // for(Shape shape : shapes) {
    // // for each featureShape, find corresponding featureShape
    // if (shape instanceof StructureShape){
    // StructureShape fs = (FeatureShape)shape;
    // if(!structureContainerShape.contains(fs)) {
    // structureContainerShape.addChildShape(fs);
    // }
    // nullParentCount++;
    // }
    // }
    fireGraphChanged(new GraphEvent(this));
}
Also used : GeometryClass(cbit.vcell.geometry.GeometryClass) Shape(cbit.gui.graph.Shape) StructureMapping(cbit.vcell.mapping.StructureMapping) GraphEvent(cbit.gui.graph.GraphEvent) Structure(cbit.vcell.model.Structure)

Example 8 with GeometryClass

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

the class AbstractMathMapping method getDefaultGeometryClass.

protected GeometryClass getDefaultGeometryClass(Expression expr) throws ExpressionException, MappingException {
    GeometryClass geometryClass = null;
    if (simContext.getGeometry().getDimension() == 0) {
        return null;
    }
    String[] symbols = expr.getSymbols();
    // if expr has no symbols, model param cannot be localized to a domain (its a const).
    if (symbols == null) {
        return null;
    } else {
        Expression modelParamExpr = substituteGlobalParameters(expr);
        symbols = modelParamExpr.getSymbols();
        for (int k = 0; symbols != null && k < symbols.length; k++) {
            Structure symbolStructure = null;
            SymbolTableEntry ste = modelParamExpr.getSymbolBinding(symbols[k]);
            if (ste instanceof SpeciesContext) {
                symbolStructure = ((SpeciesContext) ste).getStructure();
            } else if (ste instanceof StructureSize) {
                symbolStructure = ((StructureSize) ste).getStructure();
            } else if (ste instanceof MembraneVoltage) {
                symbolStructure = ((MembraneVoltage) ste).getMembrane();
            }
            if (symbolStructure != null) {
                StructureMapping sm = simContext.getGeometryContext().getStructureMapping(symbolStructure);
                GeometryClass symbolGeomClass = sm.getGeometryClass();
                if (geometryClass == null) {
                    geometryClass = symbolGeomClass;
                } else {
                    if (geometryClass != symbolGeomClass) {
                        if (geometryClass instanceof SurfaceClass) {
                            if (symbolGeomClass instanceof SurfaceClass) {
                                throw new MappingException("The expression '" + expr.infix() + "' references variables in surface domain '" + geometryClass.getName() + "' & surface domain '" + symbolGeomClass.getName() + "' that cannot be evaluated.");
                            } else if (symbolGeomClass instanceof SubVolume) {
                                // geomClass : surfaceClass; symbolGeomClass : subVol
                                if (!((SurfaceClass) geometryClass).isAdjacentTo((SubVolume) symbolGeomClass)) {
                                    throw new MappingException("The expression '" + expr.infix() + "' references variables in surface domain '" + geometryClass.getName() + "' & volume domain '" + symbolGeomClass.getName() + "' that cannot be evaluated.");
                                }
                            } else {
                                throw new MappingException("unexpected geometry class : " + symbolGeomClass.getClass());
                            }
                        } else if (geometryClass instanceof SubVolume) {
                            // geometryClass is a SubVolume
                            if (symbolGeomClass instanceof SubVolume) {
                                // check if adjacent; if so, choose separating membrane.
                                SurfaceClass surfaceClass = simContext.getGeometry().getGeometrySurfaceDescription().getSurfaceClass((SubVolume) symbolGeomClass, (SubVolume) geometryClass);
                                if (surfaceClass != null) {
                                    geometryClass = surfaceClass;
                                } else {
                                    throw new MappingException("The expression '" + expr.infix() + "' references variables in volume domain '" + geometryClass.getName() + "' & volume domain '" + symbolGeomClass.getName() + "' that cannot be evaluated.");
                                }
                            } else {
                                // geomClass : subVol; symbolGeomClass = surfaceClass
                                SurfaceClass surfaceSymbolGeomClass = (SurfaceClass) symbolGeomClass;
                                if (!surfaceSymbolGeomClass.isAdjacentTo((SubVolume) geometryClass)) {
                                    throw new MappingException("The expression '" + expr.infix() + "' references variables in surface domain '" + surfaceSymbolGeomClass.getName() + "' & volume domain '" + geometryClass.getName() + "' that cannot be evaluated.");
                                } else {
                                    geometryClass = symbolGeomClass;
                                }
                            }
                        } else {
                            throw new MappingException("unexpected geometry class : " + geometryClass.getClass());
                        }
                    }
                }
            }
        }
    }
    return geometryClass;
}
Also used : GeometryClass(cbit.vcell.geometry.GeometryClass) SurfaceClass(cbit.vcell.geometry.SurfaceClass) SpeciesContext(cbit.vcell.model.SpeciesContext) StructureSize(cbit.vcell.model.Structure.StructureSize) SymbolTableEntry(cbit.vcell.parser.SymbolTableEntry) Expression(cbit.vcell.parser.Expression) MembraneVoltage(cbit.vcell.model.Membrane.MembraneVoltage) SubVolume(cbit.vcell.geometry.SubVolume) CompartmentSubVolume(cbit.vcell.geometry.CompartmentSubVolume) Structure(cbit.vcell.model.Structure)

Example 9 with GeometryClass

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

the class AbstractMathMapping method addSpeciesConcentrationParameter.

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

Example 10 with GeometryClass

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

the class AbstractMathMapping method addObservableConcentrationParameter.

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

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