Search in sources :

Example 1 with CompartmentSubVolume

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

the class FeatureMapping method getNormalizedConcentrationCorrection.

/**
 * TotalConservationCorrection is the term that takes local units (micro-molar) to either volume normalized micro-molar or area normalized molecules/sq-um
 * @return cbit.vcell.parser.Expression
 */
public Expression getNormalizedConcentrationCorrection(SimulationContext simulationContext, UnitFactorProvider unitFactorProvider) throws ExpressionException, MappingException {
    if (getGeometryClass() instanceof CompartmentSubVolume) {
        if (simulationContext.getGeometryContext().isAllSizeSpecifiedPositive()) {
            // 
            // everything mapped to micro-molar : just need size
            // 
            Expression exp = new Expression(getSizeParameter(), simulationContext.getNameScope());
            return exp;
        } else {
            throw new MappingException("\nIn non-spatial application '" + simulationContext.getName() + "', " + "size of structure '" + getStructure().getName() + "' must be assigned a " + "positive value if referenced in the model.\n\nPlease go to 'Structure Mapping' tab to check the size.");
        }
    } else if (getGeometryClass() instanceof SubVolume) {
        // 
        // everything mapped to micro-molar : just need volume fraction
        // 
        Expression exp = new Expression(getVolumePerUnitVolumeParameter(), simulationContext.getNameScope());
        return exp;
    } else if (getGeometryClass() instanceof SurfaceClass) {
        // 
        // everything mapped to molecules/sq-um : need volume/area fraction and KMOLE
        // 
        Expression unitFactor = unitFactorProvider.getUnitFactor(modelUnitSystem.getMembraneSubstanceUnit().divideBy(modelUnitSystem.getVolumeSubstanceUnit()));
        Expression exp = Expression.mult(new Expression(getVolumePerUnitAreaParameter(), simulationContext.getNameScope()), unitFactor);
        return exp;
    } else {
        throw new RuntimeException("structure " + getStructure().getName() + " not mapped");
    }
}
Also used : CompartmentSubVolume(cbit.vcell.geometry.CompartmentSubVolume) Expression(cbit.vcell.parser.Expression) SurfaceClass(cbit.vcell.geometry.SurfaceClass) SubVolume(cbit.vcell.geometry.SubVolume) CompartmentSubVolume(cbit.vcell.geometry.CompartmentSubVolume)

Example 2 with CompartmentSubVolume

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

the class MembraneMapping method getNormalizedConcentrationCorrection.

/**
 * This method was created in VisualAge.
 * @return cbit.vcell.parser.Expression
 */
@Override
public Expression getNormalizedConcentrationCorrection(SimulationContext simulationContext, UnitFactorProvider unitFactorProvider) throws ExpressionException, MappingException {
    Expression exp = getSizeCorrection(simulationContext);
    if (getGeometryClass() instanceof CompartmentSubVolume || getGeometryClass() instanceof SubVolume) {
        Expression unitFactor = unitFactorProvider.getUnitFactor(modelUnitSystem.getVolumeSubstanceUnit().divideBy(modelUnitSystem.getMembraneSubstanceUnit()));
        exp = Expression.mult(exp, unitFactor);
    }
    return exp;
}
Also used : CompartmentSubVolume(cbit.vcell.geometry.CompartmentSubVolume) Expression(cbit.vcell.parser.Expression) SubVolume(cbit.vcell.geometry.SubVolume) CompartmentSubVolume(cbit.vcell.geometry.CompartmentSubVolume)

Example 3 with CompartmentSubVolume

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

the class AbstractMathMapping method getFluxCorrectionParameter.

/**
 * This method was created in VisualAge.
 * @return Expression
 */
public KFluxParameter getFluxCorrectionParameter(StructureMapping sourceStructureMapping, StructureMapping targetStructureMapping) throws MappingException, ExpressionException {
    for (int i = 0; i < fieldMathMappingParameters.length; i++) {
        if (fieldMathMappingParameters[i] instanceof KFluxParameter) {
            KFluxParameter kfluxParameter = (KFluxParameter) fieldMathMappingParameters[i];
            if (kfluxParameter.getSourceStructureMapping() == sourceStructureMapping && kfluxParameter.getTargetStructureMapping() == targetStructureMapping) {
                return kfluxParameter;
            }
        }
    }
    // 
    // not found, add new parameter
    // 
    String sourceName = sourceStructureMapping.getStructure().getNameScope().getName();
    String targetName = targetStructureMapping.getStructure().getNameScope().getName();
    Parameter sourceSizeParameter = null;
    Parameter targetSizeParameter = null;
    if (sourceStructureMapping.getGeometryClass() instanceof CompartmentSubVolume) {
        sourceSizeParameter = sourceStructureMapping.getSizeParameter();
    } else {
        sourceSizeParameter = sourceStructureMapping.getUnitSizeParameter();
    }
    if (targetStructureMapping.getGeometryClass() instanceof CompartmentSubVolume) {
        targetSizeParameter = targetStructureMapping.getSizeParameter();
        if (targetSizeParameter == null || targetSizeParameter.getExpression() == null) {
            throw new MappingException("structure mapping sizes not set for application " + simContext.getName());
        }
    } else {
        targetSizeParameter = targetStructureMapping.getUnitSizeParameter();
    }
    Expression fluxCorrectionExp = Expression.div(new Expression(sourceSizeParameter, simContext.getNameScope()), new Expression(targetSizeParameter, simContext.getNameScope()));
    VCUnitDefinition sourceSizeUnit = sourceSizeParameter.getUnitDefinition();
    VCUnitDefinition targetSizeUnit = targetSizeParameter.getUnitDefinition();
    VCUnitDefinition unit = sourceSizeUnit.divideBy(targetSizeUnit);
    fluxCorrectionExp.bindExpression(this);
    String parameterName = PARAMETER_K_FLUX_PREFIX + sourceName + "_" + targetName;
    KFluxParameter kFluxParameter = new KFluxParameter(parameterName, fluxCorrectionExp, unit, sourceStructureMapping, targetStructureMapping);
    MathMappingParameter[] newMathMappingParameters = (MathMappingParameter[]) BeanUtils.addElement(this.fieldMathMappingParameters, kFluxParameter);
    try {
        setMathMapppingParameters(newMathMappingParameters);
    } catch (java.beans.PropertyVetoException e) {
        e.printStackTrace(System.out);
        throw new RuntimeException(e.getMessage());
    }
    return kFluxParameter;
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) VCUnitDefinition(cbit.vcell.units.VCUnitDefinition) CompartmentSubVolume(cbit.vcell.geometry.CompartmentSubVolume) Expression(cbit.vcell.parser.Expression) ProxyParameter(cbit.vcell.model.ProxyParameter) Parameter(cbit.vcell.model.Parameter) KineticsParameter(cbit.vcell.model.Kinetics.KineticsParameter) LocalParameter(cbit.vcell.mapping.ParameterContext.LocalParameter) ModelParameter(cbit.vcell.model.Model.ModelParameter)

Example 4 with CompartmentSubVolume

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

the class GeometryContext method refreshStructureMappings.

/**
 * This method was created by a SmartGuide.
 * @throws ExpressionBindingException
 */
public void refreshStructureMappings() throws MappingException, PropertyVetoException {
    // 
    // step through all structure mappings
    // 
    StructureMapping[] newStructureMappings = (StructureMapping[]) fieldStructureMappings.clone();
    // fill in geometryClass for those MembraneMappings that were not mapped explicitly (and topology is available)
    for (int j = 0; j < newStructureMappings.length; j++) {
        StructureMapping structureMapping = newStructureMappings[j];
        if (structureMapping instanceof MembraneMapping && structureMapping.getGeometryClass() == null) {
            MembraneMapping membraneMapping = (MembraneMapping) structureMapping;
            Feature insideFeature = getModel().getStructureTopology().getInsideFeature(membraneMapping.getMembrane());
            Feature outsideFeature = getModel().getStructureTopology().getOutsideFeature(membraneMapping.getMembrane());
            if (insideFeature != null && outsideFeature != null) {
                FeatureMapping insideFeatureMapping = (FeatureMapping) getStructureMapping(insideFeature);
                FeatureMapping outsideFeatureMapping = (FeatureMapping) getStructureMapping(outsideFeature);
                if (insideFeatureMapping.getGeometryClass() == outsideFeatureMapping.getGeometryClass()) {
                    membraneMapping.setGeometryClass(insideFeatureMapping.getGeometryClass());
                } else if (insideFeatureMapping.getGeometryClass() instanceof SubVolume && outsideFeatureMapping.getGeometryClass() instanceof SubVolume) {
                    SubVolume insideSubVolume = (SubVolume) insideFeatureMapping.getGeometryClass();
                    SubVolume outsideSubVolume = (SubVolume) outsideFeatureMapping.getGeometryClass();
                    SurfaceClass surfaceClass = getGeometry().getGeometrySurfaceDescription().getSurfaceClass(insideSubVolume, outsideSubVolume);
                    if (surfaceClass != null) {
                        membraneMapping.setGeometryClass(surfaceClass);
                    }
                }
            }
        }
    }
    for (int j = 0; j < newStructureMappings.length; j++) {
        StructureMapping structureMapping = newStructureMappings[j];
        Structure mappedStructure = structureMapping.getStructure();
        // SubVolume mappedSubvolume = structureMapping.getSubVolume();
        Structure newStructure = null;
        GeometryClass newGeometryClass = null;
        boolean structureFound = false;
        boolean geometryClassFound = false;
        // 
        // match up with structures defined within model
        // 
        Structure[] modelStructures = getModel().getStructures();
        for (int i = 0; i < modelStructures.length; i++) {
            Structure modelStructure = modelStructures[i];
            if (modelStructure.compareEqual(mappedStructure)) {
                structureFound = true;
                newStructure = modelStructure;
                break;
            }
        }
        // 
        // match up with geometryClasses defined within geometry
        // 
        GeometryClass[] geometryClasses = getGeometry().getGeometryClasses();
        for (int i = 0; i < geometryClasses.length; i++) {
            if (geometryClasses[i].compareEqual(structureMapping.getGeometryClass())) {
                geometryClassFound = true;
                newGeometryClass = geometryClasses[i];
                break;
            }
        }
        // 
        if (!(structureFound && geometryClassFound)) {
            newStructureMappings = (StructureMapping[]) BeanUtils.removeElement(newStructureMappings, structureMapping);
            j--;
        // //
        // // delete accompanied membrane mapping if exists
        // //
        // for (int i = 0; i < newStructureMappings.length; i++){
        // if (newStructureMappings[i] instanceof MembraneMapping){
        // MembraneMapping membraneMapping = (MembraneMapping)newStructureMappings[i];
        // if (membraneMapping.getMembrane()==null ||
        // membraneMapping.getMembrane().getInsideFeature() == structureMapping.getStructure() ||
        // membraneMapping.getMembrane().getOutsideFeature() == structureMapping.getStructure()){
        // newStructureMappings = (StructureMapping[])BeanUtils.removeElement(newStructureMappings,membraneMapping);
        // break;
        // }
        // }
        // }
        } else {
            // update references to Structure and SubVolume to correspond to those of Model and Geometry
            structureMapping.setGeometryClass(newGeometryClass);
        }
        if (structureFound) {
            structureMapping.setStructure(newStructure);
        }
    }
    // 
    // add default mappings for any new structures
    // 
    Structure[] structures = getModel().getStructures();
    for (int i = 0; i < structures.length; i++) {
        Structure structure = structures[i];
        StructureMapping sm = null;
        for (int j = 0; j < newStructureMappings.length; j++) {
            if (newStructureMappings[j].getStructure().compareEqual(structure)) {
                sm = newStructureMappings[j];
            }
        }
        if (sm == null) {
            if (structure instanceof Feature) {
                FeatureMapping fm = new FeatureMapping((Feature) structure, fieldSimulationContext, getModel().getUnitSystem());
                fm.setSimulationContext(this.fieldSimulationContext);
                newStructureMappings = (StructureMapping[]) BeanUtils.addElement(newStructureMappings, fm);
                if (getGeometry().getDimension() == 0) {
                    fm.setGeometryClass((CompartmentSubVolume) getGeometry().getGeometrySpec().getSubVolumes()[0]);
                }
            } else if (structure instanceof Membrane) {
                MembraneMapping mm = new MembraneMapping((Membrane) structure, fieldSimulationContext, getModel().getUnitSystem());
                mm.setSimulationContext(fieldSimulationContext);
                newStructureMappings = (StructureMapping[]) BeanUtils.addElement(newStructureMappings, mm);
                if (getGeometry().getDimension() == 0) {
                    mm.setGeometryClass((CompartmentSubVolume) getGeometry().getGeometrySpec().getSubVolumes()[0]);
                }
            } else {
                throw new MappingException("unsupported Structure Mapping for structure " + structure.getClass().toString());
            }
        }
    }
    if (newStructureMappings != fieldStructureMappings) {
        try {
            setStructureMappings(newStructureMappings);
        } catch (Exception e) {
            e.printStackTrace(System.out);
            throw new MappingException(e.getMessage());
        }
    }
    fixMembraneMappings();
}
Also used : GeometryClass(cbit.vcell.geometry.GeometryClass) SurfaceClass(cbit.vcell.geometry.SurfaceClass) Feature(cbit.vcell.model.Feature) PropertyVetoException(java.beans.PropertyVetoException) ExpressionException(cbit.vcell.parser.ExpressionException) ExpressionBindingException(cbit.vcell.parser.ExpressionBindingException) CompartmentSubVolume(cbit.vcell.geometry.CompartmentSubVolume) SubVolume(cbit.vcell.geometry.SubVolume) CompartmentSubVolume(cbit.vcell.geometry.CompartmentSubVolume) Membrane(cbit.vcell.model.Membrane) Structure(cbit.vcell.model.Structure)

Example 5 with CompartmentSubVolume

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

the class SubVolumeTable method getAnalyticOrCompartmentSubVolume.

/**
 * This method was created in VisualAge.
 * @return Model
 * @param rset ResultSet
 * @param log SessionLog
 */
public SubVolume getAnalyticOrCompartmentSubVolume(KeyValue key, ResultSet rset) throws SQLException, ExpressionException, DataAccessException {
    // KeyValue key = new KeyValue(rset.getBigDecimal(id.toString(),0));
    String svName = rset.getString(name.toString());
    int handleValue = rset.getInt(handle.toString());
    String expString = rset.getString(expression.toString());
    if (rset.wasNull()) {
        return new CompartmentSubVolume(key, handleValue);
    } else {
        try {
            if (expString.startsWith("<") && expString.endsWith(">")) {
                String xmlStr = TokenMangler.getSQLRestoredString(expString);
                XmlReader xmlReader = new XmlReader(true);
                Element csgObjElement = (XmlUtil.stringToXML(xmlStr, null)).getRootElement();
                try {
                    CSGObject csgObject = xmlReader.getCSGObject(csgObjElement, key);
                    return csgObject;
                } catch (Exception e1) {
                    throw new DataAccessException(e1.getMessage(), e1);
                }
            }
            Expression exp = new Expression(expString);
            return new AnalyticSubVolume(key, svName, exp, handleValue);
        } catch (Exception e) {
            throw new DataAccessException(e.getMessage(), e);
        }
    }
}
Also used : CompartmentSubVolume(cbit.vcell.geometry.CompartmentSubVolume) Expression(cbit.vcell.parser.Expression) Element(org.jdom.Element) XmlReader(cbit.vcell.xml.XmlReader) CSGObject(cbit.vcell.geometry.CSGObject) AnalyticSubVolume(cbit.vcell.geometry.AnalyticSubVolume) DataAccessException(org.vcell.util.DataAccessException) ExpressionException(cbit.vcell.parser.ExpressionException) SQLException(java.sql.SQLException) DataAccessException(org.vcell.util.DataAccessException)

Aggregations

CompartmentSubVolume (cbit.vcell.geometry.CompartmentSubVolume)7 Expression (cbit.vcell.parser.Expression)5 SubVolume (cbit.vcell.geometry.SubVolume)3 PropertyVetoException (java.beans.PropertyVetoException)3 SurfaceClass (cbit.vcell.geometry.SurfaceClass)2 ExpressionException (cbit.vcell.parser.ExpressionException)2 AnalyticSubVolume (cbit.vcell.geometry.AnalyticSubVolume)1 CSGObject (cbit.vcell.geometry.CSGObject)1 GeometryClass (cbit.vcell.geometry.GeometryClass)1 MembraneMapping (cbit.vcell.mapping.MembraneMapping)1 LocalParameter (cbit.vcell.mapping.ParameterContext.LocalParameter)1 ReactionSpec (cbit.vcell.mapping.ReactionSpec)1 StructureMappingParameter (cbit.vcell.mapping.StructureMapping.StructureMappingParameter)1 DistributedKinetics (cbit.vcell.model.DistributedKinetics)1 Feature (cbit.vcell.model.Feature)1 KineticsParameter (cbit.vcell.model.Kinetics.KineticsParameter)1 LumpedKinetics (cbit.vcell.model.LumpedKinetics)1 Membrane (cbit.vcell.model.Membrane)1 ModelParameter (cbit.vcell.model.Model.ModelParameter)1 Parameter (cbit.vcell.model.Parameter)1